/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-14);
  line-height: 1.45;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.011em; text-wrap: balance; }
h1 { font-size: var(--fs-20); line-height: 1.25; }
h2 { font-size: var(--fs-14); line-height: 1.3; }
h3 { font-size: var(--fs-13); line-height: 1.3; }
p { margin: 0; }
a { color: inherit; text-decoration-color: var(--g-300); text-underline-offset: 0.18em; }
a:hover { text-decoration-color: currentColor; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--violet-soft); color: var(--violet-ink); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-md); }
* { scrollbar-width: thin; scrollbar-color: var(--g-300) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--g-300); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
[hidden] { display: none !important; }
.num, td.num, .tnum { font-variant-numeric: tabular-nums; }
.code { font-family: var(--mono); font-size: 0.92em; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: var(--fs-12); }
.xs { font-size: var(--fs-11); }
.strong { font-weight: 600; }
.green { color: var(--green); }
.amber { color: var(--amber); }
.red { color: var(--red); }
.violet { color: var(--violet-ink); }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ic { width: 16px; height: 16px; stroke-width: 1.75; flex: none; vertical-align: -3px; }
svg.lucide { width: 16px; height: 16px; stroke-width: 1.75; flex: none; }
.ic-sm, svg.lucide.ic-sm { width: 14px; height: 14px; }
.ic-lg, svg.lucide.ic-lg { width: 20px; height: 20px; }

/* ---------- layout helpers ---------- */
.row { display: flex; align-items: center; gap: var(--s-2); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.stack { display: flex; flex-direction: column; gap: var(--s-3); }
.stack-lg { display: flex; flex-direction: column; gap: var(--s-5); }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: var(--s-4); align-items: start; }
.gap-1 { gap: var(--s-1); } .gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); }
.mt-1 { margin-top: var(--s-1); } .mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); }
.mb-2 { margin-bottom: var(--s-2); } .mb-3 { margin-bottom: var(--s-3); } .mb-4 { margin-bottom: var(--s-4); } .mb-6 { margin-bottom: var(--s-6); }
.ml-auto { margin-left: auto; }
.p-4 { padding: var(--s-4); }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--layer); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: var(--s-3) var(--s-2) var(--s-3);
}
.brand { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-2) var(--s-3); font-weight: 600; letter-spacing: -0.02em; }
.brand-logo { height: 20px; width: auto; display: block; }
.os-tag { font-size: var(--fs-11); font-weight: 600; letter-spacing: 0.06em; color: var(--muted); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 1px 5px; }
.logo-dark { display: none; }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; height: 32px; padding: 0 var(--s-2);
  border-radius: var(--r-md); color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: var(--fs-13);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-item:hover { background: rgb(25 27 28 / 0.05); color: var(--ink); }
:root[data-theme="dark"] .nav-item:hover { background: rgb(255 255 255 / 0.05); }
.nav-item.active { background: var(--sheet); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.nav-item.active svg { color: var(--violet); }
.nav-item .count { margin-left: auto; font-size: var(--fs-11); color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item .count.alert { color: var(--red); font-weight: 600; }
.nav-sub { display: flex; flex-direction: column; gap: 1px; margin: 1px 0 6px 26px; padding-left: 8px; border-left: 1px solid var(--line); }
.nav-sub a { height: 28px; display: flex; align-items: center; padding: 0 var(--s-2); border-radius: var(--r-sm); color: var(--muted); text-decoration: none; font-size: var(--fs-13); }
.nav-sub a:hover { color: var(--ink); background: rgb(25 27 28 / 0.04); }
.nav-sub a.active { color: var(--ink); font-weight: 500; }
.sidebar-foot { margin-top: auto; padding-top: var(--s-3); border-top: 1px solid var(--line); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-6);
  background: color-mix(in srgb, var(--ground) 88%, transparent); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.searchbox {
  display: flex; align-items: center; gap: var(--s-2); height: 32px; width: min(420px, 100%);
  padding: 0 var(--s-2) 0 var(--s-3); border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--sheet); color: var(--muted); cursor: text; font-size: var(--fs-13);
}
.searchbox kbd { margin-left: auto; }
kbd { font-family: var(--mono); font-size: var(--fs-11); padding: 1px 5px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--sheet-alt); color: var(--muted); }
.content { padding: var(--s-6); max-width: 1440px; width: 100%; margin: 0 auto; }
.proto-bar {
  display: flex; align-items: center; gap: var(--s-2); padding: 6px var(--s-6);
  background: var(--sheet); border-bottom: 1px solid var(--line); font-size: var(--fs-12); color: var(--muted);
}
.proto-bar b { color: var(--ink); font-weight: 600; }

.mobile-tabs { display: none; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; font-size: var(--fs-13); }
.page-head .actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 var(--s-3); border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--sheet); color: var(--ink);
  font-size: var(--fs-13); font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:hover { background: var(--sheet-alt); border-color: var(--g-300); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.violet { background: var(--violet); border-color: var(--violet); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: rgb(25 27 28 / 0.05); color: var(--ink); }
:root[data-theme="dark"] .btn.ghost:hover { background: rgb(255 255 255 / 0.06); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-bg); border-color: var(--red-line); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.sm { height: 26px; padding: 0 var(--s-2); font-size: var(--fs-12); gap: 4px; }
.btn.icon { width: 32px; padding: 0; }
.btn.sm.icon { width: 26px; }
.btn.loading { color: transparent !important; position: relative; pointer-events: none; }
.btn.loading::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--primary-ink); border-right-color: transparent; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.linkbtn { background: none; border: 0; padding: 0; color: var(--violet-ink); cursor: pointer; font-weight: 500; font-size: inherit; }
.linkbtn:hover { text-decoration: underline; text-underline-offset: 0.18em; }

/* ---------- sheets (white working surfaces) ---------- */
.sheet { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; }
.sheet-head { display: flex; align-items: center; gap: var(--s-2); padding: 12px var(--s-4); border-bottom: 1px solid var(--line-soft); min-height: 46px; }
.sheet-head h2 { font-size: var(--fs-14); }
.sheet-head .meta { color: var(--muted); font-size: var(--fs-12); font-weight: 400; }
.sheet-head .tools { margin-left: auto; display: flex; gap: var(--s-1); align-items: center; }
.sheet-body { padding: var(--s-4); }
.sheet-foot { padding: 10px var(--s-4); border-top: 1px solid var(--line-soft); font-size: var(--fs-12); color: var(--muted); display: flex; gap: var(--s-2); align-items: center; }
.inset { background: var(--sheet-alt); border: 1px solid var(--line-soft); border-radius: var(--r-md); padding: var(--s-3); }

/* ---------- number strip ---------- */
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-lg); }
.strip-cell { padding: 14px var(--s-4); border-left: 1px solid var(--line-soft); min-width: 0; text-decoration: none; color: inherit; display: block; }
.strip-cell:first-child { border-left: 0; }
a.strip-cell:hover { background: var(--sheet-alt); }
.strip-label { font-size: var(--fs-12); color: var(--muted); display: flex; align-items: center; gap: 6px; }
.strip-value { font-size: var(--fs-24); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 4px; line-height: 1.15; white-space: nowrap; }
.strip-value .cur { font-size: var(--fs-13); font-weight: 500; color: var(--muted); margin-right: 3px; letter-spacing: 0; }
.strip-sub { font-size: var(--fs-12); color: var(--muted); margin-top: 4px; }
.strip-value.incomplete { font-size: var(--fs-16); color: var(--amber); }

/* ---------- pace bar ---------- */
.pace { position: relative; height: 6px; background: var(--g-150); border-radius: 6px; overflow: visible; }
:root[data-theme="dark"] .pace { background: var(--line); }
.pace-fill { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: var(--ink); }
.pace-fill.green { background: var(--green-mark); }
.pace-fill.amber { background: var(--amber-mark); }
.pace-fill.red { background: var(--red-mark); }
.pace-mark { position: absolute; top: -4px; width: 2px; height: 14px; background: var(--violet); border-radius: 2px; transform: translateX(-1px); }
.bar { height: 6px; background: var(--g-150); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ink); border-radius: 6px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: var(--r-sm);
  font-size: var(--fs-11); font-weight: 600; letter-spacing: 0.01em; white-space: nowrap;
  background: var(--sheet-alt); color: var(--ink-2); border: 1px solid var(--line);
}
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--green-bg); color: var(--green); border-color: var(--green-line); }
.badge.amber { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-line); }
.badge.red { background: var(--red-bg); color: var(--red); border-color: var(--red-line); }
.badge.violet { background: var(--violet-soft); color: var(--violet-ink); border-color: var(--violet-line); }
.badge.blue { background: var(--blue-bg); color: var(--blue); border-color: var(--blue-line); }
.badge.ink { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.temp { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-12); font-weight: 500; }
.temp i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.temp.hot i { background: var(--red-mark); } .temp.warm i { background: var(--amber-mark); } .temp.cold i { background: #6aa7e6; }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-13); }
.t th {
  text-align: left; font-weight: 500; font-size: var(--fs-12); color: var(--muted); background: var(--sheet-alt);
  padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.t th.sortable { cursor: pointer; user-select: none; }
.t th.sortable:hover { color: var(--ink); }
.t th .sort { opacity: 0.6; margin-left: 2px; }
.t td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr { transition: background var(--t-fast); }
.t tbody tr.clickable { cursor: pointer; }
.t tbody tr.clickable:hover, .t tbody tr:hover { background: var(--sheet-alt); }
.t td.num, .t th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t td.act { width: 1%; white-space: nowrap; text-align: right; }
.t tfoot td { font-weight: 600; background: var(--sheet-alt); border-top: 1px solid var(--line); border-bottom: 0; }
.t tr.muted-row td { color: var(--faint); }
.t tr.muted-row td .badge { opacity: 0.8; }
.t .sub { display: block; font-size: var(--fs-12); color: var(--muted); margin-top: 1px; }
.sheet > .table-wrap:first-child .t th:first-child { border-top-left-radius: var(--r-lg); }
.sheet > .table-wrap:first-child .t th:last-child { border-top-right-radius: var(--r-lg); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: var(--s-3); padding: 10px var(--s-4); border-bottom: 1px solid var(--line-soft); min-width: 0; }
.li:last-child { border-bottom: 0; }
.li.clickable { cursor: pointer; }
.li.clickable:hover { background: var(--sheet-alt); }
.li .lead { width: 28px; height: 28px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--sheet-alt); border: 1px solid var(--line-soft); color: var(--ink-2); flex: none; }
.li .lead.red { color: var(--red); background: var(--red-bg); border-color: var(--red-line); }
.li .lead.amber { color: var(--amber); background: var(--amber-bg); border-color: var(--amber-line); }
.li .lead.green { color: var(--green); background: var(--green-bg); border-color: var(--green-line); }
.li .lead.violet { color: var(--violet-ink); background: var(--violet-soft); border-color: var(--violet-line); }
.li .title { font-weight: 500; }
.li .meta { font-size: var(--fs-12); color: var(--muted); margin-top: 1px; }
.li .end { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); flex: none; }
.group-label { padding: 10px var(--s-4) 6px; font-size: var(--fs-12); color: var(--muted); font-weight: 500; background: var(--sheet-alt); border-bottom: 1px solid var(--line-soft); }

/* definition grid */
.dl { display: grid; grid-template-columns: minmax(120px, 0.6fr) minmax(0, 1fr); gap: 8px var(--s-4); font-size: var(--fs-13); }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- tabs & segmented ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: var(--s-5); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { position: relative; display: inline-flex; align-items: center; gap: 6px; padding: 9px 10px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: var(--fs-13); white-space: nowrap; background: none; border: 0; cursor: pointer; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); }
.tab.active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--ink); border-radius: 2px; }
.tab .count { font-size: var(--fs-11); color: var(--muted); background: var(--sheet-alt); border: 1px solid var(--line-soft); border-radius: 10px; padding: 0 6px; }
.seg { display: inline-flex; padding: 2px; background: var(--layer); border: 1px solid var(--line); border-radius: var(--r-md); gap: 2px; }
.seg button { height: 26px; padding: 0 10px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: var(--fs-12); font-weight: 500; cursor: pointer; }
.seg button.on { background: var(--sheet); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; margin-bottom: var(--s-3); }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 14px; border: 1px solid var(--line); background: var(--sheet); font-size: var(--fs-12); font-weight: 500; color: var(--ink-2); cursor: pointer; }
.chip:hover { border-color: var(--g-300); }
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

/* ---------- forms ---------- */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3) var(--s-3); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; grid-column: span 2; }
.field.half { grid-column: span 1; }
.field label, .label { font-size: var(--fs-12); font-weight: 500; color: var(--ink-2); }
.field .hint { font-size: var(--fs-12); color: var(--muted); }
.field .err { font-size: var(--fs-12); color: var(--red); }
.input, .select, .textarea {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--sheet); color: var(--ink); font-size: var(--fs-13);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.textarea { height: auto; min-height: 84px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--g-300); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgb(255 107 44 / 0.16); }
.input[readonly] { background: var(--sheet-alt); color: var(--ink-2); }
.input.invalid, .select.invalid { border-color: var(--red); }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.money-input { display: flex; }
.money-input .select { width: 82px; border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: 0; flex: none; }
.money-input .input { border-top-left-radius: 0; border-bottom-left-radius: 0; text-align: right; font-variant-numeric: tabular-nums; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-13); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--violet); margin: 0; }
.select { appearance: none; padding-right: 28px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2387898c' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; }
.form-section { grid-column: span 2; font-size: var(--fs-12); font-weight: 600; color: var(--muted); padding-top: var(--s-2); border-top: 1px solid var(--line-soft); margin-top: var(--s-1); }

/* ---------- overlays ---------- */
.scrim { position: fixed; inset: 0; background: rgb(14 16 17 / 0.32); z-index: 60; opacity: 0; transition: opacity var(--t-mid) var(--ease); }
.scrim.open { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 61;
  background: var(--sheet); border-left: 1px solid var(--line); box-shadow: var(--shadow-drawer);
  display: flex; flex-direction: column; transform: translateX(16px); opacity: 0;
  transition: transform var(--t-mid) var(--ease), opacity var(--t-mid) var(--ease);
}
.drawer.wide { width: min(820px, 100vw); }
.drawer.open { transform: none; opacity: 1; }
.drawer-head { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: var(--fs-16); }
.drawer-head .sub { color: var(--muted); font-size: var(--fs-12); margin-top: 2px; }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--s-5); }
.drawer-foot { display: flex; gap: var(--s-2); justify-content: flex-end; padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line); background: var(--sheet-alt); }
.drawer-foot .left { margin-right: auto; display: flex; gap: var(--s-2); }

.dialog {
  position: fixed; left: 50%; top: 18vh; transform: translate(-50%, 8px); width: min(460px, calc(100vw - 32px)); z-index: 71;
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-pop);
  opacity: 0; transition: opacity var(--t-mid) var(--ease), transform var(--t-mid) var(--ease);
}
.dialog.open { opacity: 1; transform: translate(-50%, 0); }
.dialog .d-body { padding: var(--s-5); }
.dialog .d-body h2 { font-size: var(--fs-16); margin-bottom: 6px; }
.dialog .d-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line); background: var(--sheet-alt); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.scrim.top { z-index: 70; }

.menu {
  position: fixed; z-index: 80; min-width: 200px; padding: 4px; background: var(--sheet); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-pop); animation: pop var(--t-fast) var(--ease);
}
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; height: 32px; padding: 0 10px; border: 0; background: none; border-radius: var(--r-md); font-size: var(--fs-13); color: var(--ink); text-decoration: none; cursor: pointer; text-align: left; }
.menu button:hover, .menu a:hover, .menu .hl { background: var(--sheet-alt); }
.menu .sep { height: 1px; background: var(--line-soft); margin: 4px 0; }
.menu .mlabel { padding: 6px 10px 4px; font-size: var(--fs-11); color: var(--muted); font-weight: 600; }
.menu .danger { color: var(--red); }
.menu kbd { margin-left: auto; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }

.palette { position: fixed; left: 50%; top: 12vh; transform: translateX(-50%); width: min(620px, calc(100vw - 24px)); z-index: 75; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); overflow: hidden; animation: pop var(--t-mid) var(--ease); }
.palette input { width: 100%; height: 50px; border: 0; border-bottom: 1px solid var(--line); padding: 0 var(--s-4); font-size: var(--fs-16); background: transparent; outline: none; }
.palette .results { max-height: 52vh; overflow-y: auto; padding: 4px; }
.palette .res { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-md); cursor: pointer; }
.palette .res.hl { background: var(--violet-soft); }
.palette .res .kind { margin-left: auto; font-size: var(--fs-11); color: var(--muted); }
.palette .grp { padding: 8px 10px 4px; font-size: var(--fs-11); font-weight: 600; color: var(--muted); }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 9px 12px 9px 14px; background: var(--g-900); color: #f3f5f7; border-radius: var(--r-lg); font-size: var(--fs-13); box-shadow: var(--shadow-pop); animation: toastIn var(--t-mid) var(--ease); max-width: calc(100vw - 32px); }
:root[data-theme="dark"] .toast { background: #f7f8fa; color: #121b28; }
.toast .ic { color: var(--green-mark); }
.toast.red .ic { color: var(--red-mark); }
.toast.amber .ic { color: var(--amber-mark); }
.toast button { background: none; border: 0; color: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 0.2em; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ---------- empty & notices ---------- */
.empty { padding: var(--s-8) var(--s-5); text-align: center; color: var(--muted); }
.empty .ei { width: 36px; height: 36px; border-radius: var(--r-lg); display: grid; place-items: center; margin: 0 auto var(--s-3); background: var(--sheet-alt); border: 1px solid var(--line-soft); color: var(--ink-2); }
.empty h3 { color: var(--ink); font-size: var(--fs-14); margin-bottom: 4px; }
.empty p { max-width: 42ch; margin: 0 auto; font-size: var(--fs-13); }
.empty .btn { margin-top: var(--s-3); }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--sheet-alt); font-size: var(--fs-13); }
.notice .ic { margin-top: 2px; }
.notice.amber { background: var(--amber-bg); border-color: var(--amber-line); color: var(--amber); }
.notice.red { background: var(--red-bg); border-color: var(--red-line); color: var(--red); }
.notice.green { background: var(--green-bg); border-color: var(--green-line); color: var(--green); }
.notice.violet { background: var(--violet-soft); border-color: var(--violet-line); color: var(--violet-ink); }
.notice.amber b, .notice.red b, .notice.green b { color: inherit; }
.incomplete { color: var(--amber); font-weight: 600; }
.incomplete-link { color: var(--amber); font-weight: 600; text-decoration: underline dotted; text-underline-offset: 0.2em; cursor: help; }

/* avatar */
.av { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 700; color: var(--ink); background: var(--g-150); flex: none; letter-spacing: 0; }
.av.lg { width: 36px; height: 36px; font-size: 13px; }
.av.v { background: var(--violet-soft); color: var(--violet-ink); }

/* ---------- kanban ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: var(--s-3); overflow-x: auto; padding-bottom: var(--s-3); align-items: start; }
.col { background: var(--layer); border: 1px solid var(--line); border-radius: var(--r-lg); display: flex; flex-direction: column; max-height: calc(100vh - 220px); min-height: 120px; }
.col-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; font-weight: 600; font-size: var(--fs-13); }
.col-head .meta { margin-left: auto; color: var(--muted); font-weight: 500; font-size: var(--fs-12); font-variant-numeric: tabular-nums; }
.col-body { padding: 0 8px 8px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 40px; }
.col.drop { background: var(--violet-soft); border-color: var(--violet-line); }
.card { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px; cursor: grab; box-shadow: 0 1px 1px rgb(16 18 20 / 0.03); }
.card:hover { border-color: var(--g-300); }
.card.dragging { opacity: 0.5; }
.card .ct { font-weight: 600; font-size: var(--fs-13); }
.card .cm { font-size: var(--fs-12); color: var(--muted); margin-top: 2px; }
.card .cf { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: var(--fs-12); }

/* ---------- timeline ---------- */
.tl { position: relative; padding-left: 20px; }
.tl::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
.tl-item { position: relative; padding-bottom: var(--s-4); }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before { content: ""; position: absolute; left: -18px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--sheet); border: 2px solid var(--g-300); }
.tl-item.done::before { background: var(--ink); border-color: var(--ink); }
.tl-item.now::before { border-color: var(--violet); box-shadow: 0 0 0 3px var(--violet-soft); }
.tl-item.late::before { border-color: var(--red-mark); }
.tl-item .when { font-size: var(--fs-12); color: var(--muted); }

/* gantt */
.gantt { position: relative; overflow-x: auto; }
.gantt-row { display: grid; grid-template-columns: 220px 1fr; border-bottom: 1px solid var(--line-soft); min-height: 36px; align-items: center; }
.gantt-label { padding: 6px 12px; font-size: var(--fs-13); position: sticky; left: 0; background: var(--sheet); z-index: 1; }
.gantt-track { position: relative; height: 36px; }
.gantt-bar { position: absolute; top: 9px; height: 18px; border-radius: 4px; background: var(--g-800); color: #fff; font-size: 11px; padding: 0 6px; display: flex; align-items: center; overflow: hidden; white-space: nowrap; }
.gantt-bar.done { background: var(--g-400); }
.gantt-bar.late { background: var(--red-mark); }
.gantt-bar.doing { background: var(--violet); }
.gantt-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--violet); z-index: 2; }

/* ---------- charts ---------- */
.chart { width: 100%; display: block; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--line-soft); }
.chart .axis line { stroke: var(--line); }
.legend { display: flex; gap: var(--s-4); flex-wrap: wrap; font-size: var(--fs-12); color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-tip { position: fixed; z-index: 85; pointer-events: none; background: var(--g-900); color: #f3f5f7; font-size: var(--fs-12); padding: 6px 8px; border-radius: var(--r-md); box-shadow: var(--shadow-pop); font-variant-numeric: tabular-nums; }

.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(118px, 1.25fr) minmax(48px, 1fr) auto; align-items: center; gap: 12px; font-size: var(--fs-13); text-decoration: none; color: inherit; }
a.hbar:hover .hb-label { text-decoration: underline; text-underline-offset: 0.18em; }
.hb-track { height: 8px; background: var(--g-150); border-radius: 4px; overflow: hidden; }
:root[data-theme="dark"] .hb-track { background: var(--line); }
.hb-track > span { display: block; height: 100%; border-radius: 4px; }
.hb-val { min-width: 72px; text-align: right; font-weight: 500; }
.splitbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--g-150); }
.splitbar > span { display: block; height: 100%; }
.chart-note { font-size: var(--fs-12); color: var(--muted); }
.settings-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--s-6); }
.show-sm { display: none; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: minmax(0, 1fr); } .show-sm { display: block; } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; }
.login-form { display: flex; align-items: center; justify-content: center; padding: var(--s-8) var(--s-5); }
.login-card { width: min(380px, 100%); }
.login-card h1 { font-size: var(--fs-24); letter-spacing: -0.02em; }
.otp { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.otp input { height: 46px; text-align: center; font-size: var(--fs-20); font-variant-numeric: tabular-nums; padding: 0; }

/* ---------- assistant ---------- */
.assistant { position: fixed; right: 16px; bottom: 16px; top: calc(var(--topbar-h) + 12px); width: min(420px, calc(100vw - 32px)); z-index: 50; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; animation: pop var(--t-mid) var(--ease); }
.as-head { display: flex; align-items: center; gap: var(--s-2); padding: 10px 12px; border-bottom: 1px solid var(--line); }
.as-body { flex: 1; overflow-y: auto; padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
.msg { max-width: 92%; font-size: var(--fs-13); line-height: 1.5; }
.msg.me { align-self: flex-end; background: var(--primary); color: var(--primary-ink); padding: 8px 12px; border-radius: 12px 12px 4px 12px; }
.msg.ai { align-self: flex-start; }
.msg.ai p + p { margin-top: 6px; }
.msg .src { margin-top: 6px; font-size: var(--fs-12); color: var(--muted); }
.action-card { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--sheet); margin-top: 6px; }
.action-card .ac-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--sheet-alt); border-bottom: 1px solid var(--line-soft); font-size: var(--fs-12); font-weight: 600; }
.action-card .ac-body { padding: 10px 12px; }
.action-card .ac-body .dl { grid-template-columns: 110px 1fr; font-size: var(--fs-12); }
.action-card .ac-foot { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line-soft); }
.action-card.done .ac-head { background: var(--green-bg); color: var(--green); }
.action-card.cancelled { opacity: 0.6; }
.as-input { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 6px; align-items: flex-end; }
.as-input textarea { flex: 1; min-height: 36px; max-height: 120px; resize: none; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sheet); font-size: var(--fs-13); }
.as-input textarea:focus { outline: none; border-color: var(--violet); }
.as-sugs { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 var(--s-4) var(--s-3); }
.as-sugs button { font-size: var(--fs-12); border: 1px solid var(--line); background: var(--sheet); border-radius: 14px; padding: 4px 10px; cursor: pointer; color: var(--ink-2); }
.as-sugs button:hover { border-color: var(--violet-line); color: var(--violet-ink); }
.mic.on { background: var(--red); border-color: var(--red); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px var(--red-bg); } }
.typing span { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); margin-right: 3px; animation: blink 1s infinite; }
.typing span:nth-child(2) { animation-delay: 0.15s; } .typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------- portal ---------- */
.portal { min-height: 100vh; background: var(--ground); }
.portal-top { background: var(--sheet); border-bottom: 1px solid var(--line); }
.portal-top .in { max-width: 1040px; margin: 0 auto; padding: var(--s-4) var(--s-5); display: flex; align-items: center; gap: var(--s-3); }
.portal-main { max-width: 1040px; margin: 0 auto; padding: var(--s-6) var(--s-5); }

/* ---------- print (invoice) ---------- */
.doc { background: #fff; color: #121b28; max-width: 780px; margin: 0 auto; padding: 48px; border: 1px solid var(--line); border-radius: var(--r-lg); font-size: 13px; }
.doc table { width: 100%; border-collapse: collapse; margin-top: 24px; }
.doc th { text-align: left; font-size: 11px; color: #6f7276; font-weight: 600; border-bottom: 1px solid #121b28; padding: 8px 0; }
.doc td { padding: 10px 0; border-bottom: 1px solid #e5e8eb; }
.doc .num { text-align: right; }
.doc .stamp { display: inline-block; border: 2px solid currentColor; padding: 2px 10px; font-weight: 700; letter-spacing: 0.08em; transform: rotate(-4deg); }
@media print {
  body * { visibility: hidden; }
  .doc, .doc * { visibility: visible; }
  .doc { position: absolute; left: 0; top: 0; border: 0; max-width: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .strip { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .strip-cell { border-left: 0; border-top: 1px solid var(--line-soft); }
  .strip-cell:nth-child(-n+3) { border-top: 0; }
  .strip-cell:not(:nth-child(3n+1)) { border-left: 1px solid var(--line-soft); }
}
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { padding: 0 var(--s-4); }
  .content { padding: var(--s-4) var(--s-4) calc(76px + env(safe-area-inset-bottom)); }
  .proto-bar { padding: 6px var(--s-4); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .mobile-tabs {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--sheet); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-tabs a, .mobile-tabs button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 7px; font-size: 10px; font-weight: 500; color: var(--muted); text-decoration: none; background: none; border: 0; }
  .mobile-tabs .active { color: var(--ink); }
  .mobile-tabs .active svg { color: var(--violet); }
  .assistant { top: 12px; bottom: calc(72px + env(safe-area-inset-bottom)); right: 8px; width: calc(100vw - 16px); }
  .hide-sm { display: none !important; }
}
@media (max-width: 640px) {
  .strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strip-cell { border-left: 0 !important; border-top: 1px solid var(--line-soft) !important; }
  .strip-cell:nth-child(-n+2) { border-top: 0 !important; }
  .strip-cell:nth-child(2n) { border-left: 1px solid var(--line-soft) !important; }
  .strip-value { font-size: var(--fs-20); }
  .form { grid-template-columns: minmax(0, 1fr); }
  .field.half { grid-column: span 1; }
  .field, .form-section { grid-column: span 1; }
  .page-head { align-items: flex-start; }
  h1 { font-size: var(--fs-18); }
  /* tables become stacked records */
  .t.stackable thead { display: none; }
  .t.stackable, .t.stackable tbody, .t.stackable tr, .t.stackable td, .t.stackable tfoot { display: block; width: 100%; }
  .t.stackable tr { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
  .t.stackable td { border: 0; padding: 3px 0; display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 4px 8px; text-align: right !important; }
  .t.stackable td::before { content: attr(data-label); color: var(--muted); font-size: var(--fs-12); text-align: left; flex: none; margin-right: auto; }
  .t.stackable td.primary-cell { display: block; text-align: left !important; font-weight: 600; padding-bottom: 4px; }
  .t.stackable td.primary-cell::before { content: none; }
  .t.stackable td.act { justify-content: flex-end; }
  .t.stackable td.act::before { content: none; }
  .drawer-body { padding: var(--s-4); }
  .doc { padding: 20px; }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .searchbox { width: auto; flex: 1; }
  .searchbox kbd, .searchbox .hide-xs { display: none; }
  .hide-xs { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- prototype 2: lighter screens ---------- */
.proto-bar:empty { display: none; }
/* module tabs repeat the sidebar sub-menu; show them only where the sidebar is hidden */
@media (min-width: 901px) { .tabs.mod-tabs { display: none; } }
/* extra form fields stay folded until needed */
.more-fields { grid-column: span 2; border-top: 1px solid var(--line-soft); padding-top: var(--s-2); }
.more-fields > summary { cursor: pointer; font-size: var(--fs-12); font-weight: 600; color: var(--muted); padding: 4px 0; list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.more-fields > summary::-webkit-details-marker { display: none; }
.more-fields > summary::before { content: "+"; display: inline-grid; place-items: center; width: 16px; height: 16px; border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 12px; line-height: 1; }
.more-fields[open] > summary::before { content: "−"; }
.more-fields > summary:hover { color: var(--ink); }
.more-fields > .form { margin-top: var(--s-3); }
@media (max-width: 640px) { .more-fields { grid-column: span 1; } }
/* money trail */
.t tr.removed-row td { color: var(--faint); }
.t tr.removed-row td .amt { text-decoration: line-through; }
.trail { font-size: var(--fs-12); color: var(--muted); }
.trail b { color: var(--ink-2); font-weight: 500; }
.change-list { margin: 4px 0 0; padding: 0; list-style: none; font-size: var(--fs-12); }
.change-list li { padding: 2px 0; }
.change-list s { color: var(--faint); }
/* dashboard */
.strip.compact .strip-cell { padding: 10px var(--s-4); }
.strip.compact .strip-value { font-size: var(--fs-20); }
.greet { display: flex; align-items: baseline; gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-4); }
.greet h1 { font-size: var(--fs-20); }
.greet .sub { color: var(--muted); font-size: var(--fs-13); }
.explain { color: var(--muted); font-size: var(--fs-13); margin: calc(-1 * var(--s-2)) 0 var(--s-4); max-width: 72ch; }
.verdict { font-size: var(--fs-14); line-height: 1.5; }
.verdict b { font-weight: 600; }
.quick-add { display: flex; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line-soft); }
.quick-add .input { flex: 1; }
@media (max-width: 1180px) {
  .strip.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strip.compact .strip-cell { border-left: 0; border-top: 1px solid var(--line-soft); }
  .strip.compact .strip-cell:nth-child(-n+2) { border-top: 0; }
  .strip.compact .strip-cell:nth-child(2n) { border-left: 1px solid var(--line-soft); }
}
/* dashboard: one screen, equal-height cards (no gaps) */
.dash { display: grid; gap: var(--s-4); }
.dash-strip { grid-template-columns: repeat(5, minmax(0, 1fr)); grid-auto-flow: row; }
.dash-strip .strip-cell { padding: 12px var(--s-4); }
.dash-strip .strip-value { font-size: var(--fs-20); }
.dash-row > .sheet { display: flex; flex-direction: column; min-width: 0; }
.dash-row > .sheet > .list, .dash-row > .sheet > .empty { flex: 1; }
.dash-li { padding-top: 8px; padding-bottom: 8px; }
.date-chip { flex: none; width: 52px; font-size: var(--fs-12); font-variant-numeric: tabular-nums; color: var(--muted); }
.date-chip.red { color: var(--red); font-weight: 600; }
@media (max-width: 1180px) {
  .dash-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dash-row { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) { .dash-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
