:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1d2433; --muted: #5f6b7a; --line: #e2e5ea; --line2: #eef0f3;
  --brand: #0f4c5c; --brand-ink: #ffffff; --accent: #127c8a;
  --red: #c0392b; --red-bg: #fdecea; --amber: #b9770e; --amber-bg: #fef5e1; --green: #1e8449; --green-bg: #e8f6ee;
  --blue-bg: #e9f1fb; --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- top bar ---- */
.topbar { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; min-height: 52px; }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand small { display: block; font-weight: 400; font-size: 11px; opacity: .8; }
.nav { display: flex; gap: 2px; flex: 1; }
.nav a { color: #d7e9ee; padding: 8px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.userbox .who { font-size: 12px; text-align: right; line-height: 1.2; }
.role-chip { background: rgba(255,255,255,.18); padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.btn-ghost-light { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; }
.menu-btn { display: none; background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 6px; padding: 6px 10px; font-size: 14px; }

/* ---- headline strip ---- */
.headline { background: #fff; border-bottom: 1px solid var(--line); }
.headline-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: grid; grid-template-columns: repeat(auto-fit, minmax(122px, 1fr)); gap: 8px; }
.kpi { padding: 6px 10px; border-left: 3px solid var(--line); min-width: 0; overflow-wrap: anywhere; }
.kpi .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.kpi .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 11px; color: var(--muted); }
.kpi.red { border-left-color: var(--red); } .kpi.amber { border-left-color: var(--amber); } .kpi.green { border-left-color: var(--green); } .kpi.brand { border-left-color: var(--accent); }

/* ---- layout ---- */
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.panel.tight { padding: 0; overflow: hidden; }
.panel.tight > .panel-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card.red { border-left: 4px solid var(--red); } .card.amber { border-left: 4px solid var(--amber); } .card.green { border-left: 4px solid var(--green); }

/* ---- buttons & forms ---- */
button, .btn { font: inherit; cursor: pointer; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: #c5cbd3; text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #0e6a76; }
button.danger { color: var(--red); border-color: #f0c4bf; }
button.danger:hover { background: var(--red-bg); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small, .btn.small { padding: 3px 8px; font-size: 12px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
input, select, textarea { font: inherit; color: var(--ink); width: 100%; padding: 7px 9px; border: 1px solid #cfd5dc; border-radius: 7px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9fd3da; border-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { background: #f3f4f6; color: #4b5563; border-color: var(--line); }
textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 10px; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
.field.locked label::after { content: " · read-only"; color: #9aa3ad; }
.field.mine label { color: var(--brand); font-weight: 600; }
.field.changed input, .field.changed select { border-color: var(--amber); background: #fffbf2; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.inline { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.inline > .field { flex: 0 1 420px; margin-bottom: 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 4px; margin: 0 0 14px; }
fieldset.mine { border-color: #9fd3da; background: #f6fbfc; }
legend { font-weight: 700; font-size: 13px; padding: 0 6px; }
legend .tag { font-weight: 500; font-size: 11px; color: var(--muted); margin-left: 6px; }
fieldset.mine legend .tag { color: var(--accent); }

/* ---- badges ---- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--line2); color: var(--muted); white-space: nowrap; }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: var(--blue-bg); color: #1f5fa8; }
.badge.solid-red { background: var(--red); color: #fff; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: -1px; background: #ccc; }
.dot.Red { background: var(--red); } .dot.Amber { background: #e3a21a; } .dot.Green { background: var(--green); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line2); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #fafcfd; }
tr.clickable { cursor: pointer; }
td.wrap { min-width: 220px; overflow-wrap: anywhere; }
tfoot td { font-weight: 700; background: #fafbfc; }

/* ---- task list ---- */
.tasks { list-style: none; margin: 0; padding: 0; counter-reset: t; }
.tasks li { display: grid; grid-template-columns: 32px 1fr; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--line2); }
.tasks li:last-child { border-bottom: 0; }
.tasks .n { font-weight: 700; color: var(--muted); text-align: right; }
.tasks li.u0 .n { color: var(--red); }
.tasks .chips { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 11px; padding: 1px 7px; border: 1px solid var(--line); border-radius: 99px; color: var(--accent); background: #fff; }
.dept-head { display: flex; align-items: center; gap: 8px; }
.empty { color: var(--muted); padding: 10px 0; }

/* ---- filters ---- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand); color: #fff; }
.filters select, .filters input { width: auto; min-width: 150px; }

/* ---- misc ---- */
select[data-status] { min-width: 128px; }
select[data-role] { min-width: 130px; }
.mt { margin-top: 10px; } .mt16 { margin-top: 16px; } .pad { padding: 12px 16px; }
tr.warnrow td { background: var(--amber-bg); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 16px; }
.kv .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.remark { border-left: 3px solid var(--line); padding: 4px 10px; margin-bottom: 10px; white-space: pre-wrap; }
.remark .meta { font-size: 11px; color: var(--muted); white-space: normal; }
pre.update { white-space: pre-wrap; font: 13px/1.5 var(--mono); background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 0; max-height: 420px; overflow: auto; }
textarea.update { font: 13px/1.5 var(--mono); min-height: 360px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--blue-bg); color: #1f4e86; margin-bottom: 12px; font-size: 13px; }
.notice.warn { background: var(--amber-bg); color: #7a5208; }
.notice.err { background: var(--red-bg); color: var(--red); }
.toast-wrap { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 520px); }
.toast { background: #1d2433; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--red); }
.login { max-width: 380px; margin: 10vh auto; }
.login .panel { padding: 24px; }
.login h1 { margin-bottom: 2px; }
details > summary { cursor: pointer; color: var(--accent); }
.split-row { display: grid; grid-template-columns: 1fr 140px 32px; gap: 6px; margin-bottom: 6px; }
.stage-pill { font-size: 12px; white-space: nowrap; }
.big-status { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---- responsive ---- */
@media (max-width: 900px) {
  .menu-btn { display: inline-block; }
  .topbar-inner { flex-wrap: wrap; padding: 8px 16px; }
  .nav { order: 3; flex-basis: 100%; flex-direction: column; display: none; padding-bottom: 8px; }
  .nav.open { display: flex; }
  .userbox { margin-left: auto; }
  .userbox .who { display: none; }
}
@media (max-width: 720px) {
  main { padding: 12px 16px; }
  .headline-inner { grid-template-columns: repeat(2, 1fr); padding: 8px 16px; }
  .kpi { padding: 3px 8px; }
  .kpi .k, .kpi .s { font-size: 10px; }
  .kpi .v { font-size: 15px; }
  /* Tables become stacked cards */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.stack td { border: 0; padding: 3px 12px 3px 118px; position: relative; text-align: left; min-height: 24px; }
  table.stack td::before { content: attr(data-l); position: absolute; left: 12px; top: 4px; width: 98px; color: var(--muted); font-size: 12px; }
  table.stack td.num { text-align: left; }
  table.stack td.wrap { min-width: 0; }
  table.stack tfoot { display: block; }
  .filters select, .filters input { flex: 1 1 140px; min-width: 0; }
  .split-row { grid-template-columns: 1fr 110px 32px; }
}
