:root {
  color-scheme: light dark;
  --bg: #f2f4f2;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --text: #19201e;
  --muted: #5d6967;
  --border: #dde2e0;
  --border-strong: #c3cbc8;
  --accent: #0b6660;
  --accent-hover: #095550;
  --on-accent: #ffffff;
  --accent-soft: #e2f0ee;
  --ok: #1a6a3a;
  --ok-bg: #e1f3e7;
  --warn: #8a5200;
  --warn-bg: #fcefd3;
  --bad: #b3261e;
  --bad-bg: #fbe6e3;
  --shadow: 0 1px 2px rgb(20 30 28 / 6%), 0 8px 24px rgb(20 30 28 / 8%);
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1312;
    --surface: #171c1b;
    --surface-2: #1d2322;
    --text: #e6ebe9;
    --muted: #95a3a0;
    --border: #2a3230;
    --border-strong: #3b4643;
    --accent: #52beb6;
    --accent-hover: #6bcdc5;
    --on-accent: #05201e;
    --accent-soft: #15302d;
    --ok: #7dd69c;
    --ok-bg: #14301f;
    --warn: #f0bb5a;
    --warn-bg: #382b0d;
    --bad: #ff8d83;
    --bad-bg: #3c1a17;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 45%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans",
        "Microsoft YaHei", "Yu Gothic UI", "Noto Sans CJK SC", "Noto Sans CJK JP", sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }
h2 { margin: 0 0 16px; font-size: 18px; line-height: 1.3; }
h3 { margin: 16px 0 8px; font-size: 14px; }
a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.spacer { flex: 1; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace; font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 8px 28px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 700; letter-spacing: .01em;
  padding: 14px 0; color: var(--text);
}
.brand svg { color: var(--accent); flex: none; }

.tabs { display: flex; gap: 4px; align-self: stretch; flex: 1; }
.tab {
  background: none; border: 0; padding: 0 12px; cursor: pointer;
  color: var(--muted); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }

.lang {
  display: flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.lang button {
  border: 0; background: none; cursor: pointer;
  padding: 4px 12px; border-radius: 5px; color: var(--muted); font-size: 13px;
}
.lang button:hover { color: var(--text); }
.lang button[aria-pressed="true"] {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: 0 0 0 1px var(--border-strong);
}

main { max-width: 1440px; margin: 0 auto; padding: 20px 20px 48px; }

/* ---------- stats ---------- */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; text-align: left; min-width: 0;
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value {
  font-size: 26px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
button.stat { cursor: pointer; }
button.stat:hover { border-color: var(--border-strong); }
.stat-low.alert .stat-value { color: var(--warn); }
.stat-low[aria-pressed="true"] { border-color: var(--warn); background: var(--warn-bg); }
.stats.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat-filter[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.stat-filter.bad.alert .stat-value { color: var(--bad); }
.stat-filter.warn.alert .stat-value { color: var(--warn); }
.stat-filter.bad[aria-pressed="true"] { border-color: var(--bad); background: var(--bad-bg); }
.stat-filter.warn[aria-pressed="true"] { border-color: var(--warn); background: var(--warn-bg); }

/* ---------- toolbar / controls ---------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }

input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 7px 10px; min-height: 36px; max-width: 100%;
}
textarea { resize: vertical; min-height: 60px; width: 100%; }
input::placeholder { color: var(--muted); opacity: .85; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.search { flex: 1 1 280px; max-width: 420px; }

.check, .range { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.check { cursor: pointer; padding: 0 4px; }
.range span { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; cursor: pointer; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px;
  font-weight: 600; list-style: none; user-select: none;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn.danger:hover:not(:disabled) { background: var(--bad); filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.btn.small { min-height: 28px; padding: 0 10px; font-size: 13px; }
.btn.in { color: var(--ok); }
.btn.out { color: var(--warn); }

.icon-btn {
  display: inline-grid; place-items: center; width: 28px; height: 28px; vertical-align: middle;
  border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-bg); color: var(--bad); }

.menu { position: relative; }
.menu summary::-webkit-details-marker { display: none; }
.caret { font-size: 11px; color: var(--muted); }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px;
}
.menu-hint { padding: 6px 10px 8px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-pop a { display: block; padding: 8px 10px; border-radius: 5px; color: var(--text); text-decoration: none; }
.menu-pop a:hover { background: var(--accent-soft); }

.bulkbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; padding: 8px 12px;
  background: var(--accent-soft); border-radius: var(--radius); font-weight: 600;
}
.bulkbar input[type="number"] { width: 110px; min-height: 28px; padding: 2px 8px; }
.bulkbar .range span { color: inherit; font-weight: 400; }
td input.ss-input { width: 84px; min-height: 30px; padding: 3px 8px; text-align: right; font-variant-numeric: tabular-nums; }
td input.ss-input:disabled { opacity: .6; }
td input.ss-input:read-only { background: var(--accent-soft); border-color: transparent; font-weight: 600; cursor: default; }
.bulkbar select { min-height: 28px; padding: 2px 8px; }
#form-part input[name="min_stock"]:read-only { background: var(--accent-soft); font-weight: 600; cursor: default; }

/* ---------- tables ---------- */

.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; vertical-align: middle; }
th.num, td.num { text-align: right; }
thead th {
  background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 600;
  white-space: nowrap; border-bottom: 1px solid var(--border);
}
tbody tr + tr td { border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }

.th-sort { background: none; border: 0; padding: 0; cursor: pointer; font-weight: inherit; color: inherit; font-size: inherit; }
.th-sort:hover { color: var(--text); }
.sort-arrow { display: inline-block; width: 12px; margin-left: 3px; font-size: 9px; color: var(--accent); }
th[aria-sort="ascending"] .th-sort, th[aria-sort="descending"] .th-sort { color: var(--text); }

.c-check { width: 36px; padding-right: 0; }
.c-name { min-width: 160px; }
.c-actions, thead th:last-child { text-align: right; }
.c-actions > * + * { margin-left: 4px; }
.sub { color: var(--muted); font-size: 12.5px; }
.qty { font-weight: 600; }
.unit { color: var(--muted); font-size: 12.5px; }
.pos { color: var(--ok); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
td.num .badge { margin-right: 8px; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.type-in { background: var(--ok-bg); color: var(--ok); }
.badge.type-out { background: var(--warn-bg); color: var(--warn); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 48px 20px; text-align: center; color: var(--muted); }
.empty strong { color: var(--text); font-size: 15px; }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--muted); }
.pager select { min-height: 28px; padding: 2px 8px; }
.pager-pos { font-variant-numeric: tabular-nums; }

/* ---------- dialogs ---------- */

dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(10 16 15 / 45%); }
dialog > form, dialog > .import { padding: 22px 24px; }
#dlg-confirm, #dlg-stock { width: min(480px, calc(100vw - 32px)); }
#dlg-confirm p { margin: 0; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.grid label > span { color: var(--muted); font-size: 13px; }
.grid label.wide { grid-column: 1 / -1; }
.grid input { width: 100%; }
.req { color: var(--bad); font-style: normal; }

.hint { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.form-error { margin: 12px 0 0; color: var(--bad); font-weight: 600; min-height: 0; }
.form-error:empty { display: none; }
.dlg-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 20px; }

.part-line { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin: -8px 0 14px; color: var(--muted); }
.part-line .mono { color: var(--text); font-weight: 600; }

.seg { display: flex; margin-bottom: 14px; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.seg label { flex: 1; position: relative; cursor: pointer; text-align: center; }
.seg label + label { border-left: 1px solid var(--border-strong); }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.seg span { display: block; padding: 7px 8px; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--accent); color: var(--on-accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }

.calc {
  display: flex; flex-wrap: wrap; align-items: baseline; align-content: end; gap: 2px 6px;
  color: var(--muted); font-size: 13px; padding-bottom: 7px;
}
.calc b { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.calc b.neg { color: var(--bad); }
.calc .arrow { margin: 0 4px; }

/* ---------- import ---------- */

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 28px 20px; cursor: pointer; position: relative;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
}
.drop:hover, .drop.over, .drop:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.drop span { color: var(--muted); font-size: 13px; max-width: 46ch; }

.modes { border: 0; padding: 0; margin: 16px 0 0; display: grid; gap: 6px; }
.modes legend { padding: 0; margin-bottom: 6px; font-weight: 600; }
.modes label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.file-name { margin: 0 0 12px; font-weight: 600; word-break: break-all; }
.imp-counts { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.imp-count { padding: 10px 8px; border-radius: var(--radius); background: var(--surface-2); text-align: center; }
.imp-count b { display: block; font-size: 22px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.imp-count span { font-size: 12.5px; color: var(--muted); }
.imp-count.ok b { color: var(--ok); }
.imp-count.bad { background: var(--bad-bg); }
.imp-count.bad b, .imp-count.bad span { color: var(--bad); }
.imp-count.zero b { color: var(--muted); font-weight: 400; }
.err-list { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.err-list td { padding: 6px 10px; font-size: 13px; }

/* ---------- toasts ---------- */

#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1000; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  padding: 10px 16px; border-radius: var(--radius); font-weight: 600; box-shadow: var(--shadow);
  background: var(--text); color: var(--bg); max-width: min(90vw, 480px);
}
.toast.error { background: var(--bad); color: var(--surface); }

/* ---------- small screens ---------- */

@media (max-width: 820px) {
  .topbar-inner { padding: 0 16px; }
  .brand { padding: 12px 0 4px; flex: 1; }
  .tabs { order: 3; flex-basis: 100%; }
  .tab { padding: 8px 12px; }
  main { padding: 16px 16px 40px; }
  .stats, .stats.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats.five > :last-child { grid-column: 1 / -1; }
  .stat-value { font-size: 22px; }
  .search { max-width: none; flex-basis: 100%; }
  .grid { grid-template-columns: 1fr; }
  .imp-counts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .menu-pop { right: auto; left: 0; }
}

/* ---------- EAM: dashboard, detail dialog ---------- */

.tabs { overflow-x: auto; scrollbar-width: none; }
.tab { white-space: nowrap; }

.stats.auto { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stats.kpi { margin-bottom: 0; }
.stats.kpi .stat { background: var(--surface-2); }
.stat-value small { font-size: 14px; font-weight: 600; color: var(--muted); }
.stat.is-warn .stat-value { color: var(--warn); }
.stat.is-bad .stat-value { color: var(--bad); }
.kpi-note { margin: 8px 0 16px; }

.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel h3 { margin: 0 0 10px; }
.panel .table-wrap, .detail .table-wrap { border: 0; border-radius: 0; }
.hint.none { margin: 0; }
.hint:empty { display: none; }

table.mini th, table.mini td { padding: 7px 10px; }
table.mini thead th { background: none; }

.link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--accent); font-weight: 600; }
.link:hover { text-decoration: underline; }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.sub.clip { max-width: 36ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid select { width: 100%; }

#dlg-detail { width: min(920px, calc(100vw - 32px)); }
.detail { padding: 20px 24px 24px; }
.detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.detail-head h2 { margin: 0 4px 0 0; }
.detail h3 { margin: 20px 0 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 20px; margin: 0; }
.info-grid dt { color: var(--muted); font-size: 12.5px; }
.info-grid dd { margin: 0; overflow-wrap: anywhere; }
.text-block { margin-top: 12px; }
.text-block h4 { margin: 0 0 2px; font-size: 12.5px; font-weight: 400; color: var(--muted); }
.text-block p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.add-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.add-row.end { justify-content: flex-end; }
.add-row input { min-height: 30px; padding: 3px 8px; }
.add-row .add-part { flex: 1 1 180px; max-width: 280px; }
.add-row .add-qty, .add-row .add-price { width: 96px; }

@media (max-width: 820px) {
  .panels { grid-template-columns: 1fr; }
  .detail { padding: 16px; }
}

/* ---------- EAM: asset / spare part tree ---------- */

.switch { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.switch button { border: 0; background: var(--surface); min-height: 34px; padding: 0 12px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.switch button + button { border-left: 1px solid var(--border-strong); }
.switch button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

.tree-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); }
.tree { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 12px; overflow-x: auto; }
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul ul { margin-left: 13px; padding-left: 14px; border-left: 1px solid var(--border); }
.tree-row { display: flex; align-items: center; gap: 4px 10px; min-height: 38px; padding: 3px 6px; border-radius: 6px; white-space: nowrap; }
.tree-row:hover { background: var(--surface-2); }
.tree-row.asset .btn { visibility: hidden; }
.tree-row.asset:hover .btn, .tree-row.asset:focus-within .btn { visibility: visible; }
.tree-toggle { width: 22px; height: 22px; flex: none; border: 0; border-radius: 4px; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0; }
button.tree-toggle:hover { background: var(--accent-soft); color: var(--accent); }
.tree-dot { width: 6px; height: 6px; margin: 0 8px; flex: none; border-radius: 50%; background: var(--border-strong); }
.tree-num { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; min-width: 110px; justify-content: flex-end; }
.tree-num b { color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.tree-num b.neg { color: var(--bad); }
.tree input.bom-qty, .tree .add-qty { width: 76px; min-height: 28px; padding: 2px 8px; text-align: right; font-variant-numeric: tabular-nums; }
.tree .add-row { margin-top: 0; flex-wrap: nowrap; }
.tree .add-part { width: 220px; flex: none; min-height: 28px; padding: 2px 8px; }
@media (hover: none) { .tree-row.asset .btn { visibility: visible; } }

/* ---------- user guide ---------- */

.help { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; }
.help-toc { position: sticky; top: 76px; }
.help-toc h2 { margin-bottom: 10px; }
.help-toc ol { margin: 0; padding-left: 22px; display: grid; gap: 6px; color: var(--muted); }
.help-toc a { text-decoration: none; }
.help-toc a:hover { text-decoration: underline; }
.help-main { display: grid; gap: 12px; max-width: 900px; }
.help-main .panel { scroll-margin-top: 76px; }
.help-main h3 { font-size: 16px; }
.help-main p { margin: 0 0 8px; color: var(--muted); }
.help-main ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.help-main code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
@media (max-width: 820px) {
  .help { grid-template-columns: 1fr; }
  .help-toc { position: static; }
}

/* ---------- login / accounts ---------- */

body.signed-out > .topbar, body.signed-out > main { display: none; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login form {
  width: min(380px, 100%); display: grid; gap: 14px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.login .brand { padding: 0; }
.login h2 { margin: 6px 0 0; }
.login label { display: grid; gap: 4px; }
.login label > span { color: var(--muted); font-size: 13px; }
.login input { width: 100%; }
.login .form-error { margin: 0; }
.login .btn { min-height: 40px; }
#user-menu .menu-pop { min-width: 160px; }
.view-title { margin: 0; }
.audit-bar, .users-bar { margin-top: 32px; }
#flow-table th[scope="row"] { white-space: nowrap; width: 1%; }
#flow-table thead th:last-child { text-align: left; }
#flow-table td:nth-child(2):not([colspan]) { width: 1%; padding-right: 32px; }
#flow-table select { min-height: 30px; padding: 3px 8px; max-width: 240px; }
#flow-table .chips { align-items: center; gap: 6px 8px; }
#flow-table .badge button { background: none; border: 0; padding: 0 0 0 4px; cursor: pointer; color: inherit; }
/* Zone leaders only look and approve: everything that changes data is hidden. */
body.read-only [data-act]:not([data-ro]), body.read-only .add-row, body.read-only .bulkbar,
body.read-only :is(#assets-import, #assets-add, #bom-import, #bom-add, #wo-add, #plans-generate, #plans-add, #btn-import,
  #btn-add, #po-add, #req-add) { display: none !important; }
body.read-only :is(.ss-input, .rpn-sel) { pointer-events: none; }
body.read-only #rpn-import { display: none !important; }
#approve-body h3 { margin: 20px 0 8px; }
.audit-bar .search { flex: 0 1 260px; }
#audit-table .detail { max-width: 380px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- dashboard charts ---------- */

:root { --chart-line: #c2410c; }
@media (prefers-color-scheme: dark) { :root { --chart-line: #f0895a; } }

.panels.charts { margin-bottom: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h3 { margin: 0; }
.switch.small button { min-height: 28px; padding: 0 10px; font-size: 12.5px; }

svg.chart { display: block; width: 100%; height: auto; }
svg.chart .grid { stroke: var(--border); stroke-width: 1; }
svg.chart .ref { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 4 4; }
svg.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.chart .tick.strong { fill: var(--text); font-weight: 600; }
svg.chart .hit { fill: transparent; }
svg.chart .bar { fill: var(--accent); }
svg.chart g:hover .hit { fill: var(--surface-2); }
svg.chart .cum { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; }
svg.chart .cum-dot { fill: var(--chart-line); stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.legend .key { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 3px; background: var(--accent); vertical-align: -1px; }
.legend .key.cum { height: 2px; border-radius: 0; background: var(--chart-line); vertical-align: 4px; }

.bars { display: grid; gap: 2px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 11fr) minmax(0, 9fr) 4.5em; align-items: center; gap: 10px; padding: 4px 6px; margin: 0 -6px; border-radius: 6px; }
.bar-row:hover { background: var(--surface-2); }
.bar-label, .bar-label .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-row:hover .bar-track { background: var(--border); }
.bar-fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); }
.bar-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.meter + .meter { margin-top: 18px; }
.meter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-weight: 600; }
.meter-value { font-size: 26px; font-variant-numeric: tabular-nums; }
.meter .bar-track { height: 14px; margin-bottom: 6px; }

.chart-tip { position: fixed; z-index: 1000; max-width: 320px; padding: 8px 10px; border-radius: 6px; background: var(--text); color: var(--surface); font-size: 12.5px; line-height: 1.5; white-space: pre-line; pointer-events: none; box-shadow: var(--shadow); }

/* ---------- RPN scores ---------- */

select.rpn-sel { min-height: 30px; padding: 2px 6px; width: 4.2em; text-align: center; font-variant-numeric: tabular-nums; }
select.rpn-sel.unset { color: var(--muted); }
.rpn-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.rpn-scale { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.rpn-scale > div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; color: var(--muted); font-size: 13px; }
.rpn-scale strong { display: block; color: var(--text); margin-bottom: 4px; }
@media (max-width: 760px) { .rpn-scale { grid-template-columns: 1fr; } }

/* ---------- top bar: tabs on their own row ---------- */

/* There are more tabs than fit beside the title; they wrap instead of scrolling out of sight. */
.brand { flex: 1; padding: 10px 0 2px; }
.tabs { order: 3; flex-basis: 100%; flex-wrap: wrap; overflow-x: visible; }
.tab { padding: 8px 12px; }
.help-toc { top: 104px; }
.help-main .panel { scroll-margin-top: 104px; }

/* ---------- data linked from another module (read-only here, click to go there) ---------- */

.link.plain { color: inherit; font: inherit; text-decoration: none; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; }
.link.plain:hover { background: var(--accent-soft); color: inherit; }
.link.plain .sub { display: inline; }
