/* Layout: app shell — header + module chips, tab bar, then list sidebar + working area.
   Results sit directly under the input they are calculated from. */
:root {
  --bg: #F2F4F1; --surface: #FFFFFF; --surface-2: #F7F9F6; --ink: #17201C; --muted: #5A6862; --line: #D9E0DB;
  --accent: #1D6A4E; --accent-ink: #FFFFFF; --accent-soft: #E2F0E9; --spice: #C27803;
  --good: #1F7A4D; --good-soft: #E3F2EA; --warn: #A75A05; --warn-soft: #FDF2E2; --bad: #B42318; --bad-soft: #FCE9E7;
  --info: #3B5B8C; --info-soft: #E8EEF7; --overlay: rgba(15, 22, 19, .45);
  --display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --r: 10px;
  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: #0F1412; --surface: #171E1B; --surface-2: #1C2420; --ink: #E5EBE7; --muted: #97A59E; --line: #2A3530;
  --accent: #5BC097; --accent-ink: #0C1511; --accent-soft: #1D3229; --spice: #EBB13F;
  --good: #5BC097; --good-soft: #1B2F25; --warn: #EBB13F; --warn-soft: #2E2614; --bad: #F2877D; --bad-soft: #3A1D1A;
  --info: #9DB8E6; --info-soft: #1D2635; --overlay: rgba(0, 0, 0, .6); color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #0F1412; --surface: #171E1B; --surface-2: #1C2420; --ink: #E5EBE7; --muted: #97A59E; --line: #2A3530;
  --accent: #5BC097; --accent-ink: #0C1511; --accent-soft: #1D3229; --spice: #EBB13F;
  --good: #5BC097; --good-soft: #1B2F25; --warn: #EBB13F; --warn-soft: #2E2614; --bad: #F2877D; --bad-soft: #3A1D1A;
  --info: #9DB8E6; --info-soft: #1D2635; --overlay: rgba(0, 0, 0, .6); color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 14px/1.5 var(--body); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 0 40px; }
[hidden] { display: none !important; }
#app { max-width: 1280px; margin: 0 auto; }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; letter-spacing: -.01em; }
h2 { font-size: 18px; }
h3 { font-size: 15px; margin-bottom: 10px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.n, td.n, th.n { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.short { color: var(--bad); font-weight: 600; }
.ok { color: var(--good); }

/* header */
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; padding-block: 18px 10px; }
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.brand h1 { font-size: 26px; }
.brand h1 span { color: var(--accent); }
.tag-line { color: var(--muted); font-size: 13px; }
.controls { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.ctl { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; gap: 2px; }
.ctl select { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; padding: 5px 8px; max-width: 240px; color: var(--ink); }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; height: 32px; }
.lang button { border: 0; background: transparent; padding: 0 12px; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.modules { display: flex; gap: 6px; flex-wrap: wrap; padding-bottom: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--surface); }
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.chip.on { color: var(--ink); } .chip.on i { background: var(--good); }
.chip.core { border-color: var(--accent); color: var(--accent); font-weight: 600; } .chip.core i { background: var(--accent); }
.chip.off { text-decoration: line-through; }

nav.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
nav.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
nav.tabs button:hover { color: var(--ink); }
nav.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.ro-banner { background: var(--info-soft); color: var(--info); border-radius: var(--r); padding: 10px 14px; margin-bottom: 16px; font-size: 13px; }

/* layout */
.split { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 820px) { .split { grid-template-columns: minmax(0, 1fr); } }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .two { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.stack-s { display: flex; flex-direction: column; gap: 8px; min-width: 0; align-items: flex-start; }
#view { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row.head { margin: 0 0 14px; }
.row.tight { gap: 4px; flex-wrap: nowrap; margin: 0; }
.spacer { flex: 1; }

.side { display: flex; flex-direction: column; gap: 6px; }
.side .entry { display: block; width: 100%; text-align: left; border: 1px solid transparent; background: transparent; border-radius: var(--r); padding: 10px 12px; cursor: pointer; }
.side .entry:hover { background: var(--surface); }
.side .entry[aria-current="true"] { background: var(--surface); border-color: var(--line); }
.side .entry b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .entry small { display: block; color: var(--muted); font-size: 12px; }
.side .entry .pill { margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; min-width: 0; }
.card > h2 { margin-bottom: 14px; }
.eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* forms */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.fields.one { grid-template-columns: minmax(0, 1fr); }
.fields .wide { grid-column: span 2; }
@media (max-width: 520px) { .fields .wide { grid-column: auto; } }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; min-width: 0; }
input, select, textarea { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0; color: var(--ink); }
input:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--muted); }
input:disabled, select:disabled, textarea:disabled { background: transparent; border-color: transparent; opacity: 1; color: var(--ink); -webkit-text-fill-color: var(--ink); }
select:disabled { appearance: none; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); padding: 0; }
input.compact, select.compact { width: auto; min-width: 160px; }
input.n { text-align: right; }
textarea { font-family: var(--mono); font-size: 12px; min-height: 160px; resize: vertical; }
textarea.plain { font-family: var(--body); font-size: 14px; min-height: 70px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle.small { font-size: 12px; margin-right: 10px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; color: var(--ink); }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--bad); }
.btn.danger { color: var(--bad); }
.btn.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }
.link:hover { text-decoration: underline; }

.days { display: flex; gap: 3px; }
.day { border: 1px solid var(--line); background: transparent; border-radius: 6px; font-size: 11px; padding: 3px 6px; cursor: pointer; color: var(--muted); }
.day.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { border-collapse: collapse; width: 100%; }
th { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th.n, td.n { text-align: right; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 600; border-top: 1px solid var(--ink); border-bottom: 0; }
table.edit td { padding: 4px 6px; }
tr.done td:nth-child(2), tr.done td:nth-child(2) input { text-decoration: line-through; color: var(--muted); }
details summary { cursor: pointer; }
.trace { font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 6px 0 2px; }
.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

/* status */
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.s-inquiry { background: var(--info-soft); color: var(--info); }
.s-confirmed { background: var(--accent-soft); color: var(--accent); }
.s-done { background: var(--good-soft); color: var(--good); }
.s-cancelled { background: var(--bad-soft); color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; min-width: 0; }
.stat .v { font-family: var(--display); font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; overflow-wrap: anywhere; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.hl { background: var(--accent-soft); border-color: transparent; }
.stat .v.neg { color: var(--bad); }
.flow { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.flow b { color: var(--ink); }
.flow .arr { color: var(--spice); }
.warns { background: var(--warn-soft); border-radius: var(--r); padding: 12px 16px; color: var(--warn); font-size: 13px; }
.warns ul { margin: 4px 0 0; padding-left: 18px; }

/* panel / dialog */
.overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: calc(40px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); z-index: 20; overflow-y: auto; }
.dialog { background: var(--surface); border-radius: 14px; width: min(760px, 100%); padding: 16px 20px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.dialog-bar { margin: 0 0 6px; }
.dialog-body { display: flex; flex-direction: column; gap: 12px; }
.sheet section { margin-top: 18px; }
.sheet table td { padding: 4px 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; }
footer { margin-top: 28px; font-size: 12px; color: var(--muted); }

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

@media print {
  body.printing #app, body.printing .toast { display: none !important; }
  body.printing { background: #fff; color: #000; padding: 0; }
  body.printing .overlay { position: static; background: none; padding: 0; }
  body.printing .dialog { box-shadow: none; width: 100%; padding: 0; }
  body.printing .dialog-bar { display: none; }
}
