:root {
  --ink: #16181d;
  --ink-soft: #3a3f4b;
  --muted: #6b7280;
  --paper: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #e4e2db;
  --line-strong: #d3d0c7;
  --accent: #3b49df;
  --accent-ink: #ffffff;
  --signal: #12a150;
  --signal-bg: #e7f6ed;
  --alert: #e5484d;
  --alert-bg: #fdeaea;
  --warn: #b7791f;
  --warn-bg: #fbf1dc;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 22, 28, .06), 0 8px 24px -12px rgba(20, 22, 28, .18);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Menlo", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9e8e3;
    --ink-soft: #b9b7b0;
    --muted: #8b8f98;
    --paper: #14151a;
    --surface: #1c1e25;
    --surface-2: #22252d;
    --line: #2c2f38;
    --line-strong: #3a3e49;
    --accent: #6b78ff;
    --accent-ink: #0d0e12;
    --signal: #3ec77e;
    --signal-bg: #16301f;
    --alert: #ff6b6f;
    --alert-bg: #3a1c1e;
    --warn: #e0b25a;
    --warn-bg: #332a15;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -14px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
a { color: inherit; }

.mono { font-family: var(--mono); font-feature-settings: "tnum" 1; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 17px;
  font-family: var(--mono);
}
.brand-name { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
.login-sub { color: var(--muted); margin: 14px 0 22px; font-size: 13px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  letter-spacing: .01em;
}
.input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 14px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
textarea.input { resize: vertical; min-height: 60px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line-strong);
  transition: filter .12s, background .12s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-danger { background: var(--alert); color: #fff; border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: var(--surface-2); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

.form-error {
  color: var(--alert);
  font-size: 13px;
  margin: 4px 0 12px;
  min-height: 18px;
}

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand { padding: 0 8px 18px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 550;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.nav-item .ico { width: 17px; text-align: center; opacity: .9; }
.nav-spacer { flex: 1; }
.nav-foot { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.nav-user { font-size: 12px; color: var(--muted); padding: 0 8px 8px; word-break: break-all; }

.main { min-width: 0; }
.topbar {
  height: 58px;
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.content { padding: 26px 28px; max-width: 1080px; }
.page-head { margin-bottom: 20px; }
.page-title { font-size: 21px; font-weight: 680; letter-spacing: -.02em; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* ---------- Stat tiles ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
}
.stat .k { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-family: var(--mono); font-size: 28px; font-weight: 600; letter-spacing: -.02em; margin-top: 6px; line-height: 1; }
.stat .v.ok { color: var(--signal); }
.stat .v.bad { color: var(--alert); }

.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 18px;
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
}

/* ---------- Cards / tables ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.toolbar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar .grow { flex: 1; min-width: 180px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: none; }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.row-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* SMS feed – signature element */
.sms { align-items: flex-start; }
.sms-dot {
  width: 9px; height: 9px; border-radius: 50%;
  margin-top: 6px; flex-shrink: 0;
  background: var(--line-strong);
}
.sms-dot.sent { background: var(--signal); box-shadow: 0 0 0 3px var(--signal-bg); }
.sms-dot.failed { background: var(--alert); box-shadow: 0 0 0 3px var(--alert-bg); }
.sms-sender { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.sms-body { color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sms-meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; margin-top: 4px; flex-wrap: wrap; }
.route {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 11.5px;
  padding: 1px 7px; border-radius: 20px;
  background: var(--signal-bg); color: var(--signal);
}
.route.failed { background: var(--alert-bg); color: var(--alert); }
.route.none { background: var(--surface-2); color: var(--muted); }

.chip {
  font-family: var(--mono); font-size: 11px;
  padding: 2px 7px; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink-soft);
}
.badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px;
}
.badge.on { background: var(--signal-bg); color: var(--signal); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.dot-live { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-live.on { background: var(--signal); }
.dot-live.off { background: var(--line-strong); }

.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 15px; color: var(--ink-soft); margin-bottom: 6px; }

.center-load { display: grid; place-items: center; padding: 60px; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(10, 11, 14, .5);
  display: grid; place-items: center;
  padding: 20px; z-index: 50;
}
.modal {
  width: 100%; max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 88vh; overflow: auto;
}
.modal-head { padding: 18px 20px 0; }
.modal-title { font-size: 16px; font-weight: 680; }
.modal-body { padding: 16px 20px; }
.modal-foot { padding: 14px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.switch-txt .t { font-weight: 600; font-size: 13.5px; }
.switch-txt .d { color: var(--muted); font-size: 12px; }
.toggle { position: relative; width: 40px; height: 23px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track {
  position: absolute; inset: 0; border-radius: 20px;
  background: var(--line-strong); transition: background .15s;
}
.toggle .track::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 17px; height: 17px; border-radius: 50%; background: #fff;
  transition: transform .15s;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::before { transform: translateX(17px); }

.keybox {
  font-family: var(--mono); font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 12px;
  word-break: break-all; user-select: all;
}
.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow); animation: rise .2s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; left: 0; top: 0; bottom: 0;
    width: 232px; transform: translateX(-100%); transition: transform .2s;
    height: 100dvh;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .topbar { display: flex; }
  .content { padding: 18px 16px; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
}
