/* ============================================================
   S. — Design System: Precision Metric
   Brand: Modern minimalist utility SaaS for link shortening
   Font: Plus Jakarta Sans (headings) + Inter (body) + JetBrains Mono (code)
   ============================================================ */

/* ---------- Token (CSS Custom Properties) ---------- */
:root {
  /* Palette */
  --surface: #f8f9ff;
  --surface-dim: #cbdbf5;
  --surface-bright: #f8f9ff;
  --surface-container-lowest: #ffffff;
  --surface-container-low: #eff4ff;
  --surface-container: #e5eeff;
  --surface-container-high: #dce9ff;
  --surface-container-highest: #d3e4fe;
  --on-surface: #0b1c30;
  --on-surface-variant: #464555;
  --inverse-surface: #213145;
  --inverse-on-surface: #eaf1ff;
  --outline: #777587;
  --outline-variant: #c7c4d8;

  /* Primary / Indigo */
  --primary: #3525cd;
  --primary-fg: #ffffff;
  --primary-container: #4f46e5;
  --primary-container-hover: #4338ca;
  --on-primary-container: #dad7ff;
  --inverse-primary: #c3c0ff;
  --primary-fixed: #e2dfff;
  --primary-fixed-dim: #c3c0ff;
  --on-primary-fixed: #0f0069;
  --on-primary-fixed-variant: #3323cc;

  /* Secondary / Blue */
  --secondary: #0051d5;
  --secondary-fg: #ffffff;
  --secondary-container: #316bf3;
  --on-secondary-container: #fefcff;
  --secondary-fixed: #dbe1ff;
  --secondary-fixed-dim: #b4c5ff;
  --on-secondary-fixed: #00174b;
  --on-secondary-fixed-variant: #003ea8;

  /* Tertiary / Cyan */
  --tertiary: #00505f;
  --tertiary-fg: #ffffff;
  --tertiary-container: #006a7c;
  --on-tertiary-container: #93e8ff;
  --tertiary-fixed: #acedff;
  --tertiary-fixed-dim: #4cd7f6;
  --on-tertiary-fixed: #001f26;
  --on-tertiary-fixed-variant: #004e5c;

  /* Neutrals (Slate) */
  --bg: #f8f9ff;
  --on-bg: #0b1c30;
  --surface-variant: #d3e4fe;
  --white: #ffffff;
  --muted-border: #e2e8f0;
  --strong-border: #cbd5e1;
  --text-muted: #64748b;
  --text-body: #334155;
  --text-head: #0f172a;

  /* Semantic */
  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-fg: #065f46;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-fg: #92400e;
  --error: #ef4444;
  --error-bg: #fef2f2;
  --error-fg: #991b1b;

  /* Elevation */
  --shadow-card: 0 1px 3px 0 rgba(15, 23, 42, 0.05), 0 1px 2px -1px rgba(15, 23, 42, 0.05);
  --shadow-hover: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-overlay: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-modal: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.06);
  --backdrop: rgba(15, 23, 42, 0.4);

  /* Spacing (4px grid) */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 0.75rem;
  --space-lg: 1.25rem;
  --space-xl: 2rem;
  --gutter: 1.5rem;
  --gutter-sm: 0.75rem;
  --margin: 2rem;
  --margin-mobile: 1rem;

  /* Radius */
  --radius-sm: 0.125rem;
  --radius-md: 0.25rem;
  --radius-def: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --radius-full: 9999px;

  /* Typography */
  --font-display: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'JetBrains Mono Fallback', ui-monospace, monospace;

  /* Sizes */
  --sidebar-w: 260px;
  --sidebar-collapsed: 64px;
  --toolbar-h: 60px;
  --btn-h-default: 40px;
  --btn-h-dense: 36px;
  --input-h: 36px;
  --input-h-lg: 48px;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--on-bg);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

img, svg, video { max-width: 100%; height: auto; display: block; }
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ---------- Grid & Layout ---------- */
.container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--gutter);
}

@media (max-width: 1023px) {
  .container { padding: var(--gutter-sm); }
}
@media (max-width: 767px) {
  .container { padding: var(--margin-mobile); }
}

/* ---------- Typography Tokens ---------- */
.display-hero {
  font-family: var(--font-display);
  font-size: clamp(32px, 5vw, 40px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--text-head);
}

.headline-lg {
  font-family: var(--font-display);
  font-size: clamp(22px, 4vw, 28px);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.02em;
}

.headline-md {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.015em;
}

.label-md {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.38;
  letter-spacing: 0.005em;
}

.label-sm {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.code-sm {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.33;
  letter-spacing: 0;
}

.body-lg {
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: -0.005em;
}

/* ---------- Elevation Layers ---------- */
.elev-0 { background: var(--bg); }
.elev-1 {
  background: var(--white);
  border: 1px solid var(--muted-border);
}
.elev-2:hover {
  background: var(--surface-container-low);
  box-shadow: var(--shadow-hover);
  transition: box-shadow 0.15s ease, background 0.15s ease;
}
.elev-3 {
  background: var(--white);
  border: 1px solid var(--strong-border);
  box-shadow: var(--shadow-overlay);
}
.elev-4 {
  background: var(--white);
  box-shadow: var(--shadow-modal);
  border: 1px solid var(--muted-border);
}

/* ---------- Surface Components ---------- */
.surface-card {
  background: var(--white);
  border: 1px solid var(--muted-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-card);
}

.surface-panel {
  background: var(--white);
  border: 1px solid var(--muted-border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  height: var(--btn-h-default);
  padding: 0 var(--space-lg);
  border-radius: var(--radius-def);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--primary-container);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: var(--primary-container);
}
.btn-primary:hover {
  background: var(--primary-container-hover);
  border-color: var(--primary-container-hover);
  box-shadow: var(--shadow-hover);
}

.btn-secondary {
  background: var(--white);
  color: var(--text-head);
  border-color: var(--muted-border);
}
.btn-secondary:hover {
  background: var(--surface-container-low);
  border-color: var(--strong-border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--surface-container-low);
  color: var(--text-head);
}

.btn-icon {
  padding: 0 var(--space-sm);
  min-width: var(--btn-h-default);
}

.btn-sm {
  height: var(--btn-h-dense);
  padding: 0 var(--space-md);
  font-size: 13px;
  border-radius: var(--radius-md);
}

.btn-lg {
  height: var(--btn-h-default);
  padding: 0 var(--space-xl);
  font-size: 15px;
}

/* ---------- Inputs ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.f-label {
  @extend .label-md;
  color: var(--text-muted);
}

.input {
  height: var(--input-h);
  padding: 0 var(--space-md);
  border: 1px solid var(--muted-border);
  border-radius: var(--radius-def);
  background: var(--white);
  color: var(--text-head);
  font-size: 14px;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.input::placeholder { color: var(--text-muted); }

.input-lg {
  height: var(--input-h-lg);
  font-size: 15px;
  padding: 0 var(--space-lg);
}

.input-group {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--muted-border);
  border-radius: var(--radius-def);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input-group:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.input-group .prefix {
  display: flex;
  align-items: center;
  padding: 0 var(--space-md);
  background: var(--surface-container-low);
  border-right: 1px solid var(--muted-border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.input-group .input {
  border: none;
  box-shadow: none;
  flex: 1;
  min-width: 0;
}
.input-group .input:focus { box-shadow: none; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.badge-success {
  background: var(--success-bg);
  color: var(--success-fg);
}
.badge-warning {
  background: var(--warning-bg);
  color: var(--warning-fg);
}
.badge-error {
  background: var(--error-bg);
  color: var(--error-fg);
}
.badge-neutral {
  background: var(--surface-container);
  color: var(--on-surface-variant);
}
.badge-primary {
  background: var(--primary-fixed);
  color: var(--on-primary-fixed);
}

/* ---------- Tables / Rows ---------- */
.table-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: var(--white);
  border-bottom: 1px solid var(--muted-border);
  transition: background 0.12s ease;
}
.table-row:last-child { border-bottom: none; }
.table-row:hover { background: var(--surface-container-low); }

.table-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-lg);
  padding: var(--space-sm) var(--space-lg);
  background: var(--surface-container-lowest);
  border-bottom: 1px solid var(--muted-border);
}
.table-header span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ---------- KPI / Metric Cards ---------- */
.metric-card {
  background: var(--white);
  border: 1px solid var(--muted-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  position: relative;
  overflow: hidden;
}
.metric-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary-container), var(--tertiary-fixed));
}
.metric-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-sm);
}
.metric-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-head);
}
.metric-trend {
  position: absolute;
  top: var(--space-lg);
  right: var(--space-lg);
  font-size: 12px;
  font-weight: 500;
  color: var(--success-fg);
  background: var(--success-bg);
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
}

/* ---------- App Shell (Sidebar + Main) ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--white);
  border-right: 1px solid var(--muted-border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  padding: 0 var(--space-xl);
  border-bottom: 1px solid var(--muted-border);
  gap: var(--space-md);
}
.sidebar-nav {
  flex: 1;
  padding: var(--space-md) var(--space-sm);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-def);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  cursor: pointer;
}
.nav-item:hover, .nav-item.active {
  background: var(--surface-container-low);
  color: var(--text-head);
}
.nav-item.active {
  color: var(--primary);
  font-weight: 600;
}
.nav-item-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.toolbar {
  height: var(--toolbar-h);
  border-bottom: 1px solid var(--muted-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-md);
  background: var(--white);
  position: sticky;
  top: 0;
  z-index: 10;
}
.content {
  flex: 1;
  padding: var(--space-xl);
}

/* ---------- Mobile Nav (Bottom Sheet) ---------- */
@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
  .content { padding: var(--space-md); }
}
@media (max-width: 767px) {
  .table-row, .table-header {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
    padding: var(--space-md);
  }
  .table-row .actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
  }
}

/* ---------- Dark Mode ---------- */
[data-theme="dark"] {
  --surface: #1a1f36;
  --surface-dim: #0f1424;
  --surface-bright: #242b42;
  --surface-container-lowest: #131827;
  --surface-container-low: #1a2035;
  --surface-container: #1f2540;
  --surface-container-high: #252c49;
  --surface-container-highest: #2b3252;
  --on-surface: #e8eaf6;
  --on-surface-variant: #949dbf;
  --inverse-surface: #e8eaf6;
  --inverse-on-surface: #1a1f36;
  --outline: #5c6478;
  --outline-variant: #3a4258;
  --bg: #0f1424;
  --on-bg: #e8eaf6;
  --surface-variant: #252c49;
  --white: #1a2035;
  --muted-border: #2b3252;
  --strong-border: #3a4258;
  --text-muted: #949dbf;
  --text-body: #b8bdd4;
  --text-head: #e8eaf6;
  --primary-container-hover: #5b51f5;
  --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px -1px rgba(0, 0, 0, 0.2);
  --shadow-hover: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-overlay: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
  --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
  --backdrop: rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .surface-card,
[data-theme="dark"] .surface-panel,
[data-theme="dark"] .metric-card,
[data-theme="dark"] .sidebar,
[data-theme="dark"] .toolbar,
[data-theme="dark"] footer {
  background: var(--surface-container-low);
  border-color: var(--muted-border);
}
[data-theme="dark"] .table-row { background: var(--surface-container); }
[data-theme="dark"] .table-row:hover { background: var(--surface-container-high); }
[data-theme="dark"] .table-header { background: var(--surface-container-low); }
[data-theme="dark"] .input { background: var(--surface-container); color: var(--on-surface); border-color: var(--strong-border); }
[data-theme="dark"] .input::placeholder { color: var(--text-muted); }
[data-theme="dark"] .input-group .prefix { background: var(--surface-container); border-color: var(--strong-border); color: var(--text-muted); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: #1a1f36; --surface-dim: #0f1424;
    --bg: #0f1424; --on-bg: #e8eaf6;
    --white: #1a2035; --muted-border: #2b3252;
    --text-muted: #949dbf; --text-body: #b8bdd4; --text-head: #e8eaf6;
  }
}
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }
.text-muted { color: var(--text-muted); }
.text-head { color: var(--text-head); }
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }
