/* Base reset, layout shell, and typography — Median Snap dashboard.
 *
 * Light theme: white + Snap yellow + cyan accent.
 * Light sidebar (subtle gray tint to separate from main).
 *
 * This file owns:
 *   - CSS reset
 *   - body / html base typography
 *   - layout shell (.app, .sidebar, .main)
 *   - sidebar nav structure
 *   - page-level structure (.page-header, grids, utility helpers)
 *
 * Component-level styling lives in components.css.
 */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Ambient brand glow — sits behind content, barely visible. On a light
   background the radial yellow tint is naturally subtle. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--brand-glow);
  pointer-events: none;
  z-index: 0;
}
.app { position: relative; z-index: 1; }

/* Scrollbars — neutral, soft, not visually loud */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-pill);
  border: 2px solid var(--surface-base);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Selection — yellow tint, visible on white backgrounds */
::selection { background: var(--state-selected); color: var(--text-primary); }

/* Links — cyan, our "data" accent. Underline draws in on hover instead
   of a binary toggle: a faux underline via background-image grows from
   left to right. Subtler than a hard text-decoration jump and standard
   on Linear, Stripe, Vercel marketing pages. */
a {
  color: var(--text-accent);
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size var(--duration-normal) var(--ease-standard);
}
a:hover { background-size: 100% 1px; }
/* Skip the animation in places where links are inside utility chrome
   (nav, buttons, badges) so the underline animation doesn't compete. */
.nav-item, .btn, .badge, .tab, .toolbar a, .empty-state a {
  background-image: none;
  background-size: auto;
}

/* =========================================================================
   TYPOGRAPHY
   ========================================================================= */
h1, h2, h3, h4 {
  color: var(--text-primary);
  font-weight: var(--font-semibold);
  letter-spacing: var(--tracking-tight);
  margin: 0;
  line-height: var(--leading-tight);
}
h1 { font-size: var(--text-3xl); letter-spacing: var(--tracking-display); }
h2 { font-size: var(--text-2xl); letter-spacing: var(--tracking-tight); }
h3 { font-size: var(--text-xl);  letter-spacing: var(--tracking-snug); }
h4 { font-size: var(--text-lg);  letter-spacing: var(--tracking-snug); }

p { margin: 0; color: var(--text-primary); }

.page-title {
  font-size: var(--text-3xl);
  font-weight: var(--font-semibold);
  letter-spacing: var(--tracking-display);
  color: var(--text-primary);
  margin: 0 0 var(--space-1);
}

.eyebrow {
  font-size: var(--text-xs);
  font-weight: var(--font-emphasis);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* Color helpers */
.text-primary    { color: var(--text-primary); }
.text-secondary  { color: var(--text-secondary); }
.text-tertiary   { color: var(--text-tertiary); }
.text-quaternary { color: var(--text-quaternary); }
.text-brand      { color: var(--text-brand); }
.text-accent     { color: var(--text-accent); }
.text-success    { color: var(--color-success); }
.text-warning    { color: var(--color-warning); }
.text-error      { color: var(--color-error); }

/* Size helpers */
.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg   { font-size: var(--text-lg); }
.text-xl   { font-size: var(--text-xl); }
.text-2xl  { font-size: var(--text-2xl); }

/* Weight helpers */
.font-regular  { font-weight: var(--font-regular); }
.font-emphasis { font-weight: var(--font-emphasis); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold     { font-weight: var(--font-bold); }

.mono { font-family: var(--font-mono); font-size: 0.92em; }
.tabular { font-variant-numeric: tabular-nums; }

/* =========================================================================
   LAYOUT SHELL — full light, sidebar with subtle tint
   ========================================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* Sidebar — light gray, subtle separation from white main */
.sidebar {
  background: var(--surface-ground);
  border-right: 1px solid var(--border-subtle);
  padding: var(--space-3) var(--space-1-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-0-5);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* Brand mark — top of sidebar */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-1) var(--space-3);
  font-weight: var(--font-bold);
  font-size: var(--text-base);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
}
.sidebar-brand .logo {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: var(--brand-gradient);
  box-shadow: var(--shadow-glow);
  position: relative;
  display: grid;
  place-items: center;
  font-size: var(--text-2xs);
  font-weight: var(--font-bold);
  color: var(--text-on-brand);
  letter-spacing: 0;
  flex-shrink: 0;
}
.sidebar-brand .logo::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.25) 0%, transparent 50%);
  pointer-events: none;
}
.sidebar-brand .logo-snap {
  background: transparent;
  box-shadow: var(--shadow-glow);
}
.sidebar-brand .logo-snap svg {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
}

/* Nav groups */
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label {
  padding: var(--space-2) var(--space-1) var(--space-1);
  font-size: var(--text-2xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  font-weight: var(--font-semibold);
}

/* Nav items — yellow tint on active, restored to original treatment.
   Hover = neutral subtle bg + text-primary. Active = yellow tint bg
   + bolder text + glowing yellow side bar. This is the version that
   was there at the start of today's redesign. */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
  padding: var(--space-1) var(--space-1-5);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--font-emphasis);
  transition: background var(--duration-fast) var(--ease-standard),
              color var(--duration-fast) var(--ease-standard);
  text-decoration: none;
  position: relative;
}

/* Lucide-style icon — sits inside .nav-item / .btn / inline text.
   16x16 default with stroke=currentColor so it inherits the parent
   text color (active nav / hover state propagate naturally). Mirror
   of Median Web v2 components-v2.css `.icon`. */
.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  vertical-align: middle;
}
.nav-item .icon {
  /* Subtle dim on idle — keeps the label primary on the eye, icon as
     ambient hint. opacity beats color override because it composes
     correctly with hover/active state's `color: currentColor` cascade
     without needing per-state overrides (Web v2 pattern, audit ref). */
  opacity: 0.78;
  transition: opacity var(--duration-fast) var(--ease-standard);
}
.nav-item:hover .icon,
.nav-item.active .icon {
  opacity: 1;
}
/* Slightly smaller in buttons — keeps the label dominant. */
.btn .icon { width: 14px; height: 14px; }
.nav-item:hover {
  background: var(--state-hover);
  color: var(--text-primary);
  text-decoration: none;
}
/* Active nav — white card with relief borders. Lifts off the gray
   sidebar bg via subtle shadow + inset highlights. */
.nav-item.active {
  background: var(--surface-raised);
  color: var(--text-primary);
  font-weight: var(--font-semibold);
  border: 1px solid var(--border-default);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    0 1px 0 rgba(0, 0, 0, 0.04),
    0 2px 4px rgba(0, 0, 0, 0.06);
  /* Compensate for the 1px border so text alignment stays steady when
     toggling between non-active (no border) and active (1px border). */
  padding: calc(var(--space-1) - 1px) calc(var(--space-1) - 1px);
}
/* Active side marker — neutral dark bar (operator preference). The
   yellow tint stays on the .active background as the brand anchor. */
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--text-primary);
  border-radius: var(--radius-pill);
}

/* Main content area */
.main {
  padding: var(--space-4) var(--space-5);
  max-width: var(--content-max-width);
  width: 100%;
  /* Critical for grid children with `1fr`: without `min-width: 0`,
     a wide child (like the accounts table) forces the grid track to
     expand to fit content → horizontal page scroll. With `min-width:
     0`, the grid lets the track shrink, and the table's overflow
     handles the local scroll. */
  min-width: 0;
}

/* Page header — title + subtitle on left, page-level actions on right */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-3);
}
.page-header .title-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.page-header h1 { margin: 0; }
.page-header .subtitle {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

/* =========================================================================
   GRID + FLEX UTILITIES
   ========================================================================= */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); }

/* Stats grid — auto-fit so 4/5/6 cards all lay out flat on wide screens
   and wrap gracefully on narrow. Min 160px per card keeps stat-value
   numbers readable (tabular-nums + ~24px height). Mirror of Web v2's
   approach (which uses `grid-4` as alias for 5-col); we keep grid-4 strict
   and introduce a dedicated `stat-grid` for the overview stat strip. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-2);
}

.flex-row  { display: flex; align-items: center; gap: var(--space-2); }
.flex-col  { display: flex; flex-direction: column; gap: var(--space-2); }
.flex-wrap { flex-wrap: wrap; }
.flex-1    { flex: 1; min-width: 0; }
.flex-none { flex: none; }

.gap-0-5 { gap: var(--space-0-5); }
.gap-1   { gap: var(--space-1); }
.gap-1-5 { gap: var(--space-1-5); }
.gap-2   { gap: var(--space-2); }
.gap-3   { gap: var(--space-3); }
.gap-4   { gap: var(--space-4); }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: var(--space-1) var(--space-2);
  }
  .sidebar-brand { padding: var(--space-1) 0; }
  .nav-group { flex-direction: row; gap: var(--space-0-5); }
  .nav-group-label { display: none; }
  .nav-item.active::before { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .main { padding: var(--space-3) var(--space-2); }
}
