: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;

    /* Service type colors */
    --mot-color: #ff9800;
    --service-color: #4caf50;
    --diagnostic-color: #2196f3;
    --repair-color: #9c27b0;
    --viewing-color: #607d8b;
    --other-color: #795548;

    /* 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;
  }
  /* Side menu */
  .side-menu-backdrop {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
  }
  .side-menu {
    position: fixed;
    right: -320px;
    top: 0;
    width: 320px;
    max-width: 85vw;
    height: 100vh;
    background: var(--secondary-color);
    color: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }
  .side-menu.open {
    right: 0;
  }
  .side-menu .side-header {
    background: #204d74;
    padding: 20px 18px 16px 18px;
    font-size: 1.1em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-shrink: 0;
  }
  .side-menu .side-header img {
    height: 28px;
    width: 28px;
    object-fit: contain;
  }
  .business-name {
    font-size: 0.9em;
    color: var(--accent-color);
    padding: 0 18px 12px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 8px;
    font-weight: 500;
  }
  .side-menu .side-links {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 12px 20px;
  }
  .side-menu .side-link {
    color: #fff;
    text-decoration: none;
    padding: 14px 16px;
    font-size: 1em;
    border-radius: 6px;
    margin: 1px 0;
    font-weight: 500;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
  }
  .side-menu .side-link.active,
  .side-menu .side-link:hover {
    background: #204d74;
  }

  /* 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;
    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);
  }


  /* ────────────────────────────────────────────────────────────
     v4 2026-06-22 — Diary toolbar + filters + views
     ──────────────────────────────────────────────────────────── */

  .diary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
  }
  .diary-title {
    font-size: 1.6em;
    font-weight: 600;
    color: var(--theme-text);
    margin: 0;
  }
  .diary-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
  }

  /* ── v15 2026-06-22 — Site selector ────────────────────────── */
  .site-selector {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    padding: 4px 4px 4px 10px;
  }
  .site-selector-label {
    font-size: 0.72em;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .site-select {
    background: transparent;
    border: none;
    border-radius: 6px;
    padding: 6px 28px 6px 8px;
    font-size: 0.9em;
    font-weight: 600;
    color: var(--theme-text);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 14px) center, calc(100% - 9px) center;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    transition: background-color 0.15s;
  }
  .site-select:hover { background-color: var(--theme-border); }
  .site-select:focus { outline: 2px solid var(--secondary-color); outline-offset: 1px; }

  /* View switcher (segmented control) */
  .view-switcher {
    display: inline-flex;
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
  }
  .view-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
  }
  .view-btn:hover { color: var(--theme-text); }
  .view-btn.active {
    background: var(--secondary-color);
    color: #fff;
  }

  /* Date nav */
  .date-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    padding: 4px 8px;
  }
  .date-nav button {
    background: transparent;
    color: var(--theme-text);
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
  }
  .date-nav button:hover { background: var(--theme-border); }
  .date-nav .date-nav-today {
    background: var(--secondary-color);
    color: #fff;
  }
  .date-nav-label {
    min-width: 180px;
    text-align: center;
    font-weight: 600;
    color: var(--theme-text);
    font-size: 0.95em;
    padding: 0 4px;
  }

  .add-booking-btn {
    background: var(--success-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    transition: background 0.15s;
  }
  .add-booking-btn:hover { background: #2e7d32; }

  /* ── Filter row ─────────────────────────────────────────────── */
  .diary-filters {
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .filter-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }
  .filter-row-label {
    font-size: 0.78em;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    min-width: 56px;
  }
  .filter-pills,
  .filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1 1 auto;
  }

  /* Bay pills (single-select) */
  .filter-pill {
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    color: var(--theme-text);
    border-radius: 999px;
    padding: 5px 14px;
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
  }
  .filter-pill:hover { border-color: var(--secondary-color); }
  .filter-pill.active {
    background: var(--secondary-color);
    color: #fff;
    border-color: var(--secondary-color);
  }

  /* Service + status chips (multi-select). Border colours
     match the service-type palette so they double as the legend. */
  .filter-chip {
    background: transparent;
    border: 1px solid var(--theme-border);
    color: var(--theme-text);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.82em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .filter-chip::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
  }
  .filter-chip[data-color="mot"]::before        { background: var(--mot-color); }
  .filter-chip[data-color="service"]::before    { background: var(--service-color); }
  .filter-chip[data-color="diagnostic"]::before { background: var(--diagnostic-color); }
  .filter-chip[data-color="repair"]::before     { background: var(--repair-color); }
  .filter-chip[data-color="viewing"]::before    { background: var(--viewing-color); }
  .filter-chip[data-color="other"]::before      { background: var(--other-color); }
  .filter-chip:hover { border-color: var(--secondary-color); }
  .filter-chip.active {
    border-color: var(--secondary-color);
    background: rgba(40, 96, 144, 0.1);
    font-weight: 600;
  }

  .filter-search {
    flex: 0 0 220px;
    border: 1px solid var(--theme-border);
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 0.9em;
    background: var(--theme-bg);
    color: var(--theme-text);
  }
  .filter-search:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(40, 96, 144, 0.2);
  }

  /* ── Service colour customisation (v5 2026-06-22) ──────────── */
  .service-colour-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    flex: 1 1 auto;
  }
  .colour-swatch-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82em;
    color: var(--theme-text);
    cursor: pointer;
    user-select: none;
  }
  .colour-swatch {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--theme-border);
    cursor: pointer;
    padding: 0;
    background: transparent;
    overflow: hidden;
    transition: transform 0.1s, box-shadow 0.1s;
  }
  .colour-swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  }
  .colour-swatch::-webkit-color-swatch-wrapper { padding: 0; }
  .colour-swatch::-webkit-color-swatch { border: none; border-radius: 50%; }
  .colour-swatch::-moz-color-swatch { border: none; border-radius: 50%; }
  .colour-reset-btn {
    background: transparent;
    border: 1px solid var(--theme-border);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.78em;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    margin-left: auto;
    transition: all 0.15s;
  }
  .colour-reset-btn:hover {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
  }

  /* ── View stage ─────────────────────────────────────────────── */
  .diary-view-stage {
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
  }
  .diary-empty-hint {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 0.95em;
    background: var(--theme-surface);
    border-top: 1px solid var(--theme-border);
  }

  /* ── MONTH view (compact) ───────────────────────────────────── */
  .month-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: var(--table-header-bg);
    border-bottom: 1px solid var(--theme-border);
  }
  .month-header .day-header {
    padding: 10px 8px;
    text-align: center;
    font-size: 0.78em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
  }
  .month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(82px, 1fr);
  }
  .month-cell {
    border-right: 1px solid var(--theme-border);
    border-bottom: 1px solid var(--theme-border);
    padding: 6px 8px;
    background: var(--theme-surface);
    cursor: pointer;
    transition: background 0.12s;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 82px;
  }
  .month-cell:nth-child(7n) { border-right: none; }
  .month-cell:hover { background: rgba(40, 96, 144, 0.06); }
  .month-cell.other-month {
    background: var(--theme-bg);
    color: var(--text-secondary);
    opacity: 0.55;
  }
  .month-cell.today { background: rgba(40, 96, 144, 0.1); }
  .month-cell.today .month-cell-date { color: var(--secondary-color); font-weight: 700; }
  .month-cell.weekend { background: rgba(0,0,0,0.02); }

  .month-cell-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .month-cell-date {
    font-weight: 600;
    font-size: 0.95em;
  }
  .month-cell-count {
    background: var(--secondary-color);
    color: #fff;
    font-size: 0.7em;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
  }
  .month-cell-dots {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
  }
  .month-cell-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--other-color);
  }
  .month-cell-dot.mot        { background: var(--mot-color); }
  .month-cell-dot.service    { background: var(--service-color); }
  .month-cell-dot.diagnostic { background: var(--diagnostic-color); }
  .month-cell-dot.repair     { background: var(--repair-color); }
  .month-cell-dot.viewing    { background: var(--viewing-color); }
  .month-cell-dot.other      { background: var(--other-color); }
  .month-cell-dot.completed  { background: var(--success-color); opacity: 0.7; }
  .month-cell-more {
    font-size: 0.7em;
    font-weight: 600;
    color: var(--text-secondary);
    padding-left: 4px;
  }

  /* ── FLIP GRID (Plan E, v9 2026-06-22) ──────────────────────
     Day + Week views share this layout: time axis horizontal
     across the top, rows running vertically down. Each row
     has a label cell and a content cell containing absolutely-
     positioned PENCILS (bookings) laid left-to-right by start
     time, sized by duration, lane-stacked on overlap. */

  /* Both day and week grids use the same structure. */
  .day-grid, .week-grid {
    display: grid;
    /* grid-template-columns, grid-template-rows, min-width set in JS */
    position: relative;
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    overflow: hidden;
  }
  #dayViewContainer, #weekViewContainer { overflow-x: auto; }

  .flip-corner {
    background: var(--table-header-bg);
    border-bottom: 1px solid var(--theme-border);
    border-right: 1px solid var(--theme-border);
  }

  .flip-time-header {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    background: var(--table-header-bg);
    border-bottom: 1px solid var(--theme-border);
  }
  .flip-hour {
    padding: 10px 4px;
    font-size: 0.78em;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
    border-left: 1px solid var(--theme-border);
    letter-spacing: 0.04em;
  }
  .flip-hour:first-child { border-left: none; }

  .flip-row-label {
    padding: 10px 12px;
    background: var(--table-header-bg);
    border-bottom: 1px solid var(--theme-border);
    border-right: 1px solid var(--theme-border);
    font-size: 0.85em;
    font-weight: 700;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .flip-row-label.today {
    background: rgba(40, 96, 144, 0.10);
    color: var(--theme-accent, var(--secondary-color));
  }
  .flip-row-label.unassigned {
    background: var(--theme-bg);
    opacity: 0.8;
  }
  /* Week view day-label: stack "Mon" / "22" */
  .flip-row-day-label { text-transform: none; }
  .flip-row-day-label .flip-row-day {
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .flip-row-day-label .flip-row-date {
    font-size: 1.6em;
    font-weight: 900;
    color: var(--theme-text);
    line-height: 1.1;
  }
  .flip-row-label.today.flip-row-day-label .flip-row-date {
    color: var(--secondary-color);
  }

  .flip-row-content {
    position: relative;
    border-bottom: 1px solid var(--theme-border);
    min-height: 38px;
    cursor: pointer;
    transition: background-color 0.1s;
    /* 12 hourly gridlines */
    background-image: repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(100% / 12 - 1px),
      rgba(0,0,0,0.06) calc(100% / 12 - 1px),
      rgba(0,0,0,0.06) calc(100% / 12)
    );
  }
  .flip-row-content:hover {
    background-color: rgba(40, 96, 144, 0.03);
  }
  .flip-row-content.today {
    background-color: rgba(40, 96, 144, 0.04);
  }
  .flip-row-content.unassigned {
    background-color: var(--theme-bg);
    opacity: 0.92;
  }

  /* ── v12 2026-06-22 — Now bar + now line ────────────────────
     Above the day/week scrollable diary, a thin status bar
     shows current time + the user's timezone. A vertical red
     line marks "now" inside each row's content area (today
     only). Both auto-update every minute. */
  .diary-now-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
    margin: 0 0 8px;
    background: var(--theme-surface);
    border: 1px solid var(--theme-border);
    border-radius: 8px;
    font-size: 0.85em;
  }
  .diary-now-bar .now-bar-pill {
    background: #d92d20;
    color: #fff;
    font-weight: 800;
    letter-spacing: 0.08em;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.78em;
  }
  /* v13: dim the red pill when outside workshop hours */
  .diary-now-bar.outside-hours .now-bar-pill {
    background: var(--text-secondary);
    opacity: 0.7;
  }
  .diary-now-bar .now-bar-time {
    font-variant-numeric: tabular-nums;
    font-weight: 800;
    font-size: 1.05em;
    color: var(--theme-text);
  }
  .diary-now-bar .now-bar-ctx {
    color: var(--text-secondary);
    font-weight: 500;
  }

  .now-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    margin-left: -1px; /* centre on the time */
    background: #d92d20;
    pointer-events: none;
    z-index: 8; /* above pencils (z-index 3-5), below tooltips */
    box-shadow: 0 0 8px rgba(217, 45, 32, 0.55);
  }
  .now-line::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    width: 10px;
    height: 10px;
    background: #d92d20;
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(217, 45, 32, 0.6);
  }

  /* ── Pencil booking pills ──────────────────────────────────── */
  .pencil {
    position: absolute;
    height: 22px;
    min-width: 60px; /* v11: never narrower than this, even for short bookings */
    border-radius: 4px;
    padding: 0 6px;
    font-size: 0.78em;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.22);
    border-left: 3px solid rgba(0,0,0,0.22);
    z-index: 3;
    transition: transform 0.1s, box-shadow 0.1s;
    box-sizing: border-box;
  }
  .pencil:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.30);
    z-index: 5;
  }
  .pencil.mot        { background: var(--mot-color); }
  .pencil.service    { background: var(--service-color); }
  .pencil.diagnostic { background: var(--diagnostic-color); }
  .pencil.repair     { background: var(--repair-color); }
  .pencil.viewing    { background: var(--viewing-color); }
  .pencil.other      { background: var(--other-color); }
  .pencil.completed  { background: var(--success-color); opacity: 0.85; }

  .pencil .pl-reg {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.02em;
  }

  /* ── Mobile ─────────────────────────────────────────────────── */
  @media (max-width: 768px) {
    .diary-header { flex-direction: column; align-items: stretch; }
    .diary-controls { justify-content: space-between; }
    .view-switcher { width: 100%; justify-content: stretch; }
    .view-btn { flex: 1; }
    .date-nav { flex: 1; justify-content: space-between; }
    .date-nav-label { min-width: 0; flex: 1; }
    .add-booking-btn { width: 100%; text-align: center; }

    .filter-row-label { min-width: 0; flex: 0 0 100%; margin-bottom: 4px; }
    .filter-search { flex: 1 1 100%; }

    /* Month: smaller cells, hide dots if tight */
    .month-grid { grid-auto-rows: minmax(62px, 1fr); }
    .month-cell { padding: 4px; min-height: 62px; }
    .month-cell-dots { gap: 3px; }
    .month-cell-dot { width: 6px; height: 6px; }

    /* Day/week flip grid: narrower labels and pencils on mobile.
       Grid templates (cols/rows) are JS-driven so we don't
       override them here. */
    .day-grid, .week-grid { min-width: 600px; }
    .flip-row-label { padding: 6px 8px; font-size: 0.75em; }
    .flip-row-day-label .flip-row-date { font-size: 1.3em; }
    .flip-hour { padding: 7px 2px; font-size: 0.7em; }
    .pencil { font-size: 0.7em; height: 20px; gap: 4px; padding: 0 4px; }
  }


  /* Modal Styles */
  .modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
  }

  .modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
  }

  .modal-content {
    background: var(--theme-surface);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
  }

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

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

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

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

  .close-btn {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
  }

  .close-btn:hover {
    background: var(--table-bg);
  }

  .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .form-group {
    margin-bottom: 16px;
  }

  .form-group.full-width {
    grid-column: 1 / -1;
  }

  .form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--theme-text);
    font-size: 0.95em;
  }

  .form-label .required {
    color: var(--danger-color);
    margin-left: 2px;
  }

  .form-input,
  .form-select,
  .form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--theme-border);
    border-radius: 6px;
    background: var(--theme-surface);
    color: var(--theme-text);
    font-size: 0.95em;
    transition: border-color 0.2s;
    font-family: inherit;
  }

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

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

  .modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--theme-border);
  }

  .btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    transition: all 0.2s;
  }

  .btn-primary {
    background: var(--secondary-color);
    color: #fff;
  }

  .btn-primary:hover:not(:disabled) {
    background: #204d74;
    transform: translateY(-1px);
  }

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

  .btn-secondary:hover {
    background: #555;
  }

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

  .btn-danger:hover {
    background: #c82333;
  }

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

  /* Loading state */
  .loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }

  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }

  /* 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;
  }
    .booking-item.completed {
      background: #4caf50 !important; /* Green for completed */
      opacity: 0.8;
      text-decoration: line-through;
    }
    
    /* Add completed legend color */
    .legend-color.completed {
      background: #4caf50;
      border: 2px solid #2e7d32;
    }

    /* Add Complete button styling */
    .btn-success {
      background: var(--success-color);
      color: #fff;
    }
    
    .btn-success:hover {
      background: #2e7d32;
      transform: translateY(-1px);
    }
  /* Responsive styles */
  @media (max-width: 768px) {
    .header .logo img {
      height: 132px;
      width: 132px;
    }

    .container {
      margin: 12px auto;
      padding: 16px;
      width: calc(100% - 16px);
    }

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

    .diary-controls {
      justify-content: center;
    }

    .form-row {
      grid-template-columns: 1fr;
    }

    .calendar-container {
      overflow-x: auto;
    }

    .calendar-header,
    .calendar-grid {
      min-width: 700px;
    }

    .modal-content {
      padding: 16px;
      width: 95%;
    }
  }

  @media (max-width: 480px) {
    .container {
      margin: 8px auto;
      padding: 12px;
      width: calc(100% - 12px);
    }

    .diary-title {
      font-size: 1.5em;
    }

    .calendar-day {
      min-height: 100px;
      padding: 4px;
    }

    .service-legend {
      flex-direction: column;
      gap: 8px;
    }

    .booking-item {
      font-size: 0.65em;
      padding: 2px 4px;
    }
  }
