/* ============================================================
   CSAgent Design System — Apple Human Interface Guidelines
   ============================================================
   Foundations: Color, Typography, Spacing, Depth, Motion
   Components: Buttons, Cards, Navigation, Forms, Tables, Modals
   ============================================================ */

/* --- CSS Custom Properties (Design Tokens) --- */

:root {
  /* ---- Typography: SF Pro / System Font Stack ---- */
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", SFMono-Regular, ui-monospace, Menlo, monospace;

  /* Apple HIG iOS Type Scale */
  --text-large-title: 2.125rem;   /* 34pt */
  --text-title1: 1.75rem;         /* 28pt */
  --text-title2: 1.375rem;        /* 22pt */
  --text-title3: 1.25rem;         /* 20pt */
  --text-headline: 1.0625rem;     /* 17pt semibold */
  --text-body: 1.0625rem;         /* 17pt */
  --text-callout: 1rem;           /* 16pt */
  --text-subheadline: 0.9375rem;  /* 15pt */
  --text-footnote: 0.8125rem;     /* 13pt */
  --text-caption1: 0.75rem;       /* 12pt */
  --text-caption2: 0.6875rem;     /* 11pt — minimum */

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  --leading-tight: 1.2;
  --leading-normal: 1.47;
  --leading-relaxed: 1.6;

  /* ---- Spacing Scale (4pt grid) ---- */
  --space-2: 0.125rem;
  --space-4: 0.25rem;
  --space-6: 0.375rem;
  --space-8: 0.5rem;
  --space-10: 0.625rem;
  --space-12: 0.75rem;
  --space-16: 1rem;
  --space-20: 1.25rem;
  --space-24: 1.5rem;
  --space-32: 2rem;
  --space-40: 2.5rem;
  --space-48: 3rem;
  --space-64: 4rem;

  /* ---- Touch Target ---- */
  --tap-min: 2.75rem; /* 44pt minimum */

  /* ---- Radius ---- */
  --radius-sm: 0.5rem;    /* 8pt */
  --radius-md: 0.75rem;   /* 12pt */
  --radius-lg: 1rem;       /* 16pt */
  --radius-xl: 1.25rem;    /* 20pt */
  --radius-full: 624.9375rem;

  /* ---- Shadows (Depth) ---- */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);
  --shadow-xl: 0 24px 60px rgba(0,0,0,0.16), 0 8px 20px rgba(0,0,0,0.08);

  /* ---- Transitions (Motion) ---- */
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
  --ease-default: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);

  /* ---- Z-Index Scale ---- */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-toast: 500;

  /* ---- Layout ---- */
  --sidebar-width: 16rem;
  --content-max: 72rem;
  --header-height: 3.5rem;
}

/* ---- Light Mode (Default) — Enterprise Banking Palette ---- */
:root,
[data-theme="light"] {
  --color-bg: #FFFFFF;
  --color-bg-secondary: #F5F6F8;
  --color-bg-tertiary: #FFFFFF;
  --color-bg-grouped: #F0F2F5;
  --color-bg-grouped-secondary: #FFFFFF;

  --color-label: #1A1D23;
  --color-label-secondary: rgba(42, 48, 60, 0.72);
  --color-label-tertiary: rgba(42, 48, 60, 0.40);
  --color-label-quaternary: rgba(42, 48, 60, 0.20);

  --color-separator: rgba(42, 48, 60, 0.12);
  --color-separator-opaque: #D8DCE3;

  --color-fill: rgba(42, 48, 60, 0.08);
  --color-fill-secondary: rgba(42, 48, 60, 0.06);
  --color-fill-tertiary: rgba(42, 48, 60, 0.04);
  --color-fill-quaternary: rgba(42, 48, 60, 0.02);

  /* Tint Colors — professional banking tones */
  --color-blue: #1B6EF3;
  --color-green: #0D9F6E;
  --color-indigo: #4F46E5;
  --color-orange: #E6850A;
  --color-pink: #E03177;
  --color-purple: #8B5CF6;
  --color-red: #DC2626;
  --color-teal: #0891B2;
  --color-yellow: #D4A017;

  /* Semantic */
  --color-accent: #1B6EF3;
  --color-destructive: #DC2626;
  --color-success: #0D9F6E;
  --color-warning: #E6850A;

  /* Glass / Translucency */
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-bg-thick: rgba(255, 255, 255, 0.95);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-blur: 20px;
}

/* ---- Dark Mode — Enterprise banking palette, night-shift tuned ---- */
[data-theme="dark"] {
  --color-bg: #0F1419;
  --color-bg-secondary: #161B22;
  --color-bg-tertiary: #1C222B;
  --color-bg-grouped: #0B0F14;
  --color-bg-grouped-secondary: #161B22;

  --color-label: #E8EAED;
  --color-label-secondary: rgba(232, 234, 237, 0.72);
  --color-label-tertiary: rgba(232, 234, 237, 0.45);
  --color-label-quaternary: rgba(232, 234, 237, 0.22);

  --color-separator: rgba(255, 255, 255, 0.08);
  --color-separator-opaque: #2A3038;

  --color-fill: rgba(255, 255, 255, 0.08);
  --color-fill-secondary: rgba(255, 255, 255, 0.06);
  --color-fill-tertiary: rgba(255, 255, 255, 0.04);
  --color-fill-quaternary: rgba(255, 255, 255, 0.03);

  /* Slightly brighter tints for better dark-mode contrast */
  --color-blue: #4F9CFF;
  --color-green: #34D399;
  --color-indigo: #818CF8;
  --color-orange: #FBA94C;
  --color-pink: #F472B6;
  --color-purple: #A78BFA;
  --color-red: #F87171;
  --color-teal: #22D3EE;
  --color-yellow: #FACC15;

  --color-accent: #4F9CFF;
  --color-destructive: #F87171;
  --color-success: #34D399;
  --color-warning: #FBA94C;

  --glass-bg: rgba(22, 27, 34, 0.85);
  --glass-bg-thick: rgba(22, 27, 34, 0.95);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: 20px;

  color-scheme: dark;
}

/* Auto-apply dark palette when user prefers it and no explicit theme set. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #0F1419;
    --color-bg-secondary: #161B22;
    --color-bg-tertiary: #1C222B;
    --color-bg-grouped: #0B0F14;
    --color-bg-grouped-secondary: #161B22;
    --color-label: #E8EAED;
    --color-label-secondary: rgba(232, 234, 237, 0.72);
    --color-label-tertiary: rgba(232, 234, 237, 0.45);
    --color-label-quaternary: rgba(232, 234, 237, 0.22);
    --color-separator: rgba(255, 255, 255, 0.08);
    --color-separator-opaque: #2A3038;
    --color-fill: rgba(255, 255, 255, 0.08);
    --color-fill-secondary: rgba(255, 255, 255, 0.06);
    --color-fill-tertiary: rgba(255, 255, 255, 0.04);
    --color-fill-quaternary: rgba(255, 255, 255, 0.03);
    --color-accent: #4F9CFF;
    --glass-bg: rgba(22, 27, 34, 0.85);
    --glass-bg-thick: rgba(22, 27, 34, 0.95);
    --glass-border: rgba(255, 255, 255, 0.08);
    color-scheme: dark;
  }
}

/* Dark mode removed — enterprise banking light-only theme */

/* ---- Reduce Motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ============================================================
   RESET & BASE
   ============================================================ */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-system);
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  color: var(--color-label);
  background-color: var(--color-bg-grouped);
  min-height: 100vh;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: opacity var(--duration-fast) var(--ease-default);
}

a:hover { opacity: 0.72; }
a:active { opacity: 0.56; }

img, svg, video {
  display: block;
  max-width: 100%;
}

/* Focus — accessibility visible ring */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}


/* ============================================================
   TYPOGRAPHY
   ============================================================ */

.text-large-title {
  font-size: var(--text-large-title);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
}
.text-title1 {
  font-size: var(--text-title1);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.015em;
}
.text-title2 {
  font-size: var(--text-title2);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
}
.text-title3 {
  font-size: var(--text-title3);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}
.text-headline {
  font-size: var(--text-headline);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-normal);
}
.text-body {
  font-size: var(--text-body);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
}
.text-callout {
  font-size: var(--text-callout);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
}
.text-subheadline {
  font-size: var(--text-subheadline);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
}
.text-footnote {
  font-size: var(--text-footnote);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  color: var(--color-label-secondary);
}
.text-caption1 {
  font-size: var(--text-caption1);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  color: var(--color-label-secondary);
}
.text-caption2 {
  font-size: var(--text-caption2);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  color: var(--color-label-tertiary);
}

.text-secondary { color: var(--color-label-secondary); }
.text-tertiary  { color: var(--color-label-tertiary); }
.text-accent    { color: var(--color-accent); }
.text-success   { color: var(--color-success); }
.text-warning   { color: var(--color-warning); }
.text-destructive { color: var(--color-red); }


/* ============================================================
   LAYOUT
   ============================================================ */

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar (persistent tab-bar equivalent for desktop) --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-bg);
  border-right: 1px solid var(--color-separator);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  transition: transform var(--duration-normal) var(--ease-default);
}

.sidebar-header {
  padding: var(--space-16) var(--space-16);
  border-bottom: 1px solid var(--color-separator);
  height: var(--header-height);
  display: flex;
  align-items: center;
}

.sidebar-brand {
  font-size: var(--text-headline);
  font-weight: var(--weight-bold);
  color: var(--color-label);
  display: flex;
  align-items: center;
  gap: var(--space-8);
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-8) var(--space-8);
  overflow-y: auto;
}

.sidebar-section-title {
  font-size: var(--text-caption1);
  font-weight: var(--weight-semibold);
  color: var(--color-label-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-16) var(--space-12) var(--space-4);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-10) var(--space-12);
  border-radius: var(--radius-sm);
  color: var(--color-label-secondary);
  font-size: var(--text-subheadline);
  font-weight: var(--weight-medium);
  min-height: var(--tap-min);
  transition: background var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
  cursor: pointer;
}

.sidebar-link:hover {
  background: var(--color-fill-tertiary);
  color: var(--color-label);
  opacity: 1;
}

.sidebar-link.active {
  background: var(--color-fill-secondary);
  color: var(--color-label);
  font-weight: var(--weight-semibold);
}

.sidebar-link .icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.sidebar-badge {
  margin-left: auto;
  background: var(--color-red);
  color: #FFFFFF;
  font-size: var(--text-caption2);
  font-weight: var(--weight-bold);
  padding: 0.125rem 0.4375rem;
  border-radius: var(--radius-full);
  min-width: 1.25rem;
  text-align: center;
}

.sidebar-footer {
  padding: var(--space-12) var(--space-16);
  border-top: 1px solid var(--color-separator);
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Top Header / Navigation Bar --- */
.top-bar {
  height: var(--header-height);
  padding: 0 var(--space-24);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-separator);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.top-bar-title {
  font-size: var(--text-headline);
  font-weight: var(--weight-semibold);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

/* --- Icon button (top-bar utilities) --- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-label-secondary);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
}
.icon-btn:hover {
  background: var(--color-fill-tertiary);
  color: var(--color-label);
}
.icon-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.icon-btn .icon {
  width: 18px;
  height: 18px;
}

/* Show correct glyph based on active theme. */
.theme-icon-moon { display: inline-block; }
.theme-icon-sun  { display: none; }
[data-theme="dark"] .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun  { display: inline-block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-moon { display: none; }
  :root:not([data-theme="light"]) .theme-icon-sun  { display: inline-block; }
}

/* --- Keyboard shortcut palette --- */
.shortcut-palette-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  z-index: 1000;
  animation: fadeIn var(--duration-fast) var(--ease-default);
}
.shortcut-palette-backdrop.open { display: flex; }
.shortcut-palette {
  width: min(560px, 92vw);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--color-bg);
  color: var(--color-label);
  border: 1px solid var(--color-separator-opaque);
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: var(--space-20);
}
.shortcut-palette h2 {
  margin: 0 0 var(--space-16);
  font-size: var(--text-headline);
  font-weight: var(--weight-semibold);
}
.shortcut-palette dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-12) var(--space-16);
  margin: 0;
}
.shortcut-palette dt {
  color: var(--color-label);
  font-size: var(--text-body);
}
.shortcut-palette dd {
  margin: 0;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.shortcut-palette kbd {
  display: inline-block;
  min-width: 1.75rem;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: var(--text-footnote);
  color: var(--color-label);
  background: var(--color-fill);
  border: 1px solid var(--color-separator-opaque);
  border-radius: 4px;
  text-align: center;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- Page Content --- */
.page {
  flex: 1;
  padding: var(--space-24);
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
}

.page-header {
  margin-bottom: var(--space-24);
}

.page-title {
  font-size: var(--text-large-title);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-4);
}

.page-subtitle {
  font-size: var(--text-subheadline);
  color: var(--color-label-secondary);
}


/* ============================================================
   COMPONENTS — Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  min-height: var(--tap-min);
  padding: 0 var(--space-20);
  border: none;
  border-radius: var(--radius-full);
  font-family: var(--font-system);
  font-size: var(--text-subheadline);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled {
  opacity: 0.36;
  pointer-events: none;
}

.btn-primary {
  background: var(--color-accent);
  color: #FFFFFF;
}
.btn-primary:hover { background: color-mix(in srgb, var(--color-accent), #000 12%); opacity: 1; }

.btn-secondary {
  background: var(--color-fill-secondary);
  color: var(--color-accent);
}
.btn-secondary:hover { background: var(--color-fill); opacity: 1; }

.btn-destructive {
  background: var(--color-destructive);
  color: #FFFFFF;
}
.btn-destructive:hover { background: color-mix(in srgb, var(--color-destructive), #000 12%); opacity: 1; }

.btn-ghost {
  background: transparent;
  color: var(--color-accent);
  padding: 0 var(--space-12);
}
.btn-ghost:hover { background: var(--color-fill-quaternary); opacity: 1; }

.btn-sm {
  min-height: 2rem;
  padding: 0 var(--space-12);
  font-size: var(--text-footnote);
  border-radius: var(--radius-full);
}

.btn-lg {
  min-height: 3.125rem;
  padding: 0 var(--space-32);
  font-size: var(--text-body);
  border-radius: var(--radius-full);
}

.btn-icon {
  width: var(--tap-min);
  height: var(--tap-min);
  padding: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-accent);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease-default);
}
.btn-icon:hover { background: var(--color-fill-tertiary); }


/* ============================================================
   COMPONENTS — Cards (Grouped Table Style)
   ============================================================ */

.card {
  background: var(--color-bg-grouped-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: var(--space-16) var(--space-20);
  border-bottom: 1px solid var(--color-separator);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header-title {
  font-size: var(--text-headline);
  font-weight: var(--weight-semibold);
}

.card-body {
  padding: var(--space-16) var(--space-20);
}

.card-footer {
  padding: var(--space-12) var(--space-20);
  border-top: 1px solid var(--color-separator);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-8);
}

/* Glass Card (Liquid Glass) */
.card-glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}


/* ============================================================
   COMPONENTS — Stat / Metric Cards
   ============================================================ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: var(--space-16);
}

.stat-card {
  background: var(--color-bg-grouped-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-20);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: var(--text-footnote);
  font-weight: var(--weight-medium);
  color: var(--color-label-secondary);
  margin-bottom: var(--space-4);
}

.stat-value {
  font-size: var(--text-title1);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
}

.stat-change {
  font-size: var(--text-caption1);
  font-weight: var(--weight-medium);
  margin-top: var(--space-4);
}
.stat-change.positive { color: var(--color-success); }
.stat-change.negative { color: var(--color-destructive); }


/* ============================================================
   COMPONENTS — Forms
   ============================================================ */

.form-group {
  margin-bottom: var(--space-20);
}

.form-label {
  display: block;
  font-size: var(--text-subheadline);
  font-weight: var(--weight-medium);
  color: var(--color-label-secondary);
  margin-bottom: var(--space-6);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-10) var(--space-16);
  background: var(--color-fill-quaternary);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-system);
  font-size: var(--text-body);
  color: var(--color-label);
  transition: border-color var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  background: var(--color-bg);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent), transparent 72%);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-label-tertiary);
}

.form-textarea {
  min-height: 5.5rem;
  resize: vertical;
}

.form-help {
  font-size: var(--text-caption1);
  color: var(--color-label-tertiary);
  margin-top: var(--space-4);
}

.form-error {
  font-size: var(--text-caption1);
  color: var(--color-destructive);
  margin-top: var(--space-4);
}

/* Toggle / Switch */
.toggle {
  position: relative;
  width: 3.125rem;
  height: 1.875rem;
  appearance: none;
  -webkit-appearance: none;
  background: var(--color-fill);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--duration-normal) var(--ease-default);
}
.toggle::after {
  content: "";
  position: absolute;
  top: 0.125rem;
  left: 0.125rem;
  width: 1.625rem;
  height: 1.625rem;
  background: #FFFFFF;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-normal) var(--ease-spring);
}
.toggle:checked {
  background: var(--color-success);
}
.toggle:checked::after {
  transform: translateX(1.25rem);
}


/* ============================================================
   COMPONENTS — Tables (List Style)
   ============================================================ */

.table-container {
  background: var(--color-bg-grouped-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  padding: var(--space-10) var(--space-16);
  text-align: left;
  font-size: var(--text-footnote);
  font-weight: var(--weight-semibold);
  color: var(--color-label-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--color-fill-quaternary);
  border-bottom: 1px solid var(--color-separator);
}

.table td {
  padding: var(--space-12) var(--space-16);
  font-size: var(--text-subheadline);
  border-bottom: 1px solid var(--color-separator);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background: var(--color-fill-quaternary);
}


/* ============================================================
   COMPONENTS — Badges / Tags
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-8);
  border-radius: var(--radius-full);
  font-size: var(--text-caption1);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

.badge-blue    { background: color-mix(in srgb, var(--color-blue) 16%, transparent); color: var(--color-blue); }
.badge-green   { background: color-mix(in srgb, var(--color-green) 16%, transparent); color: var(--color-green); }
.badge-orange  { background: color-mix(in srgb, var(--color-orange) 16%, transparent); color: var(--color-orange); }
.badge-red     { background: color-mix(in srgb, var(--color-red) 16%, transparent); color: var(--color-red); }
.badge-purple  { background: color-mix(in srgb, var(--color-purple) 16%, transparent); color: var(--color-purple); }
.badge-gray    { background: var(--color-fill-secondary); color: var(--color-label-secondary); }


/* ============================================================
   COMPONENTS — Modal / Sheet
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) var(--ease-default);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  background: var(--color-bg);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 40rem;
  max-height: 92vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--duration-slow) var(--ease-out);
  box-shadow: var(--shadow-xl);
}
.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

/* Desktop centered modal */
@media (min-width: 640px) {
  .modal-overlay {
    align-items: center;
  }
  .modal-sheet {
    border-radius: var(--radius-xl);
    max-height: 80vh;
    transform: translateY(2rem) scale(0.96);
    opacity: 0;
  }
  .modal-overlay.open .modal-sheet {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.modal-handle {
  width: 2.25rem;
  height: 0.3125rem;
  background: var(--color-fill);
  border-radius: var(--radius-full);
  margin: var(--space-8) auto var(--space-4);
}

.modal-header {
  padding: var(--space-16) var(--space-20);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-separator);
}

.modal-body {
  padding: var(--space-20);
}

.modal-footer {
  padding: var(--space-12) var(--space-20);
  border-top: 1px solid var(--color-separator);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-8);
}


/* ============================================================
   COMPONENTS — Toast / Notification
   ============================================================ */

.toast-container {
  position: fixed;
  top: var(--space-16);
  right: var(--space-16);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

.toast {
  background: var(--glass-bg-thick);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-12) var(--space-16);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-12);
  min-width: 18rem;
  max-width: 24rem;
  animation: toast-in var(--duration-normal) var(--ease-spring) forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(1rem) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

.toast-icon {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
}

.toast-message {
  font-size: var(--text-subheadline);
  font-weight: var(--weight-medium);
  flex: 1;
}


/* ============================================================
   COMPONENTS — Segmented Control
   ============================================================ */

.segmented-control {
  display: inline-flex;
  background: var(--color-fill-secondary);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  gap: var(--space-2);
}

.segmented-control-item {
  padding: var(--space-6) var(--space-16);
  border-radius: calc(var(--radius-sm) - var(--space-2));
  font-size: var(--text-footnote);
  font-weight: var(--weight-medium);
  color: var(--color-label-secondary);
  cursor: pointer;
  min-height: 2rem;
  display: flex;
  align-items: center;
  transition: all var(--duration-fast) var(--ease-default);
  border: none;
  background: transparent;
  font-family: var(--font-system);
}

.segmented-control-item.active {
  background: var(--color-bg);
  color: var(--color-label);
  box-shadow: var(--shadow-sm);
}


/* ============================================================
   COMPONENTS — Avatar
   ============================================================ */

.avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius-full);
  background: var(--color-fill-secondary);
  color: var(--color-label-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-subheadline);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 2rem; height: 2rem; font-size: var(--text-caption1); }
.avatar-lg { width: 3.5rem; height: 3.5rem; font-size: var(--text-title3); }

/* Online indicator */
.avatar-wrapper {
  position: relative;
  display: inline-flex;
}
.avatar-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  border: 2px solid var(--color-bg);
}
.avatar-status.online  { background: var(--color-success); }
.avatar-status.offline { background: var(--color-label-quaternary); }
.avatar-status.busy    { background: var(--color-orange); }


/* ============================================================
   COMPONENTS — Empty State
   ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-64) var(--space-24);
}

.empty-state-icon {
  width: 4rem;
  height: 4rem;
  color: var(--color-label-tertiary);
  margin-bottom: var(--space-16);
}

.empty-state-title {
  font-size: var(--text-title3);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-8);
}

.empty-state-description {
  font-size: var(--text-subheadline);
  color: var(--color-label-secondary);
  max-width: 20rem;
  margin-bottom: var(--space-24);
}


/* ============================================================
   COMPONENTS — Pagination
   ============================================================ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-16) 0;
}

.pagination-btn {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-accent);
  font-family: var(--font-system);
  font-size: var(--text-subheadline);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default);
}
.pagination-btn:hover { background: var(--color-fill-tertiary); }
.pagination-btn.active {
  background: var(--color-accent);
  color: #FFFFFF;
}
.pagination-btn:disabled {
  color: var(--color-label-quaternary);
  pointer-events: none;
}


/* ============================================================
   RESPONSIVE — Mobile Tab Bar
   ============================================================ */

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .main-content {
    margin-left: 0;
    padding-bottom: 5rem; /* space for tab bar */
  }

  .mobile-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 5rem;
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: var(--color-bg);
    border-top: 1px solid var(--color-separator);
    z-index: var(--z-sticky);
    justify-content: space-around;
    align-items: flex-start;
    padding-top: var(--space-6);
  }

  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    min-width: var(--tap-min);
    min-height: var(--tap-min);
    padding: var(--space-4);
    color: var(--color-label-tertiary);
    font-size: var(--text-caption2);
    font-weight: var(--weight-medium);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-default);
    border: none;
    background: none;
    cursor: pointer;
    font-family: var(--font-system);
  }
  .tab-item:hover { opacity: 1; }
  .tab-item.active {
    color: var(--color-accent);
  }
  .tab-item .icon {
    width: 1.5rem;
    height: 1.5rem;
  }

  .page {
    padding: var(--space-16);
  }
}

@media (min-width: 769px) {
  .mobile-tab-bar { display: none; }
}


/* ============================================================
   UTILITY CLASSES
   ============================================================ */

.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4  { gap: var(--space-4); }
.gap-8  { gap: var(--space-8); }
.gap-12 { gap: var(--space-12); }
.gap-16 { gap: var(--space-16); }
.gap-24 { gap: var(--space-24); }

.mt-4  { margin-top: var(--space-4); }
.mt-8  { margin-top: var(--space-8); }
.mt-16 { margin-top: var(--space-16); }
.mt-24 { margin-top: var(--space-24); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-8  { margin-bottom: var(--space-8); }
.mb-16 { margin-bottom: var(--space-16); }
.mb-24 { margin-bottom: var(--space-24); }

.w-full { width: 100%; }
.hidden { display: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(1.5rem); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.animate-fade-in-up {
  animation: fadeInUp var(--duration-slow) var(--ease-out) both;
}

.animate-fade-in {
  animation: fadeIn var(--duration-slow) var(--ease-out) both;
}

.delay-1 { animation-delay: 100ms; }
.delay-2 { animation-delay: 200ms; }
.delay-3 { animation-delay: 300ms; }
.delay-4 { animation-delay: 400ms; }
.delay-5 { animation-delay: 500ms; }
.delay-6 { animation-delay: 600ms; }
