:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1a1d23;
  --muted: #646b78;
  --accent: #1f4fd8;
  --accent-soft: #e8eefc;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --ok: #1b7f4a;
  --warn: #a86500;
  --s-delivered: #2e9e5b;
  --s-read: #1f4fd8;
  --s-failed: #d14343;
  --s-disabled: #b0b6c0;
  --s-submitted: #e0a33a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --surface: #1a1d23; --surface-2: #22262e; --border: #2e333c;
    --text: #e8eaee; --muted: #9aa1ad; --accent: #6b93ff; --accent-soft: #1e2a4a;
    --danger: #ff6b6b; --danger-soft: #3a1d1d; --ok: #4cc38a; --warn: #f0b44c;
    --s-delivered: #4cc38a; --s-read: #6b93ff; --s-failed: #ff6b6b; --s-disabled: #5b616b; --s-submitted: #f0b44c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.boot { padding: 40px; color: var(--muted); }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; font-weight: 600; }
.brand img { width: 28px; height: 28px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .sep { height: 1px; background: var(--border); margin: 10px 4px; }
.side-foot { margin-top: 16px; padding: 10px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.main { padding: 24px 28px 60px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar { display: none; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.two { grid-template-columns: 2fr 1fr; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 12px; }
.mt { margin-top: 16px; }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
td.wrap { white-space: normal; min-width: 240px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.right { text-align: right; }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 6px; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.row input, .row select { width: auto; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.error { color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 8px; margin-top: 12px; }
.notice { background: var(--accent-soft); padding: 10px 12px; border-radius: 8px; }

/* bits */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill.ok { color: var(--ok); }
.pill.bad { color: var(--danger); }
.pill.warn { color: var(--warn); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-2); min-width: 120px; }
.bar span { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.preview-msg { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; white-space: pre-wrap; max-width: 420px; }
.summary-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-top: 12px; }
.summary-box div { background: var(--surface-2); border-radius: 8px; padding: 10px; }
.summary-box b { display: block; font-size: 18px; }
.chart svg { width: 100%; height: 200px; display: block; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .grid-line { stroke: var(--border); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 5px 12px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 13px; }
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login .brand { padding: 0 0 12px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); z-index: 10; }
#toast.show { opacity: 1; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; max-width: 460px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 4; }
  .main { padding: 16px; }
  .two { grid-template-columns: 1fr; }
}
