/* ============================================================
   Pulse Analytics — design system
   Self-contained (no CSS framework). Light + dark themes.
   ============================================================ */

:root {
  --bg:        #fbfbfa;
  --surface:   #ffffff;
  --surface-2: #f4f5f4;
  --border:    #eaebe9;
  --text:      #111413;
  --muted:     #6d7370;
  --primary:   #16a34a;
  --primary-2: #22c55e;
  --accent:    #0ea5a4;
  --success:   #16a34a;
  --danger:    #e5484d;
  --warning:   #d97706;
  --ring: 0 0 0 3px rgba(22, 163, 74, .18);
  --shadow: 0 1px 2px rgba(17,20,19,.05);
  --radius: 12px;
  --mono: 'SF Mono', ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', Consolas, 'Liberation Mono', monospace;
}

:root[data-theme="dark"] {
  --bg:        #0a0c0b;
  --surface:   #111413;
  --surface-2: #191d1b;
  --border:    #232826;
  --text:      #eef1ee;
  --muted:     #8b938d;
  --primary:   #22c55e;
  --primary-2: #4ade80;
  --success:   #22c55e;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0a0c0b;
    --surface:   #111413;
    --surface-2: #191d1b;
    --border:    #232826;
    --text:      #eef1ee;
    --muted:     #8b938d;
    --primary:   #22c55e;
    --primary-2: #4ade80;
    --success:   #22c55e;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--text); text-decoration: none; }
a:hover { color: var(--primary); }
h1 { font-size: 25px; font-weight: 600; letter-spacing: -.03em; margin: 0 0 .3em; }
h2 { font-size: 19px; font-weight: 600; letter-spacing: -.022em; margin: 0 0 .3em; }
h3 { font-size: 14.5px; font-weight: 600; letter-spacing: -.012em; margin: 0 0 .2em; }
.muted { color: var(--muted); }
.mono, .num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
/* mono eyebrow — the terminal signature used across the app */
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .06em; color: var(--primary); text-transform: none; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 244px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 1px;
  overflow-y: auto; overscroll-behavior: contain;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; padding: 6px 10px 14px; letter-spacing: -.03em; position: sticky; top: -16px; background: var(--surface); z-index: 2; }
.brand .dot { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; color: #fff; }
.nav-div { height: 1px; background: var(--border); margin: 8px 8px; }
.nav-link { position: relative; display: flex; align-items: center; gap: 11px; padding: 8px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; font-size: 14px; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav-link svg { width: 17px; height: 17px; opacity: .8; }
.nav-link.active svg { opacity: 1; color: var(--primary); }
.sidebar .spacer { flex: 1; min-height: 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 28px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 20;
}
.content { padding: 26px 28px 60px; max-width: 1240px; width: 100%; }
.verify-bar { display: flex; align-items: center; gap: 8px; padding: 9px 28px; background: color-mix(in srgb, var(--warning) 12%, var(--surface)); border-bottom: 1px solid var(--border); font-size: 13.5px; color: var(--text); }
.verify-bar a { color: var(--primary); font-weight: 600; margin-inline-start: auto; }
.view-tabs { display: flex; gap: 2px; margin: -4px 0 22px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.view-tabs a { padding: 9px 14px; font-size: 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.view-tabs a:hover { color: var(--text); text-decoration: none; }
.view-tabs a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(22,163,74,.14), transparent 60%),
    radial-gradient(800px 500px at 90% 100%, rgba(14,165,164,.10), transparent 55%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 410px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 18px 20px; }
.grid { display: grid; gap: 14px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.span-2 { grid-column: span 2; }

/* ---------- Stat tiles (editorial) ---------- */
.stat { padding: 16px 18px; position: relative; }
.stat .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.stat .value { font-size: 30px; font-weight: 600; letter-spacing: -.04em; margin-top: 10px; line-height: 1; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 12.5px; margin-top: 7px; font-weight: 550; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }
.stat-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; margin-left: auto; }

/* ---------- Live badge ---------- */
.live { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 0 rgba(16,185,129,.6); animation: pulse 1.8s infinite; }
@keyframes pulse { 0%{ box-shadow: 0 0 0 0 rgba(16,185,129,.55);} 70%{ box-shadow: 0 0 0 12px rgba(16,185,129,0);} 100%{ box-shadow: 0 0 0 0 rgba(16,185,129,0);} }

/* ---------- Tables / lists ---------- */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.list-row:last-child { border-bottom: 0; }
.list-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .count { font-weight: 700; }
.bar { position: relative; flex: 1; height: 7px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > span { position: absolute; inset: 0 auto 0 0; background: var(--primary); border-radius: 3px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; gap: 10px; }
.section-head h3 { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.section-head h3::before { content: "// "; color: var(--primary); font-family: var(--mono); font-weight: 600; opacity: .8; }
.content > h1, .content h1 { letter-spacing: -.025em; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; padding: 11px 13px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 14.5px; font-family: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--ring); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; font-family: inherit;
  background: var(--primary); color: #fff;
  transition: filter .15s, background .15s, border-color .15s;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn:active { filter: brightness(.97); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }

/* ---------- Misc ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 6px; background: var(--surface-2); font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
.alert { padding: 12px 14px; border-radius: 11px; font-size: 14px; margin-bottom: 14px; }
.alert.err { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert.ok  { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; font-family: 'SF Mono', ui-monospace, Consolas, monospace; font-size: 13px; overflow-x: auto; white-space: pre; color: var(--text); }
.icon-btn { background: var(--surface-2); border: 1px solid var(--border); width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--border); }
.select-inline { width: auto; min-width: 180px; padding: 9px 12px; }
.flag { font-size: 18px; line-height: 1; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) { .cols-4 { grid-template-columns: repeat(2,1fr);} .cols-3{ grid-template-columns:1fr 1fr;} }
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -260px; z-index: 60; transition: left .2s; box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .cols-4, .cols-3, .cols-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .content { padding: 18px 16px 50px; }
  .topbar { padding: 14px 16px; }
  .hamburger { display: grid !important; }
  .backdrop.show { display: block; }
}
.hamburger { display: none; }
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; }

/* ---------- Micro-interactions ---------- */
.card { transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease; }
.nav-link, .btn, .icon-btn, .pill { transition: background .15s, color .15s, transform .08s, box-shadow .15s, border-color .15s; }
a.card:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.stat .value { transition: color .2s; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: none; } }
.content > * { animation: fadeUp .35s ease both; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; z-index: 200; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; max-width: 340px; }
:root[dir="rtl"] #toasts { right: auto; left: 20px; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 14px; font-weight: 500; animation: fadeUp .25s ease both; }
.toast .ic { width: 22px; height: 22px; flex-shrink: 0; display: grid; place-items: center; border-radius: 7px; color: #fff; font-size: 13px; }
.toast.ok  .ic { background: var(--success); }
.toast.err .ic { background: var(--danger); }
.toast.info .ic { background: var(--primary); }
.toast.hide { animation: toastOut .25s ease forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ---------- Command palette ---------- */
#cmdk { position: fixed; inset: 0; z-index: 300; display: none; align-items: flex-start; justify-content: center; padding-top: 12vh; background: rgba(8,10,16,.55); backdrop-filter: blur(4px); }
#cmdk.open { display: flex; }
.cmdk-box { width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 24px 70px rgba(0,0,0,.4); overflow: hidden; animation: fadeUp .2s ease both; }
.cmdk-box input { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 16px 18px; font-size: 16px; background: transparent; }
.cmdk-box input:focus { box-shadow: none; }
.cmdk-list { max-height: 52vh; overflow-y: auto; padding: 8px; }
.cmdk-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; cursor: pointer; font-size: 14.5px; }
.cmdk-item .k { margin-left: auto; font-size: 11px; color: var(--muted); }
.cmdk-item.sel, .cmdk-item:hover { background: var(--surface-2); }
.cmdk-item svg { width: 17px; height: 17px; opacity: .8; }
.cmdk-group { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 12px 4px; font-weight: 700; }

/* ---------- Notifications ---------- */
.notif-wrap { position: relative; }
.notif-badge { position: absolute; top: -3px; right: -3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; display: grid; place-items: center; }
.notif-panel { position: absolute; top: 46px; right: 0; width: 320px; max-height: 400px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); display: none; z-index: 30; }
:root[dir="rtl"] .notif-panel { right: auto; left: 0; }
.notif-panel.open { display: block; animation: fadeUp .18s ease both; }
.notif-item { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.notif-item:last-child { border-bottom: 0; }
.notif-item.unread { background: color-mix(in srgb, var(--primary) 7%, transparent); }
.notif-item .t { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ---------- Chart annotation markers ---------- */
.anno-flag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-size: 12px; font-weight: 600; }

.star-btn { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 17px; line-height: 1; padding: 2px; }
.star-btn.on { color: #f59e0b; }
kbd { background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }

/* ---------- Onboarding tour ---------- */
#tour { position: fixed; inset: 0; z-index: 400; display: none; }
#tour.on { display: block; }
#tourSpot { position: absolute; border-radius: 12px; box-shadow: 0 0 0 9999px rgba(8,10,16,.62); transition: all .3s ease; pointer-events: none; }
#tourPop { position: absolute; width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4); padding: 16px; transition: all .3s ease; }
#tourPop h4 { margin: 0 0 6px; font-size: 15px; }
#tourPop p { margin: 0 0 14px; font-size: 13.5px; color: var(--muted); }
#tourPop .row { display: flex; align-items: center; justify-content: space-between; }
#tourPop .dots { display: flex; gap: 5px; }
#tourPop .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
#tourPop .dots i.on { background: var(--primary); }

/* ---------- Reorderable widgets ---------- */
.reorder [data-rk] { cursor: grab; }
.reorder [data-rk].dragging { opacity: .5; }
.reorder [data-rk].over { outline: 2px dashed var(--primary); outline-offset: 3px; }
.drag-handle { cursor: grab; color: var(--muted); user-select: none; }

/* ---------- Print / PDF ---------- */
@media print {
  .sidebar, .topbar, .backdrop { display: none !important; }
  .app, .main { display: block; }
  .content { padding: 0; max-width: 100%; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  body { background: #fff; }
  :root { --bg:#fff; --surface:#fff; --text:#000; --muted:#444; --border:#ddd; --surface-2:#f4f4f4; }
}
