:root {
  color-scheme: dark;
  --bg: #11151b;
  --surface: #181e27;
  --side: #141921;
  --inset: #10151c;
  --line: #303b49;
  --grid: #23303e;
  --text: #eef4fa;
  --muted: #a9b7c8;
  --accent: #60e2c6;
  --on-accent: #09251f;
  --selected: #1c3739;
  --error: #ffb1a6;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #fff;
  --side: #f9fbfd;
  --inset: #f4f7fa;
  --line: #c6d1de;
  --grid: #e0e7ef;
  --text: #182637;
  --muted: #4a5e72;
  --accent: #006754;
  --on-accent: #fff;
  --selected: #d7eee8;
  --error: #a7291d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 1rem/1.5 system-ui, sans-serif; }
a { color: inherit; }
button, input, textarea { font: inherit; }
button, .file-button { cursor: pointer; }
:focus-visible, .file-button:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
.layout { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--side); border-right: 1px solid var(--line); padding: 28px 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; margin: 0 4px 30px; font-size: .92rem; letter-spacing: .03em; }
.brand img { border-radius: 9px; }
.brand strong { color: var(--accent); }
.brand small { display: block; color: var(--muted); font-size: .79rem; letter-spacing: 0; }
nav { display: grid; gap: 5px; }
nav a { display: block; padding: 8px 10px; border: 1px solid transparent; border-radius: 7px; color: var(--muted); text-decoration: none; font-size: .9rem; }
nav a:hover { border-color: var(--line); }
nav a[aria-current="page"] { color: var(--accent); background: var(--selected); border-color: var(--line); font-weight: 650; }
.machine { display: grid; margin: 28px 4px 0; padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--inset); }
.machine span, .machine small { color: var(--muted); font-size: .8rem; }
.machine strong { font-size: .92rem; margin: 5px 0 2px; }
main { min-width: 0; width: min(100%, 1500px); margin-inline: auto; padding: 0 clamp(16px, 3vw, 48px) 36px; }
.topbar, .panel-heading, .file-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.topbar { min-height: 72px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .9rem; padding-block: 10px; }
.version { margin-left: .35rem; color: var(--accent); font-family: ui-monospace, monospace; }
.intro { margin: 26px 0 23px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.75rem, 3vw, 2.5rem); line-height: 1.18; letter-spacing: -.035em; }
.intro p { margin-top: 7px; color: var(--muted); }
h2 { font-size: 1.1rem; line-height: 1.3; }
.panels { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; gap: 16px; }
.panel { min-width: 0; padding: clamp(14px, 2vw, 22px); border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.panel-heading { margin-bottom: 14px; }
.format { color: var(--muted); font-size: .82rem; }
.preview { display: grid; place-items: center; height: clamp(235px, 38vh, 430px); border: 1px dashed var(--line); border-radius: 8px; overflow: hidden; background: linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 24px 24px, linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 24px 24px, var(--inset); }
.empty { display: grid; gap: 5px; justify-items: center; padding: 16px; text-align: center; color: var(--muted); }
.empty strong { color: var(--text); }
.crosshair { color: var(--accent); font-size: 2.75rem; line-height: 1; margin-bottom: 6px; }
.preview img, .preview iframe { display: block; width: 100%; height: 100%; min-height: 0; min-width: 0; object-fit: contain; border: 0; }
.file-meta { justify-content: start; margin-top: 10px; font-size: .875rem; }
#file-name { flex-basis: 100%; overflow-wrap: anywhere; color: var(--muted); }
.text-action { color: var(--accent); background: none; border: 0; padding: 4px 0; text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.drawing-actions, .form-actions { margin-top: 14px; }
.primary, .secondary { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 13px; border-radius: 7px; border: 1px solid var(--line); font-size: .9rem; font-weight: 650; text-decoration: none; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.secondary { background: var(--inset); color: var(--text); }
.primary:hover, .secondary:hover { filter: brightness(1.12); }
button:disabled, .file-button:has(input:disabled) { opacity: .6; cursor: default; }
.file-button { position: relative; }
.file-button input { position: absolute; inset: 0; margin: 0; width: 100%; opacity: 0; cursor: inherit; }
form > label { display: block; margin-top: 10px; font-size: .9rem; font-weight: 550; }
form > label span { color: var(--accent); }
form input, textarea { display: block; width: 100%; margin-top: 4px; background: var(--inset); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; }
form input { min-height: 42px; }
textarea { resize: vertical; }
::placeholder { color: var(--muted); }
.status { color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.status:not(:empty) { margin-top: 8px; }
[data-error="true"] { color: var(--error); }
.library { margin-top: 16px; }
#library-status { color: var(--muted); }
#cards { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
#cards button { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; justify-content: space-between; width: 100%; min-height: 44px; padding: 8px 12px; text-align: left; overflow-wrap: anywhere; }
#cards small { color: var(--muted); }
.back-link { margin-top: 14px; }

@media (max-width: 1050px) {
  .layout { grid-template-columns: 215px minmax(0, 1fr); }
}
@media (max-width: 850px) {
  .layout { display: block; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px 8px; display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
  .brand { margin: 0; }
  .machine { margin: 0 0 0 auto; padding: 0; border: 0; background: none; }
  .machine span { display: none; }
  .machine strong { margin: 0; }
  nav { order: 1; width: 100%; display: flex; overflow-x: auto; padding: 3px; }
  nav a { flex: 0 0 auto; min-height: 44px; }
}
@media (max-width: 600px) {
  .panels { grid-template-columns: minmax(0, 1fr); }
  .topbar { min-height: 0; }
  .machine { margin-left: 0; }
}

#analysis-result { margin-top: 16px; }
#recognized-fields { display: grid; gap: 6px; list-style: none; padding: 0; }
#recognized-fields li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px; }
#recognized-fields span { flex: 1 1 220px; overflow-wrap: anywhere; }
.table-scroll { overflow-x: auto; margin-top: 12px; }
.table-scroll table { width: 100%; min-width: 560px; border-collapse: collapse; text-align: left; }
.table-scroll th, .table-scroll td { border-bottom: 1px solid var(--line); padding: 8px 10px; vertical-align: top; overflow-wrap: anywhere; }
.table-scroll th { color: var(--muted); font-size: .9rem; }
.uncertain { background: #574222; color: #ffdf97; }
:root[data-theme="light"] .uncertain { background: #ffefc7; color: #68460b; }
