:root {
  --ink: #15181c;
  --muted: #5b6470;
  --quiet: #8a929c;
  --ground: #f4f5f7;
  --surface: #ffffff;
  --line: #e2e5ea;
  --line-soft: #edeff2;
  --accent: #1f55c4;
  --accent-ink: #163f94;
  --accent-soft: #e8eefb;
  --accent-line: #c7d5f5;
  --green: #17803d;
  --green-ink: #145c30;
  --green-soft: #e6f4ea;
  --orange: #d9822b;
  --orange-ink: #a85107;
  --orange-soft: #fdf0e3;
  --red: #b42318;
  --red-soft: #fdecea;
  --grey: #9aa2ad;
  --grey-soft: #eef0f3;
  --grey-ink: #3f4752;
  --radius: 12px;
  --mono: "JetBrains Mono", Consolas, "Courier New", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ground); color: var(--ink); }
body { font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
h3 { margin: 0; font-size: 14px; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: 12px; }

/* top bar */
.topbar { background: var(--ink); color: #fff; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 8px 32px; display: flex; flex-wrap: wrap; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: #fff; }
.brand:hover { color: #fff; text-decoration: none; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a { color: #c9ced6; padding: 10px 14px; border-radius: 6px; }
.nav a:hover { color: #fff; text-decoration: none; background: #23282f; }
.nav a.active { color: #fff; background: #2c323a; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.topbar-right a { color: #c9ced6; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #3b4350; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; }

main { max-width: 1400px; margin: 0 auto; padding: 24px 32px 56px; display: flex; flex-direction: column; gap: 24px; }

/* layout */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.subtle { color: var(--muted); font-size: 13px; }
.cols { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.col-main { flex: 999 1 640px; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.col-side { flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-pad { padding: 16px 20px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--line); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; color: var(--ink); display: block; }
a.kpi:hover { text-decoration: none; border-color: var(--accent-line); }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 30px; font-weight: 700; margin-top: 2px; }
.kpi .value small { font-size: 17px; color: var(--muted); font-weight: 500; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.kpi.accent { background: var(--accent-soft); border-color: var(--accent-line); }
.kpi.accent .label, .kpi.accent .foot { color: #1f4aa8; }

/* status bar */
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line-soft); }
.bar span { display: block; }
.bg-green { background: var(--green); } .bg-orange { background: var(--orange); } .bg-red { background: var(--red); } .bg-grey { background: var(--grey); }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill.high, .pill.red { background: var(--red-soft); color: var(--red); }
.pill.medium, .pill.orange { background: var(--orange-soft); color: var(--orange-ink); }
.pill.low, .pill.grey { background: var(--grey-soft); color: var(--grey-ink); }
.pill.green { background: var(--green-soft); color: var(--green-ink); }
.pill.blue { background: var(--accent-soft); color: #1f4aa8; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.green { background: var(--green); } .dot.orange { background: var(--orange); } .dot.red { background: var(--red); } .dot.grey { background: var(--grey); }
.dot.hollow { background: transparent; border: 2px solid var(--grey); }
.health { display: inline-flex; align-items: center; gap: 10px; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 500; }
.health.ok { background: var(--green-soft); color: var(--green-ink); }
.health.bad { background: var(--red-soft); color: var(--red); }
.health.off { background: var(--grey-soft); color: var(--grey-ink); }

/* tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; padding: 10px 12px; white-space: nowrap; }
table.t td { padding: 12px; border-top: 1px solid var(--line-soft); vertical-align: top; }
table.t th:first-child, table.t td:first-child { padding-left: 20px; }
table.t th:last-child, table.t td:last-child { padding-right: 20px; }
table.t tr.clickable { cursor: pointer; }
table.t tr.clickable:hover td { background: #fafbfc; }
.t .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.empty { padding: 28px 20px; color: var(--muted); text-align: center; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; padding: 8px 12px; border-radius: 6px; border: 1px solid #d3d7de; background: #fff; color: var(--ink); min-height: 36px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b8bec8; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); color: #fff; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.dark:hover { color: #fff; background: #2c323a; }
.btn.danger { color: var(--red); border-color: #f0c2bd; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.lg { font-size: 14px; padding: 10px 16px; min-height: 44px; border-radius: 8px; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.seg { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.seg .btn.on { background: var(--ink); border-color: var(--ink); color: #fff; }

/* forms */
label.f { display: block; font-size: 13px; font-weight: 600; }
.input, select.input, textarea.input { width: 100%; padding: 9px 12px; border: 1px solid #d3d7de; border-radius: 8px; background: #fff; min-height: 40px; }
.input:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input.sm { width: 76px; min-height: 36px; padding: 6px 8px; }
textarea.input { resize: vertical; }
fieldset.box { border: 1px solid var(--line); border-radius: 10px; margin: 0; padding: 14px 16px; }
fieldset.box legend { font-size: 14px; font-weight: 600; padding: 0 6px; }
.check { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.check input[type=checkbox] { width: 18px; height: 18px; }
.hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

/* list rows */
.list-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.list-row:first-child { border-top: 0; }
.time { font-family: var(--mono); font-size: 13px; color: var(--muted); width: 44px; flex: none; }
.progress { display: flex; gap: 3px; }
.progress span { height: 8px; border-radius: 2px; background: var(--line); }
.progress span.on { background: var(--orange); }

/* customer cards */
.cust { display: block; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--ink); }
.cust:hover { text-decoration: none; border-color: var(--accent-line); color: var(--ink); }

/* tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs a { color: var(--muted); padding: 10px 14px; }
.tabs a.active { color: var(--ink); font-weight: 600; border-bottom: 2px solid var(--ink); margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.count { background: var(--accent-soft); color: #1f4aa8; border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600; }

/* detail */
.op-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.op-card { background: var(--surface); border: 1px solid var(--line); border-top-width: 4px; border-radius: 10px; padding: 14px 18px; }
.op-card.green { border-top-color: var(--green); } .op-card.orange { border-top-color: var(--orange); } .op-card.red { border-top-color: var(--red); } .op-card.grey { border-top-color: var(--grey); }
.strip-row { display: flex; align-items: center; gap: 12px; }
.strip-row .name { width: 96px; flex: none; font-size: 13px; font-weight: 500; }
.strip { display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 3px; flex: 1; min-width: 540px; }
.strip span { height: 22px; border-radius: 3px; background: var(--line); }
.strip span.green { background: var(--green); } .strip span.orange { background: var(--orange); } .strip span.red { background: var(--red); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; font-size: 13px; }
.timeline li { display: flex; gap: 12px; }
.timeline .dot { margin-top: 4px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 13px; color: var(--muted); }
.meta strong { color: var(--ink); font-weight: 600; }
.notice { border-radius: 10px; padding: 12px 16px; display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.notice.warn { background: var(--orange-soft); color: #6b3a07; }
.notice.bad { background: var(--red-soft); color: #7a1a12; }
.notice.info { background: var(--accent-soft); color: #1f3d80; }
pre.mailbody { margin: 0; padding: 16px 20px; white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; max-height: 520px; overflow: auto; background: #fbfbfc; border-top: 1px solid var(--line); }
iframe.original { width: 100%; height: 560px; border: 0; border-top: 1px solid var(--line); background: #fff; }

/* toast + dialog */
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 14px; max-width: 420px; box-shadow: 0 6px 24px rgba(0,0,0,.18); z-index: 50; }
.toast.err { background: var(--red); }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(520px, 92vw); }
dialog::backdrop { background: rgba(21, 24, 28, 0.35); }
dialog .dlg-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog .dlg-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.login { max-width: 420px; margin: 12vh auto; text-align: center; }
.spinner { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 640px) {
  .topbar-inner, main { padding-left: 16px; padding-right: 16px; }
  h1 { font-size: 22px; }
}
