/* =========================================================
   Analytics Portal — Component Library
   Pure CSS classes. Use these instead of ad-hoc styles.
   ========================================================= */

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
  user-select: none;
  white-space: nowrap;
}
.btn:focus-visible { outline: none; box-shadow: var(--sh-focus); }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }

.btn-primary {
  background: var(--accent); color: var(--text-on-accent);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }

.btn-secondary {
  background: var(--surface); color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-alt); }

.btn-ghost {
  background: transparent; color: var(--text);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-alt); }

.btn-danger {
  background: var(--surface); color: var(--danger);
  border-color: var(--danger-border);
}
.btn-danger:hover { background: var(--danger-soft); }

.btn-sm { height: var(--control-h-sm); padding: 0 8px; font-size: var(--fs-sm); border-radius: var(--r-xs); }
.btn-lg { height: var(--control-h-lg); padding: 0 16px; font-size: var(--fs-md); }
.btn-icon { width: var(--control-h); padding: 0; }

/* ===================== Inputs ===================== */
.input, .select, .textarea {
  width: 100%;
  height: var(--control-h);
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
.input::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-soft); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--sh-focus);
}
.textarea { height: auto; min-height: 80px; padding: 8px 10px; line-height: 1.5; resize: vertical; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text);
  letter-spacing: -0.005em;
}
.field-hint { font-size: var(--fs-xs); color: var(--text-soft); }
.field-error { font-size: var(--fs-xs); color: var(--danger); }

.input-group {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-sm);
  height: var(--control-h);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
.input-group:focus-within { border-color: var(--accent); box-shadow: var(--sh-focus); }
.input-group .input {
  border: 0; box-shadow: none; background: transparent;
}
.input-group .input:focus { box-shadow: none; }
.input-group-addon {
  display: inline-flex; align-items: center; padding: 0 8px;
  color: var(--text-soft); font-size: var(--fs-sm);
  border-right: 1px solid var(--border);
}
.input-group-addon:last-child { border-right: 0; border-left: 1px solid var(--border); }

/* ===================== Checkbox / Radio / Switch ===================== */
.check, .radio {
  appearance: none;
  width: 16px; height: 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-xs);
  display: inline-grid; place-content: center;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
  flex: 0 0 auto;
}
.radio { border-radius: 999px; }
.check:hover, .radio:hover { border-color: var(--text-soft); }
.check:focus-visible, .radio:focus-visible { outline: none; box-shadow: var(--sh-focus); }

.check:checked {
  background: var(--accent); border-color: var(--accent);
}
.check:checked::after {
  content: "";
  width: 9px; height: 5px;
  border: 1.6px solid #fff;
  border-top: 0; border-right: 0;
  transform: rotate(-45deg) translate(1px, -1px);
}
.check:indeterminate { background: var(--accent); border-color: var(--accent); }
.check:indeterminate::after { content: ""; width: 8px; height: 1.6px; background: #fff; }

.radio:checked { border-color: var(--accent); border-width: 4px; background: var(--surface); }

.switch {
  appearance: none;
  width: 28px; height: 16px;
  background: var(--border-strong);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease);
  flex: 0 0 auto;
}
.switch::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: #fff;
  border-radius: 999px;
  transition: transform var(--dur-2) var(--ease);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(12px); }
.switch:focus-visible { outline: none; box-shadow: var(--sh-focus); }

.check-row { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: var(--fs-base); }
.check-row .label { color: var(--text); }

/* ===================== Badges ===================== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-xs);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  letter-spacing: 0;
  border: 1px solid transparent;
  background: var(--surface-alt);
  color: var(--text-muted);
}
.badge-neutral { background: var(--surface-alt); color: var(--text-muted); border-color: var(--border); }
.badge-accent  { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.badge-success { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.badge-warn    { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.badge-danger  { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.badge-info    { background: var(--info-soft); color: var(--info); }

.badge .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }

/* status pill (uppercase) */
.status {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.06em;
  font-weight: var(--fw-semibold);
  padding: 2px 6px;
  border-radius: var(--r-xs);
}

/* ===================== Cards ===================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); letter-spacing: -0.01em; }
.card-subtitle { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
.card-body { padding: 16px; }
.card-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex; align-items: center; justify-content: space-between;
  font-size: var(--fs-sm); color: var(--text-muted);
  border-radius: 0 0 var(--r-md) var(--r-md);
}

/* ===================== KPI ===================== */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px 16px;
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
}
.kpi-label {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--fs-sm); color: var(--text-muted);
  font-weight: var(--fw-medium);
}
.kpi-value {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1;
  font-size: 26px; line-height: 32px;
  letter-spacing: -0.02em;
  font-weight: var(--fw-medium);
  color: var(--text);
}
.kpi-delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-sm);
  font-family: var(--font-mono);
  font-weight: var(--fw-medium);
}
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta.flat { color: var(--text-soft); }

.kpi-spark { height: 32px; margin-top: 4px; }

/* ===================== Tabs ===================== */
.tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  position: relative;
  padding: 8px 12px;
  font-size: var(--fs-base);
  color: var(--text-muted);
  cursor: pointer;
  border: 0; background: transparent;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); font-weight: var(--fw-medium); }
.tab.is-active::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px;
  height: 2px; background: var(--accent); border-radius: 2px 2px 0 0;
}
.tab .count {
  font-size: var(--fs-xs);
  background: var(--surface-alt);
  padding: 1px 5px; border-radius: var(--r-xs);
  color: var(--text-muted);
}

/* segmented (compact toggle) */
.segmented {
  display: inline-flex;
  background: var(--surface-sunk);
  border-radius: var(--r-sm);
  padding: 2px;
  gap: 2px;
}
.segmented > button {
  border: 0; background: transparent;
  height: 24px; padding: 0 10px;
  font-size: var(--fs-sm); color: var(--text-muted);
  border-radius: var(--r-xs);
  cursor: pointer;
}
.segmented > button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--sh-xs);
}

/* ===================== Table ===================== */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-base);
}
.tbl thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg);
  text-align: left;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  font-weight: var(--fw-medium);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.tbl tbody td {
  padding: 0 12px;
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.tbl tbody tr:hover { background: var(--surface-alt); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tbl-compact tbody td { height: var(--row-h-compact); }
.tbl .col-sort { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.tbl .col-sort:hover { color: var(--text); }

/* row-level color band */
.tbl .band-good { box-shadow: inset 2px 0 0 var(--success); }
.tbl .band-warn { box-shadow: inset 2px 0 0 var(--warn); }
.tbl .band-bad  { box-shadow: inset 2px 0 0 var(--danger); }

/* ===================== Sidebar ===================== */
.sidebar {
  width: var(--sidebar-w);
  height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex: 0 0 auto;
}
.sidebar-header {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section { padding: 12px 8px 4px; }
.sidebar-section-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-soft);
  padding: 4px 8px;
  font-weight: var(--fw-semibold);
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px;
  margin: 2px 0;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: var(--fs-md);
  cursor: pointer;
  text-decoration: none;
  position: relative;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.nav-item:hover { background: var(--surface-alt); color: var(--text); }
.nav-item.is-active {
  color: var(--text);
  background: var(--surface-alt);
  font-weight: var(--fw-medium);
}
.nav-item.is-active::before {
  content: "";
  position: absolute; left: -8px; top: 6px; bottom: 6px;
  width: 2px; border-radius: 2px;
  background: var(--accent);
}
.nav-item .ico-tile {
  width: 28px; height: 28px; flex: 0 0 auto;
  border-radius: 7px;
  display: grid; place-content: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-muted);
  position: relative;
}
.nav-item.is-active .ico-tile {
  background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent);
}
.nav-item .ico-tile svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item .ico-tile.amber  { background: oklch(0.95 0.06 75 / 1);  border-color: oklch(0.83 0.10 75); color: oklch(0.55 0.13 60); }
.nav-item .ico-tile.violet { background: oklch(0.95 0.05 295);     border-color: oklch(0.85 0.08 295); color: oklch(0.50 0.15 295); }
.nav-item .ico-tile.green  { background: oklch(0.95 0.05 155);     border-color: oklch(0.83 0.10 155); color: oklch(0.50 0.13 155); }
.nav-item .ico-tile.indigo { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }
.nav-item .ico-tile.teal   { background: oklch(0.95 0.05 200);     border-color: oklch(0.83 0.09 200); color: oklch(0.50 0.12 200); }
.nav-item .ico-tile.coral  { background: oklch(0.95 0.04 25);      border-color: oklch(0.83 0.10 25);  color: oklch(0.55 0.16 25); }
.nav-item .ico-tile.blue   { background: oklch(0.95 0.04 240);     border-color: oklch(0.83 0.09 240); color: oklch(0.50 0.14 240); }
.nav-item .ico-tile .pulse { position: absolute; top: -2px; right: -2px; width: 7px; height: 7px; border-radius: 999px; background: var(--warn); border: 1.5px solid var(--bg); }
.nav-item .chev { margin-left: auto; color: var(--text-faint); flex: 0 0 auto; }
.nav-item .badge { margin-left: auto; }

/* ===================== Topbar ===================== */
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex; align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-muted); }
.crumbs .sep { color: var(--text-faint); }
.crumbs .here { color: var(--text); font-weight: var(--fw-medium); }

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 4px;
  font-family: var(--font-mono); font-size: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text-muted);
}

.search {
  display: inline-flex; align-items: center; gap: 8px;
  height: 28px; padding: 0 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  width: 280px;
  color: var(--text-faint);
  font-size: var(--fs-sm);
  cursor: pointer;
}
.search:hover { border-color: var(--text-soft); }
.search .grow { flex: 1; }

/* ===================== Tooltips & Popovers ===================== */
.tooltip {
  display: inline-block;
  background: #1C1B19;
  color: #F4F2EE;
  font-size: var(--fs-sm);
  padding: 6px 8px;
  border-radius: var(--r-sm);
  box-shadow: var(--sh-md);
  position: relative;
}
.tooltip::after {
  content: ""; position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%) rotate(45deg);
  width: 8px; height: 8px; background: #1C1B19;
}

.popover {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  padding: 8px;
  min-width: 200px;
}

/* ===================== Calendar (date range) ===================== */
.cal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  padding: 12px;
  width: 280px;
}
.cal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.cal-title { font-weight: var(--fw-medium); font-size: var(--fs-md); }
.cal-nav {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  background: transparent; border: 0; border-radius: var(--r-xs);
  color: var(--text-muted); cursor: pointer;
}
.cal-nav:hover { background: var(--surface-alt); color: var(--text); }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 0;
}
.cal-grid .dow {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-soft); text-align: center;
  padding: 4px 0;
}
.cal-day {
  height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm);
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--text);
  cursor: pointer;
  border-radius: 0;
}
.cal-day:hover { background: var(--surface-alt); }
.cal-day.muted { color: var(--text-faint); }
.cal-day.in-range { background: var(--accent-soft); color: var(--accent); border-radius: 0; }
.cal-day.range-start, .cal-day.range-end {
  background: var(--accent); color: #fff; font-weight: var(--fw-medium);
}
.cal-day.range-start { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.cal-day.range-end   { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.cal-day.range-start.range-end { border-radius: var(--r-sm); }
.cal-day.today { box-shadow: inset 0 0 0 1px var(--accent-border); }

.cal-presets {
  display: flex; flex-direction: column; gap: 1px;
  padding: 8px; border-right: 1px solid var(--border);
  width: 130px;
}
.cal-presets button {
  text-align: left;
  padding: 6px 8px;
  background: transparent; border: 0;
  border-radius: var(--r-xs);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: pointer;
}
.cal-presets button:hover { background: var(--surface-alt); color: var(--text); }
.cal-presets button.is-active { background: var(--accent-soft); color: var(--accent); font-weight: var(--fw-medium); }

/* ===================== Empty / Loading ===================== */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text-muted);
  background: var(--bg);
}
.empty .empty-title { font-size: var(--fs-md); color: var(--text); font-weight: var(--fw-medium); margin-bottom: 4px; }
.empty .empty-body { font-size: var(--fs-sm); max-width: 320px; }

.skel {
  background: linear-gradient(90deg, var(--surface-alt) 0%, var(--surface-sunk) 50%, var(--surface-alt) 100%);
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  border-radius: var(--r-xs);
}
@keyframes skel { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ===================== Layout helpers ===================== */
.app-shell { display: flex; height: 100%; min-height: 100%; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content { flex: 1; padding: 20px 24px; overflow: auto; }
.row { display: flex; gap: 12px; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }
.h1 { font-size: var(--fs-2xl); line-height: var(--lh-2xl); font-weight: var(--fw-semibold); letter-spacing: -0.02em; margin: 0; }
.h2 { font-size: var(--fs-xl); line-height: var(--lh-xl); font-weight: var(--fw-semibold); letter-spacing: -0.015em; margin: 0; }
.h3 { font-size: var(--fs-lg); line-height: var(--lh-lg); font-weight: var(--fw-semibold); letter-spacing: -0.01em; margin: 0; }
.eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-soft); font-weight: var(--fw-semibold); }
