/* ============================================================
   Lens Preview - application styles (index.html)
   The login page keeps using styles.css.
   ============================================================ */

:root {
    --bg: #080b11;
    --panel: #0e131d;
    --card: #141b28;
    --card-2: #1a2333;
    --field: #0d121b;
    --line: #253046;
    --line-soft: #1c2536;
    --text: #e8eefc;
    --muted: #93a2bf;
    --dim: #63718c;
    --accent: #6fb6ff;
    --accent-strong: #3d8bfd;
    --od: #2f8fdc;
    --os: #dd7430;
    --good: #3ddc97;
    --warn: #f5b84b;
    --bad: #ff6b6b;
    --info: #7fd4ff;
    --radius: 10px;
    --topbar-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

small { font-size: 0.8em; font-weight: 400; color: var(--dim); }

/* ---------- App grid: inputs | stage | results ---------- */
.app {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr) 380px;
    grid-template-rows: var(--topbar-h) minmax(0, 1fr);
    grid-template-areas: "top top top" "inputs stage results";
    height: 100vh;
    height: 100dvh;
}

/* ---------- Top bar ---------- */
.topbar {
    grid-area: top;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 18px;
    background: var(--panel);
    border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; min-width: 0; }
.brand-mark { width: 40px; height: 24px; color: var(--accent); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 1.08em; letter-spacing: 0.01em; }
.brand-text span { font-size: 0.82em; color: var(--muted); white-space: nowrap; }

.status {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.85em;
    color: var(--muted);
    white-space: nowrap;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.status[data-state="ok"] .status-dot { background: var(--good); }
.status[data-state="busy"] .status-dot { background: var(--accent); animation: pulse 0.9s ease-in-out infinite; }
.status[data-state="wait"] .status-dot { background: var(--warn); }
.status[data-state="error"] .status-dot { background: var(--bad); }
.status[data-state="error"] { color: var(--text); border-color: var(--bad); }
@keyframes pulse { 50% { opacity: 0.25; } }

.top-actions { display: flex; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
    font: inherit; font-weight: 600;
    padding: 8px 14px;
    color: var(--text);
    background: var(--card-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #222d42; border-color: #34425e; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: #5a9dff; border-color: #5a9dff; }
.btn-quiet { background: transparent; color: var(--muted); font-weight: 500; }
.btn-quiet:hover { color: var(--text); }
.btn-dashed { width: 100%; background: transparent; border-style: dashed; color: var(--muted); font-weight: 500; }
.btn-dashed:hover { color: var(--text); background: var(--card-2); }

.icon-btn {
    width: 24px; height: 24px; flex: none;
    font: inherit; font-size: 0.8em; color: var(--muted);
    background: transparent; border: 1px solid var(--line); border-radius: 50%;
    cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--bad); }

.chip-btn {
    font: inherit; font-size: 0.8em; font-weight: 600;
    padding: 2px 10px;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
}
.chip-btn:hover { color: var(--text); }
.chip-btn.is-on { color: #06121f; background: var(--accent); border-color: var(--accent); cursor: default; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Side panels and cards ---------- */
.panel {
    display: flex; flex-direction: column; gap: 12px;
    padding: 12px;
    background: var(--panel);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
}
.panel.inputs { grid-area: inputs; border-right: 1px solid var(--line-soft); }
.panel.results { grid-area: results; border-left: 1px solid var(--line-soft); }

.card {
    background: var(--card);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    padding: 14px;
}
.card h2 {
    font-size: 0.78em; font-weight: 700;
    letter-spacing: 0.09em; text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
}
.card-note { margin-top: 10px; font-size: 0.82em; color: var(--dim); }

/* ---------- Form controls ---------- */
input[type="number"], select {
    width: 100%;
    font: inherit; font-variant-numeric: tabular-nums;
    padding: 7px 8px;
    color: var(--text);
    background: var(--field);
    border: 1px solid var(--line);
    border-radius: 7px;
    transition: border-color 0.15s;
}
input[type="number"]:hover, select:hover { border-color: #3a4864; }
input[type="number"]:focus, select:focus { outline: none; border-color: var(--accent); }
input[readonly] { color: var(--muted); background: transparent; border-style: dashed; }
input:disabled, select:disabled { opacity: 0.5; cursor: not-allowed; }
input.is-invalid { border-color: var(--bad); }
select option { background: var(--card); color: var(--text); }
label { color: var(--muted); font-size: 0.88em; }

.eye-tag {
    display: inline-block;
    min-width: 30px; padding: 1px 6px;
    font-size: 0.78em; font-weight: 700; letter-spacing: 0.04em; text-align: center;
    color: #fff; border-radius: 5px;
}
.eye-tag.od { background: var(--od); }
.eye-tag.os { background: var(--os); }

.grid-table { width: 100%; border-collapse: separate; border-spacing: 6px 6px; margin: -6px; width: calc(100% + 12px); }
.grid-table th { font-weight: 500; font-size: 0.85em; color: var(--muted); text-align: left; white-space: nowrap; }
.grid-table thead th { text-align: center; padding-bottom: 0; }
.grid-table tbody th small { display: block; margin-top: 1px; }
.rx-table tbody th { width: 46px; }
.rx-table input { text-align: center; font-size: 1.05em; font-weight: 600; padding: 9px 4px; }
.fit-table input { text-align: center; padding: 7px 2px; }
.fit-table tbody th { white-space: normal; line-height: 1.15; }
.fit-table tbody th small { display: block; }
input[type="number"] { -moz-appearance: textfield; }
.grid-table input::-webkit-outer-spin-button, .grid-table input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.field-row { display: grid; gap: 8px; margin-top: 10px; }
.field-row.two { grid-template-columns: 1fr 1fr; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.control-group.stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.control-group.stack label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frame-field-disabled { opacity: 0.55; }

.field { display: grid; grid-template-columns: 1fr 150px; align-items: center; gap: 8px; margin-top: 8px; }
.prism-block { margin-top: 4px; }
.prism-inputs { margin: 6px 0 4px; padding: 2px 10px 10px; background: var(--field); border-radius: 8px; }

.tracer-upload-section { margin-bottom: 2px; }
.frame-source { display: flex; gap: 8px; }
.frame-source .btn { flex: 1 1 0; width: auto; padding-left: 8px; padding-right: 8px; }
.tracer-file-info .chip-btn { flex: none; margin-left: auto; }
.tracer-file-info {
    align-items: center; justify-content: space-between; gap: 8px;
    margin-top: 8px; padding: 6px 10px;
    font-size: 0.85em; color: var(--text);
    background: rgba(61, 220, 151, 0.1);
    border: 1px solid rgba(61, 220, 151, 0.4);
    border-radius: 7px;
}
.tracer-file-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bc-block { margin-top: 14px; }
.bc-head { display: flex; align-items: center; justify-content: space-between; }
.bc-controls { display: grid; grid-template-columns: 1fr 76px; align-items: center; gap: 10px; margin-top: 6px; }
.bc-info { margin-top: 4px; font-size: 0.8em; color: var(--dim); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
input[type="range"]:disabled { opacity: 0.35; cursor: not-allowed; }

.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); font-size: 0.9em; user-select: none; }
.toggle input { appearance: none; position: relative; flex: none; width: 30px; height: 17px; border-radius: 999px; background: var(--line); cursor: pointer; transition: background 0.15s; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.toggle input:checked { background: var(--accent-strong); }
.toggle input:checked::after { transform: translateX(13px); }

/* ---------- 3D stage ---------- */
.stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; background: #0b0f17; }
#canvas-container { position: absolute; inset: 0; overflow: hidden; }
#canvas-container canvas { cursor: grab; }
#canvas-container canvas:active { cursor: grabbing; }

.loading {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    display: none; z-index: 50;
    padding: 14px 26px;
    color: var(--text);
    background: rgba(14, 19, 30, 0.9);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.loading.active { display: block; }

.viewer-hint {
    position: absolute; left: 14px; top: 12px;
    max-width: 55%;
    font-size: 0.78em; color: rgba(190, 205, 235, 0.5);
    pointer-events: none; user-select: none;
}

.viewer-legend {
    position: absolute; top: 14px; right: 14px;
    display: none; flex-direction: column; gap: 6px;
    padding: 10px 12px;
    font-size: 0.8em; color: var(--text);
    background: rgba(10, 14, 22, 0.72);
    border: 1px solid var(--line);
    border-radius: 8px;
    pointer-events: none; user-select: none;
}
.viewer-legend .vl-title { color: var(--muted); line-height: 1.25; }
.viewer-legend .vl-body { display: flex; gap: 8px; height: 130px; }
.viewer-legend .vl-bar { width: 12px; border-radius: 6px; }
.viewer-legend .vl-ticks { display: flex; flex-direction: column; justify-content: space-between; font-variant-numeric: tabular-nums; }

.viewer-tip {
    position: absolute; display: none; z-index: 60;
    padding: 5px 9px;
    font-size: 0.88em; font-variant-numeric: tabular-nums; white-space: nowrap;
    color: var(--text);
    background: rgba(10, 14, 22, 0.92);
    border: 1px solid var(--line);
    border-radius: 6px;
    pointer-events: none;
}
.viewer-tip b { color: var(--muted); margin-right: 4px; }

.stage-toolbar {
    position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
    display: flex; align-items: center; gap: 6px;
    max-width: calc(100% - 24px);
    padding: 6px 10px;
    background: rgba(14, 19, 30, 0.82);
    border: 1px solid var(--line);
    border-radius: 12px;
    backdrop-filter: blur(8px);
    z-index: 40;
}
.stage-toolbar button {
    font: inherit; font-weight: 600; font-size: 0.9em;
    padding: 6px 12px;
    color: var(--text); background: transparent;
    border: 1px solid transparent; border-radius: 8px;
    cursor: pointer;
}
.stage-toolbar button:hover { background: var(--card-2); border-color: var(--line); }
.stage-toolbar .sep { width: 1px; height: 22px; margin: 0 4px; background: var(--line); }
.stage-toolbar .toggle { white-space: nowrap; }
.stage-toolbar #sectionAngle { width: 120px; }
.stage-toolbar .section-angle { min-width: 38px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Optical-centre banner (created by app.js) */
.oc-warning-overlay { position: absolute; top: 44px; left: 50%; transform: translateX(-50%); display: none; z-index: 45; pointer-events: none; }
.oc-warning-content {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 14px;
    font-weight: 600; font-size: 0.9em; color: var(--text);
    background: rgba(60, 16, 20, 0.9);
    border: 1px solid var(--bad);
    border-radius: 999px;
    white-space: nowrap;
}

/* Toasts */
.toasts {
    position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    width: min(460px, calc(100% - 28px));
    z-index: 70; pointer-events: none;
}
.toast {
    display: flex; align-items: flex-start; gap: 10px;
    width: 100%;
    padding: 10px 12px;
    font-size: 0.9em; color: var(--text);
    background: rgba(16, 22, 34, 0.96);
    border: 1px solid var(--line);
    border-left: 4px solid var(--info);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    pointer-events: auto;
    animation: toast-in 0.2s ease-out;
}
.toast.error { border-left-color: var(--bad); }
.toast.warning { border-left-color: var(--warn); }
.toast.success { border-left-color: var(--good); }
.toast .toast-kind { font-weight: 700; white-space: nowrap; }
.toast .toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast button { font: inherit; color: var(--muted); background: none; border: none; cursor: pointer; }
.toast button:hover { color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- Results ---------- */
.eye-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.eye-card { padding: 12px 10px; background: var(--card-2); border: 1px solid var(--line-soft); border-radius: 9px; min-width: 0; }
.eye-card-head { display: flex; align-items: center; gap: 8px; font-size: 0.88em; color: var(--muted); }
.hero { display: flex; flex-direction: column; margin: 10px 0 8px; }
.hero-value { font-size: 1.9em; font-weight: 650; line-height: 1.1; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hero-label { font-size: 0.8em; color: var(--muted); }
.eye-card dl > div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line-soft); }
.eye-card dt { font-size: 0.8em; color: var(--muted); white-space: nowrap; }
.eye-card dd { font-size: 0.92em; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.not-achieved { color: var(--bad); }
.eye-card.is-dim { opacity: 0.45; }

.optics-table { margin-top: 6px; border-spacing: 0; width: 100%; margin-left: 0; margin-right: 0; margin-bottom: 0; }
.optics-table th, .optics-table td { padding: 6px 4px; border-top: 1px solid var(--line-soft); }
.optics-table thead th { border-top: none; padding-top: 10px; }
.optics-table td { text-align: center; font-weight: 600; font-size: 0.86em; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Material comparison */
.mat-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.mat-table th { padding: 0 4px 6px; font-size: 0.8em; font-weight: 500; color: var(--muted); text-align: right; white-space: nowrap; }
.mat-table th:first-child { text-align: left; }
.mat-table td { padding: 6px 4px; font-size: 0.9em; text-align: right; white-space: nowrap; border-top: 1px solid var(--line-soft); }
.mat-table td:first-child { text-align: left; width: 40%; }
.mat-table tbody tr { cursor: pointer; }
.mat-table tbody tr:hover td { background: var(--card-2); }
.mat-table tbody tr.is-current td { background: rgba(111, 182, 255, 0.1); font-weight: 650; }
.mat-table tbody tr.is-current td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.mat-name { display: flex; align-items: baseline; gap: 6px; }
.mat-name b { font-weight: 650; }
.mat-name span { font-size: 0.86em; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.mat-bar { height: 3px; margin-top: 4px; border-radius: 2px; background: var(--line); }
.mat-bar i { display: block; height: 100%; border-radius: 2px; background: var(--muted); }
.mat-table tr.is-current .mat-bar i { background: var(--accent); }
.mat-table td small { margin-left: 2px; }

/* Edge chart */
.chart-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 0.86em; color: var(--text); }
.chart-legend .chart-unit { margin-left: auto; color: var(--dim); }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; vertical-align: baseline; }
.swatch.od { background: var(--od); }
.swatch.os { background: var(--os); }
.lens-explorer { margin-top: 8px; }
.lens-explorer canvas { display: block; width: 100%; aspect-ratio: 1; cursor: crosshair; touch-action: none; }
.chart-readout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.chart-readout > div { display: flex; flex-direction: column; padding: 7px 9px; background: var(--card-2); border-radius: 8px; }
.ro-label { font-size: 0.8em; color: var(--muted); }
.ro-value { font-size: 1.1em; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Balance */
.metric-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { display: flex; flex-direction: column; padding: 9px; background: var(--card-2); border-radius: 8px; min-width: 0; }
.tile-value { font-size: 1.1em; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile-label { font-size: 0.78em; color: var(--muted); }

/* Notes (constraints, balance warnings, guidance) */
.note-list { display: flex; flex-direction: column; gap: 6px; }
.note-list:not(:empty) { margin-top: 10px; }
.notes-eye { display: grid; grid-template-columns: 34px 1fr; align-items: start; gap: 8px; }
.notes-eye + .notes-eye { margin-top: 8px; }
.notes-eye .note-list:not(:empty) { margin-top: 0; }
.notes-eye .eye-tag { margin-top: 7px; }
.constraint-warning, .balance-warning, .validation-box > div, .guidance-note {
    padding: 8px 10px;
    font-size: 0.86em;
    background: var(--card-2);
    border-left: 3px solid var(--info);
    border-radius: 6px;
}
.constraint-warning.success, .balance-warning.success { border-left-color: var(--good); }
.constraint-warning.warning, .balance-warning.warning { border-left-color: var(--warn); }
.constraint-warning.error, .balance-warning.error, .validation-box.error > div { border-left-color: var(--bad); }
.constraint-title, .warning-title { font-weight: 650; }
.constraint-message, .warning-message { color: var(--text); }
.constraint-difference, .constraint-suggestion, .warning-suggestion { margin-top: 3px; color: var(--muted); }

/* ---------- Sign-in page ---------- */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
    background: radial-gradient(900px 500px at 50% 0%, #16223a 0%, var(--bg) 70%); }
.login-card { width: min(380px, 100%); padding: 28px; background: var(--card); border: 1px solid var(--line-soft); border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45); }
.login-card .brand { margin: 0 0 22px; }
.login-card h1 { font-size: 1.35em; margin-bottom: 4px; }
.login-card p.sub { color: var(--muted); margin-bottom: 20px; }
.login-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.login-field input { width: 100%; font: inherit; padding: 10px 12px; color: var(--text); background: var(--field);
    border: 1px solid var(--line); border-radius: 8px; }
.login-field input:focus { outline: none; border-color: var(--accent); }
.login-card .btn-primary { width: 100%; padding: 11px; margin-top: 6px; }
.login-card .btn-primary:disabled { opacity: 0.6; cursor: default; }
.login-error { min-height: 1.4em; margin-top: 12px; font-size: 0.9em; color: var(--bad); }

/* ---------- Tablet and phone ---------- */
@media (max-width: 1180px) {
    .app {
        height: auto; min-height: 100vh;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-rows: var(--topbar-h) min(58vh, 620px) auto;
        grid-template-areas: "top top" "stage stage" "inputs results";
    }
    .topbar { position: sticky; top: 0; z-index: 80; }
    .panel { overflow: visible; }
    .panel.inputs { border-right: 1px solid var(--line-soft); }
    .viewer-hint { display: none; }
}

@media (max-width: 760px) {
    .app {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: var(--topbar-h) 52vh auto auto;
        grid-template-areas: "top" "stage" "inputs" "results";
    }
    .brand-text, .status { display: none; }
    .top-actions { gap: 6px; }
    .top-actions .btn { padding: 7px 8px; font-size: 0.88em; }
    .topbar { padding: 0 12px; gap: 8px; }
    .btn { padding: 7px 10px; }
    .stage-toolbar { flex-wrap: wrap; justify-content: center; bottom: 8px; width: calc(100% - 16px); gap: 2px 6px; padding: 4px 8px; }
    .stage-toolbar button { padding: 5px 9px; }
    .stage-toolbar #sectionAngle { flex: 1; min-width: 80px; }
    .stage-toolbar .sep { display: none; }
    .viewer-legend .vl-body { height: 90px; }
}

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

/* ============================================================
   Lens designs, tint and treatment, lens database
   ============================================================ */
[hidden] { display: none !important; }

/* Segmented control (lens type, database tabs) */
.seg-control { display: flex; padding: 3px; gap: 3px; background: var(--field); border: 1px solid var(--line); border-radius: 9px; }
.seg-control button {
    flex: 1; min-width: 0;
    font: inherit; font-size: 0.9em; font-weight: 600;
    padding: 6px 8px;
    color: var(--muted); background: transparent;
    border: none; border-radius: 6px;
    cursor: pointer; white-space: nowrap;
}
.seg-control button:hover { color: var(--text); }
.seg-control button.is-on { color: #06121f; background: var(--accent); }

.design-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; margin-top: 10px; }
.design-row .btn { padding: 7px 12px; }
.design-summary { margin-top: 6px; font-size: 0.82em; color: var(--muted); line-height: 1.45; }
.design-summary:empty { display: none; }
.design-summary .stars { color: var(--warn); letter-spacing: 1px; margin-right: 6px; }
.design-summary b { color: var(--text); font-weight: 600; }
.criteria { margin-top: 8px; padding: 2px 10px 10px; background: var(--field); border-radius: 8px; }
.criteria .btn-dashed { margin-top: 10px; }
#multifocalFields { margin-top: 12px; }
#multifocalFields .fit-table input::placeholder, .criteria input::placeholder { color: var(--dim); }
#optionRow { align-items: end; }
.thinning-toggle { padding-bottom: 8px; }

/* Tint and treatment pickers */
.look-row { display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: end; gap: 10px; }
.look-row + .look-row { margin-top: 10px; }
.look-swatch {
    display: block; width: 34px; height: 34px;
    border: 1px solid var(--line); border-radius: 50%;
    background: var(--field) center / cover no-repeat;
}
.look-swatch.ghost { visibility: hidden; height: 0; }

/* Results: chosen design */
.design-result { margin-top: 10px; padding: 8px 10px; font-size: 0.86em; color: var(--muted); background: var(--card-2); border-radius: 8px; line-height: 1.5; }
.design-result b { color: var(--text); font-weight: 650; }

/* Aberration legend on the 3D stage */
.viewer-ab-legend {
    position: absolute; left: 14px; bottom: 70px;
    display: none; flex-direction: column; gap: 5px;
    max-width: 230px; padding: 10px 12px;
    font-size: 0.8em; color: var(--text);
    background: rgba(10, 14, 22, 0.78);
    border: 1px solid var(--line); border-radius: 8px;
    pointer-events: none; user-select: none;
}
.viewer-ab-legend .ab-title { color: var(--muted); }
.viewer-ab-legend .ab-bands { display: flex; gap: 2px; }
.viewer-ab-legend .ab-bands span { flex: 1; text-align: center; font-variant-numeric: tabular-nums; }
.viewer-ab-legend .ab-bands i { display: block; height: 10px; margin-bottom: 3px; border-radius: 2px; border: 1px solid rgba(255, 255, 255, 0.25); }
.viewer-ab-legend .ab-note { color: var(--dim); line-height: 1.3; }

/* Database dialog */
dialog.catalogue {
    width: min(980px, calc(100vw - 24px)); height: min(720px, calc(100dvh - 24px));
    margin: auto; padding: 0;
    color: var(--text); background: var(--panel);
    border: 1px solid var(--line); border-radius: 14px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}
dialog.catalogue[open] { display: flex; flex-direction: column; }
dialog.catalogue::backdrop { background: rgba(4, 6, 10, 0.66); }
.cat-head { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
.cat-head strong { font-size: 1.05em; white-space: nowrap; }
.cat-head .seg-control { flex: 0 1 340px; }
.cat-head .icon-btn { margin-left: auto; width: 28px; height: 28px; }
.cat-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.cat-tools .cat-spacer { flex: 1; }
.cat-tools a.btn { text-decoration: none; }
.cat-tools .btn { padding: 7px 12px; font-size: 0.9em; }
.cat-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.cat-list { overflow-y: auto; border-right: 1px solid var(--line-soft); padding: 6px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.cat-group { padding: 10px 8px 4px; font-size: 0.72em; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--dim); }
.cat-item {
    display: flex; align-items: center; gap: 9px; width: 100%;
    padding: 7px 8px; text-align: left;
    font: inherit; color: var(--text); background: transparent;
    border: 1px solid transparent; border-radius: 7px; cursor: pointer;
}
.cat-item:hover { background: var(--card); }
.cat-item.is-on { background: var(--card-2); border-color: var(--line); }
.cat-item .ci-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-item .ci-meta { font-size: 0.8em; color: var(--muted); white-space: nowrap; }
.cat-item .look-swatch { width: 22px; height: 22px; flex: none; }
.cat-empty { padding: 18px 10px; color: var(--dim); font-size: 0.9em; }
.cat-detail { overflow-y: auto; padding: 14px 16px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.cat-detail h3 { font-size: 1.05em; margin-bottom: 2px; }
.cat-detail .sub { color: var(--muted); font-size: 0.86em; margin-bottom: 12px; }
.cat-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.cat-form .wide { grid-column: 1 / -1; }
.cat-form .f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cat-form .f small { color: var(--dim); line-height: 1.3; }
.cat-form h4 { grid-column: 1 / -1; margin-top: 6px; font-size: 0.74em; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
input[type="text"], input[type="search"], textarea {
    width: 100%; font: inherit;
    padding: 7px 8px;
    color: var(--text); background: var(--field);
    border: 1px solid var(--line); border-radius: 7px;
}
input[type="text"]:focus, input[type="search"]:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 58px; }
.cat-tools input[type="search"] { width: 220px; }
.colour-field { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 6px; }
.colour-field input[type="color"] { width: 38px; height: 34px; padding: 2px; background: var(--field); border: 1px solid var(--line); border-radius: 7px; cursor: pointer; }
.cat-preview { display: flex; align-items: center; gap: 12px; }
.cat-preview .look-swatch { width: 64px; height: 64px; flex: none; }
.cat-preview .btn { padding: 6px 10px; font-size: 0.86em; }
.cat-ranges { width: 100%; border-collapse: collapse; font-size: 0.86em; font-variant-numeric: tabular-nums; }
.cat-ranges th { text-align: left; font-weight: 500; color: var(--muted); padding: 3px 6px 3px 0; }
.cat-ranges td { padding: 3px 6px 3px 0; border-top: 1px solid var(--line-soft); }
.cat-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line-soft); min-height: 54px; }
.cat-foot .cat-msg { flex: 1; min-width: 0; font-size: 0.88em; color: var(--muted); }
.cat-foot .cat-msg.error { color: var(--bad); }
.cat-foot .cat-msg.ok { color: var(--good); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }
.cat-report h3 { margin-bottom: 8px; }
.cat-report ul { margin: 4px 0 12px 18px; font-size: 0.9em; color: var(--muted); }
.cat-report .counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.cat-report .err { color: var(--bad); }

@media (max-width: 760px) {
    .cat-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: 36% minmax(0, 1fr); }
    .cat-list { border-right: none; border-bottom: 1px solid var(--line-soft); }
    .cat-form { grid-template-columns: minmax(0, 1fr); }
    .cat-head { flex-wrap: wrap; }
    .cat-tools input[type="search"] { width: 100%; }
    .viewer-ab-legend { bottom: 96px; }
}

.card-note { margin-top: 10px; font-size: 0.82em; color: var(--dim); }

/* ============================================================
   Wearer's view: the scene through the progressive lens
   ============================================================ */
.stage-toolbar .tb-accent {
    display: inline-flex; align-items: center; gap: 7px;
    color: #06121f; background: var(--accent); border-color: var(--accent);
    white-space: nowrap;
}
.stage-toolbar .tb-accent:hover { background: #8cc6ff; border-color: #8cc6ff; }
.stage-toolbar .tb-accent svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

html.vision-open, html.vision-open body { overflow: hidden; }

.vision {
    position: fixed; inset: 0; z-index: 500;
    background: #05070b;
    color: #eef3fc;
    font-size: 14px;
    user-select: none; -webkit-user-select: none;
    --glass: rgba(9, 13, 21, 0.58);
    --glass-line: rgba(255, 255, 255, 0.11);
    --vision-accent: #7cc4ff;
}
.vision canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.vision.is-dragging canvas { cursor: grabbing; }
/* the butterfly drawn on the HUD is the pointer */
.vision #visionCanvas, .vision.is-dragging #visionCanvas { cursor: none; }
.vision #visionHud { pointer-events: none; cursor: default; }

.vision-panel, .vision-btn, .vision-seg {
    background: var(--glass);
    border: 1px solid var(--glass-line);
    -webkit-backdrop-filter: blur(18px) saturate(1.25);
    backdrop-filter: blur(18px) saturate(1.25);
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.vision-panel { position: absolute; border-radius: 14px; padding: 14px 16px; }
.vision-kicker { font-size: 0.72em; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--vision-accent); }

/* design, top left */
.vision-head { top: 18px; left: 18px; width: min(330px, calc(100vw - 36px)); }
.vision-name { margin-top: 6px; font-size: 1.32em; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; overflow-wrap: anywhere; }
.vision-spec { margin-top: 3px; color: rgba(226, 234, 248, 0.72); font-variant-numeric: tabular-nums; }
.vision-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 12px; }
.vision select {
    width: 100%; min-width: 0;
    font: inherit; padding: 7px 8px;
    color: #eef3fc; background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-line); border-radius: 9px;
}
.vision select:hover { border-color: rgba(255, 255, 255, 0.24); }
.vision select:focus { outline: none; border-color: var(--vision-accent); }
.vision select option, .vision select optgroup { background: #121824; color: #eef3fc; }

/* segmented controls */
.vision-seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 11px; }
.vision-row .vision-seg { background: rgba(255, 255, 255, 0.06); box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.vision-seg button {
    font: inherit; font-weight: 600; font-size: 0.92em;
    padding: 6px 13px;
    color: rgba(226, 234, 248, 0.72); background: transparent;
    border: none; border-radius: 8px;
    cursor: pointer; white-space: nowrap;
    transition: color 0.15s, background 0.15s;
}
.vision-seg button:hover { color: #fff; }
.vision-seg button.is-on { color: #04101c; background: var(--vision-accent); }

/* tools, top right */
.vision-tools { position: absolute; top: 18px; right: 18px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; max-width: calc(100vw - 36px); }
.vision-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 38px; padding: 0 14px;
    font: inherit; font-weight: 600; font-size: 0.92em;
    color: rgba(236, 242, 252, 0.86);
    border-radius: 11px;
    cursor: pointer; white-space: nowrap; touch-action: none;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.vision-btn:hover { color: #fff; border-color: rgba(255, 255, 255, 0.3); }
.vision-btn.is-on { color: var(--vision-accent); border-color: rgba(124, 196, 255, 0.6); background: rgba(22, 44, 70, 0.62); }
.vision-btn.vision-icon { width: 38px; padding: 0; }
.vision-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#visionCompare.is-on { color: #04101c; background: var(--vision-accent); border-color: var(--vision-accent); }
.vision :focus-visible { outline: 2px solid var(--vision-accent); outline-offset: 2px; }

/* read-out, bottom left */
.vision-read { left: 18px; bottom: 18px; width: 252px; transition: opacity 0.2s; pointer-events: none; }
.vision-read.is-off { opacity: 0; }
.vision-read.is-changed { animation: vision-changed 0.9s ease-out; }
@keyframes vision-changed {
    0% { border-color: var(--vision-accent); box-shadow: 0 0 0 3px rgba(124, 196, 255, 0.35), 0 10px 34px rgba(0, 0, 0, 0.32); }
    100% { border-color: var(--glass-line); box-shadow: 0 0 0 0 rgba(124, 196, 255, 0), 0 10px 34px rgba(0, 0, 0, 0.32); }
}
.vision-read dl { margin-top: 8px; }
.vision-read dl > div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 5px 0; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.vision-read dl > div:first-child { border-top: none; }
.vision-read dt { color: rgba(226, 234, 248, 0.66); font-size: 0.9em; }
.vision-read dd { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.vision-state {
    display: flex; align-items: center; gap: 8px;
    margin-top: 8px; padding: 7px 10px;
    font-weight: 650;
    background: rgba(255, 255, 255, 0.05); border-radius: 9px;
}
.vision-state::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 10px currentColor; }
.vision-state[data-state="soft"]::before { background: var(--warn); }
.vision-state[data-state="blurred"]::before { background: var(--bad); }
.vision-state[data-state="sharp"] { color: #9df0c8; }
.vision-state[data-state="soft"] { color: #ffd98c; }
.vision-state[data-state="blurred"] { color: #ffaaaa; }

/* zone legend, right */
.vision-legend { right: 18px; top: 68px; display: flex; flex-direction: column; gap: 7px; padding: 11px 14px; font-size: 0.86em; color: rgba(226, 234, 248, 0.82); pointer-events: none; }
.vision-legend span { display: flex; align-items: center; gap: 9px; }
.vision-legend i { flex: none; width: 22px; height: 0; border-top: 2px solid #5cc7ff; border-radius: 2px; }
.vision-legend i.vl-mark { border-top-color: #ffdb5c; }
.vision-legend .vl-bands { gap: 4px; }
.vision-legend .vl-bands b {
    flex: 1; padding: 3px 7px; border-radius: 5px; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums;
    color: #fff; background: color-mix(in srgb, var(--c) 38%, transparent); border: 1px solid var(--c);
}

/* where to look, bottom centre */
.vision-foot { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 9px; max-width: calc(100vw - 36px); pointer-events: none; }
.vision-foot .vision-seg { pointer-events: auto; }
.vision-hint { font-size: 0.82em; color: rgba(236, 242, 252, 0.62); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8); text-align: center; }
.vision-note { position: absolute; right: 18px; bottom: 18px; width: min(300px, 26vw); font-size: 0.74em; line-height: 1.4; text-align: right; color: rgba(236, 242, 252, 0.5); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8); pointer-events: none; }

/* the reference picture is announced, so it is never mistaken for the lens */
.vision.is-compare::after {
    content: "Reference: every distance in focus, no lens effect";
    position: absolute; top: 74px; left: 50%; transform: translateX(-50%);
    padding: 7px 14px;
    font-weight: 600; font-size: 0.9em; color: #04101c;
    background: var(--vision-accent); border-radius: 999px;
    white-space: nowrap; pointer-events: none;
}

.vision-loading { position: absolute; inset: 0; display: grid; place-items: center; background: #05070b; }
.vision-loading-box { width: min(300px, 70vw); text-align: center; color: rgba(236, 242, 252, 0.8); }
.vision-progress { height: 3px; margin-top: 14px; background: rgba(255, 255, 255, 0.1); border-radius: 2px; overflow: hidden; }
.vision-progress i { display: block; width: 0; height: 100%; background: var(--vision-accent); transition: width 0.2s; }
.vision-loading.is-error .vision-progress { display: none; }
.vision-loading.is-error .vision-loading-box { color: #ffb4b4; }

@media (max-width: 1040px) {
    .vision-tools { max-width: calc(100vw - 380px); }
    .vision-legend { top: 114px; }
}
@media (max-width: 900px) {
    .vision-tools { max-width: calc(100vw - 340px); }
    .vision-legend { top: 160px; }
    .vision-note { display: none; }
    .vision-read { width: 210px; bottom: 98px; }
    .vision-head { width: min(290px, calc(100vw - 36px)); padding: 11px 13px; }
    .vision-name { font-size: 1.12em; }
}
@media (max-width: 640px) {
    .vision-head { top: 10px; left: 10px; right: 10px; width: auto; }
    .vision-tools { top: auto; bottom: 96px; right: 10px; left: 10px; max-width: none; justify-content: center; }
    .vision-legend { top: 138px; right: 10px; }
    .vision-read { display: none; }
    .vision-foot { bottom: 10px; }
    .vision-seg button { padding: 6px 10px; }
    .vision-hint { display: none; }
    .vision.is-compare::after { top: 138px; }
}

/* ---------- Frame database ---------- */
.fr-mini { width: 34px; height: 24px; flex: none; }
.fr-mini path { fill: rgba(111, 182, 255, 0.12); stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.fr-badge {
    flex: none; padding: 1px 6px; border-radius: 999px;
    font-size: 0.72em; color: var(--warn); border: 1px solid rgba(245, 184, 75, 0.5);
}
.fr-stage { margin-bottom: 12px; padding: 8px; background: var(--field); border: 1px solid var(--line-soft); border-radius: 8px; }
.fr-draw { display: block; width: 100%; max-height: 230px; }
.fr-draw .fr-lens { fill: rgba(255, 255, 255, 0.04); stroke-width: 1.8; vector-effect: non-scaling-stroke; }
.fr-draw .fr-lens.od { stroke: var(--od); }
.fr-draw .fr-lens.os { stroke: var(--os); }
.fr-draw .fr-box { fill: none; stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.fr-draw .fr-tag { font-size: 5px; fill: var(--muted); }
.fr-warn { margin-top: 10px; font-size: 0.88em; color: var(--warn); }

/* ---------- Capture with the phone ---------- */
.cat-foot a.btn { text-decoration: none; }
.cat-form input[type="file"] {
    width: 100%; font: inherit; padding: 7px 8px;
    color: var(--text); background: var(--field);
    border: 1px solid var(--line); border-radius: 7px;
}
.cp-grid { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; align-items: start; }
.cp-qr img { display: block; width: 100%; height: auto; border-radius: 10px; image-rendering: pixelated; }
.cp-qr p { margin-top: 10px; font-size: 0.9em; }
.cp-qr small { display: block; margin-top: 4px; color: var(--dim); line-height: 1.35; }
.cp-shots { display: flex; flex-direction: column; gap: 8px; }
.cp-shot {
    display: flex; align-items: center; gap: 10px; min-height: 62px; padding: 8px 10px;
    background: var(--field); border: 1px solid var(--line-soft); border-radius: 9px;
}
.cp-num {
    flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
    font-size: 0.8em; font-weight: 700; color: var(--muted); border: 1.5px solid var(--line);
}
.cp-shot.is-done .cp-num { color: var(--bg); background: var(--good); border-color: var(--good); }
.cp-what { flex: 1; min-width: 0; }
.cp-what strong { display: block; font-weight: 600; }
.cp-what small { display: block; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.35; }
.cp-thumb { flex: none; }
.cp-thumb img { display: block; width: 78px; height: 46px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.cp-note { margin-top: 14px; font-size: 0.86em; color: var(--dim); }
.cp-shape { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line, rgba(128, 128, 128, 0.3)); }
.cp-shape h4 { margin: 0 0 8px; }
.cp-shape-pic { display: block; width: 100%; height: auto; border-radius: 8px; background: #fff; }
.cp-sizes { margin-top: 12px; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.cp-sizes th, .cp-sizes td { padding: 4px 16px 4px 0; text-align: left; font-size: 0.92em; }
.cp-sizes tr:first-child td { color: var(--dim); font-size: 0.8em; }
.cp-sizes th { font-weight: 600; }
.cp-warn { color: #d9892b; }
.cp-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.cp-actions .cp-note { margin-top: 0; }
@media (max-width: 720px) {
    .cp-grid { grid-template-columns: 1fr; }
    .cp-qr img { max-width: 230px; }
}
