* { box-sizing: border-box; }
/* Ensure the `hidden` attribute wins over `.state.*` display rules below */
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  background: #0a0a18;
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 14px 24px;
  background: linear-gradient(135deg, #16213e, #1a1a2e);
  border-bottom: 1px solid rgba(79, 143, 247, 0.3);
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.topbar .brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.topbar .brand img { width: 28px; height: 28px; }
.topbar .brand span { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: 0.2px; }
.topbar .crumbs { color: #93c5fd; font-size: 13px; border-left: 1px solid #334; padding-left: 18px; }
.topbar .sub { margin-left: auto; color: #6b7a99; font-size: 11px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  padding: 22px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}
@media (min-width: 960px) {
  .layout { grid-template-columns: 380px 1fr; }
}

/* When a result is showing, hide the upload controls and give the full canvas
   to the image (zoomable) + parsed entries side-by-side. */
body.results-mode .layout { grid-template-columns: 1fr; max-width: 1600px; }
body.results-mode .left { display: none; }

.left { display: flex; flex-direction: column; gap: 18px; }

.step {
  background: #12122a;
  border: 1px solid #1e2442;
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.step-head {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; font-weight: 600; color: #93c5fd;
  text-transform: uppercase; letter-spacing: 0.8px;
}
.step-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: #4f8ff7; color: #fff; font-size: 12px; font-weight: 700;
}

.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  background: #1a1a2e; border: 1px solid #263150;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.chip input { display: none; }
.chip .chip-label { font-size: 13px; font-weight: 600; color: #e0e0e0; }
.chip .chip-desc { font-size: 11px; color: #6b7a99; }
.chip:hover { border-color: rgba(79, 143, 247, 0.5); }
.chip.active { border-color: #4f8ff7; background: rgba(79, 143, 247, 0.12); }
.chip.active .chip-label { color: #fff; }

.dropzone {
  border: 2px dashed rgba(79, 143, 247, 0.4);
  border-radius: 12px;
  padding: 42px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  background: rgba(79, 143, 247, 0.04);
  color: #93c5fd;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  outline: none;
}
.dropzone:hover, .dropzone.over, .dropzone:focus-visible {
  border-color: #4f8ff7;
  background: rgba(79, 143, 247, 0.10);
  color: #fff;
}
.dropzone.has-file { border-color: #4ade80; color: #4ade80; background: rgba(74, 222, 128, 0.05); }
.dz-icon { opacity: 0.7; }
.dz-title { margin: 0; font-size: 14px; color: #e0e0e0; }
.dz-title strong { color: #fff; }
.dz-title u { color: #4f8ff7; text-decoration-thickness: 2px; }
.dz-sub { margin: 0; font-size: 12px; color: #6b7a99; }
.dz-sub kbd {
  padding: 1px 6px; border-radius: 4px; background: #1a1a2e; border: 1px solid #334;
  font-size: 11px; color: #93c5fd; font-family: ui-monospace, monospace;
}

.sample {
  background: transparent; border: 1px solid #334; color: #93c5fd;
  padding: 8px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
  align-self: center;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.sample:hover:not(:disabled) { border-color: #4f8ff7; color: #fff; }
.sample:disabled { opacity: 0.5; cursor: default; }

.preview-wrap {
  background: #12122a; border: 1px solid #1e2442; border-radius: 10px;
  overflow: hidden;
}
.preview-head {
  padding: 8px 12px; display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid #1e2442; font-size: 11px; color: #6b7a99;
  word-break: break-all;
}
.clear {
  background: transparent; border: 0; color: #f88; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 0 6px;
}
.preview-wrap img { width: 100%; max-height: 260px; object-fit: contain; display: block; background: #050510; }

.go {
  padding: 14px 18px; border: 0; border-radius: 10px;
  background: linear-gradient(135deg, #22d3ee, #a855f7);
  color: #fff; font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.go:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
.go:disabled { background: #263150; color: #6b7a99; cursor: not-allowed; }

/* RIGHT panel */
.right {
  background: #12122a;
  border: 1px solid #1e2442;
  border-radius: 12px;
  padding: 24px;
  min-height: 480px;
  display: flex;
  flex-direction: column;
}

.state { flex: 1; }
.state .muted { color: #6b7a99; font-size: 13px; margin: 0; }

.state.idle {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 14px; padding: 60px 20px;
}
.idle-title { font-size: 18px; color: #fff; margin: 0; font-weight: 600; }

.state.loading { text-align: center; padding: 70px 20px; }
.spinner {
  width: 56px; height: 56px;
  border: 4px solid rgba(79, 143, 247, 0.15);
  border-top-color: #4f8ff7; border-right-color: #a855f7;
  border-radius: 50%; animation: spin 1s linear infinite;
  margin: 0 auto 24px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ld-title { font-size: 18px; color: #fff; margin: 0 0 4px; font-weight: 600; }
.bar {
  width: 80%; max-width: 420px; height: 4px; background: #1a1a2e;
  border-radius: 4px; margin: 20px auto 10px; overflow: hidden;
}
.bar-fill {
  height: 100%; width: 0%; border-radius: 4px;
  background: linear-gradient(90deg, #22d3ee, #a855f7);
  transition: width 0.25s ease;
}
.ld-sub { font-size: 12px; color: #93c5fd; margin: 6px 0 0; font-style: italic; }

.state.error {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 14px; padding: 60px 20px;
}
.err-title { font-size: 18px; color: #f88; margin: 0; font-weight: 600; }

.again {
  background: transparent; border: 1px solid #4f8ff7; color: #4f8ff7;
  padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.again:hover { background: #4f8ff7; color: #fff; }

/* Result panel */
.state.result { display: flex; flex-direction: column; gap: 16px; }
.result-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
}
.summary { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 5px 12px; background: #1a1a2e;
  border: 1px solid rgba(79, 143, 247, 0.3); border-radius: 999px;
  color: #93c5fd; font-size: 12px; font-weight: 600;
}
.pill-ok { border-color: #4ade80; color: #4ade80; }

.result-body {
  display: grid; grid-template-columns: 1fr; gap: 16px;
}
@media (min-width: 1000px) {
  .result-body { grid-template-columns: minmax(380px, 52%) 1fr; }
}
/* On focused results-mode (upload hidden), give the image more room. */
@media (min-width: 1200px) {
  body.results-mode .result-body { grid-template-columns: minmax(520px, 58%) 1fr; }
}
.result-img {
  background: #050510; border: 1px solid #1e2442; border-radius: 10px;
  padding: 8px; align-self: start; position: sticky; top: 20px;
}
.rimg-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: #050510;
  height: 70vh;
  max-height: calc(100vh - 220px);
  min-height: 420px;
  cursor: grab;
  outline: none;
}
.rimg-wrap:focus-visible { box-shadow: 0 0 0 2px #4f8ff7; }
.rimg-wrap.dragging { cursor: grabbing; }
.rimg-wrap:fullscreen { height: 100vh; background: #000; border-radius: 0; }
.rimg-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}
.rimg-zoom {
  position: absolute; bottom: 8px; left: 8px;
  background: rgba(10,10,24,0.85); color: #93c5fd;
  padding: 3px 8px; border-radius: 4px;
  font: 11px ui-monospace, monospace;
  pointer-events: none;
  border: 1px solid rgba(79,143,247,0.25);
}
.rimg-ctrl {
  position: absolute; bottom: 8px; right: 8px;
  display: flex; gap: 2px;
}
.rimg-ctrl button {
  background: rgba(10,10,24,0.85);
  border: 1px solid rgba(79,143,247,0.25);
  color: #93c5fd;
  padding: 3px 9px; border-radius: 4px;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  line-height: 1.2;
}
.rimg-ctrl button:hover { background: #4f8ff7; color: #fff; border-color: #4f8ff7; }
.rimg-ctrl button:active { transform: translateY(1px); }

.entries { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow-y: auto; padding-right: 4px; }
.entry {
  background: #1a1a2e; border-radius: 10px;
  padding: 12px 14px; border-left: 3px solid #4f8ff7;
}
.entry .row { display: flex; padding: 3px 0; gap: 10px; }
.entry .k {
  min-width: 80px; font-size: 11px; color: #6b7a99;
  text-transform: uppercase; letter-spacing: 0.5px; padding-top: 3px;
}
.entry .v { flex: 1; font-size: 14px; color: #e0e0e0; }
.entry .v.hi { font-size: 15px; color: #fff; }
.entry .v.num { font-family: ui-monospace, monospace; color: #93c5fd; }
.entry .v.small { font-size: 12px; color: #c0c0d0; }

.raw { }
.raw summary { cursor: pointer; color: #6b7a99; font-size: 12px; padding: 6px 0; }
.raw pre {
  margin-top: 6px; background: #050510; padding: 12px; border-radius: 6px;
  font-size: 11px; color: #93c5fd; overflow: auto; max-height: 320px;
  font-family: ui-monospace, monospace;
}
