:root {
    --primary-color: #222;
    --secondary-color: #286090;
    --accent-color: #b3e5fc;
    --success-color: #43a047;
    --warning-color: #ffe082;
    --info-color: #5bc0de;
    --danger-color: #dc3545;
    --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);
  }

  /* 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;
    --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: hidden;
    display: flex;
    flex-direction: column;
    font-size: 16px;
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
  }

  /* Header styles */
  .header {
    background: var(--primary-color);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    min-height: 60px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-wrap: nowrap;
  }
  .header .logo {
    display: flex;
    align-items: center;
    font-size: 1.4em;
    font-weight: 600;
  }
  .header .logo img {
    height: 132px;
    width: 132px;
    margin-right: 8px;
    object-fit: contain;
  }
  .header .header-subtext {
    font-size: 0.8em;
    font-weight: normal;
    color: var(--accent-color);
    margin-left: 10px;
    white-space: nowrap;
  }
  .header .right {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  /* Theme dropdown */
  .theme-dropdown {
    position: relative;
    margin: 4px 12px 8px 12px;
  }
  .theme-toggle {
    color: #fff;
    padding: 14px 16px;
    font-size: 1em;
    border-radius: 6px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    transition: background 0.2s;
  }
  .theme-toggle:hover {
    background: #204d74;
  }
  .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;
  }
  .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;
    padding: 12px 20px;
    font-size: 0.95em;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: background 0.2s;
  }
  .theme-option:hover {
    background: #204d74;
  }
  .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;
  }

  /* Main container */
  .container {
    max-width: 1400px;
    margin: 24px auto;
    padding: 0 24px 24px;
    min-height: 60vh;
    flex: 1 0 auto;
    width: 100%;
  }

  /* Dashboard header */
  .dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 16px;
    background: var(--theme-surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  }

  .dashboard-title {
    font-size: 2.2em;
    font-weight: 700;
    color: var(--theme-text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .dashboard-actions {
    display: flex;
    gap: 12px;
    align-items: center;
  }

  .add-sale-btn {
    background: var(--success-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1em;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  .add-sale-btn:hover {
    background: #2e7d32;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }

  /* v3 2026-07-09 Thu — "Add Stock" action (inventory), sits left of
     the green "Add Car Sale"; blue to distinguish the two actions. */
  .add-stock-btn {
    background: var(--secondary-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1em;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  .add-stock-btn:hover {
    background: #1f4e78;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }

  /* v4 2026-07-09 Thu — "View Stock" action → car-stock.html list.
     Outline style so the three actions read as: View (outline) /
     Add Stock (blue) / Add Car Sale (green). 2px border + 10/18
     padding keeps its height matched to the filled buttons. */
  .view-stock-btn {
    background: transparent;
    color: var(--secondary-color);
    border: 2px solid var(--secondary-color);
    border-radius: 8px;
    padding: 10px 18px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1em;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .view-stock-btn:hover {
    background: var(--secondary-color);
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }

/* Stats Cards
   v2 2026-06-23 Tue — house rule: never repeat(auto-fit, minmax()).
   4 cards must follow 4→2→1 with explicit breakpoints. At 769-1024px,
   auto-fit with min 250px gave a 3+1 wrap because the container at
   that width only fits 3 cards. Switched to explicit 4 columns,
   with 1024 + 480 breakpoints doing 2x2 and 1-col respectively. */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

  .stat-card {
    background: var(--theme-surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    border-left: 4px solid var(--secondary-color);
  }

  .stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  .stat-card.success {
    border-left-color: var(--success-color);
  }

  .stat-card.warning {
    border-left-color: var(--warning-color);
  }

  .stat-card.info {
    border-left-color: var(--info-color);
  }

  .stat-card.danger {
    border-left-color: var(--danger-color);
  }

  .stat-icon {
    font-size: 2em;
    margin-bottom: 12px;
    opacity: 0.8;
  }

  .stat-label {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
  }

  .stat-value {
    font-size: 2.2em;
    font-weight: 700;
    color: var(--theme-text);
    line-height: 1;
    margin-bottom: 8px;
  }

  .stat-change {
    font-size: 0.85em;
    color: var(--success-color);
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .stat-change.negative {
    color: var(--danger-color);
  }

  /* Sales Table Section */
  .sales-section {
    background: var(--theme-surface);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  }

  .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--theme-border);
  }

  .section-title {
    font-size: 1.5em;
    font-weight: 600;
    color: var(--theme-text);
    margin: 0;
  }

  .filter-controls {
    display: flex;
    gap: 12px;
    align-items: center;
  }

  .search-input {
    padding: 8px 16px;
    border: 1px solid var(--theme-border);
    border-radius: 6px;
    background: var(--theme-surface);
    color: var(--theme-text);
    font-size: 0.95em;
    min-width: 250px;
    transition: border-color 0.2s;
  }

  .search-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(40, 96, 144, 0.1);
  }

  .filter-select {
    padding: 8px 12px;
    border: 1px solid var(--theme-border);
    border-radius: 6px;
    background: var(--theme-surface);
    color: var(--theme-text);
    font-size: 0.95em;
    cursor: pointer;
    transition: border-color 0.2s;
  }

  .filter-select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(40, 96, 144, 0.1);
  }

  /* Table Styles */
  .table-container {
    overflow-x: auto;
    border: 1px solid var(--theme-border);
    border-radius: 8px;
  }

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

  .sales-table th {
    background: var(--table-header-bg);
    padding: 14px;
    text-align: left;
    font-weight: 600;
    color: var(--theme-text);
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--theme-border);
    white-space: nowrap;
  }

  .sales-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--theme-border);
    color: var(--theme-text);
  }

  .sales-table tbody tr {
    transition: background 0.2s;
    cursor: pointer;
  }

  .sales-table tbody tr:hover {
    background: var(--table-bg);
  }

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

  .car-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .car-make-model {
    font-weight: 600;
    color: var(--theme-text);
  }

  .car-reg {
    font-size: 0.85em;
    color: var(--text-secondary);
  }

  .customer-name {
    font-weight: 500;
    color: var(--theme-text);
  }

  .sale-date {
    color: var(--text-secondary);
    white-space: nowrap;
  }

  .sale-price {
    font-weight: 600;
    color: var(--success-color);
    white-space: nowrap;
  }

  .profit-amount {
    font-weight: 600;
    white-space: nowrap;
  }

  .profit-amount.positive {
    color: var(--success-color);
  }

  .profit-amount.negative {
    color: var(--danger-color);
  }

  .status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .status-badge.completed {
    background: rgba(67, 160, 71, 0.1);
    color: var(--success-color);
  }

  .status-badge.pending {
    background: rgba(255, 224, 130, 0.2);
    color: #f57c00;
  }

  .status-badge.cancelled {
    background: rgba(220, 53, 69, 0.1);
    color: var(--danger-color);
  }

  .action-buttons {
    display: flex;
    gap: 8px;
  }

  .action-btn {
    background: none;
    border: 1px solid var(--theme-border);
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--theme-text);
    font-size: 0.85em;
    transition: all 0.2s;
  }

  .action-btn:hover {
    background: var(--secondary-color);
    color: #fff;
    border-color: var(--secondary-color);
  }

  /* Empty state */
  .empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
  }

  .empty-state-icon {
    font-size: 4em;
    margin-bottom: 16px;
    opacity: 0.5;
  }

  .empty-state-title {
    font-size: 1.5em;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--theme-text);
  }

  .empty-state-text {
    font-size: 1em;
    margin-bottom: 24px;
  }

  /* 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%;
  }
  .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;
  }
    /* Loading overlay and spinner */
    .loading-overlay {
      display: none;
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.5);
      z-index: 9999;
      justify-content: center;
      align-items: center;
    }

    .loading-overlay.show {
      display: flex !important;
    }

    .loading-spinner {
      width: 50px;
      height: 50px;
      border: 4px solid #f3f3f3;
      border-top: 4px solid var(--secondary-color);
      border-radius: 50%;
      animation: spin 1s linear infinite;
    }
    /* Car Sales Paywall Styles */
    .paywall-locked {
      filter: blur(5px);
      pointer-events: none;
      user-select: none;
    }
    .car-sales-paywall-overlay {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(0, 0, 0, 0.8);
      backdrop-filter: blur(5px);
      z-index: 9999;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 20px;
      overflow-y: auto;
      animation: fadeIn 0.3s ease;
    }

    .paywall-modal {
      background: var(--theme-surface);
      border-radius: 12px;
      padding: 40px;
      max-width: 500px;
      width: 90%;
      max-height: 90vh;        /* ADD THIS */
      overflow-y: auto;        /* ADD THIS */
      margin: auto;            /* ADD THIS */
      text-align: center;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
      animation: slideIn 0.4s ease;
      color: var(--theme-text);
    }

    .paywall-content h2 {
      color: var(--theme-text);
      margin-bottom: 16px;
    }

    .paywall-icon {
      font-size: 60px;
      margin-bottom: 20px;
    }

    .plan-badge {
      background: #e5e7eb;
      padding: 4px 12px;
      border-radius: 20px;
      font-weight: 600;
      text-transform: capitalize;
      color: #374151;
    }

    .paywall-features {
      text-align: left;
      margin: 24px 0;
    }

    .paywall-features h3 {
      color: var(--theme-text);
      margin-bottom: 12px;
      text-align: center;
    }

    .paywall-features ul {
      list-style: none;
      padding: 0;
    }

    .paywall-features li {
      padding: 8px 0;
      color: var(--theme-text);
      font-size: 0.95em;
    }

    .paywall-actions {
      display: flex;
      gap: 12px;
      justify-content: center;
      flex-wrap: wrap;
    }

    .btn-upgrade {
      background: var(--success-color);
      color: white;
      padding: 14px 28px;
      border: none;
      border-radius: 8px;
      font-size: 16px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.3s ease;
      text-decoration: none;
      display: inline-block;
    }

    .btn-upgrade:hover {
      background: #2e7d32;
      transform: translateY(-2px);
      box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    .btn-back {
      background: transparent;
      color: var(--theme-text);
      padding: 14px 28px;
      border: 2px solid var(--theme-border);
      border-radius: 8px;
      font-size: 16px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.3s ease;
    }

    .btn-back:hover {
      background: var(--theme-border);
    }

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

    @keyframes slideIn {
      from {
        opacity: 0;
        transform: translateY(-20px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }
    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
  /* Responsive styles */
@media (max-width: 1024px) {
  /* v2 2026-06-23 — explicit 2x2 instead of auto-fit minmax(200px). */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

  @media (max-width: 768px) {
    .container {
      margin: 12px auto;
      padding: 0 16px 16px;
    }

    .dashboard-header {
      flex-direction: column;
      align-items: stretch;
      gap: 16px;
    }

    .dashboard-title {
      font-size: 1.8em;
    }

    /* v2 2026-06-23 — removed `grid-template-columns: 1fr` here so the
       1024px 2x2 layout inherits down to 481px. 1 column only kicks in
       at <=480px (see the 480px block at the bottom of this file).
       gap kept tighter on smaller screens. */
    .stats-grid {
      gap: 12px;
    }

    .filter-controls {
      flex-direction: column;
      width: 100%;
    }

    .search-input {
      width: 100%;
    }

    .section-header {
      flex-direction: column;
      align-items: stretch;
      gap: 12px;
    }

    .sales-table {
      font-size: 0.9em;
    }

    .sales-table th,
    .sales-table td {
      padding: 10px;
    }

    .action-buttons {
      flex-direction: column;
    }
    .car-sales-paywall-overlay {
      padding: 10px;
    }
    
    .car-sales-paywall-overlay .paywall-modal {
      padding: 30px 20px;
      max-height: 95vh;
    }
  }

@media (max-width: 480px) {
  /* v2 2026-06-23 — final drop to single column for phones. */
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-title {
    font-size: 1.4em;
  }

  .stat-value {
    font-size: 1.8em;
  }

    .sales-table {
      font-size: 0.85em;
    }

    .sales-table th,
    .sales-table td {
      padding: 8px;
    }
  }
