:root {
  --bg: #0a0d12;
  --bg-elev: #0e1218;
  --surface: #14191f;
  --surface-2: #1a212a;
  --surface-3: #212a34;
  --border: #232c37;
  --border-strong: #303b48;
  --text: #eef2f7;
  --text-dim: #b3bdc9;
  --muted: #7d8a9a;
  --faint: #5a6675;
  --accent: #4c8dff;
  --accent-2: #6aa1ff;
  --accent-hover: #3d7bf0;
  --accent-soft: rgba(76, 141, 255, 0.12);
  --accent-ring: rgba(76, 141, 255, 0.35);
  --ok: #37c46a;
  --ok-soft: rgba(55, 196, 106, 0.13);
  --warn: #e0a63a;
  --warn-soft: rgba(224, 166, 58, 0.14);
  --err: #ff6b63;
  --err-soft: rgba(255, 107, 99, 0.13);
  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 2px 6px rgba(0, 0, 0, 0.35), 0 14px 40px rgba(0, 0, 0, 0.28);
  --ring: 0 0 0 3px var(--accent-ring);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 620px at 78% -8%, rgba(76, 141, 255, 0.08), transparent 60%),
    radial-gradient(900px 520px at 0% 0%, rgba(76, 141, 255, 0.045), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent-2); text-decoration: none; transition: color 0.14s ease; }
a:hover { color: var(--text); text-decoration: none; }

.layout { min-height: 100vh; display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 28px;
  height: 60px;
  background: rgba(12, 16, 21, 0.82);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  white-space: nowrap;
  font-weight: 650;
  color: var(--text);
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: linear-gradient(150deg, var(--accent-2), var(--accent-hover));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset, 0 2px 8px rgba(76, 141, 255, 0.5);
}
.brand:hover { color: var(--text); }

.nav {
  display: flex; align-items: center; gap: 3px; flex: 1; min-width: 0;
  overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav > * { flex: 0 0 auto; }
.nav a {
  position: relative;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: color 0.14s ease, background 0.14s ease;
}
.nav a:hover { color: var(--text-dim); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.nav a.active::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.content { width: 100%; max-width: 1040px; margin: 0 auto; padding: 34px 28px 72px; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 26px; gap: 16px;
}
h1 { font-size: 25px; margin: 0; font-weight: 680; letter-spacing: -0.02em; }
h2 {
  font-size: 12px; margin: 0 0 18px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted);
}

/* Cards */
.card {
  position: relative;
  background: linear-gradient(180deg, var(--surface), var(--bg-elev));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  border-radius: var(--radius) var(--radius) 0 0;
}

.muted { color: var(--muted); }
.mono {
  font-family: "SF Mono", "SFMono-Regular", ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  font-size: 12.5px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.right { text-align: right; }
.text-err { color: var(--err); }

/* Forms */
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; font-weight: 500; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); background: var(--bg-elev); box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 92px; line-height: 1.5; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row-form { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.field { min-width: 170px; }
.field.grow { flex: 1; }
.inline { display: inline; margin: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.05s ease, box-shadow 0.14s ease;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); color: var(--text); }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent; color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 3px 10px rgba(76, 141, 255, 0.32);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--accent), var(--accent-hover)); color: #fff; }
.btn-small { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-danger { color: var(--err); border-color: rgba(255, 107, 99, 0.32); background: var(--err-soft); }
.btn-danger:hover { background: rgba(255, 107, 99, 0.2); color: #ffb3ae; border-color: rgba(255, 107, 99, 0.5); }
.link-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 0; font-family: inherit; transition: color 0.14s ease;
}
.link-btn:hover { color: var(--text); }

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 650; background: var(--bg-elev);
}
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td { font-size: 14px; }
td.msg { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.rl-form { display: flex; gap: 6px; align-items: center; }
.rl-input { width: 130px; padding: 7px 10px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: 11.5px; font-weight: 600; line-height: 1.5;
  border: 1px solid transparent; letter-spacing: 0.01em;
}
.badge-ok { background: var(--ok-soft); color: #55d986; border-color: rgba(55, 196, 106, 0.25); }
.badge-err { background: var(--err-soft); color: #ff9a94; border-color: rgba(255, 107, 99, 0.28); }
.badge-warn { background: var(--warn-soft); color: #edc06a; border-color: rgba(224, 166, 58, 0.28); }
.badge-muted { background: var(--surface-3); color: var(--text-dim); border-color: var(--border-strong); }

/* Flashes */
.flashes { margin-bottom: 22px; display: flex; flex-direction: column; gap: 10px; }
.flash {
  position: relative;
  padding: 13px 16px 13px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; box-shadow: var(--shadow-sm);
}
.flash::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; border-radius: 3px 0 0 3px; background: var(--accent); }
.flash-error { border-color: rgba(255, 107, 99, 0.28); background: var(--err-soft); }
.flash-error::before { background: var(--err); }
.flash-info { border-color: rgba(76, 141, 255, 0.28); background: var(--accent-soft); }
.flash-info::before { background: var(--accent); }
.flash-key {
  border-color: rgba(55, 196, 106, 0.3); background: var(--ok-soft);
  font-family: ui-monospace, Consolas, monospace; word-break: break-all;
}
.flash-key::before { background: var(--ok); }

/* Login */
.login-wrap { min-height: 82vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { margin-bottom: 4px; }
.login-card .muted { margin-top: 0; margin-bottom: 22px; }
.login-card form { text-align: left; }

.empty { text-align: center; padding: 40px 28px; color: var(--muted); }
.empty-icon { width: 44px; height: 44px; color: var(--accent); margin-bottom: 14px; opacity: 0.85; }
.empty p { margin: 5px 0; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 20px; }

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card {
  position: relative;
  background: linear-gradient(180deg, var(--surface), var(--bg-elev));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* Signal metric cards */
.signal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}
.metric {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 15px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}
.metric-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.metric-value { font-size: 23px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.metric-tag {
  align-self: flex-start; margin-top: 4px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
  padding: 2px 9px; border-radius: var(--radius-pill);
  background: var(--surface-3); color: var(--text-dim); border: 1px solid var(--border-strong);
}
.metric-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--border-strong); }
.metric-bar::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 33%; background: var(--muted); transition: width 0.3s ease; }
.metric-good .metric-bar::after { width: 100%; background: var(--ok); }
.metric-good .metric-tag { background: var(--ok-soft); color: #55d986; border-color: rgba(55, 196, 106, 0.28); }
.metric-ok .metric-bar::after { width: 62%; background: var(--warn); }
.metric-ok .metric-tag { background: var(--warn-soft); color: #edc06a; border-color: rgba(224, 166, 58, 0.28); }
.metric-poor .metric-bar::after { width: 30%; background: var(--err); }
.metric-poor .metric-tag { background: var(--err-soft); color: #ff9a94; border-color: rgba(255, 107, 99, 0.28); }

/* Key/value rows */
.health-grid { display: flex; flex-direction: column; }
.health-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.health-row:last-child { border-bottom: none; }
.health-row > span:last-child { text-align: right; }

/* Progress bars (storage / usage) */
.storage { margin-top: 18px; }
.storage-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; font-size: 13px; }
.storage-bar {
  width: 100%; height: 9px; border-radius: var(--radius-pill);
  background: var(--surface-3); overflow: hidden;
  border: 1px solid var(--border);
}
.storage-bar-fill {
  height: 100%; border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px rgba(76, 141, 255, 0.5);
}
.storage-bar-fill.storage-bar-full { background: linear-gradient(90deg, var(--err), #ff9a94); box-shadow: 0 0 12px rgba(255, 107, 99, 0.5); }
.storage-warning { margin: 11px 0 0; color: var(--err); font-size: 13px; }

/* Settings */
.settings-form { display: flex; flex-direction: column; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 16px 0; border-bottom: 1px solid var(--border);
}
.setting-row:last-of-type { border-bottom: none; }
.setting-info { flex: 1; }
.setting-info label { margin-bottom: 3px; color: var(--text); font-size: 14px; font-weight: 550; }
.setting-info .help { margin: 0; font-size: 12.5px; color: var(--muted); }
.setting-control { flex-shrink: 0; }
.setting-control input[type="number"], .setting-control input[type="text"] { width: 200px; }
.setting-row-wide { align-items: flex-start; flex-direction: column; }
.setting-control-wide { width: 100%; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; }
.setting-control .choice-option {
  display: flex; align-items: center; gap: 9px; margin: 0; padding: 9px 11px;
  color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
}
.setting-control .choice-option input[type="checkbox"] {
  width: 16px; height: 16px; flex: 0 0 16px; appearance: auto; -webkit-appearance: checkbox;
  border: initial; border-radius: initial; background: initial;
}
.setting-control .choice-option input[type="checkbox"]::after { content: none; }
.choice-option small { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.setting-control input[type="checkbox"] {
  width: 42px; height: 24px; appearance: none; -webkit-appearance: none;
  background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  position: relative; cursor: pointer; transition: background 0.16s ease, border-color 0.16s ease;
}
.setting-control input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #cdd6e0; transition: transform 0.16s ease, background 0.16s ease;
}
.setting-control input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.setting-control input[type="checkbox"]:checked::after { transform: translateX(18px); background: #fff; }
.setting-control input[type="checkbox"]:focus-visible { outline: none; box-shadow: var(--ring); }
.settings-form > .btn { align-self: flex-start; margin-top: 20px; }
.stack > .btn { align-self: flex-start; }

/* Actions row */
.action-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* Segmented tabs */
.tabs {
  display: inline-flex; gap: 3px; margin-bottom: 20px; padding: 4px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.tab {
  padding: 6px 16px; border-radius: 7px; color: var(--muted);
  font-size: 13.5px; font-weight: 550; transition: color 0.14s ease, background 0.14s ease;
}
.tab:hover { color: var(--text-dim); }
.tab.active { background: var(--surface-2); color: var(--text); box-shadow: var(--shadow-sm); }

.head-stats { display: flex; align-items: center; gap: 12px; }

/* Inbox */
.inbox-list { padding: 0; overflow: hidden; }
.inbox-item { border-bottom: 1px solid var(--border); }
.inbox-item:last-child { border-bottom: none; }
.inbox-item > summary {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 20px; cursor: pointer; list-style: none;
  transition: background 0.12s ease;
}
.inbox-item > summary::-webkit-details-marker { display: none; }
.inbox-item > summary:hover { background: var(--surface-2); }
.inbox-item.is-unread > summary { border-left: 2px solid var(--accent); padding-left: 18px; }

.chevron {
  width: 7px; height: 7px; flex-shrink: 0;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform 0.15s ease;
}
.inbox-item[open] .chevron { transform: rotate(45deg); }

.inbox-from {
  flex-shrink: 0; width: 160px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text-dim);
}
.inbox-item.is-unread .inbox-from { color: var(--text); font-weight: 650; }
.inbox-preview {
  flex: 1; min-width: 0; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inbox-item.is-unread .inbox-preview { color: var(--text-dim); }
.inbox-tags { flex-shrink: 0; display: flex; align-items: center; gap: 9px; }
.inbox-date { font-size: 12px; }

.inbox-body { padding: 4px 20px 20px 45px; }
.inbox-text {
  white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 13px 15px; font-size: 14px; line-height: 1.6;
}
.inbox-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.inbox-actions .spacer { flex: 1; }

/* Responsive */
@media (max-width: 860px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 14px; }
  .content { padding: 24px 16px 56px; }
  .nav { gap: 0; }
  .nav a { padding: 7px 9px; }
  .signal-grid { grid-template-columns: 1fr; }
  .row-form { flex-direction: column; align-items: stretch; }
  .field { min-width: 0; }
  .setting-row { flex-direction: column; align-items: stretch; gap: 12px; }
  .setting-control input[type="number"], .setting-control input[type="text"] { width: 100%; }
  .inbox-from { width: 104px; }
  .inbox-date { display: none; }
  .inbox-body { padding-left: 20px; }
}
