/* The extract page: input pane, camera modal, and the four result views.
   Loads after base.css. */

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid { grid-template-columns: 1fr; } }

/* -- input ---------------------------------------------------------------- */
#drop {
  border: 2px dashed var(--line); border-radius: 8px; padding: 22px 12px;
  text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
#drop.hot { border-color: var(--accent); background: #eef6f2; }
#drop strong { color: var(--ink); }
.srcrow { display: flex; gap: 8px; margin-top: 10px; }
.srcrow button {
  flex: 1; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer;
}
.srcrow button:hover { border-color: var(--accent); color: var(--accent); }
#preview { display: none; max-width: 100%; max-height: 320px; margin: 12px auto 0; border-radius: 6px; border: 1px solid var(--line); }

fieldset { border: 0; margin: 14px 0 0; padding: 0; }
legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 6px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px 16px; }
label.opt { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

button#go {
  margin-top: 18px; width: 100%; padding: 11px 16px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 15px; font-weight: 600; cursor: pointer;
}
button#go:disabled { opacity: .55; cursor: wait; }
#status { margin-top: 12px; font-size: 13px; min-height: 20px; color: var(--muted); }
#status.err { color: var(--err); font-weight: 600; }
#status.ok { color: var(--ok); }

/* -- camera modal --------------------------------------------------------- */
#camOverlay {
  position: fixed; inset: 0; background: rgba(15, 16, 18, .72); z-index: 40;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
#camOverlay.open { display: flex; }
#camModal {
  background: var(--panel); border-radius: 12px; padding: 14px; width: min(720px, 100%);
  display: flex; flex-direction: column; gap: 10px;
}
#camHead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#camHead h3 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#camVideoWrap { position: relative; }
/* object-fit is explicit: camera.js sizes #camOutline to this contain-box.
   The two have to agree or the green quad drifts off the receipt. */
#camVideo { display: block; width: 100%; max-height: 58vh; object-fit: contain;
  background: #17181a; border-radius: 8px; }
#camFlash {
  position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none;
  border-radius: 8px; transition: opacity .1s ease-out;
}
#camFlash.on { opacity: .85; transition: none; }
/* left/top/width/height come from the video's contain box (camera.js). A 100%
   canvas is the wrap, which is wider than a portrait stream once max-height
   binds, and that stretch is the outline sitting outside the paper. */
#camOutline { position: absolute; pointer-events: none; }
select#camDevice {
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
  background: var(--panel); color: var(--ink); max-width: 100%;
}
#camBtns { display: flex; gap: 8px; }
#camBtns button { flex: 1; padding: 10px; border: 0; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
#camShot { background: var(--accent); color: var(--accent-ink); }
#camClose { background: transparent; border: 1px solid var(--line) !important; color: var(--muted); }
#camErr { font-size: 13px; color: var(--err); min-height: 18px; }
#camAutoRow { display: flex; align-items: center; gap: 10px; font-size: 13px; }
#camAutoState { color: var(--muted); flex: 1; }

/* -- result views --------------------------------------------------------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.bar h2 { margin: 0; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted);
}
.tabs button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.warns { margin: 10px 0 0; padding-left: 20px; font-size: 13px; color: #7a5b00; }

/* boxes tab: the tokens the OCR produced, drawn over the image it read */
#boxesWrap { position: relative; margin-top: 10px; overflow: auto; max-height: 70vh; }
#boxesCanvas { display: block; border: 1px solid var(--line); border-radius: 6px; background: #0b0f14; }
#boxesTip {
  position: absolute; pointer-events: none; z-index: 5; white-space: nowrap;
  background: var(--ink); color: var(--panel); padding: 3px 7px; border-radius: 4px;
  font: 600 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}
#boxesHint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* markdown tab: the page as the engine (or the token geometry) renders it */
#mdView { max-height: 70vh; overflow: auto; }
.md { font-size: 15px; line-height: 1.55; color: var(--ink); }
.md h3, .md h4, .md h5 { margin: 14px 0 6px; font-size: 15px; letter-spacing: .02em; }
.md h4, .md h5 { color: var(--muted); font-size: 14px; }
.md p { margin: 6px 0; }
.md ul { margin: 6px 0 6px 18px; padding: 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 7px; vertical-align: top; }
.md th { background: #f2f1ed; text-align: left; font-weight: 600; }
.md code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: #f2f1ed; padding: 0 3px; border-radius: 3px; }
