:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1c2230; --muted: #5d6677; --line: #dde1e8;
  --accent: #0b6bcb; --accent-ink: #ffffff; --ok: #1f8a4c; --warn: #b26a00; --bad: #c0392b;
  --sel: #fff4c2; --code-bg: #0f1522; --code-ink: #d8e1f0; --code-hl: #34507a;
  --hole: #0b6bcb; --plane: #e8ecf3; --plane-line: #9aa6b8;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151d; --panel: #1a202b; --ink: #e5e9f0; --muted: #9aa4b5; --line: #2c3442;
    --sel: #3b3519; --plane: #232b38; --plane-line: #56627a; --hole: #5aa9ff; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border-radius: 6px; padding: 8px 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:disabled { opacity: .45; cursor: not-allowed; }
button.ghost:hover { border-color: var(--accent); }
button.small { padding: 4px 10px; font-size: 13px; }
input, select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 5px;
  background: var(--panel); color: var(--ink); }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 18px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 8px; }
.logo { color: var(--accent); }
.steps { display: flex; gap: 6px; flex: 1; }
.steps span { padding: 4px 10px; border-radius: 20px; color: var(--muted); font-size: 13px; }
.steps span.on { background: var(--accent); color: var(--accent-ink); }

.screen { padding: 20px; max-width: 1700px; margin: 0 auto; }
.intro h1 { margin: 10px 0 6px; font-size: 24px; }
.intro p { color: var(--muted); max-width: 820px; line-height: 1.5; }
.drops { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0; }
.drop { background: var(--panel); border: 2px dashed var(--line); border-radius: 12px; padding: 34px 20px;
  text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); }
.drop.has { border-style: solid; border-color: var(--ok); }
.drop input { display: none; }
.drop-icon { font-size: 34px; color: var(--accent); }
.drop-title { font-weight: 600; font-size: 16px; margin-top: 6px; }
.drop-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.drop-file { margin-top: 14px; font-size: 13px; color: var(--muted); word-break: break-all; }
.drop.has .drop-file { color: var(--ok); font-weight: 600; }
.row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.actions { margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .field select { color: var(--ink); min-width: 220px; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check input { min-width: 0; }
.ocr-state { font-size: 13px; color: var(--muted); }
.ocr-state b.ok { color: var(--ok); } .ocr-state b.no { color: var(--warn); }
.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); padding: 10px 14px; border-radius: 8px; }

.runbox { max-width: 760px; margin: 40px auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 30px; }
.log { font-family: Consolas, monospace; font-size: 13px; color: var(--muted); padding-left: 22px; }
.log li { margin: 4px 0; } .log li.err { color: var(--bad); font-weight: 600; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite; }
.spinner.stop { animation: none; border-top-color: var(--bad); }
@keyframes spin { to { transform: rotate(360deg); } }

.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; min-width: 110px; }
.stat b { display: block; font-size: 18px; } .stat span { font-size: 12px; color: var(--muted); }
.notes { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.note { font-size: 13px; padding: 6px 12px; border-radius: 6px; background: color-mix(in srgb, var(--warn) 10%, var(--panel)); border-left: 3px solid var(--warn); }
.note.info { background: color-mix(in srgb, var(--accent) 8%, var(--panel)); border-left-color: var(--accent); }

.grid { display: grid; grid-template-columns: minmax(280px, 0.9fr) minmax(640px, 2fr) minmax(380px, 1.3fr); gap: 14px; align-items: start; }
@media (max-width: 1500px) { .grid { grid-template-columns: minmax(280px, 1fr) minmax(640px, 2fr); } .panel.right { grid-column: 1 / -1; } }
@media (max-width: 800px) { .grid, .drops { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-width: 0; }
.panel h3 { margin: 4px 0 10px; font-size: 15px; }
.panel h3 small { color: var(--muted); font-weight: 400; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button { padding: 4px 10px; font-size: 13px; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#partView { width: 100%; height: auto; max-height: 560px; background: var(--bg); border-radius: 8px; }
#partView .pl { fill: var(--plane); stroke: var(--plane-line); stroke-width: .4; }
#partView .hole { fill: var(--panel); stroke: var(--hole); stroke-width: .8; cursor: pointer; }
#partView .hole.side { fill: var(--hole); opacity: .6; }
#partView .hole.sel { stroke: var(--warn); stroke-width: 1.6; fill: var(--sel); }
#partView .hole.off { stroke-dasharray: 2 1.5; opacity: .5; }
#partView text { font-size: 4px; fill: var(--muted); pointer-events: none; }
#partView .axis { stroke: var(--bad); stroke-width: .6; }
#partView .axis.y { stroke: var(--ok); }
.hint { font-size: 12px; color: var(--muted); }
.drawing { height: 560px; }
.drawing iframe, .drawing img { width: 100%; height: 100%; border: 0; object-fit: contain; background: #fff; border-radius: 6px; }
.drawing-text { white-space: pre-wrap; font-size: 12px; max-height: 560px; overflow: auto; background: var(--bg); padding: 10px; border-radius: 6px; }

.datums { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.datums label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.datums select { min-width: 190px; }
.table-head { display: flex; justify-content: space-between; align-items: center; }
.table-wrap { max-height: 640px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 6px 4px; position: sticky; top: 0; background: var(--panel); }
td { border-bottom: 1px solid var(--line); padding: 4px; vertical-align: top; }
tr.sel td { background: var(--sel); }
tr.off td { opacity: .5; }
td input.num { width: 62px; }
.table-wrap table { min-width: 720px; }
td .lbl { max-width: 170px; }
td select { max-width: 165px; font-size: 12px; padding: 3px 4px; }
td .lbl { font-weight: 600; }
td .sub { font-size: 11px; color: var(--muted); margin-top: 2px; max-width: 260px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 10px; white-space: nowrap; }
.badge.associato { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.assunto { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.solo { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.badge.non { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }

.code-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.code-head .btns { display: flex; gap: 6px; }
.code { background: var(--code-bg); color: var(--code-ink); font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 12px; line-height: 1.45; padding: 10px; border-radius: 8px; max-height: 700px; overflow: auto; margin: 0;
  position: relative; }
.code .ln { display: block; white-space: pre; }
.code .ln.hl { background: var(--code-hl); box-shadow: inset 3px 0 0 #ffd479; }
.code .kw { color: #7fc4ff; } .code .nm { color: #ffd479; } .code .cm { color: #8ea0b8; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; max-width: 720px; width: 95%;
  background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.35); }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; padding: 10px 14px; display: flex; flex-direction: column; gap: 10px; }
legend { font-weight: 600; padding: 0 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two .field input { min-width: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 20; }
.login { display: flex; justify-content: center; padding-top: 12vh; }
.login .runbox { width: 100%; max-width: 380px; margin: 0 16px; display: flex; flex-direction: column; gap: 12px; }
.login .field input { min-width: 0; width: 100%; }
.srv-key { font-size: 13px; color: var(--muted); }
.example-box { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.steps-list { line-height: 1.6; padding-left: 20px; }
