/* ============================================================
   LBOS Design System — v1.0
   Brand: Navy #0B1F3A · Gold #C9A84C
   Style: Enterprise SaaS — clean, white, minimal shadows
   ============================================================ */

/* ============================================================
   1. CUSTOM PROPERTIES (DESIGN TOKENS)
   ============================================================ */
:root {
  /* Brand */
  --navy:           #0B1F3A;
  --navy-light:     #162f57;
  --navy-dark:      #071527;
  --gold:           #C9A84C;
  --gold-light:     #d9bb72;
  --gold-dark:      #a8872e;
  --gold-muted:     rgba(201, 168, 76, 0.12);

  /* Grays */
  --gray-50:        #f9fafb;
  --gray-100:       #f3f4f6;
  --gray-200:       #e5e7eb;
  --gray-300:       #d1d5db;
  --gray-400:       #9ca3af;
  --gray-500:       #6b7280;
  --gray-600:       #4b5563;
  --gray-700:       #374151;
  --gray-800:       #1f2937;
  --gray-900:       #111827;

  /* Semantic */
  --color-success:       #047857;
  --color-success-bg:    #d1fae5;
  --color-success-border:#a7f3d0;
  --color-danger:        #dc2626;
  --color-danger-bg:     #fee2e2;
  --color-danger-border: #fca5a5;
  --color-warning:       #d97706;
  --color-warning-bg:    #fef3c7;
  --color-warning-border:#fde68a;
  --color-info:          #2563eb;
  --color-info-bg:       #dbeafe;
  --color-info-border:   #bfdbfe;
  --color-orange:        #ea580c;
  --color-orange-bg:     #fff7ed;
  --color-orange-border: #fed7aa;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg:  0 10px 20px rgba(0,0,0,0.08), 0 4px 8px rgba(0,0,0,0.04);
  --shadow-xl:  0 25px 50px rgba(0,0,0,0.12);

  /* Border radius */
  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  8px;
  --radius-xl:  12px;
  --radius-2xl: 16px;
  --radius-full: 9999px;

  /* Spacing scale */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Typography */
  --font-ui:    'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-prose: Georgia, 'Times New Roman', serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', Consolas, monospace;

  --text-xs:   0.6875rem;
  --text-sm:   0.8125rem;
  --text-base: 0.875rem;
  --text-md:   0.9375rem;
  --text-lg:   1.0625rem;
  --text-xl:   1.125rem;
  --text-2xl:  1.375rem;
  --text-3xl:  1.75rem;

  --leading-tight:  1.25;
  --leading-normal: 1.5;
  --leading-relaxed:1.75;

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --content-max-w: 1280px;

  /* Transitions */
  --transition-fast:   0.1s ease;
  --transition-normal: 0.15s ease;
  --transition-slow:   0.25s ease;
}


/* ============================================================
   2. RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--gray-900);
  background: var(--gray-50);
}

a {
  color: var(--gold);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--gold-dark); text-decoration: underline; }

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

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: var(--leading-tight);
  color: var(--navy);
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); }

p { margin-bottom: var(--space-4); }
p:last-child { margin-bottom: 0; }

ul, ol { padding-left: var(--space-6); }

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--gray-100);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--navy);
}


/* ============================================================
   3. IMPERSONATION BANNER
   ============================================================ */
.impersonation-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--color-orange);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: 0.5rem var(--space-6);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 8px rgba(234, 88, 12, 0.35);
}

.impersonation-banner__icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.impersonation-banner__text {
  flex: 1;
  text-align: center;
}

.impersonation-banner__exit {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--radius-md);
  padding: 0.25rem 0.875rem;
  font-size: var(--text-xs);
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition-fast);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-family: var(--font-ui);
}
.impersonation-banner__exit:hover { background: rgba(255,255,255,0.3); }

/* Shift layout when impersonation banner is active.
   The is-impersonating class is on .layout (not body),
   so selectors must match that. Sidebar and topbar are fixed/sticky
   so they need explicit top offsets. */
.layout.is-impersonating .sidebar {
  top: 36px;
}
.layout.is-impersonating .topbar {
  top: 36px;
}
.layout.is-impersonating .main {
  padding-top: 36px;
}


/* ============================================================
   4. LAYOUT SHELL
   ============================================================ */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition-slow);
}

.sidebar-logo {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-logo .wordmark {
  font-size: 1.375rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.03em;
  line-height: 1;
}
.sidebar-logo .wordmark span { color: var(--gold); }

.sidebar-logo .tagline {
  font-size: var(--text-xs);
  color: rgba(255, 255, 255, 0.6);
  margin-top: 0.3rem;
  letter-spacing: 0.01em;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: var(--radius-full); }

.nav-section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.875rem 1.25rem 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5625rem 1.25rem;
  font-size: var(--text-base);
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--gold);
  text-decoration: none;
}

.nav-item.active {
  color: var(--gold);
  border-left-color: var(--gold);
  background: var(--gold-muted);
}
.nav-item.active:hover { background: rgba(201, 168, 76, 0.16); }

.nav-icon {
  width: 18px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
  opacity: 1;
  color: #fff;
  transition: color var(--transition-fast);
}
.nav-item:hover .nav-icon { color: var(--gold); }
.nav-item.active .nav-icon { color: var(--gold); opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--gold);
  color: var(--navy);
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
  line-height: 1.4;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: var(--space-4) 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-info {
  margin-bottom: var(--space-3);
}

.user-name {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: var(--text-xs);
  color: var(--gold);
  letter-spacing: 0.01em;
}

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

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.topbar-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--gray-400);
}
.topbar-breadcrumb a { color: var(--gray-500); }
.topbar-breadcrumb a:hover { color: var(--navy); }
.topbar-breadcrumb .sep { color: var(--gray-300); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Hamburger for mobile */
.sidebar-toggle {
  display: none;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--gray-600);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.sidebar-toggle:hover { background: var(--gray-100); }

/* ---- CONTENT ---- */
.content {
  padding: 1.75rem;
  flex: 1;
  max-width: var(--content-max-w);
  width: 100%;
}

.content-full {
  padding: 1.75rem;
  flex: 1;
}


/* ============================================================
   5. PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}

.page-header-left { flex: 1; min-width: 0; }

.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--gray-500);
  margin-top: 0.25rem;
  font-weight: 400;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}


/* ============================================================
   6. BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.5rem 1.125rem;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast),
              border-color var(--transition-fast), box-shadow var(--transition-fast),
              opacity var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
}
.btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.btn:disabled, .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Sizes */
.btn-xs { padding: 0.25rem 0.625rem; font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-sm { padding: 0.375rem 0.875rem; font-size: var(--text-sm); }
.btn-lg { padding: 0.6875rem 1.5rem; font-size: var(--text-md); }
.btn-xl { padding: 0.875rem 2rem;    font-size: var(--text-lg); border-radius: var(--radius-lg); }

/* Variants */
.btn-primary {
  background: var(--gold);
  color: var(--navy);
  border-color: var(--gold);
}
.btn-primary:hover {
  background: var(--gold-dark);
  border-color: var(--gold-dark);
  color: var(--navy);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.btn-secondary:hover {
  background: var(--navy-light);
  border-color: var(--navy-light);
  color: #fff;
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
  border-color: var(--gray-300);
}
.btn-ghost:hover {
  background: var(--gray-50);
  color: var(--gray-900);
  border-color: var(--gray-400);
  text-decoration: none;
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
  text-decoration: none;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--color-danger);
  border-color: var(--color-danger-border);
}
.btn-danger-ghost:hover {
  background: var(--color-danger-bg);
  border-color: var(--color-danger);
  text-decoration: none;
}

.btn-success {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}
.btn-success:hover { background: #035f44; color: #fff; text-decoration: none; }

.btn-outline-navy {
  background: transparent;
  color: var(--navy);
  border-color: var(--navy);
}
.btn-outline-navy:hover { background: var(--navy); color: #fff; text-decoration: none; }

/* Icon-only button */
.btn-icon {
  padding: 0.5rem;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-md);
}
.btn-icon.btn-sm { width: 1.75rem; height: 1.75rem; padding: 0.3125rem; }

/* Full-width */
.btn-block { width: 100%; }

/* Loading state */
.btn-loading { position: relative; color: transparent; pointer-events: none; }
.btn-loading::after {
  content: '';
  position: absolute;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}


/* ============================================================
   7. CARDS
   ============================================================ */
.card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  padding: var(--space-6);
  box-shadow: var(--shadow-xs);
}

.card-sm { padding: var(--space-4); }
.card-lg { padding: var(--space-8); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--gray-100);
}

.card-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.01em;
}
.card-subtitle {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin-top: 0.125rem;
}

.card-body { flex: 1; }

.card-footer {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Hover card */
.card-hover {
  transition: box-shadow var(--transition-normal), transform var(--transition-normal);
  cursor: pointer;
}
.card-hover:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}


/* ============================================================
   8. STAT CARDS
   ============================================================ */
.stat-card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  padding: 1.25rem 1.5rem 1.375rem;
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--gray-200);
}

.stat-gold::before   { background: var(--gold); }
.stat-navy::before   { background: var(--navy); }
.stat-green::before  { background: var(--color-success); }
.stat-red::before    { background: var(--color-danger); }
.stat-blue::before   { background: var(--color-info); }
.stat-orange::before { background: var(--color-orange); }

.stat-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--navy);
  margin-top: 0.3rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

.stat-meta {
  font-size: var(--text-xs);
  color: var(--gray-400);
  margin-top: var(--space-2);
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: var(--text-xs);
  font-weight: 600;
  margin-top: var(--space-1);
}
.stat-change.up   { color: var(--color-success); }
.stat-change.down { color: var(--color-danger); }

/* Stat grid helper */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }
.stats-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stats-grid-2 { grid-template-columns: repeat(2, 1fr); }


/* ============================================================
   9. BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-gold    { background: var(--color-warning-bg);  color: #92400e; }
.badge-green   { background: var(--color-success-bg);  color: var(--color-success); }
.badge-red     { background: var(--color-danger-bg);   color: var(--color-danger); }
.badge-gray    { background: var(--gray-100);          color: var(--gray-600); }
.badge-navy    { background: var(--navy);              color: #fff; }
.badge-blue    { background: var(--color-info-bg);     color: var(--color-info); }
.badge-orange  { background: var(--color-orange-bg);   color: var(--color-orange); }
.badge-purple  { background: #f3e8ff;                  color: #7c3aed; }
.badge-teal    { background: #ccfbf1;                  color: #0f766e; }

/* Role-specific badges */
.badge-role-client    { background: var(--color-info-bg);    color: var(--color-info); }
.badge-role-advisor   { background: var(--color-success-bg); color: var(--color-success); }
.badge-role-lwcg      { background: var(--navy);             color: var(--gold); }

/* Outline badges */
.badge-outline {
  background: transparent;
  border: 1px solid currentColor;
}

/* Dot indicator */
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  flex-shrink: 0;
}


/* ============================================================
   10. TABLES
   ============================================================ */
.table-wrap {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}

.table th {
  text-align: left;
  padding: 0.6875rem 1rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}

/* Sortable column header */
.th-sortable {
  cursor: pointer;
  transition: color var(--transition-fast);
}
.th-sortable:hover { color: var(--navy); }
.th-sortable::after {
  content: ' ↕';
  opacity: 0.4;
  font-size: 0.7em;
}
.th-sort-asc::after  { content: ' ↑'; opacity: 1; color: var(--gold); }
.th-sort-desc::after { content: ' ↓'; opacity: 1; color: var(--gold); }

.table td {
  padding: 0.8125rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  vertical-align: middle;
}

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

.table tbody tr {
  transition: background var(--transition-fast);
}
.table tbody tr:hover td {
  background: var(--gray-50);
}

/* Table footer for pagination / summary */
.table-footer {
  padding: 0.75rem 1rem;
  background: var(--gray-50);
  border-top: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--gray-500);
}

/* Cell helpers */
.td-mono  { font-family: var(--font-mono); font-size: 0.8125rem; }
.td-right { text-align: right; }
.td-center { text-align: center; }
.td-truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Empty state inside table */
.table-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
}
.table-empty-icon { font-size: 2.5rem; margin-bottom: var(--space-3); opacity: 0.5; }
.table-empty-msg  { font-size: var(--text-md); font-weight: 600; color: var(--gray-500); }
.table-empty-sub  { font-size: var(--text-sm); margin-top: var(--space-2); }


/* ============================================================
   11. FORMS
   ============================================================ */
.form-group {
  margin-bottom: 1.125rem;
}

.form-group:last-child { margin-bottom: 0; }

label, .label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.375rem;
  line-height: 1.4;
}

.label-optional {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--gray-400);
  margin-left: 0.25rem;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--gray-500);
  margin-top: 0.3rem;
}
.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-top: 0.3rem;
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
textarea,
select {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  color: var(--gray-900);
  background: #fff;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}

input::placeholder,
textarea::placeholder {
  color: var(--gray-400);
}

input:disabled,
textarea:disabled,
select:disabled {
  background: var(--gray-50);
  color: var(--gray-400);
  cursor: not-allowed;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

textarea { resize: vertical; min-height: 100px; }

/* Input with prefix/suffix icon */
.input-group {
  position: relative;
}
.input-prefix,
.input-suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: var(--text-base);
  pointer-events: none;
}
.input-prefix { left: 0.75rem; }
.input-suffix { right: 0.75rem; }
.input-group input[type="text"],
.input-group input[type="email"],
.input-group input[type="search"] {
  padding-left: 2.25rem;
}
.input-group.has-suffix input { padding-right: 2.25rem; }

/* Error state */
.input-error {
  border-color: var(--color-danger) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}

/* Checkbox and radio */
input[type="checkbox"],
input[type="radio"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--gold);
  cursor: pointer;
}

.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}
.form-check input { flex-shrink: 0; }
.form-check label { margin-bottom: 0; cursor: pointer; }

/* Inline form */
.form-inline {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.form-inline .form-group { margin-bottom: 0; flex: 1; }

/* Search bar */
.search-bar {
  position: relative;
  max-width: 320px;
}
.search-bar input {
  padding-left: 2.25rem;
  padding-right: var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  height: 36px;
}
.search-bar__icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  font-size: 0.875rem;
  pointer-events: none;
}


/* ============================================================
   12. ALERTS / NOTIFICATIONS
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  border: 1px solid transparent;
  margin-bottom: var(--space-4);
}

.alert-icon { flex-shrink: 0; font-size: 1rem; margin-top: 0.1rem; }
.alert-body { flex: 1; }
.alert-title { font-weight: 700; margin-bottom: 0.2rem; font-size: var(--text-base); }
.alert-close {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  font-size: 1rem;
  padding: 0;
  flex-shrink: 0;
}
.alert-close:hover { opacity: 1; }

.alert-error   { background: var(--color-danger-bg);  color: var(--color-danger);  border-color: var(--color-danger-border); }
.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success-border); }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning-border); }
.alert-info    { background: var(--color-info-bg);    color: var(--color-info);    border-color: var(--color-info-border); }


/* ============================================================
   13. MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 58, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-4);
}

.modal-box {
  background: #fff;
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  padding: 2rem;
  box-shadow: var(--shadow-xl);
  position: relative;
  animation: modal-in 0.18s ease;
}

.modal-box-lg { max-width: 720px; }
.modal-box-sm { max-width: 360px; }

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.modal-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.02em;
}
.modal-subtitle { font-size: var(--text-sm); color: var(--gray-500); margin-top: 0.2rem; }

.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 1.25rem;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
  flex-shrink: 0;
  margin-left: var(--space-3);
}
.modal-close:hover { color: var(--gray-700); background: var(--gray-100); }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--gray-100);
}


/* ============================================================
   14. TABS
   ============================================================ */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: var(--space-6);
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.625rem 1.125rem;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--gray-500);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  text-decoration: none;
}
.tab-item:hover { color: var(--navy); text-decoration: none; }
.tab-item.active {
  color: var(--navy);
  border-bottom-color: var(--gold);
  font-weight: 700;
}

.tab-count {
  background: var(--gray-100);
  color: var(--gray-500);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-full);
}
.tab-item.active .tab-count {
  background: var(--gold-muted);
  color: var(--gold-dark);
}


/* ============================================================
   15. AVATAR
   ============================================================ */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  text-transform: uppercase;
}

.avatar-xs { width: 1.5rem;  height: 1.5rem;  font-size: 0.5rem; }
.avatar-sm { width: 2rem;    height: 2rem;    font-size: 0.6875rem; }
.avatar-md { width: 2.5rem;  height: 2.5rem;  font-size: 0.875rem; }
.avatar-lg { width: 3rem;    height: 3rem;    font-size: 1.125rem; }
.avatar-xl { width: 4rem;    height: 4rem;    font-size: 1.5rem; }

/* Color variants for initials */
.avatar-navy   { background: var(--navy);  color: var(--gold); }
.avatar-gold   { background: var(--gold);  color: var(--navy); }
.avatar-blue   { background: #dbeafe;      color: #1e40af; }
.avatar-green  { background: #d1fae5;      color: #065f46; }
.avatar-purple { background: #ede9fe;      color: #6d28d9; }
.avatar-red    { background: #fee2e2;      color: #991b1b; }
.avatar-teal   { background: #ccfbf1;      color: #115e59; }
.avatar-orange { background: #ffedd5;      color: #9a3412; }


/* ============================================================
   16. DROPDOWN / ACTION MENU
   ============================================================ */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 160px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  overflow: hidden;
  animation: dropdown-in 0.12s ease;
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.5625rem 1rem;
  font-size: var(--text-base);
  color: var(--gray-700);
  cursor: pointer;
  transition: background var(--transition-fast);
  text-decoration: none;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-ui);
}

.dropdown-item:hover { background: var(--gray-50); color: var(--navy); text-decoration: none; }
.dropdown-item.danger { color: var(--color-danger); }
.dropdown-item.danger:hover { background: var(--color-danger-bg); }

.dropdown-divider {
  height: 1px;
  background: var(--gray-100);
  margin: var(--space-1) 0;
}

.dropdown-header {
  padding: 0.375rem 1rem;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}


/* ============================================================
   17. EMPTY STATE
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--gray-400);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--gray-600);
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: var(--text-base);
  max-width: 380px;
  margin-bottom: var(--space-6);
  line-height: var(--leading-relaxed);
}


/* ============================================================
   18. PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  background: #fff;
}
.page-link:hover { background: var(--gray-50); border-color: var(--gray-300); text-decoration: none; }
.page-link.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.page-link:disabled { opacity: 0.4; cursor: not-allowed; }


/* ============================================================
   19. UTILITY CLASSES
   ============================================================ */

/* Flex helpers */
.flex      { display: flex; }
.flex-col  { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.flex-1    { flex: 1; }
.gap-1     { gap: var(--space-1); }
.gap-2     { gap: var(--space-2); }
.gap-3     { gap: var(--space-3); }
.gap-4     { gap: var(--space-4); }
.gap-6     { gap: var(--space-6); }
.flex-wrap { flex-wrap: wrap; }

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

/* Spacing */
.mt-1  { margin-top: var(--space-1); }
.mt-2  { margin-top: var(--space-2); }
.mt-3  { margin-top: var(--space-3); }
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mt-8  { margin-top: var(--space-8); }
.mb-1  { margin-bottom: var(--space-1); }
.mb-2  { margin-bottom: var(--space-2); }
.mb-3  { margin-bottom: var(--space-3); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }
.mb-8  { margin-bottom: var(--space-8); }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }

/* Text */
.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-navy   { color: var(--navy); }
.text-gold   { color: var(--gold); }
.text-muted  { color: var(--gray-400); }
.text-light  { color: var(--gray-500); }
.text-dark   { color: var(--gray-700); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.font-mono   { font-family: var(--font-mono); }
.font-bold   { font-weight: 700; }
.font-semibold { font-weight: 600; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Misc */
.divider {
  height: 1px;
  background: var(--gray-200);
  margin: var(--space-4) 0;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0; }

/* Dot separator */
.dot-sep::before {
  content: '·';
  margin: 0 var(--space-2);
  color: var(--gray-300);
}


/* ============================================================
   20. HTMX HELPERS
   ============================================================ */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner {
  display: inline-block;
  width: 1rem; height: 1rem;
  border: 2px solid var(--gray-200);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-sm { width: 0.75rem; height: 0.75rem; }
.spinner-lg { width: 1.5rem; height: 1.5rem; }


/* ============================================================
   21. DRAG AND DROP KANBAN
   ============================================================ */
.kanban-board {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  align-items: flex-start;
  padding-bottom: var(--space-4);
}

.kanban-column {
  flex-shrink: 0;
  width: 280px;
  background: var(--gray-100);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  padding: var(--space-1) var(--space-1);
}

.kanban-column-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kanban-count {
  background: var(--gray-300);
  color: var(--gray-600);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
}

.kanban-card {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  cursor: grab;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition-fast);
}
.kanban-card:hover { box-shadow: var(--shadow-sm); }
.kanban-card.dragging { opacity: 0.5; cursor: grabbing; }


/* ============================================================
   22. RESPONSIVE — SIDEBAR MOBILE COLLAPSE
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 58, 0.5);
  z-index: 99;
  backdrop-filter: blur(1px);
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-overlay.is-open {
    display: block;
  }

  .main {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: flex;
  }

  .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  /* Sidebar is hidden off-canvas — hamburger (sidebar-toggle) reveals it */
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0 !important;
    padding: 0 !important;
  }

  .sidebar-toggle {
    display: flex;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .stats-grid-4 {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Kanban/engagement board columns stack vertically */
  .board {
    flex-direction: column !important;
  }
  .board-col {
    flex: none !important;
    width: 100% !important;
  }

  table {
    font-size: 0.8125rem;
  }

  .topbar {
    padding: 0.75rem 1rem !important;
  }
}

@media (max-width: 640px) {
  .content, .content-full { padding: var(--space-4); }
  .topbar { padding: 0 var(--space-4); }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-actions { width: 100%; }

  .stats-grid-4 { grid-template-columns: 1fr; }
  .stats-grid-3 { grid-template-columns: 1fr; }
  .stats-grid-2 { grid-template-columns: 1fr; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  .modal-box { padding: 1.25rem; }
  .kanban-board { flex-direction: column; }
  .kanban-column { width: 100%; }

  .table th, .table td { padding: 0.625rem 0.625rem; }
}
