/* QR Studio - styles */

:root {
    color-scheme: light;
    --paper: #eef0f3;
    --surface: #ffffff;
    --sunken: #e6e9ee;
    --ink: #0f151d;
    --ink-2: #414b59;
    --ink-3: #5b6675;
    --line: #d5dae1;
    --line-strong: #b4bcc7;
    --accent: #2947f0;
    --accent-hover: #1d37cc;
    --on-accent: #ffffff;
    --warn: #7d4a00;
    --warn-bg: #fff3dc;
    --danger: #b3261e;
    --danger-bg: #fde9e7;
    --danger-solid: #b3261e;
    --shadow: 0 1px 2px rgba(15, 21, 29, .06), 0 10px 30px rgba(15, 21, 29, .07);
    --font: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --paper: #0b0e13;
    --surface: #131821;
    --sunken: #1b212c;
    --ink: #edf0f5;
    --ink-2: #b3bcc8;
    --ink-3: #8e99a8;
    --line: #283040;
    --line-strong: #3a4557;
    --accent: #8fa2ff;
    --accent-hover: #a9b8ff;
    --on-accent: #0b0e13;
    --warn: #f2b75b;
    --warn-bg: #2a2110;
    --danger: #ff8a80;
    --danger-bg: #2e1512;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .4);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

h2 { margin: 0 0 14px; font-size: 17px; font-weight: 650; letter-spacing: -.005em; }
p { margin: 0; }
code { font-family: var(--mono); font-size: .92em; background: var(--sunken); padding: 1px 5px; border-radius: 4px; }

.sr-only {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

.app { max-width: 1120px; margin: 0 auto; padding: 16px 24px 48px; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 24px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px; padding: 0 16px;
    border: 1px solid var(--line-strong); border-radius: 10px;
    background: var(--surface); color: var(--ink);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
    transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: var(--sunken); border-color: var(--ink-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 13.5px; }

.icon-btn {
    display: inline-grid; place-items: center; width: 40px; height: 40px;
    border: 0; border-radius: 10px; background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }

.link-btn {
    border: 0; background: none; padding: 0; font: inherit; font-weight: 600;
    color: var(--accent); text-decoration: underline; cursor: pointer;
}

/* ---------- Layout ---------- */
.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
    grid-template-areas: "content stage" "style stage";
    column-gap: 56px; row-gap: 40px; align-items: start;
}
.panel-content { grid-area: content; }
.panel-style { grid-area: style; }
.stage { grid-area: stage; position: sticky; top: 20px; }

/* ---------- Segmented radios ---------- */
.segmented {
    display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; max-width: 100%;
    background: var(--sunken); border-radius: 11px;
}
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segmented label > span {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 7px 14px; border-radius: 8px; white-space: nowrap;
    color: var(--ink-2); font-size: 14px; font-weight: 550;
    transition: background .15s, color .15s;
}
.segmented input:checked + span {
    background: var(--surface); color: var(--ink);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 1px var(--line);
}
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

#kindGroup { display: flex; }
#kindGroup label { flex: 1; }

.segmented-icons { display: flex; }
.segmented-icons label { flex: 1; }
.segmented-icons label > span { flex-direction: column; gap: 4px; padding: 8px 6px; font-size: 12.5px; }

/* ---------- Fields ---------- */
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; margin-top: 18px; }
.field { min-width: 0; }
.field.wide, .field-wide { grid-column: 1 / -1; }
.field > label:not(.drop):not(.check) { display: block; margin-bottom: 6px; font-size: 13.5px; font-weight: 600; }

input[type="text"], input[type="tel"], input[type="email"], input[type="url"],
input[type="date"], input[type="time"], select, textarea {
    width: 100%; min-height: 42px; padding: 10px 12px;
    background: var(--surface); color: var(--ink);
    border: 1px solid var(--line-strong); border-radius: 10px;
    font: inherit;
}
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }

.check { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 550; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.hint {
    margin-top: 10px; padding: 10px 12px; border-radius: 10px;
    background: var(--warn-bg); color: var(--warn); font-size: 13.5px;
}
.hint .link-btn { color: inherit; }

.meter { margin-top: 14px; }
.meter-track { height: 6px; border-radius: 999px; background: var(--sunken); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .2s; }
.meter[data-level="high"] .meter-fill { background: var(--warn); }
.meter[data-level="over"] .meter-fill { background: var(--danger); }
.meter-text { margin-top: 6px; font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.meter[data-level="over"] .meter-text { color: var(--danger); }

/* ---------- Drop zones and image payload ---------- */
.drop {
    display: grid; gap: 4px; padding: 26px 18px; text-align: center; cursor: pointer;
    background: var(--surface); border: 1.5px dashed var(--line-strong); border-radius: 12px;
    transition: border-color .15s, background .15s;
}
.drop:hover, .drop:focus-within { border-color: var(--accent); }
.drop-title { font-weight: 600; }
.drop-sub { font-size: 13px; color: var(--ink-3); }
.drop-small { flex: 1; min-width: 0; padding: 12px 14px; text-align: left; font-weight: 550; font-size: 14px; }

.img-result {
    display: flex; align-items: center; gap: 14px; margin-top: 12px; padding: 12px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.img-result img { image-rendering: pixelated; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.img-info { display: grid; flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.img-info span { font-size: 13px; color: var(--ink-3); }

.callout {
    margin-top: 12px; padding: 12px 14px; border-radius: 10px;
    background: var(--sunken); color: var(--ink-2); font-size: 13.5px;
}

/* ---------- Stage ---------- */
.stage {
    padding: 20px; background: var(--surface);
    border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
}

.viewfinder {
    position: relative; display: grid; place-items: center; aspect-ratio: 1;
    padding: 36px; background: var(--sunken); border-radius: 14px;
}
.vf { position: absolute; width: 26px; height: 26px; border: 0 solid var(--accent); }
.vf-tl { top: 12px; left: 12px; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 9px; }
.vf-tr { top: 12px; right: 12px; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 9px; }
.vf-bl { bottom: 12px; left: 12px; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 9px; }
.vf-br { bottom: 12px; right: 12px; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 9px; }

#preview {
    display: block; width: 100%; height: auto; aspect-ratio: 1;
    border-radius: 4px; box-shadow: 0 2px 12px rgba(0, 0, 0, .16);
}

.stage-message { text-align: center; padding: 0 8px; }
.stage-title { font-weight: 650; font-size: 16px; }
.stage-sub { margin-top: 6px; font-size: 13.5px; color: var(--ink-3); max-width: 26ch; margin-inline: auto; }
.stage-error .stage-title { color: var(--danger); }

.readout {
    display: grid; gap: 4px; margin: 16px 0 0; font-size: 13px; font-variant-numeric: tabular-nums;
}
.readout > div { display: grid; grid-template-columns: 8.5em 1fr; gap: 10px; }
.readout dt { color: var(--ink-3); }
.readout dd { margin: 0; }

.notes { list-style: none; display: grid; gap: 8px; margin: 12px 0 0; padding: 0; }
.notes:empty { display: none; }
.note { padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.note-warn { background: var(--warn-bg); color: var(--warn); }
.note-info { background: var(--sunken); color: var(--ink-2); }

.export { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.export .btn-primary { grid-column: 1 / -1; }
.export .btn { padding: 0 8px; }
.btn-save { width: 100%; margin-top: 8px; }

/* ---------- Style panel ---------- */
.style-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 32px; }
.control { min-width: 0; }
.control-label {
    display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px;
    font-size: 13.5px; font-weight: 600;
}
.control-label output { font-weight: 450; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.control-label-sub { margin-top: 14px; }
.control-help { margin-top: 8px; font-size: 13px; color: var(--ink-3); max-width: 60ch; }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.colors { display: grid; gap: 10px; }
.swatch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.swatch input[type="color"] {
    -webkit-appearance: none; appearance: none; flex: none;
    width: 44px; height: 44px; padding: 3px;
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; cursor: pointer;
}
.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
.swatch input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }
.swatch-text { display: flex; flex-direction: column; font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.swatch-text output { font: 400 12.5px var(--mono); color: var(--ink-3); }

.logo-control { margin-top: 28px; }
.logo-row { display: flex; align-items: center; gap: 12px; }
.logo-thumb {
    flex: none; width: 44px; height: 44px; object-fit: contain;
    background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}

/* ---------- History and bulk ---------- */
.library {
    display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 48px; align-items: start;
    margin-top: 56px; padding-top: 32px; border-top: 1px solid var(--line);
}
.library-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.library-head h2 { margin: 0; }
.count {
    min-width: 24px; padding: 1px 8px; text-align: center; border-radius: 999px;
    background: var(--sunken); color: var(--ink-2); font-size: 12.5px; font-weight: 600;
}
.library-actions { margin-left: auto; display: flex; gap: 2px; }

.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 12px; }
.history-empty { grid-column: 1 / -1; color: var(--ink-3); font-size: 14px; }
.history-item { position: relative; }
.history-load {
    display: grid; gap: 6px; width: 100%; padding: 0; border: 0; background: none;
    color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.history-load canvas {
    width: 100%; height: auto; aspect-ratio: 1; background: #fff;
    border: 1px solid var(--line); border-radius: 8px; transition: border-color .15s;
}
.history-load:hover canvas { border-color: var(--accent); }
.history-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--ink-2); }
.history-del {
    position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; padding: 0;
    border: 0; border-radius: 50%; background: var(--ink); color: var(--paper);
    font-size: 16px; line-height: 1; cursor: pointer; opacity: 0;
}
.history-item:hover .history-del, .history-del:focus-visible { opacity: 1; }
@media (hover: none) { .history-del { opacity: 1; } }

.bulk summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; }
.bulk summary::-webkit-details-marker { display: none; }
.bulk summary::before {
    content: ""; width: 7px; height: 7px; margin: 0 4px 0 2px;
    border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3);
    transform: rotate(-45deg); transition: transform .15s;
}
.bulk[open] summary::before { transform: rotate(45deg); }
.bulk summary h2 { margin: 0; }
.bulk .control-label { margin-top: 14px; }
.bulk textarea { min-height: 110px; font: 13px/1.5 var(--mono); }
.bulk-actions { display: flex; gap: 8px; margin-top: 12px; }
.bulk-status { margin-top: 10px; font-size: 13.5px; color: var(--ink-2); }
.bulk-status:empty { display: none; }

.footnote { margin-top: 40px; font-size: 13px; color: var(--ink-3); }

/* ---------- Scanner ---------- */
.modal {
    position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
    padding: 16px; background: rgba(6, 8, 12, .6);
}
.modal-card {
    width: min(440px, 100%); padding: 18px; background: var(--surface);
    border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2 { margin: 0; }
.scanner-view { min-height: 240px; overflow: hidden; background: #000; border-radius: 12px; }
.scan-status { margin-top: 12px; font-size: 14px; color: var(--ink-2); }
.scan-result { margin-top: 12px; }
.scan-text {
    display: block; max-height: 120px; overflow: auto; padding: 10px 12px;
    background: var(--sunken); border-radius: 10px; font: 13px/1.5 var(--mono); overflow-wrap: anywhere;
}
.scan-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- Image role sheet, drop overlay, toasts ---------- */
.sheet {
    position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translateX(-50%);
    width: min(440px, calc(100vw - 32px)); padding: 16px;
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: 16px; box-shadow: var(--shadow);
}
.sheet-title { margin-bottom: 12px; font-weight: 650; }
.sheet-actions { display: grid; gap: 8px; }

.drop-overlay {
    position: fixed; inset: 10px; z-index: 45; display: none; place-items: center; pointer-events: none;
    border: 3px dashed var(--accent); border-radius: 20px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    font-size: 22px; font-weight: 650; color: var(--accent);
}
body.dragging .drop-overlay { display: grid; }

.toasts { position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translateX(-50%); pointer-events: none; }
.toast {
    padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--paper);
    font-size: 14px; font-weight: 550; box-shadow: var(--shadow); animation: toast-in .18s ease-out;
}
.toast-error { background: var(--danger-solid); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "content" "stage" "style"; row-gap: 32px; }
    .stage { position: static; max-width: 460px; width: 100%; margin-inline: auto; }
    .library { grid-template-columns: minmax(0, 1fr); gap: 32px; }
}

@media (max-width: 560px) {
    .app { padding: 10px 16px 40px; }
    .fields, .style-grid { grid-template-columns: minmax(0, 1fr); }
    #kindGroup { flex-wrap: nowrap; }
    #kindGroup label > span { padding: 8px 4px; font-size: 13.5px; }
    .viewfinder { padding: 30px; }
}

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