/* ============================================================================
   Cadence — design system
   ========================================================================== */
:root {
  --bg-0: #0a0b14;
  --bg-1: #0f1120;
  --bg-2: #151830;
  --panel: rgba(24, 27, 51, 0.72);
  --panel-solid: #181b33;
  --panel-2: #1d2142;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --txt: #e9ecff;
  --txt-dim: #a4a9c9;
  --txt-mute: #6f759b;
  --brand: #7c6cff;
  --brand-2: #a855f7;
  --cyan: #22d3ee;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #fb7185;
  --grad: linear-gradient(120deg, #6d5efc 0%, #8b3ff0 52%, #22d3ee 120%);
  --grad-soft: linear-gradient(120deg, rgba(109,94,252,0.18), rgba(34,211,238,0.14));
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 6px 20px -10px rgba(0, 0, 0, 0.6);
  --sidebar-w: 248px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 700px at 12% -8%, rgba(124,108,255,0.16), transparent 60%),
              radial-gradient(1000px 620px at 100% 0%, rgba(34,211,238,0.10), transparent 55%),
              var(--bg-0);
  color: var(--txt);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.10); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* ---------- Login ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel);
  backdrop-filter: blur(16px); border: 1px solid var(--line-2);
  border-radius: 22px; padding: 36px 32px; box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.auth-brand svg { width: 44px; height: 44px; }
.auth-brand h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
.auth-sub { color: var(--txt-dim); margin: 0 0 26px; font-size: 13px; }
.auth-card label { display: block; font-size: 12px; color: var(--txt-dim); margin: 14px 0 6px; font-weight: 600; }
.auth-err {
  background: rgba(251,113,133,0.12); border: 1px solid rgba(251,113,133,0.35);
  color: #ffc4cd; padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-top: 16px;
}
.auth-foot { margin-top: 22px; text-align: center; color: var(--txt-mute); font-size: 12px; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, rgba(21,24,48,0.95), rgba(12,13,26,0.95));
  border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; }
.brand svg { width: 36px; height: 36px; }
.brand-name { font-weight: 700; letter-spacing: -0.02em; font-size: 17px; }
.brand-tag { font-size: 10.5px; color: var(--txt-mute); letter-spacing: 0.04em; text-transform: uppercase; }
.nav-group-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--txt-mute); padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 11px;
  color: var(--txt-dim); font-weight: 500; font-size: 13.5px; position: relative; transition: all .15s;
}
.nav-item svg { width: 18px; height: 18px; opacity: 0.85; flex: none; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--txt); }
.nav-item.active { background: var(--grad-soft); color: #fff; box-shadow: inset 0 0 0 1px var(--line-2); }
.nav-item.active::before { content: ''; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--grad); }
.nav-badge { margin-left: auto; background: var(--red); color: #fff; font-size: 10.5px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 9px; background: var(--grad); display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 13px; }
.user-chip .u-name { font-size: 13px; font-weight: 600; }
.user-chip .u-role { font-size: 11px; color: var(--txt-mute); text-transform: capitalize; }

/* ---------- Main / topbar ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 16px 28px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  background: rgba(10,11,20,0.72); backdrop-filter: blur(12px);
}
.topbar h2 { margin: 0; font-size: 19px; letter-spacing: -0.02em; }
.topbar .page-sub { color: var(--txt-mute); font-size: 12.5px; margin-top: 1px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.gw-pill {
  display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--txt-dim);
  background: var(--panel-solid); border: 1px solid var(--line); padding: 6px 11px; border-radius: 20px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--txt-mute); }
.dot.live { background: var(--green); box-shadow: 0 0 0 3px rgba(52,211,153,0.18); }
.dot.off { background: var(--amber); }
.content { padding: 24px 28px 60px; overflow-x: hidden; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 15px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--panel-solid); color: var(--txt); font-weight: 600; font-size: 13px; transition: all .15s; }
.btn:hover { border-color: var(--line-2); background: var(--panel-2); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--grad); border: none; color: #fff; box-shadow: 0 10px 24px -12px rgba(124,108,255,0.9); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 11px; font-size: 12px; border-radius: 9px; }
.btn.danger { color: #ffd0d6; border-color: rgba(251,113,133,0.4); background: rgba(251,113,133,0.08); }
.btn.danger:hover { background: rgba(251,113,133,0.16); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn svg { width: 15px; height: 15px; }

/* ---------- Inputs ---------- */
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2);
  background: rgba(10,11,22,0.6); color: var(--txt); font-size: 13.5px; font-family: inherit; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(124,108,255,0.18); }
textarea { resize: vertical; min-height: 84px; }
select option { background: var(--panel-solid); }
label.fld { display: block; font-size: 12px; color: var(--txt-dim); font-weight: 600; margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

/* ---------- Cards & grid ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.card-h { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.card-h h3 { margin: 0; font-size: 15px; letter-spacing: -0.01em; }
.card-h .sub { color: var(--txt-mute); font-size: 12px; }
.card-h .spacer { margin-left: auto; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Stat tiles ---------- */
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; position: relative; overflow: hidden; }
.stat::after { content: ''; position: absolute; inset: 0; background: var(--grad-soft); opacity: 0; transition: opacity .2s; }
.stat:hover::after { opacity: 0.5; }
.stat .k { font-size: 12px; color: var(--txt-dim); font-weight: 600; display: flex; align-items: center; gap: 7px; position: relative; }
.stat .k svg { width: 15px; height: 15px; opacity: 0.8; }
.stat .v { font-size: 27px; font-weight: 750; letter-spacing: -0.03em; margin-top: 8px; position: relative; }
.stat .d { font-size: 11.5px; color: var(--txt-mute); margin-top: 3px; position: relative; }
.stat .tag { position: absolute; top: 16px; right: 16px; font-size: 9.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--cyan); background: rgba(34,211,238,0.12); padding: 3px 7px; border-radius: 6px; }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650; padding: 3px 9px; border-radius: 7px; background: rgba(255,255,255,0.06); color: var(--txt-dim); border: 1px solid var(--line); }
.badge.green { color: #a7f3d0; background: rgba(52,211,153,0.12); border-color: rgba(52,211,153,0.3); }
.badge.amber { color: #fde68a; background: rgba(251,191,36,0.12); border-color: rgba(251,191,36,0.3); }
.badge.red { color: #fecdd3; background: rgba(251,113,133,0.12); border-color: rgba(251,113,133,0.3); }
.badge.violet { color: #ddd6fe; background: rgba(139,92,246,0.15); border-color: rgba(139,92,246,0.35); }
.badge.cyan { color: #a5f3fc; background: rgba(34,211,238,0.12); border-color: rgba(34,211,238,0.3); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 5px 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); color: var(--txt-dim); }
.chip .x { cursor: pointer; opacity: 0.6; }
.chip .x:hover { opacity: 1; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; color: var(--txt-mute); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: background .12s; }
table.tbl tbody tr:hover { background: rgba(255,255,255,0.03); }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar-cell { position: relative; }
.bar-cell .bar { position: absolute; left: 0; top: 50%; transform: translateY(-50%); height: 22px; border-radius: 5px; background: var(--grad-soft); z-index: 0; }
.bar-cell span { position: relative; z-index: 1; }

/* ---------- Toggle switch ---------- */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: rgba(255,255,255,0.14); border-radius: 24px; transition: .2s; }
.switch .track::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .track { background: var(--grad); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; background: var(--panel-solid); padding: 4px; border-radius: 12px; border: 1px solid var(--line); width: fit-content; }
.tab { padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--txt-dim); }
.tab.active { background: var(--grad-soft); color: #fff; box-shadow: inset 0 0 0 1px var(--line-2); }
.tab:hover:not(.active) { color: var(--txt); }

/* ---------- Charts ---------- */
.chart { width: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.legend .item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--txt-dim); }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; }
.axis-lbl { fill: var(--txt-mute); font-size: 10px; }

/* ---------- Funnel ---------- */
.funnel-stage { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.funnel-bar { height: 46px; border-radius: 10px; background: var(--grad); display: flex; align-items: center; padding: 0 16px; color: #fff; font-weight: 700; min-width: 90px; box-shadow: var(--shadow-sm); }
.funnel-meta { color: var(--txt-dim); font-size: 13px; }

/* ---------- Recommend cards ---------- */
.rec-hero { background: linear-gradient(120deg, rgba(109,94,252,0.16), rgba(34,211,238,0.10)); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 22px 24px; }
.rec-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.rec-card .rc-dim { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--cyan); font-weight: 700; }
.rec-card .rc-title { font-size: 16px; font-weight: 700; margin: 6px 0; letter-spacing: -0.01em; }
.rec-card .rc-why { font-size: 12.5px; color: var(--txt-dim); line-height: 1.5; }
.conf-bar { height: 6px; border-radius: 6px; background: rgba(255,255,255,0.1); overflow: hidden; margin-top: 12px; }
.conf-bar > i { display: block; height: 100%; background: var(--grad); border-radius: 6px; }

/* ---------- Requests / thread ---------- */
.req-item { display: flex; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; transition: all .15s; margin-bottom: 10px; }
.req-item:hover { border-color: var(--line-2); transform: translateY(-1px); }
.req-item.unread { box-shadow: inset 3px 0 0 var(--brand); }
.msg { padding: 11px 14px; border-radius: 12px; max-width: 76%; font-size: 13px; line-height: 1.5; }
.msg.client { background: var(--panel-2); align-self: flex-start; border: 1px solid var(--line); }
.msg.admin { background: var(--grad-soft); align-self: flex-end; border: 1px solid var(--line-2); }
.msg.status { align-self: center; background: transparent; color: var(--txt-mute); font-size: 12px; font-style: italic; max-width: 100%; }
.msg .meta { font-size: 10.5px; color: var(--txt-mute); margin-bottom: 4px; }
.thread { display: flex; flex-direction: column; gap: 10px; padding: 4px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(6,7,15,0.7); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--panel-solid); border: 1px solid var(--line-2); border-radius: 18px; width: 100%; max-width: 520px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal-h { padding: 20px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-h h3 { margin: 0; font-size: 17px; }
.modal-b { padding: 22px; }
.modal-f { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
.modal-close { margin-left: auto; color: var(--txt-mute); font-size: 22px; line-height: 1; background: none; border: none; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: var(--panel-solid); border: 1px solid var(--line-2); border-left: 3px solid var(--brand); border-radius: 11px; padding: 12px 16px; box-shadow: var(--shadow); font-size: 13px; min-width: 240px; max-width: 380px; animation: slidein .25s ease; }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---------- FAB (request a feature) ---------- */
.fab { position: fixed; bottom: 24px; right: 24px; z-index: 50; display: flex; align-items: center; gap: 9px; padding: 13px 18px; border-radius: 30px; background: var(--grad); color: #fff; font-weight: 700; font-size: 13.5px; border: none; box-shadow: 0 14px 34px -12px rgba(124,108,255,0.85); }
.fab:hover { filter: brightness(1.08); transform: translateY(-2px); }
.fab svg { width: 18px; height: 18px; }

/* ---------- Misc ---------- */
.muted { color: var(--txt-mute); }
.dim { color: var(--txt-dim); }
.center { text-align: center; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mt8{margin-top:8px}.mt16{margin-top:16px}.mt24{margin-top:24px}.mb8{margin-bottom:8px}.mb16{margin-bottom:16px}
.gap8{gap:8px}.flex{display:flex}.aic{align-items:center}.wrap{flex-wrap:wrap}
.pill-metric { font-size: 12px; color: var(--txt-dim); }
.pill-metric b { color: var(--txt); font-weight: 700; }
.skeleton { background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.09), rgba(255,255,255,0.04)); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.empty { text-align: center; padding: 40px; color: var(--txt-mute); }
.help-h { font-size: 20px; margin: 26px 0 10px; letter-spacing: -0.02em; }
.help-h:first-child { margin-top: 0; }
.help p, .help li { color: var(--txt-dim); font-size: 13.5px; line-height: 1.65; }
.help code { background: var(--panel-2); padding: 2px 6px; border-radius: 5px; font-size: 12px; color: var(--cyan); }
.help .step { display: flex; gap: 14px; margin-bottom: 14px; }
.help .step .n { width: 26px; height: 26px; border-radius: 8px; background: var(--grad); display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) { .grid.cols-4 { grid-template-columns: repeat(2,1fr); } .grid.cols-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; width: 260px; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex !important; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}
.menu-btn { display: none; }
