
  :root {
    --primary-color: #222;
    --secondary-color: #286090;
    --accent-color: #b3e5fc;
    --success-color: #43a047;
    --warning-color: #ffe082;
    --info-color: #5bc0de;
    --background-color: #f5f5f5;
    --container-bg: #fff;
    --text-primary: #333;
    --text-secondary: #666;
    --border-color: #e2e8f0;
    --table-bg: #f8fafd;
    --table-header-bg: #e3eaf5;
    --table-border: #e2e8f0;
    
    /* Theme colors */
    --theme-bg: var(--background-color);
    --theme-surface: var(--container-bg);
    --theme-text: var(--text-primary);
    --theme-text-secondary: var(--text-secondary);
    --theme-border: var(--border-color);
    
    /* Responsive breakpoints */
    --mobile-sm: 480px;
    --mobile-md: 768px;
    --tablet: 1024px;
    --desktop: 1200px;
  }

  /* Dark theme variables */
  [data-theme="dark"] {
    --primary-color: #1a1a1a;
    --background-color: #121212;
    --container-bg: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-color: #404040;
    --table-bg: #2a2a2a;
    --table-header-bg: #333333;
    --table-border: #404040;
    --accent-color: #81d4fa;
    --secondary-color: #3498db;
    
    /* Update theme colors for dark mode */
    --theme-bg: var(--background-color);
    --theme-surface: var(--container-bg);
    --theme-text: var(--text-primary);
    --theme-text-secondary: var(--text-secondary);
    --theme-border: var(--border-color);
  }

  /* Reset and base styles */
  *, *::before, *::after {
    box-sizing: border-box;
  }

  html, body {
    height: 100%;
    margin: 0;
    padding: 0;
  }

body {
  background: var(--theme-bg);
  color: var(--theme-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
  width: 100vw;
  overflow-x: clip;   /* v3 - was 'hidden'. 'hidden' silently sets   */
                      /* overflow-y to 'auto' (CSS spec) which makes  */
                      /* body a scroll container and breaks the      */
                      /* position:sticky on .header. 'clip' clips    */
                      /* horizontal overflow WITHOUT establishing a  */
                      /* scroll container, so sticky works.          */
  display: flex;
  flex-direction: column;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

  /* Enhanced header with better responsive behavior */
.header {
  background: var(--primary-color);
  color: #fff;
  padding: 0 16px; /* Reduced vertical padding to let height control it */
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  height: 60px;
  flex: 0 0 60px;             /* v4 - body is display:flex column, so .header   */
                              /* is a flex child with default flex-shrink:1.    */
                              /* On wide screens (no min-height media-query     */
                              /* override) flex was shrinking it all the way    */
                              /* to 0. flex: 0 0 60px = no grow, no shrink,     */
                              /* basis exactly 60px. Now matches the declared   */
                              /* height regardless of viewport width.           */
  overflow: hidden;
  flex-wrap: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

  .header .logo {
    display: flex;
    align-items: center;
    font-size: 1.4em;
    font-weight: 600;
    flex: 0 0 auto;
    margin-right: 16px;
  }

  .header .logo img {
    height: 132px;
    width: 132px;
    margin-right: 8px;
    object-fit: contain;
  }

  .header-title-center {
    flex: 1 1 0;
    text-align: center;
    font-size: 1.2em;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--accent-color);
    margin: 0;
    z-index: 1;
    pointer-events: none;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header .right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
  }

  .header .welcome {
    font-size: 0.9em;
    margin-right: 8px;
    white-space: nowrap;
  }

  .header .logout {
    color: var(--accent-color);
    text-decoration: none;
    font-size: 0.9em;
    margin-left: 6px;
    transition: opacity 0.2s;
  }

  .header .logout:hover {
    opacity: 0.8;
  }

  .header .garage {
    display: flex;
    align-items: center;
    font-weight: 600;
    font-size: 1em;
    white-space: nowrap;
  }

  .header .garage img {
    height: 24px;
    width: 24px;
    margin-right: 6px;
    object-fit: contain;
  }
  /* Theme dropdown in side menu */
  .theme-dropdown {
    position: relative;
    margin: 4px 12px 8px 12px;
    flex-shrink: 0; /* Prevent dropdown from shrinking */
  }

  .theme-toggle {
    color: #fff;
    text-decoration: none;
    padding: 14px 16px;
    font-size: 1em;
    border-radius: 6px;
    font-weight: 500;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
  }

  .theme-toggle:hover,
  .theme-toggle:focus {
    background: #204d74;
    outline: none;
  }

  .theme-toggle .arrow {
    transition: transform 0.2s ease;
    font-size: 0.8em;
  }

  .theme-toggle.active .arrow {
    transform: rotate(180deg);
  }

  .theme-options {
    display: none;
    background: #1a4a6b;
    border-radius: 6px;
    margin-top: 4px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }

  .theme-options.show {
    display: block;
    animation: slideDown 0.2s ease;
  }

  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .theme-option {
    color: #fff;
    text-decoration: none;
    padding: 12px 20px;
    font-size: 0.95em;
    font-weight: 500;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    min-height: 40px;
  }

  .theme-option:hover,
  .theme-option:focus {
    background: #204d74;
    outline: none;
  }

  .theme-option.active {
    background: #204d74;
    position: relative;
  }

  .theme-option.active::after {
    content: '✓';
    margin-left: auto;
    font-weight: bold;
    color: var(--accent-color);
  }

  .theme-icon {
    font-size: 1.1em;
    width: 16px;
    text-align: center;
  }

  /* Enhanced container */
  .container {
    max-width: var(--desktop);
    margin: 24px auto;
    background: var(--theme-surface);
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    padding: 24px;
    min-height: 60vh;
    flex: 1 0 auto;
    width: calc(100% - 32px);
    transition: background-color 0.3s ease;
  }

  .topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
  }

  .topbar h2 {
    margin: 0;
    font-size: 1.5em;
    font-weight: 600;
    color: var(--theme-text);
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
  }

  .topbar .top-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .topbar .top-actions button {
    background: var(--warning-color);
    color: #444;
    border: none;
    border-radius: 6px;
    padding: 10px 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95em;
    min-height: 40px;
    white-space: nowrap;
  }

  .topbar .top-actions button:last-child {
    background: var(--success-color);
    color: #fff;
  }

  .topbar .top-actions button:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  }

  /* Enhanced table styling */
  .table-container {
    overflow-x: auto;
    margin-top: 16px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    /* Enhanced mobile scrolling */
    -webkit-overflow-scrolling: touch;
  }

/* v2 2026-06-22 — border-collapse: collapse breaks sticky <th> in Chrome:
   pinned header overlaps the first tbody row. Switch to separate +
   border-spacing: 0 to keep the visual look identical while letting
   sticky positioning compute correctly. */
.staff-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--table-bg);
  font-size: 0.95em;
  min-width: 1100px;
  transition: background-color 0.3s ease;
}

  .staff-table th,
  .staff-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--table-border);
    text-align: left;
    vertical-align: middle;
  }

/* v3 2026-06-22 — top was 60px to sit below the page .header (which is
   sticky at top:0, height 60px). That math only works if sticky is computed
   against the viewport. But .table-container has overflow-x: auto, and per
   CSS spec setting one overflow axis to non-visible computes the other to
   auto — making .table-container the scroll container. Sticky <th> then
   computes 'top: 60px' as "60px below the table-container's top", which
   pushes the header DOWN onto the first tbody row, hiding it.
   Fix: top: 0. The header sits at the top of its scroll container (the
   table itself), which is where it naturally renders anyway. No viewport-
   relative sticky behaviour, but the page header is already sticky at top:0
   and 60px tall, so the column header scrolls under it on long pages —
   which is the conventional pattern on this app's other list pages. */
.staff-table th {
  background: var(--table-header-bg);
  color: var(--theme-text);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
  transition: background-color 0.3s ease;
}

  .staff-table td {
    color: var(--theme-text);
    transition: color 0.3s ease;
  }

  .staff-table td .staff-name-link {
    color: #1976d2;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
  }

  .staff-table td .staff-name-link:hover {
    background: #e3f2fd;
    text-decoration: none;
  }

  [data-theme="dark"] .staff-table td .staff-name-link:hover {
    background: rgba(25, 118, 210, 0.2);
  }

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

  .staff-table tr:hover {
    background: rgba(33, 150, 243, 0.04);
  }

  /* Status indicators */
  .status {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
  }

  .status.active {
    background: #d4edda;
    color: #155724;
  }

  .status.inactive {
    background: #f8d7da;
    color: #721c24;
  }

  /* Loading and error states */
  .loading-container,
  .error-container,
  .empty-container {
    text-align: center;
    padding: 40px 20px;
    color: var(--theme-text-secondary);
  }

  .loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--secondary-color);
    animation: spin 1s ease-in-out infinite;
  }

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

  .error-message {
    color: #d32f2f;
    margin-top: 10px;
  }

  /* Enhanced footer */
.footer {
  background: var(--primary-color);
  color: var(--accent-color);
  font-size: 0.9em;
  text-align: center;
  padding: 20px 16px;
  margin-top: auto;
  letter-spacing: 0.3px;
  border-top: 1px solid #2c5070;
  width: 100%;
  flex-shrink: 0;             /* v4 - same reason as .header */
}

  .footer a {
    color: var(--accent-color);
    text-decoration: none;
    margin: 0 8px;
    font-weight: 500;
    transition: opacity 0.2s;
  }

  .footer a:hover {
    opacity: 0.8;
    text-decoration: underline;
  }

  .footer .sep {
    color: #4fc3f7;
    font-weight: 700;
    margin: 0 8px;
  }
    /* Paywall locked state */
    .paywall-locked {
      filter: blur(5px);
      pointer-events: none;
      user-select: none;
    }

    /* Usage badge for staff limits */
    .usage-badge {
      display: inline-block;
      padding: 4px 8px;
      border-radius: 4px;
      font-size: 0.75em;
      font-weight: 600;
      vertical-align: middle;
    }
.office-badge { display:inline-block; margin-left:6px; padding:2px 8px; border-radius:10px; background:#e8f0fe; color:#1a56b0; font-size:11px; font-weight:600; vertical-align:middle; }

  /* Responsive Design */
  
  /* Large tablets and small desktops */
  @media (max-width: 1024px) {
    .container {
      margin: 16px auto;
      padding: 20px;
      width: calc(100% - 24px);
    }
    
    .header-title-center {
      font-size: 1.1em;
    }
    
    .side-menu {
      width: 280px;
      max-width: 80vw;
    }
  }

  /* Tablets */
  @media (max-width: 768px) {
    .header {
      padding: 10px 12px;
      min-height: 56px;
    }

    .header .logo {
      font-size: 1.2em;
      margin-right: 12px;
    }
    
    .header-title-center {
      font-size: 1em;
    }
    
    .header .welcome {
      font-size: 0.85em;
    }
    
    .header .garage {
      font-size: 0.9em;
    }
    
    .container {
      margin: 12px auto;
      padding: 16px;
      width: calc(100% - 16px);
      border-radius: 6px;
    }
    
    .topbar {
      flex-direction: column;
      align-items: stretch;
      gap: 12px;
    }
    
    .topbar h2 {
      font-size: 1.3em;
    }
    
    .staff-table {
      font-size: 0.9em;
    }
    
    .staff-table th,
    .staff-table td {
      padding: 10px 8px;
    }
    
    .side-menu {
      width: 300px;
      max-width: 85vw;
    }
  }

  /* Mobile phones */
  @media (max-width: 480px) {
    body {
      font-size: 14px;
    }
    .header {
      padding: 8px 12px;
      min-height: 52px;
    }
    
    .header .logo {
      font-size: 1.1em;
      margin-right: 8px;
    }
    
    .header .logo img {
      height: 28px;
      width: 28px;
    }
    
    .header-title-center {
      font-size: 0.9em;
      letter-spacing: 0.2px;
    }
    
    .header .welcome {
      display: none;
    }
    
    .header .garage {
      font-size: 0.85em;
    }
    
    .header .garage img {
      height: 20px;
      width: 20px;
    }
    
    .burger {
      width: 40px;
      height: 40px;
      margin-left: 8px;
    }
    
    .container {
      margin: 8px auto;
      padding: 12px;
      width: calc(100% - 12px);
      border-radius: 4px;
    }
    
    .topbar h2 {
      font-size: 1.2em;
    }
    
    .topbar .top-actions {
      width: 100%;
    }
    
    .topbar .top-actions button {
      flex: 1;
      font-size: 0.9em;
      padding: 8px 12px;
    }
    
    .staff-table {
      font-size: 0.85em;
      min-width: 1000px;
    }
    
    .staff-table th,
    .staff-table td {
      padding: 8px 6px;
    }
    
    .side-menu {
      width: 280px;
      max-width: 90vw;
      /* Enhanced mobile scrolling */
      height: calc(100vh - env(safe-area-inset-top));
      height: calc(100dvh - env(safe-area-inset-top));
    }
    
    .side-menu .side-links {
      /* Extra padding for mobile scrolling */
      padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
    
    .footer {
      padding: 16px 12px;
      font-size: 0.85em;
    }
    
    .footer a {
      display: inline-block;
      margin: 4px 6px;
    }
  }

  /* Very small phones */
  @media (max-width: 360px) {
    .header-title-center {
      font-size: 0.8em;
    }
    
    .side-menu {
      width: 260px;
      max-width: 95vw;
    }
    
    .container {
      padding: 10px;
      width: calc(100% - 8px);
    }
    
    .staff-table {
      min-width: 900px;
    }
  }

  /* iOS specific fixes for menu scrolling */
  @supports (-webkit-touch-callout: none) {
    .side-menu {
      /* Fix for iOS Safari viewport units */
      height: -webkit-fill-available;
    }
    
    /* Prevent bounce scrolling on body when menu is open */
    body.menu-open {
      position: fixed;
      width: 100%;
      overflow: hidden;
    }
  }

  /* Print styles */
  @media print {
    .header,
    .burger,
    .side-menu,
    .side-menu-backdrop,
    .footer,
    .topbar .top-actions {
      display: none !important;
    }
    
    .container {
      margin: 0;
      padding: 0;
      box-shadow: none;
      max-width: none;
      width: 100%;
    }
    
    .staff-table {
      font-size: 12px;
    }
  }

  /* High contrast mode support */
  @media (prefers-contrast: high) {
    .header,
    .side-menu,
    .footer {
      border: 1px solid;
    }
    
    .staff-table th,
    .staff-table td {
      border: 1px solid;
    }
  }

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