:root {
    --green: #16a34a;
    --amber: #f59e0b;
    --red: #dc2626;
    --grey: #9ca3af;
    --bg: #f3f4f6;
    --card: #ffffff;
    --ink: #1f2937;
    --ink-soft: #6b7280;
    --border: #e5e7eb;
    --brand: #1e3a5f;
    --brand-hover: #16304d;
    --accent: #2563eb;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute must always hide, even on elements whose class
   sets an explicit display (e.g. .pill { display:inline-block }). Without this,
   `display` from a class overrides the browser default for [hidden]. */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top nav ---------- */
.topbar {
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 0 16px;
    min-height: 56px;
}
.brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    margin-right: auto;
}
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.mainnav a {
    color: #dbeafe;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: .93rem;
}
.mainnav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.nav-logout { color: #fca5a5 !important; }
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
}

/* ---------- Layout ---------- */
.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}
.footer {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px;
    color: var(--ink-soft);
    font-size: .85rem;
}

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 24px 0 12px; }
.subtitle { color: var(--ink-soft); margin: 0 0 20px; }

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 16px;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.card-head h2 { margin: 0; }

/* ---------- Stat tiles ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    text-align: center;
}
.stat .num { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat .lbl { color: var(--ink-soft); font-size: .85rem; margin-top: 6px; display: flex; align-items: center; justify-content: center; gap: .3em; }
.stat.green .num { color: var(--green); }
.stat.amber .num { color: var(--amber); }
.stat.red .num { color: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: .93rem;
}
table.data th, table.data td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.data th {
    background: #f9fafb;
    font-weight: 600;
    color: var(--ink-soft);
    font-size: .82rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}
table.data tr:hover td { background: #fafbfc; }

/* ---------- Status badges ---------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: .35em;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-current  { background: #dcfce7; color: #166534; }
.badge-expiring { background: #fef3c7; color: #92400e; }
.badge-expired  { background: #fee2e2; color: #991b1b; }
.badge-none     { background: #f3f4f6; color: #4b5563; }

.clearance {
    display: inline-flex;
    align-items: center;
    gap: .4em;
    padding: 6px 16px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 1rem;
}
.cleared { background: #dcfce7; color: #166534; }
.not-cleared { background: #fee2e2; color: #991b1b; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: .93rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: #1d4ed8; text-decoration: none; }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-secondary { background: #e5e7eb; color: var(--ink); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }

/* ---------- Forms ---------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: .88rem; }
.field .hint { color: var(--ink-soft); font-size: .8rem; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=file], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: .95rem;
    font-family: inherit;
    background: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- Flash ---------- */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 500;
}
.flash-success { background: #dcfce7; color: #166534; }
.flash-error   { background: #fee2e2; color: #991b1b; }
.flash-info    { background: #dbeafe; color: #1e40af; }

/* ---------- Misc ---------- */
.muted { color: var(--ink-soft); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pill {
    display: inline-block; padding: 2px 8px; border-radius: 999px;
    background: #eef2ff; color: #3730a3; font-size: .78rem; font-weight: 600;
}
.search-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-bar input { flex: 1; min-width: 200px; }
.empty { text-align: center; color: var(--ink-soft); padding: 30px; }
.breadcrumb { font-size: .85rem; margin-bottom: 12px; }
.breadcrumb a { color: var(--ink-soft); }

/* login */
.login-wrap {
    max-width: 380px;
    margin: 8vh auto;
    padding: 0 16px;
}
.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}
.login-logo { text-align: center; font-size: 1.3rem; font-weight: 700; margin-bottom: 6px; }
.login-sub { text-align: center; color: var(--ink-soft); margin-bottom: 22px; font-size: .9rem; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
    .nav-toggle { display: block; }
    .mainnav {
        display: none;
        flex-direction: column;
        width: 100%;
        padding: 8px 0;
        gap: 2px;
    }
    .mainnav.open { display: flex; }
    .mainnav a { padding: 10px 8px; }
    h1 { font-size: 1.3rem; }
}

/* ---------- Info button + description modal ---------- */
.info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 9px;
    margin-left: 4px;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    background: #eff6ff;
    color: #1e40af;
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    vertical-align: middle;
    white-space: nowrap;
}
.info-btn:hover { background: #dbeafe; border-color: #93c5fd; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 20px 40px rgba(0,0,0,.25);
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn .15s ease-out;
}
@keyframes modalIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--ink-soft);
    cursor: pointer;
    padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }
.modal-body {
    padding: 18px;
    overflow-y: auto;
}
.modal-body p { margin: 0 0 12px; }
.modal-body p:last-child { margin-bottom: 0; }
.desc-steps {
    margin: 0 0 12px;
    padding-left: 22px;
}
.desc-steps li { margin-bottom: 8px; }
.desc-steps li:last-child { margin-bottom: 0; }
.modal-note {
    margin-top: 14px;
    padding: 10px 12px;
    background: #f0f9ff;
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    font-size: .9rem;
}
.modal-foot {
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    text-align: right;
}

/* Narrow info-button column (first column in compliance tables) */
.col-info {
    width: 100px;
    text-align: center;
    padding-left: 6px;
    padding-right: 6px;
}
.col-info .info-btn { margin-left: 0; }

/* Links inside the description modal */
.modal-body a {
    color: var(--accent);
    text-decoration: underline;
    word-break: break-word;
}
.modal-body a:hover { color: #1d4ed8; }

/* ---------- Email-invite admin panel ---------- */
.admin-only-field label { color: #92400e; }
.admin-instructions-row td { background: #fffbeb; padding-top: 6px; padding-bottom: 6px; }
.admin-instructions-row summary { cursor: pointer; font-weight: 600; color: #92400e; font-size: .9rem; }
.admin-instructions-body {
    margin-top: 8px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .9rem;
}
.admin-instructions-body p { margin: 0 0 8px; }
.admin-instructions-body p:last-child { margin-bottom: 0; }
.admin-instructions-body a { color: var(--accent); text-decoration: underline; word-break: break-word; }

.invite-panel-row td { background: #fffbeb; padding: 4px 12px 12px; }
.invite-panel-row summary { cursor: pointer; font-weight: 600; color: #92400e; padding: 6px 0; }
.invite-panel { padding-top: 8px; }
.invite-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
    margin-bottom: 12px;
}
.invite-label { font-size: .8rem; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
.copy-field {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.copy-field code {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: .9rem;
    word-break: break-all;
}
.invite-status-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 10px;
    border-top: 1px solid #fde68a;
}
.invite-status-form label { font-weight: 600; font-size: .9rem; }
.invite-status-form select { width: auto; }

/* ---------- CSS status dots (render everywhere, no emoji font needed) ---------- */
.dot {
    display: inline-block;
    width: .7em;
    height: .7em;
    border-radius: 50%;
    background: var(--grey);
    vertical-align: baseline;
    position: relative;
    top: .02em;
    margin-right: .15em;
    flex: none;
}
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-red   { background: var(--red); }
.dot-grey  { background: var(--grey); }
/* Slightly larger dot for stat tiles / headings */
.dot-lg { width: .85em; height: .85em; }

/* ---------- Employee self-entry edit row ---------- */
.edit-row td { background: #f8fafc; padding: 14px 16px; }
.self-edit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 10px;
}
.self-edit-form .field { margin-bottom: 0; }
.self-edit-form .field label { font-size: .85rem; font-weight: 600; }

/* ---------- Not-applicable requirements ---------- */
.row-na td { background: #f9fafb; color: var(--ink-soft); }
.row-na td strong { color: var(--ink-soft); font-weight: 600; }
.pill-na { background: #e5e7eb; color: #6b7280; }
.badge-na { background: #eef2f5; color: #6b7280; }
.applicable-form {
    display: inline-flex;
    margin: 0 8px 0 0;
    vertical-align: middle;
}
.applicable-check {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: .8rem;
    color: var(--ink-soft);
    cursor: pointer;
    user-select: none;
}
.applicable-check input { width: auto; margin: 0; cursor: pointer; }

/* ---------- Transient toast (AJAX feedback) ---------- */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1f2937;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: .9rem;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    opacity: 0;
    transition: opacity .25s ease, transform .25s ease;
    z-index: 200;
    pointer-events: none;
}
.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Completion count + progress bar (employees list) ---------- */
.completion { display: flex; align-items: center; gap: 8px; }
.completion-count { font-weight: 600; font-size: .9rem; white-space: nowrap; min-width: 3em; }
.progress {
    display: inline-block;
    width: 70px;
    height: 8px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
    flex: none;
}
.progress-bar { display: block; height: 100%; border-radius: 999px; }
.progress-full { background: var(--green); }
.progress-partial { background: var(--amber); }

/* ============================================================
   Responsive "card" tables — on narrow screens, tables with
   class="responsive-cards" restack from a wide row into a
   labeled, vertically-stacked card instead of forcing sideways
   scrolling. Each <td> shows its column name via data-label.
   ============================================================ */
@media (max-width: 700px) {
    table.responsive-cards { display: block; width: 100%; }
    table.responsive-cards thead { display: none; }
    table.responsive-cards tbody { display: block; width: 100%; }

    table.responsive-cards tr {
        display: block;
        position: relative;
        background: #fff;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        margin-bottom: 12px;
        padding: 12px 12px 12px 90px; /* left space for the Instructions button */
    }
    /* Full-width sub-rows (edit form, invite panel) don't need the icon offset */
    table.responsive-cards tr.edit-row,
    table.responsive-cards tr.invite-panel-row,
    table.responsive-cards tr.prereq-row {
        padding-left: 12px;
    }
    table.responsive-cards tr:last-child { margin-bottom: 0; }

    table.responsive-cards td {
        display: block;
        border: none;
        padding: 7px 0;
    }
    /* The Instructions button sits pinned top-left of the card */
    table.responsive-cards td.col-info {
        position: absolute;
        top: 12px;
        left: 8px;
        padding: 0;
        width: auto;
    }
    /* The requirement name acts as the card's title — no label, larger text */
    table.responsive-cards td.cell-title {
        padding-top: 0;
        font-size: 1.02rem;
    }
    /* Labeled fields: value on the right, column name on the left, like a receipt */
    table.responsive-cards td[data-label] {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        border-top: 1px solid var(--border);
    }
    table.responsive-cards td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: .76rem;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: var(--ink-soft);
        flex: none;
    }
    /* Action cells (buttons/checkboxes) — no label, but still separated */
    table.responsive-cards td.cell-plain {
        border-top: 1px solid var(--border);
        padding-top: 10px;
        text-align: left;
    }
    /* Full-width form/panel cells (colspan rows) need no card padding tricks */
    table.responsive-cards td.cell-full { padding: 0; }
}

/* ---------- Not-applicable collapsible section ---------- */
.na-section {
    border-top: 2px solid #fde68a;
    margin-top: 4px;
}
.na-section-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: #fffbeb;
    cursor: pointer;
    font-weight: 600;
    font-size: .9rem;
    color: #92400e;
    list-style: none;
    user-select: none;
}
.na-section-summary::-webkit-details-marker { display: none; }
.na-section-summary::before {
    content: '▸';
    font-size: .8rem;
    transition: transform .2s;
}
.na-section[open] .na-section-summary::before { transform: rotate(90deg); }
.na-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fde68a;
    color: #78350f;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
}
.na-table tbody tr { background: #fffdf0; }
.na-table tbody tr:hover td { background: #fef9c3; }
.row-na-yellow { background: #fffdf0; }

/* Mobile: N/A cards get a subtle yellow tint */
@media (max-width: 700px) {
    .na-table tr { background: #fffdf0 !important; border-color: #fde68a; }
}

/* ---------- Prerequisite warnings ---------- */
.prereq-warn {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 7px 10px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 3px solid #f59e0b;
    border-radius: 6px;
    font-size: .85rem;
    color: #78350f;
    margin-top: 4px;
}
.prereq-warn-sm {
    font-size: .78rem;
    padding: 4px 8px;
    margin-top: 4px;
}
.prereq-warn-banner {
    margin-bottom: 14px;
    font-size: .9rem;
    border-radius: 8px;
}

/* Prerequisite checkbox grid on requirements form */
.prereq-select-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 6px 16px;
    padding: 10px 0 4px;
}

/* Small prereq "Requires:" note on requirements list */
.prereq-list-hint {
    font-size: .78rem;
    color: #78350f;
    margin-top: 3px;
}

/* Prerequisite warning sub-row — spans full table width below the requirement */
.prereq-row td {
    padding: 0 8px 8px;
    background: transparent;
    border-top: none;
}
.prereq-row .prereq-warn { margin: 0; }
@media (max-width: 700px) {
    table.responsive-cards tr.prereq-row {
        padding: 0 12px 8px;
        border: none;
        box-shadow: none;
        background: transparent;
        margin-bottom: 0;
    }
    table.responsive-cards tr.prereq-row td { padding: 0; }
}
