/* =========================================================================
   OCR — in-browser image-to-text (optical character recognition)
   Dark theme, mobile-first. Full-height shell below the shared navbar v2.
   The navbar paints its own (.tt-scope) palette; everything here is the tool.
   Chrome family-matched to simpleCAD / simple3D (same buttons, overlays, toasts).
   ========================================================================= */

:root {
    /* Seed the shared navbar height (published live by tt-navbar.js) */
    --tt-topnav-h: 64px;

    --bg:        #0a0a0f;
    --bg-2:      #0e0e15;
    --panel:     #14141d;
    --panel-2:   #1a1a26;
    --inset:     #101019;
    --border:    rgba(255, 255, 255, 0.10);
    --border-2:  rgba(255, 255, 255, 0.16);

    --text:      #f2f3f8;
    --text-2:    rgba(242, 243, 248, 0.72);
    --text-3:    rgba(242, 243, 248, 0.46);

    --indigo:    #6366f1;
    --violet:    #8b5cf6;
    --cyan:      #06b6d4;
    --teal:      #14b8a6;
    --green:     #22c55e;
    --amber:     #f59e0b;
    --red:       #f87171;

    --accent:    var(--cyan);
    --accent-2:  var(--indigo);
    --grad:      linear-gradient(135deg, var(--cyan), var(--indigo));

    --stage-bg:  #0c0d16;

    --r-sm: 7px;
    --r-md: 11px;
    --r-lg: 16px;

    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    --shadow: 0 18px 50px -22px rgba(0, 0, 0, 0.75);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);

    --tap: 40px;   /* base control size; padding lifts touch targets past 44px */
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-x: clip;          /* never break position:sticky (navbar-v2 lesson) */
    overscroll-behavior: none;
}

button { font-family: inherit; }
kbd {
    font-family: var(--mono); font-size: 0.82em;
    background: var(--inset); border: 1px solid var(--border-2);
    border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--text-2);
}

/* ===================== APP SHELL ===================== */
.app {
    height: calc(100dvh - var(--tt-topnav-h));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===================== TOOLBAR ===================== */
.toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}
.toolbar::-webkit-scrollbar { height: 6px; }
.toolbar::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

.tgroup { display: flex; align-items: center; gap: 3px; flex: 0 0 auto; }
.tsep { width: 1px; align-self: stretch; margin: 4px 4px; background: var(--border); flex: 0 0 auto; }
.tspacer { flex: 1 1 auto; min-width: 6px; }

.tbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: var(--tap);
    height: var(--tap);
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-2);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
    flex: 0 0 auto;
}
.tbtn i { font-size: 1rem; }
.tbtn:hover { background: var(--panel-2); color: var(--text); }
.tbtn:active { transform: translateY(1px); }
.tbtn:disabled { opacity: .35; cursor: default; pointer-events: none; }
.tbtn-label { font-size: 0.86rem; font-weight: 600; }
.tbtn[aria-pressed="true"] {
    background: rgba(6, 182, 212, 0.16);
    color: #9fe9f5;
    border-color: rgba(6, 182, 212, 0.5);
}
.tbtn-primary { background: var(--grad); color: #fff; }
.tbtn-primary:hover { filter: brightness(1.08); color: #fff; }
.tbtn-primary:disabled { filter: grayscale(.4); }

/* inline select (layout) */
.tselect {
    display: inline-flex; align-items: center; gap: 6px;
    height: var(--tap); padding: 0 8px 0 10px; flex: 0 0 auto;
    border: 1px solid var(--border); border-radius: var(--r-sm);
    background: var(--inset); color: var(--text-2);
}
.tselect i { font-size: .9rem; color: var(--text-3); }
.tselect:focus-within { border-color: var(--accent); }   /* keyboard focus indicator for the <select> */
.ctrl {
    height: 34px; padding: 0 10px;
    background: var(--inset); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--r-sm);
    font-size: 0.88rem;
}
.ctrl:focus { outline: none; border-color: var(--accent); }
select.ctrl { cursor: pointer; }
/* Native <option>s do NOT inherit the select's dark bg — the OS renders the open
   dropdown on a default (white) surface, so without this the options are white text
   on white = invisible. Literal hex (CSS vars are unreliable on <option>). */
.ctrl option, select.ctrl option { background-color: #1a1a26; color: #f2f3f8; }
.ctrl-sm { height: 30px; border: 0; background: transparent; padding: 0 4px; font-size: .84rem; font-weight: 600; }
.ctrl-sm:focus { border: 0; }

.tmenu { position: relative; flex: 0 0 auto; }
.tmenu-pop {
    position: fixed;            /* fixed + JS-anchored: the toolbar's overflow clips an absolute dropdown */
    min-width: 220px;
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    border-radius: var(--r-md);
    box-shadow: var(--shadow);
    padding: 6px;
    z-index: calc(var(--tt-z-modal, 1000) + 5);
}
.tmenu-pop[hidden] { display: none; }
.tmenu-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 10px 12px;
    background: transparent; border: 0; border-radius: var(--r-sm);
    color: var(--text); font-size: 0.9rem; text-align: left; cursor: pointer;
}
.tmenu-item i { width: 18px; text-align: center; color: var(--text-3); }
.tmenu-item:hover { background: rgba(6,182,212,0.16); }
.tmenu-item:hover i { color: var(--accent); }

/* ===================== MOBILE PANE TABS ===================== */
.mtabs { display: none; }
.mtab {
    flex: 1 1 0; height: 42px; gap: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--panel); border: 0; border-bottom: 2px solid transparent;
    color: var(--text-3); font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.mtab.is-on { color: var(--text); border-bottom-color: var(--accent); }
.mtab i { font-size: .95rem; }
.mtab-badge {
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    background: var(--accent); color: #04222a; font-size: .68rem; font-weight: 800;
    display: inline-flex; align-items: center; justify-content: center;
}

/* ===================== WORKSPACE ===================== */
.workspace { flex: 1 1 auto; display: flex; min-height: 0; }

.pane { flex: 1 1 50%; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.pane-source { border-right: 1px solid var(--border); background: var(--bg-2); }
.pane-text { background: var(--panel); }

/* ---------- queue strip ---------- */
.queue {
    flex: 0 0 auto;
    display: flex; gap: 8px;
    padding: 8px;
    overflow-x: auto; overflow-y: hidden;
    border-bottom: 1px solid var(--border);
    scrollbar-width: thin;
}
.queue::-webkit-scrollbar { height: 6px; }
.queue::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }
.qtile {
    position: relative; flex: 0 0 auto;
    width: 74px; height: 74px; border-radius: var(--r-sm);
    border: 2px solid var(--border); overflow: hidden; cursor: pointer;
    background: var(--inset);
}
.qtile.is-active { border-color: var(--accent); }
.qtile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.qtile-x {
    position: absolute; top: 2px; right: 2px; z-index: 3;
    width: 20px; height: 20px; border-radius: 6px; border: 0;
    background: rgba(8,8,14,0.72); color: #fff; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; font-size: .7rem;
    opacity: 0; transition: opacity .12s var(--ease);
}
.qtile:hover .qtile-x { opacity: 1; }
.qtile-state {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
    height: 18px; display: flex; align-items: center; justify-content: center;
    font-size: .64rem; font-weight: 700; color: #fff;
    background: rgba(8,8,14,0.78);
}
.qtile-state.pending { color: var(--text-3); }
.qtile-state.running { color: var(--accent); }
.qtile-state.done    { color: var(--green); }
.qtile-state.error   { color: var(--red); }
.qtile-bar {
    position: absolute; left: 0; bottom: 0; z-index: 3; height: 3px;
    background: var(--accent); width: 0%;
    transition: width .2s linear;
}

/* ---------- stage (dropzone / preview) ---------- */
.stage { flex: 1 1 auto; position: relative; overflow: hidden; min-height: 0; }

.dropzone {
    position: absolute; inset: 12px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; text-align: center; padding: 24px;
    border: 2px dashed var(--border-2); border-radius: var(--r-lg);
    color: var(--text-3); background: var(--stage-bg);
    transition: border-color .15s var(--ease), background .15s var(--ease);
}
.dropzone.is-drag { border-color: var(--accent); background: rgba(6,182,212,0.07); color: var(--text-2); }
.dropzone > i { font-size: 2.8rem; color: var(--accent); opacity: .85; }
.dz-title { margin: 0; font-size: 1.04rem; font-weight: 600; color: var(--text); }
.dz-sub { margin: 0; font-size: 0.9rem; line-height: 1.55; max-width: 360px; }
.dz-formats { margin: 0; font-size: 0.78rem; color: var(--text-3); font-family: var(--mono); }
.dz-privacy { margin: 6px 0 0; font-size: 0.8rem; color: var(--teal); display: inline-flex; align-items: center; gap: 7px; }
.link-btn {
    background: none; border: 0; padding: 0; cursor: pointer;
    color: var(--accent); font: inherit; text-decoration: underline; text-underline-offset: 2px;
}
.dropzone.hidden { display: none; }

.preview { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 14px; }
.preview[hidden] { display: none; }
.preview-canvas-wrap { position: relative; max-width: 100%; max-height: 100%; line-height: 0; }
.preview-img { max-width: 100%; max-height: 100%; display: block; border-radius: var(--r-sm); box-shadow: var(--shadow); }
.preview-overlay { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.preview-overlay[hidden] { display: none; }

/* ---------- text pane ---------- */
.out-head {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.out-meta { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; }
.out-tools { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.conf-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 99px;
    background: rgba(34,197,94,0.14); color: #86efac;
    font-size: 0.78rem; font-weight: 600;
}
.conf-chip[hidden] { display: none; }
.conf-chip b { font-variant-numeric: tabular-nums; }
.conf-chip.mid { background: rgba(245,158,11,0.14); color: #fcd34d; }
.conf-chip.low { background: rgba(248,113,113,0.14); color: #fca5a5; }
.out-count { font-size: 0.78rem; color: var(--text-3); display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); }
.out-count[hidden] { display: none; }
.out-count i { color: var(--text-3); }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: var(--r-sm);
    background: transparent; border: 1px solid var(--border); color: var(--text-2);
    cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; pointer-events: none; }
.icon-btn[aria-pressed="true"] { background: rgba(6,182,212,0.16); color: #9fe9f5; border-color: rgba(6,182,212,0.5); }

.out-body { flex: 1 1 auto; position: relative; min-height: 0; display: flex; }
.out-text {
    flex: 1 1 auto; width: 100%; resize: none; border: 0; outline: none;
    padding: 16px; background: transparent; color: var(--text);
    font-family: 'Inter', sans-serif; font-size: 0.96rem; line-height: 1.6;
    white-space: pre-wrap; word-break: break-word;
}
.out-text::placeholder { color: var(--text-3); }
.out-rich {
    position: absolute; inset: 0; overflow: auto;
    padding: 16px; color: var(--text);
    font-family: 'Inter', sans-serif; font-size: 0.96rem; line-height: 1.6;
    white-space: pre-wrap; word-break: break-word; background: var(--panel);
}
.out-rich[hidden] { display: none; }
.out-rich .w-low  { background: rgba(248,113,113,0.26); border-radius: 3px; }
.out-rich .w-mid  { background: rgba(245,158,11,0.22); border-radius: 3px; }

.out-empty {
    position: absolute; inset: 0; z-index: 1; pointer-events: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; padding: 28px; text-align: center; color: var(--text-3);
    background: var(--panel);   /* opaque: cover the textarea placeholder so only one empty message shows */
}
.out-empty[hidden] { display: none; }
.out-empty i { font-size: 2.4rem; opacity: .5; }
.out-empty p { margin: 0; font-size: 0.92rem; max-width: 320px; line-height: 1.55; }
.out-empty b { color: var(--text-2); }

/* ===================== STATUS BAR ===================== */
.statusbar {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 12px;
    padding: 5px 12px; min-height: 30px;
    background: var(--panel); border-top: 1px solid var(--border);
    font-size: 0.76rem; color: var(--text-2); font-family: var(--mono);
    overflow: hidden; white-space: nowrap;
}
.statusbar i { color: var(--text-3); }
.st-item { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; }
.st-engine.busy #stEngineTxt, .st-engine.busy i { color: var(--accent); }
.st-spacer { flex: 1 1 auto; }
.st-hint { color: var(--text-3); font-family: 'Inter', sans-serif; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 auto; }
.st-progress {
    flex: 0 0 auto; width: 120px; height: 6px; border-radius: 99px;
    background: var(--inset); overflow: hidden; border: 1px solid var(--border);
}
.st-progress[hidden] { display: none; }
.st-progress-bar { display: block; height: 100%; width: 0%; background: var(--grad); transition: width .2s linear; }

/* ===================== OVERLAYS ===================== */
.overlay {
    position: fixed; inset: 0;
    z-index: calc(var(--tt-z-modal, 1000) + 10);   /* clear the shared navbar */
    display: flex; align-items: center; justify-content: center;
    padding: 18px;
    background: rgba(5, 5, 9, 0.72); backdrop-filter: blur(4px);
}
.overlay[hidden] { display: none; }
.overlay-card {
    width: min(520px, 100%); max-height: calc(100dvh - 36px);
    background: var(--panel); border: 1px solid var(--border-2);
    border-radius: var(--r-lg); box-shadow: var(--shadow);
    display: flex; flex-direction: column; overflow: hidden;
}
.overlay-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.overlay-head h2 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: 9px; }
.overlay-head h2 i { color: var(--accent); }
.overlay-sec { padding: 16px 20px; overflow-y: auto; }
.overlay-foot {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 20px; border-top: 1px solid var(--border);
}
.lang-help { margin: 0 0 14px; font-size: 0.86rem; color: var(--text-2); line-height: 1.55; }
.lang-selcount { font-size: 0.8rem; color: var(--text-3); font-family: var(--mono); }

.lang-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.lang-opt {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 11px; border-radius: var(--r-sm);
    background: var(--inset); border: 1px solid var(--border);
    cursor: pointer; user-select: none;
}
.lang-opt:hover { border-color: var(--border-2); }
.lang-opt.is-on { border-color: var(--accent); background: rgba(6,182,212,0.10); }
.lang-opt input { accent-color: var(--accent); width: 17px; height: 17px; flex: 0 0 auto; }
.lang-opt .lo-name { font-size: 0.88rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang-opt .lo-code { font-size: 0.7rem; color: var(--text-3); font-family: var(--mono); margin-left: auto; }

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    height: 40px; padding: 0 16px; border-radius: var(--r-sm);
    background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--grad); border: 0; color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }

/* Generic dialog */
.dialog-card { padding: 20px; }
.dialog-card h3 { margin: 0 0 8px; font-size: 1rem; }
.dialog-card p { margin: 0 0 14px; color: var(--text-2); font-size: 0.9rem; line-height: 1.5; }
.dialog-btns { display: flex; justify-content: flex-end; gap: 10px; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: calc(var(--tt-z-modal, 1000) + 20); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
    padding: 10px 16px; border-radius: var(--r-md);
    background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
    font-size: 0.86rem; box-shadow: var(--shadow); pointer-events: auto;
    display: flex; align-items: center; gap: 9px; animation: toastIn .25s var(--ease); max-width: 90vw;
}
.toast i { color: var(--accent); }
.toast.ok i { color: var(--green); }
.toast.err i { color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===================== MOBILE ===================== */
@media (max-width: 820px) {
    .mtabs { display: flex; flex: 0 0 auto; border-bottom: 1px solid var(--border); }
    .pane { display: none; flex-basis: 100%; }
    .pane.is-shown { display: flex; }
    .pane-source { border-right: 0; }
    .overlay { padding: 0; align-items: stretch; }
    .overlay-card { max-height: 100dvh; border-radius: 0; border: 0; width: 100%; }
    .lang-list { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .tbtn-label { display: none; }       /* icon-only on phones */
    .tselect .ctrl-sm { max-width: 92px; }
    .st-hint { display: none; }
    .st-progress { width: 84px; }
    .dz-title { font-size: 0.98rem; }
}

/* Coarse pointers: lift every tap target comfortably to ≥44px */
@media (pointer: coarse) {
    :root { --tap: 44px; }
    .icon-btn { width: 44px; height: 44px; }
    .qtile-x { width: 28px; height: 28px; opacity: 1; }
    .lang-opt input { width: 22px; height: 22px; }
    /* lift the remaining touch targets to the 44px minimum */
    .btn { height: 44px; }
    .mtab { height: 48px; }
    .lang-opt { padding: 12px 11px; }
    .tmenu-item { padding: 12px; }
    .link-btn { display: inline-block; padding: 4px 2px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
