:root {
    --navy: #1c2b3a;
    --navy-dark: #121d28;
    --gold: #c8963e;
    --gold-dark: #a97a2c;
    --bg: #f4f5f7;
    --card-bg: #ffffff;
    --border: #dfe3e8;
    --text: #202830;
    --text-muted: #647184;
    --danger: #b3261e;
    --danger-bg: #fbe9e7;
    --success: #1e7a34;
    --success-bg: #e8f5e9;
    font-size: 16px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    /* Short pages (like the login page) keep the footer at the bottom of the screen. */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* A sticky header only stays put if nothing on the page is wider than
       the viewport - horizontal overflow anywhere breaks position:sticky on
       mobile Safari/Chrome. This is a safety net on top of the header's own
       responsive layout below. */
    overflow-x: hidden;
}

a { color: var(--gold-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
    background: var(--navy);
    color: #fff;
    border-bottom: 3px solid var(--gold);
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 24px;
    height: 60px;
}

.brand {
    display: flex;
    align-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 0.02em;
}
.brand:hover { text-decoration: none; color: var(--gold); }

.brand-logo {
    height: 34px;
    width: auto;
    display: block;
    /* Logo art is chrome text on a solid black background; "screen" blend
       drops the black to transparent against the header so only the text shows. */
    mix-blend-mode: screen;
}

.tabs {
    display: flex;
    gap: 4px;
    flex: 1;
}

.tab {
    color: #cfd8e3;
    padding: 8px 14px;
    border-radius: 6px;
    font-weight: 500;
}
.tab:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,0.08); }
.tab.active { color: var(--navy-dark); background: var(--gold); }
.tab.active:hover { background: var(--gold); }

.tab-dropdown {
    position: relative;
    display: flex;
}
.tab-dropdown-trigger {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.tab-dropdown-caret {
    font-size: 0.7em;
    transition: transform 0.2s ease;
}
.tab-dropdown.open .tab-dropdown-caret {
    transform: rotate(180deg);
}
.tab-dropdown-menu {
    position: fixed;
    min-width: 200px;
    background: var(--navy-dark);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    opacity: 0;
    transform: translateY(-10px);
    max-height: 0;
    overflow: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 150;
}
.tab-dropdown.open .tab-dropdown-menu {
    opacity: 1;
    transform: translateY(0);
    max-height: 320px;
    pointer-events: auto;
}
.tab-dropdown-item {
    padding: 9px 14px;
    border-radius: 6px;
    color: #cfd8e3;
    font-weight: 500;
    font-size: 0.95rem;
    white-space: nowrap;
}
.tab-dropdown-item:hover { color: #fff; text-decoration: none; background: rgba(255, 255, 255, 0.08); }
.tab-dropdown-item.active { color: var(--navy-dark); background: var(--gold); }
.tab-dropdown-item.active:hover { background: var(--gold); }

.header-right {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-left: auto;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}
.header-user .username { color: #cfd8e3; }
.logout-link { color: #fff; opacity: 0.85; }

.theme-toggle {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.22); }
.theme-toggle::before { content: "🌙"; }
[data-theme="dark"] .theme-toggle::before { content: "☀️"; }

/* Below this width the brand + full tab set + user menu no longer fit on
   one row. Wrap onto two rows instead of letting the row overflow - an
   overflowing header is what breaks the sticky positioning above on
   mobile browsers, not just a cosmetic issue. */
@media (max-width: 768px) {
    .site-header-inner {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 16px;
        gap: 8px 16px;
    }
    .tabs {
        order: 3;
        flex: 0 0 100%;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 2px;
    }
    .tab {
        white-space: nowrap;
        padding: 8px 12px;
    }
    .header-right {
        margin-left: auto;
    }
}

.site-main {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 20px 60px;
    flex: 1 0 auto;
}

.site-footer {
    text-align: center;
    padding: 18px 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}

h1 { font-size: 1.6rem; margin: 0 0 20px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    /* Tables (quiz lists, rosters, payment history, etc.) are often wider
       than a phone screen. Scroll within the card instead of relying on
       body's overflow-x:hidden, which would just clip content off-screen
       invisibly - e.g. the "Take Quiz" button in the last table column. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
}
.stat-card .label {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}
.stat-card .value {
    font-size: 1.5rem;
    font-weight: 700;
}
.stat-card.status-green { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.stat-card.status-red { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.stat-card.status-green .label, .stat-card.status-red .label { color: inherit; }
.stat-card.status-green a, .stat-card.status-red a { color: inherit; font-weight: 600; text-decoration: underline; }
.stat-card .detail { font-size: 0.85rem; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tr.row-clocked-in td { background: var(--success-bg); }
tr.row-clocked-out td { background: var(--danger-bg); }
#invoice-transactions-table tbody tr:nth-child(even) td { background: var(--bg); }
tr.row-alt td { background: var(--bg); }

form { display: flex; flex-direction: column; gap: 14px; max-width: 480px; }
form.inline-form { flex-direction: row; align-items: center; max-width: none; gap: 8px; }

label { font-weight: 600; font-size: 0.9rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"], select, textarea {
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    width: 100%;
}
textarea { min-height: 90px; }

button, .btn {
    display: inline-block;
    background: var(--navy);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}
button:hover, .btn:hover { background: var(--navy-dark); text-decoration: none; color: #fff; }
button.secondary, .btn.secondary { background: #fff; color: var(--navy); border: 1px solid var(--border); }
button.secondary:hover, .btn.secondary:hover { background: var(--bg); color: var(--navy); }
button.danger, .btn.danger { background: var(--danger); }
button.danger:hover { background: #8f1e18; }
button.gold, .btn.gold { background: var(--gold); color: var(--navy-dark); }
button.gold:hover { background: var(--gold-dark); color: #fff; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; font-weight: 500; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-info { background: #fff4d6; color: #8a6100; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge-pass { background: var(--success-bg); color: var(--success); }
.badge-fail { background: var(--danger-bg); color: var(--danger); }
.badge-pending { background: #fff4d6; color: #8a6100; }
.badge-locked { background: #eceff2; color: var(--text-muted); }

.extra-credit-card { border: 2px dashed #d4a017; background: #fffaf0; }

.login-shell {
    max-width: 420px;
    margin: 60px auto;
}
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }

.clock-display {
    text-align: center;
    padding: 60px 20px;
}
.clock-time {
    font-size: 5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--navy);
}
.clock-date {
    font-size: 1.4rem;
    color: var(--text-muted);
    margin-bottom: 40px;
}
.clock-form {
    max-width: 360px;
    margin: 0 auto;
}
.clock-form input {
    text-align: center;
    font-size: 1.4rem;
    padding: 14px;
}

.pos-layout {
    display: grid;
    /* minmax(0, ...) keeps each track from being forced wider than the
       container by its content's intrinsic size (e.g. a wide table) - a
       bare "2fr 1fr" lets that content blow the grid out sideways. */
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

/* Grid items default to min-width:auto, meaning they still won't shrink
   below their content's intrinsic width even inside a minmax(0, ...) track -
   this is what actually stops the service grid / recent-tickets table from
   pushing the page wider than the viewport. */
.pos-layout > * {
    min-width: 0;
}

@media (max-width: 768px) {
    .pos-layout {
        grid-template-columns: 1fr;
    }
}
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-box {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.resource-viewer-box {
    max-width: 1000px;
    width: 95vw;
    height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 16px;
}
.resource-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-shrink: 0;
}
.resource-viewer-header h3 {
    margin: 0;
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.resource-viewer-body {
    flex: 1;
    min-height: 0;
    position: relative;
    background: #000;
    border-radius: 6px;
    overflow: hidden;
}
.resource-viewer-body video,
.resource-viewer-body iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: #000;
}
.card-pair {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    align-items: start;
}
.card-pair > .card {
    margin-bottom: 0;
    min-width: 0;
}
.service-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.service-tile {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    text-align: center;
    background: #fff;
    cursor: pointer;
}
.service-tile:hover { border-color: var(--gold); }
.service-tile .name { font-weight: 600; }
.service-tile .price { color: var(--text-muted); font-size: 0.9rem; }

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-top: 4px;
}
.calendar-weekday {
    text-align: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding-bottom: 4px;
}
.calendar-day {
    border: 1px solid var(--border);
    border-radius: 8px;
    min-height: 76px;
    padding: 6px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-x: hidden;
    overflow-y: auto;
}
.calendar-day.empty { background: transparent; border-color: transparent; }
.calendar-day.is-today { border-color: var(--gold); border-width: 2px; }
.calendar-day-number { font-weight: 700; font-size: 0.85rem; }
.calendar-sap-badge {
    align-self: flex-start;
    font-size: 0.62rem;
    padding: 2px 6px;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: break-word;
}
.calendar-day-appt {
    font-size: 0.7rem;
    line-height: 1.3;
    background: var(--card-bg);
    border-radius: 4px;
    padding: 2px 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
}
.calendar-day-appt form { max-width: none; }
.calendar-day-appt button { font-size: 0.7rem; padding: 0 5px; line-height: 1.4; }

.ticket-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.ticket-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.3rem;
    font-weight: 700;
    padding-top: 12px;
}

.actions { display: flex; gap: 10px; }

.subtabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border);
}
.subtab {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    opacity: 0.6;
    cursor: pointer;
}
a.subtab { display: inline-block; text-decoration: none; }
a.subtab:hover { text-decoration: none; }
.subtab:hover { background: none; opacity: 0.85; }
.subtab.active { opacity: 1; border-bottom-color: var(--gold); }
.subtab.active:hover { background: none; }

.payment-page-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* Dark mode - toggled via the header button, persisted in localStorage
   (includes/layout_top.php). Per explicit request, all text is forced to
   white rather than a dimmer "muted" tone. Components with their own
   hardcoded light background (inputs, secondary buttons, modals, service
   tiles, extra-credit cards, a couple of hardcoded badges) get an explicit
   override below so white text doesn't end up on a light surface. */
[data-theme="dark"] {
    --bg: #14181d;
    --card-bg: #1c2128;
    --border: #333941;
    --text: #ffffff;
    --text-muted: #ffffff;
    --danger: #ff6b60;
    --danger-bg: #3a1e1c;
    --success: #4caf6c;
    --success-bg: #163524;
}

[data-theme="dark"] a { color: #ffffff; }

[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--card-bg);
    color: var(--text);
    border-color: var(--border);
}

[data-theme="dark"] button.secondary,
[data-theme="dark"] .btn.secondary {
    background: var(--card-bg);
    color: #ffffff;
    border-color: var(--border);
}
[data-theme="dark"] button.secondary:hover,
[data-theme="dark"] .btn.secondary:hover { background: var(--bg); color: #ffffff; }

[data-theme="dark"] .clock-time { color: #ffffff; }

[data-theme="dark"] .modal-box { background: var(--card-bg); }

[data-theme="dark"] .service-tile { background: var(--card-bg); }

[data-theme="dark"] .extra-credit-card { background: #332a13; }

[data-theme="dark"] #invoice-transactions-table tbody tr:nth-child(even) td { background: #262e38; }
[data-theme="dark"] tr.row-alt td { background: #262e38; }
[data-theme="dark"] .badge-pending { background: #4a3c12; color: #ffffff; }
[data-theme="dark"] .alert-info { background: #4a3c12; color: #ffffff; }
[data-theme="dark"] .badge-locked { background: #333941; color: #ffffff; }

/* Reflowed table: see the stacking script at the bottom of app.js. */
table.stacked,
table.stacked tbody,
table.stacked tr,
table.stacked td { display: block; width: 100%; box-sizing: border-box; }
table.stacked thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}
table.stacked tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}
table.stacked td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
    overflow-wrap: anywhere;
}
table.stacked td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    max-width: 42%;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}
table.stacked td[data-label=""] { justify-content: flex-end; }
table.stacked td[data-label=""]::before { display: none; }
table.stacked tr:last-child td { border-bottom: 1px solid var(--border); }
table.stacked tr td:last-child { border-bottom: none; }
