:root {
  --bg: #E6EBEE; --panel: #F6F8F9; --panel2: #EDF1F3; --line: #CAD3D9; --ink: #1B2833; --muted: #5B6A76;
  --accent: #C77C00; --accent-ink: #fff; --view: #DCE3E8; --grid: rgba(27,40,51,.09); --module: #28527F;
  --ok: #23884D; --bad: #C8323A; --warnbg: #FFF4DB; --badbg: #FCE8E8; --okbg: #E3F3E9;
  --ui: 'Barlow', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --num: 'Barlow Semi Condensed', 'Barlow', 'Arial Narrow', system-ui, sans-serif;
  box-sizing: border-box; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141A20; --panel: #1B232B; --panel2: #212B34; --line: #33414C; --ink: #DCE4EA; --muted: #8E9BA6;
    --accent: #F2AA2E; --accent-ink: #1B1405; --view: #0F151A; --grid: rgba(220,228,234,.07); --module: #5B93D4;
    --ok: #4CC47F; --bad: #F06A70; --warnbg: #3A2F14; --badbg: #3D1D20; --okbg: #183424;
  }
}
:root[data-theme="dark"] {
  --bg: #141A20; --panel: #1B232B; --panel2: #212B34; --line: #33414C; --ink: #DCE4EA; --muted: #8E9BA6;
  --accent: #F2AA2E; --accent-ink: #1B1405; --view: #0F151A; --grid: rgba(220,228,234,.07); --module: #5B93D4;
  --ok: #4CC47F; --bad: #F06A70; --warnbg: #3A2F14; --badbg: #3D1D20; --okbg: #183424;
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); height: 100%; }
body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 15px/1.4 var(--ui); display: grid; grid-template-rows: auto 1fr auto; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* header */
.top { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; letter-spacing: .01em; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 13px; }
#pname { flex: 1 1 200px; max-width: 340px; background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 5px 9px; font-weight: 600; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 4px; padding: 6px 12px; font-weight: 600; cursor: pointer; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button:hover { filter: brightness(1.06); }
button:disabled { opacity: .6; cursor: progress; }

/* workspace */
main { display: grid; grid-template-columns: 318px minmax(0, 1fr) 410px; min-height: 0; }
aside { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
aside.left { border-right: 1px solid var(--line); }
aside.right { border-left: 1px solid var(--line); }
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel2); }
.tabs button { flex: 1; background: none; color: var(--muted); border-radius: 0; padding: 9px 4px; font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.pane { overflow: auto; padding: 4px 14px 18px; flex: 1; min-height: 0; }
.pane h4 { margin: 16px 0 6px; font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .02em; display: flex; align-items: center; gap: 7px; }

/* form fields (from app1.js markup) */
.fld { display: grid; grid-template-columns: 1fr 104px; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; }
.fld > span { color: var(--ink); }
.fld em { font-style: normal; color: var(--muted); margin-left: 5px; font-size: 12.5px; }
.fld input, .fld select, .trio input, .row select, .inl input { width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 3px; padding: 4px 7px; font-family: var(--num); font-variant-numeric: tabular-nums; min-width: 0; }
.fld select { font-family: var(--ui); }
.fld:has(select) { grid-template-columns: 1fr; gap: 3px; }
.fld.chk { grid-template-columns: 18px 1fr; }
.fld.chk input { width: 16px; height: 16px; accent-color: var(--accent); }
.grp { border-top: 1px solid var(--line); padding-bottom: 8px; }
.grp:first-of-type { border-top: 0; }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 2px; vertical-align: -1px; margin-right: 6px; }
.sw.dash { background: none; border-top: 2px dashed; height: 0; width: 16px; vertical-align: 3px; border-radius: 0; }
.trio { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 4px; }
.trio label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.secinfo { font-family: var(--num); font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.note { background: var(--panel2); border-left: 3px solid var(--accent); padding: 8px 10px; margin: 12px 0; font-size: 13.5px; border-radius: 0 3px 3px 0; }
.note.warn { background: var(--warnbg); }
.note.bad { background: var(--badbg); border-left-color: var(--bad); }
.optbar { margin: 10px 0 4px; padding: 10px; background: var(--panel2); border-radius: 4px; font-size: 13.5px; }
.optbar p { margin: 0 0 8px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.inl { display: flex; align-items: center; gap: 6px; }
.inl input { width: 70px; }
.muted { color: var(--muted); font-size: 13.5px; }

/* viewport */
.view { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--view); }
.vbar { display: flex; gap: 10px; align-items: center; padding: 7px 10px; flex-wrap: wrap; border-bottom: 1px solid var(--line); background: var(--panel); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg button { background: none; color: var(--ink); border-radius: 0; padding: 5px 10px; font-weight: 500; font-size: 13.5px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }
#combo { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; max-width: 260px; font-size: 13.5px; }
.vbar label { font-size: 13.5px; display: flex; gap: 5px; align-items: center; }
.vbar label input { accent-color: var(--accent); }
#viewwrap { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#cv { display: block; touch-action: none; cursor: grab; }
#cv:active { cursor: grabbing; }
.legend { position: absolute; left: 10px; right: 10px; top: 10px; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; pointer-events: none; }
.legend span { background: color-mix(in srgb, var(--panel) 86%, transparent); padding: 2px 8px; border-radius: 3px; display: inline-flex; align-items: center; }
.legend.bad span, .legend.bad { color: var(--bad); }
.legend .grad { width: 120px; height: 10px; padding: 0; background: linear-gradient(90deg, hsl(145,70%,44%), hsl(80,70%,46%), hsl(40,70%,48%), hsl(15,70%,50%)); }
.hint { position: absolute; right: 10px; bottom: 8px; font-size: 12px; color: var(--muted); pointer-events: none; }
#tip { position: absolute; background: var(--panel); border: 1px solid var(--line); padding: 5px 8px; border-radius: 4px; font-size: 13px; pointer-events: none; max-width: 240px; box-shadow: 0 3px 10px rgba(0,0,0,.18); }

/* results */
.verdict { margin: 12px 0; padding: 12px; border-radius: 4px; background: var(--okbg); }
.verdict.bad { background: var(--badbg); }
.vhead { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-weight: 600; }
.vhead b { font-family: var(--num); font-size: 30px; line-height: 1; color: var(--ok); }
.verdict.bad .vhead b { color: var(--bad); }
.ruler { position: relative; height: 8px; margin: 10px 0 8px; border-radius: 4px; background: linear-gradient(90deg, hsl(145,60%,48%) 0 50%, hsl(45,80%,52%) 50% 66.67%, hsl(352,70%,55%) 66.67%); }
.ruler i { position: absolute; top: -4px; width: 3px; height: 16px; background: var(--ink); margin-left: -1px; }
.ruler span { position: absolute; top: 10px; font-size: 11px; transform: translateX(-50%); color: var(--muted); }
.ruler span::after { content: '1.0'; }
.vsub { font-size: 13.5px; margin-top: 12px; }
.vsub a, a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 2px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.kv th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 8px 4px 0; vertical-align: top; width: 42%; }
.kv td { padding: 4px 0; font-family: var(--num); font-variant-numeric: tabular-nums; }
.grid th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 5px 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.right .pane { overflow-x: auto; }
.grid { font-size: 12.5px; }
.grid td { padding: 5px 5px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid .n { text-align: right; font-family: var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid small { display: block; color: var(--muted); font-size: 12px; }
.grid tr[data-m] { cursor: pointer; }
.grid tr[data-m]:hover td { background: var(--panel2); }
.grid tr.on td { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.u { display: inline-block; min-width: 42px; text-align: center; padding: 0 5px; border-radius: 3px; background: var(--c); color: #fff; font-weight: 600; font-family: var(--num); }
.detail { border: 1px solid var(--line); border-radius: 4px; padding: 10px; margin: 12px 0; background: var(--panel2); }
.dh { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dh button { padding: 3px 10px; font-size: 13px; }
.detail .kv th { width: 36%; }
.dias figure { margin: 8px 0 0; }
.dias figcaption { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; font-family: var(--num); }
.dias svg { width: 100%; height: 64px; display: block; }
.dias .ax { stroke: var(--line); stroke-width: 1; }
.dias .dia { fill: color-mix(in srgb, var(--accent) 28%, transparent); stroke: var(--accent); stroke-width: 1.4; }
#report h3 { margin: 12px 0 2px; }
#report p { font-size: 13.5px; max-width: 70ch; }
.bad-text { color: var(--bad); font-size: 13.5px; }

/* footer, modal, toast */
footer { font-family: var(--num); font-size: 12.5px; color: var(--muted); padding: 4px 14px; border-top: 1px solid var(--line); background: var(--panel); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#modal { position: fixed; inset: 0; background: rgba(8,12,16,.5); display: grid; place-items: center; z-index: 20; padding: 16px; }
#modal[hidden] { display: none; }
.mbox { background: var(--panel); border-radius: 6px; padding: 16px 18px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.mbox h3 { margin: 0 0 8px; }
.mbox.wide { width: min(1100px, 100%); }
.sheetprev { background: #fff; border: 1px solid var(--line); border-radius: 4px; line-height: 0; }
.sheetprev svg { display: block; width: 100%; height: auto; }
.row.end { flex-wrap: wrap; }
.small { font-size: 12.5px; }
.mbox textarea { width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 8px; font: 12.5px/1.4 ui-monospace, Menlo, Consolas, monospace; }
.plist { list-style: none; padding: 0; margin: 0; }
.plist li { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.plist li span { flex: 1; }
.plist small { display: block; color: var(--muted); }
#toast { position: fixed; bottom: calc(36px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 8px 14px; border-radius: 4px; font-size: 14px; z-index: 30; }

@media (max-width: 1180px) { main { grid-template-columns: 280px minmax(0, 1fr) 360px; } }
@media (max-width: 900px) {
  html, body { height: auto; }
  body { display: block; }
  main { display: flex; flex-direction: column; }
  .view { order: 1; height: 62vh; min-height: 360px; }
  aside.left { order: 2; border-right: 0; border-top: 1px solid var(--line); }
  aside.right { order: 3; border-left: 0; border-top: 1px solid var(--line); }
  .pane { max-height: none; overflow: visible; }
  .tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 2; }
  footer { position: sticky; bottom: 0; }
  .hint { display: none; }
}
@media print {
  body { display: block; background: #fff; color: #000; }
  body > *:not(main), main > *:not(.right), .right .tabs, .right .row, .pane:not(#paneR-rep) { display: none !important; }
  main { display: block; } aside.right { border: 0; } .pane { overflow: visible; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
body.busy #viewwrap { cursor: progress; }
body.busy #status::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--accent); animation: pulse 0.9s infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
