/* ---------- Reset & base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
}
/* Phones blow up the text size on their own (iPhones when turned
   sideways, Android and Firefox in wide boxes), which re-wraps the words
   in Info Page boxes. Keep text the exact size the page asks for. */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
    background: #f4f6f9;
    color: #1a202c;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

a { color: inherit; text-decoration: none; }

/* ---------- Login page ---------- */

.login-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f4f6f9;
    padding: 20px;
    overflow-y: auto;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.login-card h1 {
    font-size: 22px;
    margin-bottom: 4px;
    color: #1a202c;
}

.login-card .subtitle {
    color: #718096;
    font-size: 14px;
    margin-bottom: 28px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3182ce;
    box-shadow: 0 0 0 3px rgba(49,130,206,0.15);
}

.btn {
    display: inline-block;
    padding: 11px 20px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:hover { opacity: 0.9; }

.btn-primary { background: #3182ce; color: #fff; }
.btn-success { background: #38a169; color: #fff; }
.btn-danger  { background: #e53e3e; color: #fff; }
.btn-light   { background: #edf2f7; color: #2d3748; }
.btn-block   { width: 100%; }

/* ---------- App shell (header + sidebar layout) ---------- */

.app-header {
    background: #1a202c;
    color: #fff;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.app-header .brand {
    font-size: 17px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-header .brand .header-logo {
    /* Deliberately smaller than the 36px used in the License page's
       preview box - that box has its own roomy padding and can afford
       a taller logo. This is the actual slim header bar, where the
       plain text content never naturally renders taller than this -
       so the logo fits inside the header's existing height instead of
       expanding it. */
    max-height: 22px;
    max-width: 160px;
    width: auto;
    height: auto;
    display: block;
}

.app-header .user-info {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
}

.app-header .user-info .role-badge {
    background: #2d3748;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #a0aec0;
}

.app-header a.logout {
    background: rgba(255,255,255,0.1);
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 13px;
}
.app-header a.logout:hover { background: rgba(255,255,255,0.2); }

.app-body {
    display: flex;
    flex: 1;
    min-height: 0; /* required so flex children can scroll instead of overflowing */
}

/* Left sidebar (module list) */
.sidebar {
    width: 280px;
    background: #fff;
    border-right: 1px solid #e2e8f0;
    flex-shrink: 0;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* Everything ABOVE a pinned bottom item (like the portal's Birthdays box)
   lives in here and scrolls on its own - flex:1 + min-height:0 lets this
   area shrink and scroll independently, while whatever sits after it in
   .sidebar (outside this wrapper) stays fixed in view at the bottom
   regardless of how long the module list above it gets. */
.sidebar-scroll-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 0;
    box-sizing: border-box;
}

.sidebar h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #a0aec0;
    padding: 0 20px 10px;
}

.sidebar .module-item {
    display: block;
    padding: 12px 20px;
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: background 0.12s;
}
.sidebar .module-item:hover { background: #f7fafc; }
.sidebar .module-item.active {
    background: #ebf8ff;
    border-left-color: #3182ce;
}

.sidebar .module-item .m-title {
    font-size: 14px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 4px;
}

.sidebar .module-item .m-status {
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}
.m-status.not-started { background: #edf2f7; color: #718096; }
.m-status.in-progress { background: #feebc8; color: #c05621; }
.m-status.complete     { background: #c6f6d5; color: #276749; }
.m-status.renewal-due  { background: #fed7d7; color: #c53030; }

/* Main content panel - fills the full height between header and bottom of
   window, with its own scrollbar so the page layout doesn't jump around
   as different content/videos load */
.main-panel {
    flex: 1;
    padding: 28px 36px;
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Right sidebar (upcoming modules / due dates) */
.right-panel {
    width: 260px;
    background: #fff;
    border-left: 1px solid #e2e8f0;
    box-shadow: -2px 0 6px rgba(0,0,0,0.02);
    padding: 18px 0;
    flex-shrink: 0;
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
}
.right-panel h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #a0aec0;
    padding: 0 20px 10px;
}
.due-item {
    padding: 12px 20px;
    border-bottom: 1px solid #f7fafc;
}
.due-item.clickable {
    cursor: pointer;
    transition: background 0.12s;
}
.due-item.clickable:hover { background: #ebf8ff; }
.due-item.locked {
    opacity: 0.55;
}
.due-item .due-title {
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 4px;
}
.due-item .due-date {
    font-size: 12px;
    color: #a0aec0;
}
.due-item .due-date.overdue { color: #e53e3e; font-weight: 600; }
.due-item .due-date.soon { color: #dd6b20; font-weight: 600; }

.main-panel h1 {
    font-size: 22px;
    margin-bottom: 6px;
}

.main-panel .page-subtitle {
    color: #718096;
    font-size: 14px;
    margin-bottom: 24px;
}

/* ---------- Cards / tables (admin screens) ---------- */

.card {
    background: #fff;
    border-radius: 12px;
    padding: 22px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-bottom: 22px;
}

.card h2 {
    font-size: 16px;
    margin-bottom: 16px;
}

table.data-table {
    width: 100%;
    /* "separate" (not "collapse") specifically because a collapsed
       border on a sticky <th> detaches from the cell when it scrolls -
       a well-known browser quirk. border-spacing: 0 keeps the visual
       layout identical to collapse otherwise. */
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}

table.data-table th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #a0aec0;
    padding: 10px 12px;
    /* box-shadow instead of border-bottom - a box-shadow always paints
       attached to the element itself, even when sticky-positioned,
       where a border-bottom on a separate/collapsed table can detach
       or render in the wrong place while scrolling. */
    box-shadow: 0 2px 0 0 #edf2f7;
}

table.data-table td {
    padding: 12px;
    border-bottom: 1px solid #edf2f7;
    vertical-align: middle;
}

table.data-table tr:hover td { background: #fafbfc; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}
.badge.admin { background: #fefcbf; color: #975a16; }
.badge.staff { background: #e2e8f0; color: #4a5568; }

.row-actions { display: flex; gap: 8px; }
.row-actions button {
    padding: 6px 12px;
    font-size: 12px;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 28px 36px 20px 36px;
    box-sizing: border-box;
    position: sticky;
    top: 0;
    z-index: 30;
    background: #f4f6f9;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
/* When a page has a sticky .top-bar, the panel's own padding would create
   a gap above/beside it, so the panel goes padding-free and .top-bar (and
   .sticky-content-wrap below) carry the spacing instead. This avoids the
   negative-margin trick entirely, which caused a small visual jump the
   moment the bar became "stuck". */
.main-panel.has-sticky-bar { padding: 0; }
.sticky-content-wrap { padding: 0 36px 28px 36px; }
/* Uniform 75%-from-left positioning for Print buttons (and similar
   secondary actions) across every report page, regardless of what else
   is in that header - the left section always takes 75% of the width,
   so the button in the right section always starts at the same spot. */
.header-row-75 { display: flex; align-items: center; gap: 10px; }
.header-row-75 .header-left-75 { flex: 3; min-width: 0; }
.header-row-75 .header-right-75 { flex: 1; display: flex; align-items: center; }

.sticky-page-header {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    z-index: 30;
    background: #f4f6f9;
    padding: 28px 36px 0px 36px;
    box-sizing: border-box;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}

/* ---------- Sticky search bar + table header (report pages) ---------- */
/* Sits directly below the sticky .top-bar. The offset comes from a CSS
   custom property, set by a small JS snippet (see each report page)
   that measures .top-bar's REAL rendered height on load and resize -
   deliberately not a hardcoded pixel guess, since a longer title or
   subtitle on one report page versus another would throw a fixed number
   off. Stacking (highest to lowest): .top-bar (30) covers the search
   bar (25) covers the table header (20) covers ordinary scrolling rows. */
.sticky-search-wrap {
    position: sticky;
    top: var(--sticky-search-offset, 0px);
    z-index: 25;
    background: #fff;
    padding: 10px 0;
}
/* When the search wrap sits inside a .card (results.php, past_due_report.php,
   setup.php all do this - modules.php doesn't, and doesn't need this rule),
   the card's own 22px padding sits ABOVE the search wrap in normal flow -
   meaning the page has to scroll through that 22px gap before the wrap
   reaches its sticky point, which is visible as the search bar "moving up
   a little" before it catches. Pulling the wrap up by that same 22px
   (negative margin) removes the gap it has to travel through entirely,
   and adding 22px back as PADDING (inside the sticky element itself,
   travels WITH it, does not affect when it sticks) keeps the resting,
   unscrolled appearance exactly the same as before this rule existed. */
.card > .sticky-search-wrap {
    margin: -22px -22px 0 -22px;
    padding: 22px 22px 10px 22px;
}
.report-table thead th,
table.data-table thead th {
    position: sticky;
    top: var(--sticky-thead-offset, 0px);
    z-index: 20;
    background: #fff;
}

/* ---------- Help widget (the "?" button + its modal, on every page) ---------- */
.help-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #3182ce;
    color: #fff;
    border: none;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s, background 0.12s;
}
.help-fab:hover { background: #2c5282; transform: scale(1.06); }

.help-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20,24,33,0.55);
    align-items: center;
    justify-content: center;
    z-index: 10050;
}
.help-modal-overlay.open { display: flex; }

.help-modal-box {
    position: relative;
    background: #fff;
    border-radius: 12px;
    max-width: 640px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    padding: 30px 28px 26px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.help-modal-box h3 { font-size: 18px; margin-bottom: 4px; color: #1a202c; }
.help-modal-box .help-subtitle { font-size: 13px; color: #a0aec0; margin-bottom: 18px; }

/* Small, business-like close button - not a big bulky icon */
.help-close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    background: transparent;
    border: 1px solid #feb2b2;
    color: #e53e3e;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.help-close-btn:hover { background: #fff5f5; border-color: #e53e3e; }

.help-modal-content h4 { font-size: 14px; margin: 18px 0 6px; color: #2d3748; }
.help-modal-content h4:first-child { margin-top: 0; }
.help-modal-content p { font-size: 14px; color: #4a5568; line-height: 1.6; margin-bottom: 10px; }
.help-modal-content ul, .help-modal-content ol { margin: 0 0 10px 20px; font-size: 14px; color: #4a5568; line-height: 1.7; }
.help-modal-content strong { color: #2d3748; }

.admin-nav {
    display: flex;
    gap: 6px;
}
.admin-nav a {
    padding: 8px 14px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    color: #4a5568;
}
.admin-nav a:hover { background: #edf2f7; }
.admin-nav a.active { background: #3182ce; color: #fff; }

.empty-state {
    text-align: center;
    color: #a0aec0;
    padding: 40px 20px;
    font-size: 14px;
}

/* Login error message shown inside the card (no browser alert) */
.form-error {
    background: #fff5f5;
    border: 1px solid #feb2b2;
    color: #c53030;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 18px;
}

/* ---------- Phones and small tablets: side columns slide in ---------- */
/* On a screen narrower than 1000px, two side columns would leave the
   middle only a sliver. So the side columns (the admin menu, and the
   staff portal's My Training and Upcoming Training) slide in from the
   side when their button in the header is tapped, and the middle gets
   the whole width. Only pages that have those buttons do this (their
   script adds has-drawers to the page), so no page ever hides a column
   with no way to open it. */
.drawer-btn {
    display: none;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    background: rgba(255,255,255,0.12);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.drawer-btn:hover { background: rgba(255,255,255,0.22); }
.drawer-backdrop { display: none; }
@media (max-width: 1000px) {
    html.has-drawers .drawer-btn { display: inline-flex; }
    html.has-drawers .admin-side-nav,
    html.has-drawers .sidebar,
    html.has-drawers .right-panel {
        position: fixed !important;
        top: 0;
        bottom: 0;
        height: auto !important;
        width: min(300px, 85vw) !important;
        z-index: 9000;
        overflow-y: auto;
        transition: transform 0.25s ease;
    }
    html.has-drawers .admin-side-nav,
    html.has-drawers .sidebar { left: 0; transform: translateX(-105%); }
    html.has-drawers .right-panel { right: 0; transform: translateX(105%); }
    html.drawer-left-open .admin-side-nav,
    html.drawer-left-open .sidebar,
    html.drawer-right-open .right-panel { transform: none; box-shadow: 0 0 30px rgba(0,0,0,0.25); }
    html.drawer-left-open .drawer-backdrop,
    html.drawer-right-open .drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 8999;
        background: rgba(20,24,33,0.4);
    }

    /* Less space around everything, so the middle has room */
    .main-panel { padding: 16px; }
    .top-bar { padding: 14px 16px 12px; }
    .sticky-content-wrap { padding: 0 16px 16px; }
    .sticky-page-header { padding: 14px 16px 0; }

    /* Page headers scroll away with the page instead of staying pinned at
       the top - on a phone their title and buttons can take several lines,
       which left no room to see the page itself. Table column headings
       still stay at the top while scrolling a long list. */
    html.has-drawers .top-bar,
    html.has-drawers .sticky-page-header,
    html.has-drawers .sticky-search-wrap,
    html.has-drawers .card > .current-assignments-header { position: static !important; box-shadow: none; }
    html.has-drawers .report-table thead th,
    html.has-drawers table.data-table thead th { top: 0 !important; }

    /* The header stays one line: the name and buttons on the right
       slide sideways with a finger if there are more than fit */
    .app-header { padding: 8px 12px; gap: 10px; }
    .app-header .brand { flex-shrink: 0; font-size: 15px; }
    .app-header .user-info {
        flex: 1;
        min-width: 0;
        overflow-x: auto;
        justify-content: flex-start;
        gap: 8px;
        white-space: nowrap;
        scrollbar-width: none;
    }
    .app-header .user-info::-webkit-scrollbar { display: none; }
    .app-header .user-info > * { flex-shrink: 0; }
    .app-header .user-info > :first-child { margin-left: auto; }
}

/* Phones: when the header buttons don't all fit, an arrow at the edge shows
   there are more to slide to (added by the header script) */
.hdr-slide { display: none; }
@media (max-width: 1000px) {
    html.has-drawers .app-header { position: relative; }
    html.has-drawers .hdr-slide.show {
        display: flex;
        position: absolute;
        top: 0;
        bottom: 0;
        width: 38px;
        align-items: center;
        justify-content: center;
        padding: 0;
        border: none;
        color: #fff;
        font-size: 15px;
        cursor: pointer;
        z-index: 2;
    }
    html.has-drawers .hdr-slide-r { right: 0; justify-content: flex-end; padding-right: 8px; background: linear-gradient(to right, rgba(26,32,44,0), #1a202c 55%); }
    html.has-drawers .hdr-slide-l { justify-content: flex-start; padding-left: 4px; background: linear-gradient(to left, rgba(26,32,44,0), #1a202c 55%); }
}
