/* ─── Simplified Design System (No Jitter) ──── */
:root {
    --blue:       #1a73e8;
    --blue-dark:  #1558b0;
    --blue-soft:  #e8f0fe;
    --red:        #d93025;
    --red-soft:   #fce8e6;
    --green:      #1e8e3e;
    --border:     #dadce0;
    --text:       #1f2023;
    --text-muted: #70757a;
    --grey-100:   #f8f9fa;
    --grey-200:   #f1f3f4;
    --grey-300:   #e8eaed;
    --grey-400:   #dadce0;
    --grey-500:   #bdc1c6;
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md:  0 4px 16px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06);
    --shadow-lg:  0 8px 32px rgba(0,0,0,0.14), 0 4px 12px rgba(0,0,0,0.07);
    --radius:     8px;
    --radius-sm:  4px;
    --radius-lg:  12px;

    /* Heatmap (Admin Only) - UNCHANGED */
    --h3: #ffffff;
    --h2: #fef9e0;
    --h1: #fde8e6;
    --h0: #fad2d0;

    /* Surface colours (used for #fff overrides) */
    --surface:       #ffffff;
    --surface-raised: #ffffff;
    --weekend-bg:    #fafafa;
}

/* ─── Dark Mode Overrides ──────────────────────────────────── */
[data-theme="dark"] {
    --border:     #3a3b42;
    --text:       #e8eaed;
    --text-muted: #9aa0a6;
    --grey-100:   #25262b;
    --grey-200:   #2c2d33;
    --grey-300:   #35363d;
    --grey-400:   #44454d;
    --grey-500:   #5f6068;
    --shadow-sm:  0 1px 3px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.22);
    --shadow-md:  0 4px 16px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.28);
    --shadow-lg:  0 8px 32px rgba(0,0,0,0.55), 0 4px 12px rgba(0,0,0,0.35);
    --blue-soft:  #1a2e4a;

    /* Dark heatmap — subtle tints instead of jarring pastels */
    --h3: #25262b;
    --h2: #36320f;
    --h1: #3d2318;
    --h0: #4d2418;

    --surface:       #1e1f24;
    --surface-raised: #25262b;
    --weekend-bg:    #1b1c21;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'DM Sans', sans-serif;
    margin: 0;
    background: var(--surface);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    animation: simpleFade 0.15s ease-out;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--grey-400); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--grey-500); }

header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: relative;
    z-index: 10;
}

header h1 {
    font-size: 20px;
    font-weight: 500;
    color: var(--text-muted);
    margin: 0 0 0 10px; /* Added margin to push title away from arrows */
    letter-spacing: -0.2px;
}

.header-left  { display: flex; align-items: center; }
.header-right { display: flex; align-items: center; gap: 8px; }

.nav-controls { 
    display: flex; 
    gap: 4px; 
    padding-right: 10px;
    border-right: 1px solid var(--border); /* Visual separator */
}

.nav-btn {
    display: flex; align-items: center; justify-content: center;
    text-decoration: none;
    color: var(--text-muted);
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 18px; /* Slightly larger arrows */
    font-weight: 700;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    line-height: 1;
}
.nav-btn:hover { background: var(--grey-200); border-color: var(--grey-500); color: var(--text); }

.today-btn {
    text-decoration: none;
    color: var(--blue);
    padding: 5px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: background 0.12s, border-color 0.12s;
}
.today-btn:hover { background: var(--blue-soft); border-color: var(--blue); }

.logout-link {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    transition: background 0.12s, color 0.12s;
}
.logout-link:hover { background: var(--grey-200); color: var(--text); }

.role-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 99px;
    background: var(--blue-soft);
    color: var(--blue);
}
.role-badge.guest { background: var(--grey-200); color: var(--text-muted); }

/* ─── Dark Mode Toggle Button ──────────────────────────────── */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0;
    color: var(--text-muted);
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.theme-toggle:hover { background: var(--grey-200); border-color: var(--grey-500); color: var(--text); }

.main-content {
    display: flex;
    height: calc(100vh - 61px);
}

.sidebar {
    width: 262px;
    min-width: 262px;
    padding: 14px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    background: var(--grey-100);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.calendar-wrapper {
    flex-grow: 1;
    overflow-y: scroll;
    display: flex;
    flex-direction: column;
}

.day-labels-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--surface);
}

.day-label {
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 9px 4px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.day-label.weekend-label { color: #b0b8c1; }
[data-theme="dark"] .day-label.weekend-label { color: #5f6068; }

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-left: 1px solid var(--border);
    flex-grow: 1;
    grid-template-rows: repeat(6, 1fr);
}

.day-box {
    will-change: background-color;
    min-height: 118px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 5px 4px 4px;
    transition: background-color 0.16s;
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Ensures children can truncate */
}

.day-box.weekend-col { background-color: var(--weekend-bg); }
.day-box.empty { background: var(--grey-100); }
.day-box.admin-clickable { cursor: pointer; }
.day-box.admin-clickable:hover { background-color: var(--blue-soft) !important; }
.day-box.admin-clickable:hover .day-num { background: var(--blue); color: #fff !important; }

/* Heatmap - PRESERVED */
.heat-3 { background-color: var(--h3); }
.heat-2 { background-color: var(--h2); }
.heat-1 { background-color: var(--h1); }
.heat-0 { background-color: var(--h0); }

.day-num {
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin: 0 auto 4px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 50%;
    transition: background 0.14s, color 0.14s;
}
.day-num.today-num {
    background: var(--blue);
    color: #fff !important;
    font-weight: 600;
}
.day-num.weekend-num { color: #b0b8c1; }
[data-theme="dark"] .day-num.weekend-num { color: #5f6068; }

/* ─── Task Chips (Updated Typography & Truncation) ──────── */
.task-list {
    display: flex;
    flex-direction: column;
    min-width: 0; /* Critical for truncation */
}

.task-chip {
    color: #fff;
    font-size: 14px; 
    font-weight: 700;
    padding: 4px 7px;
    margin-bottom: 3px;
    border-radius: 5px;
    cursor: pointer;
    transition: filter 0.1s, box-shadow 0.1s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.18);
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.2;
    letter-spacing: -0.1px;
    min-width: 0; /* Allow the chip to shrink */
}

.task-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* Forces the ... if title is long */
    flex-grow: 1;
    min-width: 0;
}

.task-chip:hover {
    filter: brightness(90%);
    box-shadow: 0 3px 6px rgba(0,0,0,0.2);
}

/* Staff Initial Styling */
.task-chip b { 
    font-weight: 900; 
    background: rgba(0,0,0,0.15);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 11px;
    letter-spacing: 0.5px;
    flex-shrink: 0; 
}

.overflow-chip {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 2px 5px;
    margin-top: 1px;
    text-align: center;
    cursor: default;
    border-radius: var(--radius-sm);
    background: var(--grey-200);
}

.admin-card, .legend-card, .stats-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--surface-raised);
    box-shadow: var(--shadow-sm);
}

.card-title {
    margin: 0 0 11px 0;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.7px;
}

.key-item {
    font-size: 11px;
    font-weight: 500;
    padding: 5px 8px;
    margin-bottom: 4px;
    border-radius: var(--radius-sm);
    text-align: center;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.free-3 { background: var(--h3); }
.free-2 { background: var(--h2); }
.free-1 { background: var(--h1); }
.free-0 { background: var(--h0); }

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.stat-item {
    background: var(--grey-100);
    border-radius: var(--radius-sm);
    padding: 9px;
    text-align: center;
}
[data-theme="dark"] .stat-item { background: var(--grey-300); }

.stat-num {
    font-size: 20px;
    font-weight: 600;
    color: var(--blue);
    line-height: 1;
    font-family: 'DM Mono', monospace;
}
.stat-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="password"] {
    width: 100%;
    padding: 8px 10px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    color: var(--text);
    background: var(--surface-raised);
    transition: border-color 0.14s, box-shadow 0.14s;
    outline: none;
}
input[type="text"]:focus,
input[type="date"]:focus,
input[type="number"]:focus,
input[type="password"]:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(26,115,232,0.10);
}

.input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    gap: 8px;
}

.staff-picker {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin: 8px 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
}
.staff-picker label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    user-select: none;
}
.staff-picker label:hover { background: var(--blue-soft); border-color: var(--blue); }
.staff-picker input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: var(--blue);
    cursor: pointer;
}

.btn {
    background: var(--blue);
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.14s, box-shadow 0.14s;
}
.btn:hover { background: var(--blue-dark); box-shadow: 0 2px 8px rgba(26,115,232,0.32); }
.btn-del { background: var(--red); }
.btn-full { width: 100%; }

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background: rgba(32,33,36,0.42);
    animation: fadeBg 0.15s ease-out;
}
[data-theme="dark"] .modal { background: rgba(0,0,0,0.60); }

@keyframes fadeBg  { from { opacity: 0; } to { opacity: 1; } }
@keyframes simpleAppear { from { opacity: 0; } to { opacity: 1; } }

.modal.show { display: block; }

.modal-content {
    background: var(--surface-raised);
    margin: 7% auto;
    padding: 26px 28px;
    width: 400px;
    border-radius: var(--radius-lg);
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: simpleAppear 0.15s ease-out;
    border: 1px solid var(--border);
}

.close {
    position: absolute;
    right: 14px;
    top: 12px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 50%;
    transition: background 0.12s;
}
.close:hover { background: var(--grey-200); color: var(--text); }

.m-title {
    margin: 0 0 18px 0;
    color: var(--text);
    font-weight: 600;
    font-size: 18px;
    letter-spacing: -0.2px;
}

.m-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 5px;
    margin-top: 12px;
    text-transform: uppercase;
}

@keyframes simpleFade { from { opacity: 0.85; } to { opacity: 1; } }

.login-container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--grey-100);
}

.login-card {
    background: var(--surface-raised);
    padding: 44px 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-align: center;
    width: 340px;
    box-shadow: var(--shadow-md);
    animation: simpleAppear 0.2s ease-out;
}

#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    box-shadow: var(--shadow-md);
    background: #323232;
    min-width: 250px;
    text-align: center;
    animation: toastFadeIn 0.3s ease-out;
    transition: opacity 0.4s ease;
}

.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }


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

/* ─── Search Results ──────────────────────────────────────── */
.search-card input[type="text"] { margin-bottom: 0; }

.search-result-item {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow 0.14s, border-color 0.14s;
    background: var(--surface-raised);
}
.search-result-item:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--grey-500);
}
.sr-color-bar {
    width: 5px;
    flex-shrink: 0;
}
.sr-body {
    padding: 10px 12px;
    flex-grow: 1;
    min-width: 0;
}
.sr-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}
.sr-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}
.sr-date {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}
.sr-loc {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}
.sr-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.sr-badge {
    font-size: 10px;
    font-weight: 800;
    color: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    letter-spacing: 0.4px;
    background: rgba(0,0,0,0.15);
}

#search-results-list {
    max-height: 420px;
    overflow-y: auto;
    margin-top: 4px;
}

/* ─── Sidebar Toggle Button (hidden on desktop) ──── */
.sidebar-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 36px;
    height: 36px;
    padding: 6px 7px;
    margin-right: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    flex-shrink: 0;
}
.sidebar-toggle span {
    display: block;
    height: 2px;
    background: var(--text-muted);
    border-radius: 2px;
    transition: background 0.12s;
}
.sidebar-toggle:hover span { background: var(--text); }

/* ─── Sidebar Overlay (mobile only) ──── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.38);
    z-index: 99;
}
.sidebar-overlay.show { display: block; }

/* ─── Sidebar staff row (stats) ──── */
.sidebar-staff-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--grey-200);
    margin-top: 2px;
}
[data-theme="dark"] .sidebar-staff-row { border-top-color: var(--grey-300); }
.sidebar-staff-row:first-of-type { border-top: none; }
.staff-count {
    font-weight: 700;
    color: var(--blue);
    font-family: 'DM Mono', monospace;
}

/* ═══════════════════════════════════════════════════════
   MOBILE  ≤ 640px
   ═══════════════════════════════════════════════════════ */
@media (max-width: 640px) {

    /* Body & layout */
    body { overflow: auto; }

    /* Header */
    header {
        height: 52px;
        padding: 0 10px;
    }
    header h1 {
        font-size: 14px;
        margin-left: 0;
        /* Truncate long month names */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 120px;
    }
    .sidebar-toggle { display: flex; }
    .nav-controls { padding-right: 8px; }
    .nav-btn { width: 36px; height: 36px; font-size: 20px; } /* Bigger tap target */
    .role-badge { display: none; } /* Save space */
    .logout-link { font-size: 12px; padding: 5px 7px; }
    .theme-toggle { width: 30px; height: 30px; font-size: 14px; }

    /* Main layout — stack nothing, sidebar overlays */
    .main-content {
        height: calc(100vh - 53px);
        position: relative;
        overflow: hidden;
    }

    /* Sidebar — off-screen drawer */
    .sidebar {
        position: fixed;
        top: 52px;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 86vw;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.22s cubic-bezier(0.4,0,0.2,1);
        box-shadow: var(--shadow-lg);
        border-right: none;
        overflow-y: auto;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { top: 52px; }

    /* Calendar fills full width */
    .calendar-wrapper { width: 100%; }

    /* Day labels — very compact */
    .day-label {
        font-size: 8px;
        padding: 6px 1px;
        letter-spacing: 0;
    }

    /* Day cells — shorter, tighter */
    .day-box {
        min-height: 54px;
        padding: 3px 2px 2px;
    }

    /* Day number */
    .day-num {
        font-size: 10px;
        width: 19px;
        height: 19px;
        margin: 0 auto 3px;
    }

    /* Task chips → slim coloured bars, no text */
    .task-chip {
        height: 7px;
        min-height: 7px;
        padding: 0;
        margin-bottom: 2px;
        border-radius: 2px;
        gap: 0;
        box-shadow: none;
        cursor: pointer;
    }
    .task-chip b,
    .task-chip .task-text { display: none; }

    /* Modals — near full-width */
    .modal-content {
        width: 94vw;
        max-width: 94vw;
        margin: 8% auto 0;
        padding: 20px 18px 24px;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        position: absolute;
        bottom: 0;
        left: 3vw;
        right: 3vw;
        margin: 0;
        max-height: 88vh;
        overflow-y: auto;
    }
    /* Centre modals vertically on slightly taller screens */
    @media (min-height: 700px) {
        .modal-content {
            position: relative;
            bottom: auto;
            left: auto;
            right: auto;
            border-radius: var(--radius-lg);
            margin: 6% auto;
        }
    }

    /* Search results list — more height on mobile */
    #search-results-list { max-height: 52vh; }

    /* Search modal wider list */
    #searchModal .modal-content { width: 94vw; max-width: 94vw; }

    /* Inputs — slightly larger text to avoid iOS zoom-on-focus */
    input[type="text"],
    input[type="date"],
    input[type="number"],
    input[type="password"] {
        font-size: 16px; /* iOS won't zoom if ≥16px */
    }

    /* Buttons — taller tap target */
    .btn { padding: 12px 16px; font-size: 14px; }

    /* Login card */
    .login-card { width: 92vw; padding: 32px 22px; }

    /* Toast — move to top so keyboard doesn't cover it */
    #toast-container { bottom: auto; top: 64px; }

    /* Staff picker — single column on narrow screens */
    .staff-picker { grid-template-columns: 1fr 1fr; }

    /* Edit/add modal button row */
    .modal-content [style*="display:flex"][style*="gap:10px"] {
        flex-direction: column;
    }
}
