/**
 * SweatStack Component Library
 *
 * Works alongside Tachyons with a clear division of responsibilities:
 *
 * USE TACHYONS FOR:
 * - Layout: .flex, .w-100, .pa4, .mb3
 * - Typography: .f3, .fw6, .tc, .ttu
 * - Colors: .bg-white, .black, .b--black-10
 * - Simple cards: .bg-white.br2.pa4.shadow-1
 *
 * USE COMPONENT CLASSES FOR:
 * - Interactive elements: .btn, .input (need hover/focus/disabled states)
 * - Complex components: .drawer, .modal, .header (many moving parts)
 * - Semantic status: .notification-error, .badge-success (semantic meaning)
 * - Navigation: .nav-link, .sidebar-nav (active states, hover effects)
 *
 * Breakpoints (aligned with Tachyons):
 * - Small: < 30em (480px)
 * - Not-small (-ns): >= 30em (480px)
 * - Medium (-m): >= 48em (768px)
 * - Large (-l): >= 64em (1024px)
 */

/* ==========================================================================
   Font Face Declarations
   ========================================================================== */

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/JetBrainsMono-Bold.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */

:root {
  /* Colors - Black/White theme */
  --color-primary: #111;
  --color-primary-dark: #000;
  --color-primary-hover: #333;
  --color-danger: #ff4136;
  --color-success: #19a974;
  --color-warning: #ff6300;
  --color-text: #333;
  --color-text-muted: #666;
  --color-text-light: #999;
  --color-border: #e0e0e0;
  --color-border-dark: #ccc;
  --color-bg: #f4f4f4;
  --color-bg-white: #fff;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 2rem;
  --space-5: 4rem;

  /* Border radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 1rem;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);

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

  /* Layout */
  --header-height: 56px;
  --drawer-width: 280px;
  --sidebar-width: 16rem;
}

/* ==========================================================================
   Layout Components
   ========================================================================== */

/* Containers */
.container {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 var(--space-3);
}

.container-sm {
  max-width: 48rem;
  margin: 0 auto;
  padding: 0 var(--space-3);
}

.container-lg {
  max-width: 96rem;
  margin: 0 auto;
  padding: 0 var(--space-3);
}

@media (min-width: 64em) {
  .container,
  .container-sm,
  .container-lg {
    padding: 0 var(--space-4);
  }
}

/* ==========================================================================
   Header / Top Navigation
   ========================================================================== */

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--color-bg-white);
  box-shadow: var(--shadow-sm);
  z-index: 50;
  display: flex;
  align-items: center;
}

.header-inner {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 120rem;
  margin: 0 auto;
  padding: 0 var(--space-3);
  gap: var(--space-4);
}

@media (min-width: 64em) {
  .header-inner {
    padding: 0 var(--space-4);
  }
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--color-text);
  text-decoration: none;
}

.header-logo-icon {
  width: 24px;
  height: 24px;
  min-width: 24px;
  min-height: 24px;
  flex: 0 0 auto;
  object-fit: contain;
}

@media (min-width: 64em) {
  .header-logo {
    /* Match sidebar width so nav aligns with main content */
    width: var(--sidebar-width);
    flex-shrink: 0;
  }
}

.header-logo:hover {
  color: var(--color-text);
}

/* Desktop navigation - hidden on mobile */
.header-nav {
  display: none;
  align-items: center;
  gap: var(--space-3);
}

@media (min-width: 64em) {
  .header-nav {
    display: flex;
  }
}

.header-nav-link {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--color-text);
  text-decoration: none;
  font-size: 1rem;
  transition: color var(--transition-fast);
}

.header-nav-icon {
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
}

.header-nav-link:hover {
  opacity: 0.7;
}

.header-nav-link.active {
  color: var(--color-text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Header actions (right side) */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

/* Spacer to align header actions with main content right edge */
.header-spacer {
  display: none;
}

@media (min-width: 64em) {
  .header-spacer {
    display: block;
    width: var(--sidebar-width);
    flex-shrink: 999; /* Shrinks first when space is needed */
  }
}

/* ==========================================================================
   Hamburger Button
   ========================================================================== */

.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.hamburger:hover {
  background: rgba(0,0,0,0.05);
}

.hamburger:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

.hamburger-icon {
  width: 24px;
  height: 24px;
  color: var(--color-text);
}

/* Hide hamburger on desktop */
@media (min-width: 64em) {
  .hamburger {
    display: none;
  }
}

/* ==========================================================================
   Drawer / Mobile Navigation
   ========================================================================== */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.drawer-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--drawer-width);
  max-width: 85vw;
  background: var(--color-bg-white);
  z-index: 100;
  transform: translateX(-100%);
  transition: transform var(--transition-normal);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.drawer.is-open {
  transform: translateX(0);
}

/* Hide drawer components on desktop */
@media (min-width: 64em) {
  .drawer,
  .drawer-overlay {
    display: none;
  }
}

/* Drawer header */
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.drawer-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.drawer-close:hover {
  background: rgba(0,0,0,0.05);
}

.drawer-close-icon {
  width: 20px;
  height: 20px;
  color: var(--color-text);
}

/* Drawer content */
.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) 0;
}

/* Drawer user section */
.drawer-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

.drawer-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-border);
}

.drawer-user-info {
  flex: 1;
  min-width: 0;
}

.drawer-user-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-user-email {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Navigation Components
   ========================================================================== */

/* Section header for nav groups */
.nav-section {
  margin-bottom: var(--space-2);
}

.nav-section-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding: var(--space-3) var(--space-3) var(--space-2);
  margin: 0;
}

.nav-section:first-child .nav-section-header {
  padding-top: 0;
}

/* Navigation links */
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.9375rem;
  border-radius: 0;
  transition: background var(--transition-fast);
}

.nav-link:hover {
  background: rgba(0,0,0,0.05);
  color: var(--color-text);
}

.nav-link.active {
  background: rgba(0, 0, 0, 0.08);
  color: var(--color-text);
  font-weight: 600;
}

.nav-link-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-link.active .nav-link-icon {
  opacity: 1;
}

/* Expandable nav item with sub-items */
.nav-item {
  display: flex;
  flex-direction: column;
}

.nav-item-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  text-decoration: none;
  font-size: 0.9375rem;
  transition: background var(--transition-fast);
}

.nav-item-header:hover {
  background: rgba(0,0,0,0.05);
}

.nav-item.is-active > .nav-item-header {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.nav-item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.is-active .nav-item-icon {
  opacity: 1;
}

/* Sub-navigation (expanded items) */
.nav-subitems {
  display: none;
  flex-direction: column;
  padding-left: calc(var(--space-3) + 20px + var(--space-2)); /* Align with parent text */
  padding-bottom: var(--space-2);
}

.nav-item.is-expanded .nav-subitems {
  display: flex;
}

.nav-subitem {
  display: block;
  padding: var(--space-1) var(--space-3);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color var(--transition-fast);
}

.nav-subitem:hover {
  color: var(--color-text);
}

.nav-subitem.active {
  color: var(--color-text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Sidebar navigation (desktop) */
.sidebar {
  display: none;
}

@media (min-width: 64em) {
  .sidebar {
    display: block;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex-shrink: 0;
  }
}

/* Right sidebar - same width as left sidebar */
.sidebar-right {
  display: none;
}

@media (min-width: 64em) {
  .sidebar-right {
    display: block;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex-shrink: 0;
  }
}

.sidebar-sticky {
  position: sticky;
  top: calc(var(--header-height) + var(--space-4));
  margin: 0;
  padding: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  background: var(--color-bg-white);
  border-radius: var(--radius-md);
  padding: var(--space-2) 0;
  box-shadow: var(--shadow-sm);
}

.sidebar-nav .nav-link {
  padding: var(--space-2) var(--space-3);
}

.sidebar-nav .nav-link:hover {
  background: rgba(0,0,0,0.03);
}

.sidebar-nav .nav-link.active {
  background: transparent;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ==========================================================================
   Main Content Area
   ========================================================================== */

.main-wrapper {
  padding-top: var(--header-height);
  min-height: 100vh;
}

.main-layout {
  display: flex;
  gap: var(--space-4);
  max-width: 120rem;
  margin: 0 auto;
  padding: var(--space-3);
}

@media (min-width: 64em) {
  .main-layout {
    padding: var(--space-4);
  }
}

.main-content {
  flex: 1;
  min-width: 0;
}

/* Reset h1 top margin so page titles align with sidebar top */
.main-content > div:first-child > h1:first-child,
.main-content > section:first-child > h1:first-child,
.main-content > h1:first-child {
  margin-top: 0;
}

/* ==========================================================================
   Card Components
   --------------------------------------------------------------------------
   PREFER TACHYONS: Cards are simple containers without interactive states.
   Use Tachyons utilities directly:

   Default card:  .bg-white.br2.pa4.shadow-1.mb3
   Small card:    .bg-white.br2.pa3.shadow-1.mb3
   Flat card:     .bg-white.br2.pa4.ba.b--black-10.mb3
   Card header:   .mb3.pb3.bb.b--black-10
   Card footer:   .mt3.pt3.bt.b--black-10

   The .card class below is kept for backwards compatibility but
   new code should use Tachyons utilities.
   ========================================================================== */

.card {
  background: var(--color-bg-white);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-3);
  max-width: 100%;
  overflow-x: auto;
}

.card-sm {
  padding: var(--space-3);
}

.card-flat {
  box-shadow: none;
  border: 1px solid var(--color-border);
}

/* ==========================================================================
   Button Components
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--transition-fast), background var(--transition-fast);
  white-space: nowrap;
}

.btn:hover {
  opacity: 0.9;
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Button variants */
.btn-primary {
  background: white;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary);
  color: white;
  opacity: 1;
}

.btn-secondary {
  background: var(--color-border);
  color: var(--color-text);
}

.btn-secondary:hover {
  background: #d0d0d0;
  opacity: 1;
}

.btn-danger {
  background: var(--color-danger);
  color: white;
}

.btn-success {
  background: var(--color-success);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text);
}

.btn-ghost:hover {
  background: rgba(0, 0, 0, 0.05);
  opacity: 1;
}

/* Button sizes */
.btn-sm {
  padding: var(--space-1) var(--space-2);
  font-size: 0.875rem;
}

.btn-lg {
  padding: var(--space-3) var(--space-4);
  font-size: 1.125rem;
}

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

/* Button icon */
.btn-icon {
  width: 1.25em;
  height: 1.25em;
}

/* ==========================================================================
   Form Components
   ========================================================================== */

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

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--color-text);
}

.form-label-required::after {
  content: " *";
  color: var(--color-danger);
}

.input {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-white);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}

.input::placeholder {
  color: var(--color-text-light);
}

.input:disabled {
  background: var(--color-bg);
  cursor: not-allowed;
}

.input-error {
  border-color: var(--color-danger);
}

.input-error:focus {
  box-shadow: 0 0 0 3px rgba(255, 65, 54, 0.15);
}

/* Textarea */
textarea.input {
  min-height: 100px;
  resize: vertical;
}

/* Select */
select.input {
  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='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

/* Form hint/help text */
.form-hint {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

.form-error {
  font-size: 0.875rem;
  color: var(--color-danger);
  margin-top: var(--space-1);
}

/* Checkbox / Radio wrapper */
.form-check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  margin-top: 0.25rem;
  flex-shrink: 0;
}

.form-check-label {
  font-size: 0.9375rem;
  color: var(--color-text);
}

/* ==========================================================================
   Notification Components (extending existing)
   ========================================================================== */

.notification {
  width: 100%;
  text-align: center;
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid;
}

.notification-error {
  background-color: #ffe6e6;
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.notification-warning {
  background-color: #fff4e6;
  border-color: var(--color-warning);
  color: var(--color-warning);
}

.notification-success {
  background-color: #e6ffe6;
  border-color: var(--color-success);
  color: var(--color-success);
}

.notification-info {
  background-color: #f0f0f0;
  border-color: var(--color-text);
  color: var(--color-text);
}

/* ==========================================================================
   Table Components
   ========================================================================== */

.table-wrapper {
  overflow-x: auto;
  margin-bottom: var(--space-3);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.table th,
.table td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.table th {
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-bg);
}

.table tbody tr:hover {
  background: rgba(0,0,0,0.02);
}

.table-sm th,
.table-sm td {
  padding: var(--space-1) var(--space-2);
  font-size: 0.875rem;
}

/* ==========================================================================
   Badge / Tag Components
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: var(--color-border);
  color: var(--color-text);
}

.badge-primary {
  background: rgba(0, 0, 0, 0.1);
  color: var(--color-text);
}

.badge-success {
  background: rgba(25, 169, 116, 0.15);
  color: var(--color-success);
}

.badge-danger {
  background: rgba(255, 65, 54, 0.15);
  color: var(--color-danger);
}

.badge-warning {
  background: rgba(255, 99, 0, 0.15);
  color: var(--color-warning);
}

/* ==========================================================================
   Utility Classes (extensions to Tachyons)
   ========================================================================== */

/* Gap utilities */
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

/* Flex utilities */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Text utilities */
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-muted {
  color: var(--color-text-muted);
}

/* Transition utilities */
.transition {
  transition: all var(--transition-fast);
}

/* Focus ring for accessibility */
.focus-ring:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Divider */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-3) 0;
}

/* ==========================================================================
   Empty State Component
   ========================================================================== */

.empty-state {
  text-align: center;
  padding: var(--space-5) var(--space-3);
  color: var(--color-text-muted);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-3);
  opacity: 0.5;
}

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

.empty-state-text {
  font-size: 0.9375rem;
  margin-bottom: var(--space-3);
}

/* ==========================================================================
   Modal Component
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: relative;
  background: var(--color-bg-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 28rem;
  max-height: calc(100vh - var(--space-4) * 2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(-10px);
  transition: transform var(--transition-normal);
}

.modal-backdrop.is-open .modal {
  transform: scale(1) translateY(0);
}

/* Modal sizes */
.modal-sm { max-width: 20rem; }
.modal-lg { max-width: 40rem; }
.modal-xl { max-width: 56rem; }

/* Modal header */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--color-text);
}

.modal-close-icon {
  width: 20px;
  height: 20px;
}

/* Modal body */
.modal-body {
  padding: var(--space-4);
  overflow-y: auto;
  flex: 1;
}

/* Modal footer */
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ==========================================================================
   User Button / Avatar
   ========================================================================== */

.user-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 var(--space-2);
  border-radius: 9999px; /* Fully round / pill shape */
  background: white;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 4.5rem; /* Fits ~4 characters comfortably */
}

.user-button:hover {
  background: var(--color-primary);
  color: white;
}

.user-button:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* ==========================================================================
   Loading Spinner
   ========================================================================== */

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Responsive Visibility Helpers
   ========================================================================== */

/* Hide on mobile, show on desktop */
.hide-mobile {
  display: none;
}

@media (min-width: 64em) {
  .hide-mobile {
    display: block;
  }

  .hide-desktop {
    display: none;
  }
}

/* Show only on mobile */
.show-mobile {
  display: block;
}

@media (min-width: 64em) {
  .show-mobile {
    display: none;
  }
}

/* ==========================================================================
   Summary Cards
   ========================================================================== */

.summary-card {
  display: block;
  background: var(--color-bg-white);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-fast);
}

.summary-card:hover {
  box-shadow: var(--shadow-md);
}

.summary-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-2);
}

.summary-card-label {
  font-weight: 600;
}

.summary-card-meta {
  color: var(--color-text-muted);
}

.summary-card-metric {
  display: flex;
  flex-direction: column;
}

.summary-card-metric-label {
  color: var(--color-text-muted);
}

.summary-card-metric-value {
  font-weight: 600;
  line-height: 1.2;
}

.summary-card-metric-icons {
  line-height: 1.2;
}

/* Category colors */
:root {
  --color-activity: #ff3b30;
  --color-apps: #34c759;
}

/* ==========================================================================
   Apps List
   ========================================================================== */

.apps-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: var(--space-2);
}

.apps-list-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: var(--space-3) 0;
  text-decoration: none;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.apps-list-item:last-child {
  border-bottom: none;
}

.apps-list-item:hover {
  color: var(--color-primary);
}

.apps-list-icon-wrapper {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  margin-right: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.apps-list-icon-wrapper img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.apps-list-icon-wrapper i {
  font-size: 1.25rem;
  color: var(--color-text-muted);
}

.apps-list-name {
  min-width: 0;
}

.apps-list-arrow {
  color: var(--color-text-light);
  font-size: 0.75rem;
  margin-left: var(--space-2);
  flex-shrink: 0;
}

.apps-list-expand {
  margin-top: 0;
}

.apps-list-expand summary {
  cursor: pointer;
  padding: var(--space-2) 0;
  color: var(--color-link);
  font-size: 0.875rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.apps-list-expand summary::-webkit-details-marker {
  display: none;
}

.apps-list-expand summary::before {
  content: "\f078";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: 0.625rem;
  transition: transform var(--transition-fast);
}

.apps-list-expand[open] summary::before {
  transform: rotate(180deg);
}

.apps-list-expand[open] summary {
  margin-bottom: var(--space-1);
}

/* ==========================================================================
   User Switcher Card (Desktop Sidebar)
   ========================================================================== */

.user-switcher-card {
  background: var(--color-bg-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-4);
  overflow: hidden;
}

/* Profile section - centered initials and name */
.user-switcher-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-3) var(--space-3) var(--space-2);
  text-align: center;
}

.user-button--card {
  width: 48px;
  height: 48px;
  min-width: 48px;
  max-width: 48px;
  padding: 0;
  font-size: 1rem;
  margin-bottom: var(--space-1);
  cursor: default;
  pointer-events: none;
}

.user-switcher-name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.user-switcher-badge {
  font-size: 0.75rem;
  color: var(--color-primary);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

/* Dropdown trigger with explicit border */
.user-switcher-dropdown {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid black;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.user-switcher-dropdown:hover {
  background-color: var(--color-gray-50);
}

.user-switcher-dropdown-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}

.user-switcher-chevron {
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: transform var(--transition-fast);
}

.user-switcher-chevron.rotated {
  transform: rotate(180deg);
}

/* User List */
.user-switcher-list {
  margin: var(--space-2) var(--space-3) 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
}

.user-switcher-loading {
  padding: var(--space-3);
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.user-switcher-search {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.user-switcher-search-input {
  width: 100%;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 400;
}

.user-switcher-search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(0, 82, 204, 0.1);
}

.user-switcher-section {
  padding: var(--space-1) 0;
}

.user-switcher-section:first-child {
  padding-top: var(--space-2);
}

.user-switcher-section:last-child {
  padding-bottom: var(--space-2);
}

.user-switcher-section-label {
  padding: var(--space-1) var(--space-3);
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.user-switcher-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  text-decoration: none;
  transition: background-color var(--transition-fast);
  min-width: 0;
}

.user-switcher-item:hover {
  background-color: var(--color-gray-50);
}

.user-switcher-item.active {
  background-color: var(--washed-blue);
}

.user-switcher-item-name {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.user-switcher-item-you {
  font-weight: 400;
  color: var(--color-text-muted);
}

.user-switcher-check {
  flex-shrink: 0;
  color: var(--color-primary);
}

/* Footer with Logout */
.user-switcher-footer {
  padding: var(--space-3);
}

/* ==========================================================================
   User Switcher Drawer (Mobile)
   ========================================================================== */

.drawer-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-3) 0;
}

.drawer-user-switcher {
  padding: 0 var(--space-3) var(--space-3);
}

/* Adjust card styling when inside drawer */
.drawer-user-switcher .user-switcher-card {
  margin-bottom: 0;
  box-shadow: none;
  border-radius: 0;
  background: transparent;
}

.drawer-user-switcher .user-switcher-profile {
  padding: var(--space-3) 0;
}

.drawer-user-switcher .user-switcher-dropdown {
  margin: 0;
}

.drawer-user-switcher .user-switcher-list {
  margin: var(--space-2) 0 0;
}

.drawer-user-switcher .user-switcher-footer {
  padding: var(--space-3) 0 0;
}

/* ==========================================================================
   User Button Responsive Adjustments
   ========================================================================== */

/* Mobile user button - hidden on desktop */
.user-button--mobile {
  display: inline-flex;
}

@media (min-width: 64em) {
  .user-button--mobile {
    display: none;
  }
}
