:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --border: #dde3e0;
  --text: #15201b;
  --muted: #5d6b65;
  --accent: #128c4b;
  --accent-ink: #ffffff;
  --ok: #128c4b;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --idle: #4b5563;
  --idle-bg: #eceff1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 2px 8px rgba(16, 24, 20, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #171e1b;
    --surface-2: #1f2824;
    --border: #2b3631;
    --text: #e6ece9;
    --muted: #97a59f;
    --accent: #25b866;
    --accent-ink: #06210f;
    --ok: #4ad386;
    --ok-bg: #12301f;
    --warn: #f3c25b;
    --warn-bg: #33270d;
    --bad: #ff8a80;
    --bad-bg: #3a1714;
    --idle: #b4bec9;
    --idle-bg: #252c31;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.5em; margin: 8px 0 0; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* Layout */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600;
  padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; text-align: center; }
.count:empty { display: none; }
main { max-width: 1200px; margin: 0 auto; padding: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 16px; }

/* Banner */
.banner {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-radius: var(--radius); margin-bottom: 16px;
  font-weight: 600; border: 1px solid transparent;
}
.banner .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex: none; }
.banner small { display: block; font-weight: 400; opacity: .85; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.idle { background: var(--idle-bg); color: var(--idle); }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile-label { color: var(--muted); font-size: 13px; }
.tile-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 13px; min-height: 1.4em; }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.meter span.full { background: var(--warn); }

/* Facts */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* Buttons and forms */
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { border-color: transparent; background: none; }
.btn.small { padding: 4px 10px; font-size: 13px; }
label { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
select { width: auto; }
input:focus, textarea:focus, select:focus, .btn:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
form .btn { margin-top: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
.check input { width: auto; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td.nowrap { white-space: nowrap; }
.table .msg { max-width: 460px; white-space: pre-wrap; overflow-wrap: anywhere; }
.table .msg.clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.table .acts { display: flex; gap: 4px; justify-content: flex-end; }
.table .acts .btn { white-space: nowrap; }
a { color: var(--accent); }
.empty { color: var(--muted); padding: 16px 8px; text-align: center; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.sent, .tag.invoice { background: var(--ok-bg); color: var(--ok); }
.tag.failed, .tag.reminder, .tag.duplicate { background: var(--warn-bg); color: var(--warn); }
.tag.dropped, .tag.expired, .tag.deleted { background: var(--bad-bg); color: var(--bad); }
.tag.next { background: var(--accent); color: var(--accent-ink); }

/* Sign-in */
.signin { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; margin-bottom: 14px; }
.qr-box img { width: 240px; height: 240px; background: #fff; border-radius: 8px; padding: 6px; display: block; }
.pairing-code { font: 700 28px/1.2 ui-monospace, Menlo, monospace; letter-spacing: .15em; padding: 10px 14px; background: var(--surface-2); border-radius: 8px; display: inline-block; }
.steps { margin: 6px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }

.logs { margin: 0; max-height: 65vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); padding: 12px; border-radius: 8px; }
.rules { margin: 0; padding-left: 20px; color: var(--muted); }
.flash { position: fixed; right: 20px; bottom: 20px; z-index: 10; max-width: 420px; padding: 12px 16px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: 0 6px 24px rgba(0, 0, 0, .2); }
.flash.bad { background: var(--bad); color: #fff; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { margin-bottom: 2px; }
.login-card .btn { width: 100%; }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; gap: 0; }
}
@media (max-width: 560px) {
  main { padding: 16px; }
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  #logout { margin-left: auto; }
  .row { grid-template-columns: 1fr; }
  .tile-value { font-size: 22px; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 8px; }
}
.muted.small { font-size: 12px; }
