/* =========================================================================
   Application styles — built on the tokens in tokens.css.
   Put brand values in tokens.css; put component styling here.
   ========================================================================= */

/* --- Reset ------------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; }

body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd { margin: 0; }

ul[class], ol[class] { list-style: none; margin: 0; padding: 0; }

img, svg { max-width: 100%; display: block; }

button, input, select, textarea { font: inherit; color: inherit; }

/* --- Base -------------------------------------------------------------- */

body {
    font-family: var(--font-body);
    font-size: var(--fs-base);
    line-height: 1.65;
    color: var(--text-body);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    color: var(--text-heading);
    line-height: 1.25;
    font-weight: 700;
}

h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }

a {
    color: var(--indigo);
    text-decoration: none;
    transition: color var(--t-fast);
}

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

code, pre, .mono {
    font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
    font-size: 0.9em;
}

/* Keyboard focus must stay visible everywhere: candidates take timed
   assessments and some navigate entirely by keyboard. */
:focus-visible {
    outline: 2px solid var(--indigo);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

.u-visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Lets keyboard users jump the sidebar instead of tabbing it every page. */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--sp-4);
    z-index: 100;
    padding: var(--sp-3) var(--sp-5);
    background: var(--navy);
    color: var(--white);
    border-radius: 0 0 var(--r-md) var(--r-md);
}

.skip-link:focus { top: 0; color: var(--white); text-decoration: none; }

/* --- App shell --------------------------------------------------------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--navy);
    color: rgba(255, 255, 255, 0.72);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    /* The column itself does not scroll — the brand is pinned and only the nav
       below it scrolls (see .sidebar__nav). */
    overflow: hidden;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    height: var(--topbar-h);
    padding: 0 var(--sp-5);
    font-family: var(--font-display);
    font-weight: 800;
    font-size: var(--fs-md);
    color: var(--white);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.sidebar__brand:hover { text-decoration: none; color: var(--white); }

/* Only the menu scrolls; the brand above stays put. */
.sidebar__nav {
    padding: var(--sp-3) var(--sp-3) var(--sp-6);
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.sidebar__nav::-webkit-scrollbar { width: 8px; }
.sidebar__nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); border-radius: 4px; }

.sidebar__list { list-style: none; margin: 0; padding: 0; }

.sidebar__section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-subtle);
    padding: var(--sp-3) var(--sp-3) var(--sp-1);
    font-weight: 700;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0.44rem var(--sp-3);
    border-radius: var(--r-md);
    color: rgba(255, 255, 255, 0.78);
    font-size: var(--fs-dense);
    font-weight: 500;
    transition: background var(--t-fast), color var(--t-fast);
}

.sidebar__link + .sidebar__link,
.sidebar__list li + li { margin-top: 1px; }

.sidebar__link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--white);
    text-decoration: none;
}

.sidebar__link.is-active {
    background: var(--orange);
    color: var(--white);
    box-shadow: var(--shadow-orange);
}

/* Colourful icons — each item tints its own, set inline in _nav.php. */
.sidebar__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    flex-shrink: 0;
}

.sidebar__link .material-symbols-outlined.sidebar__icon { font-size: 20px; }
.sidebar__icon .nav-glyph { width: 19px; height: 19px; display: block; }

/* The active item is a solid orange pill — a tinted icon on it would fight the
   fill, so it flips to white. */
.sidebar__link.is-active .sidebar__icon { color: var(--white) !important; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    flex-shrink: 0;
    background: var(--white);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: 0 var(--px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.content { padding: var(--sp-8) var(--px); flex: 1; }

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    margin-bottom: var(--sp-6);
    flex-wrap: wrap;
}

.page-head__sub { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--sp-1); }

/* --- Buttons ----------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-5);
    font-family: var(--font-body);
    font-size: var(--fs-dense);
    font-weight: 600;
    line-height: 1.2;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    cursor: pointer;
    background: transparent;
    transition: background var(--t-base), border-color var(--t-base),
                box-shadow var(--t-base), transform var(--t-base), color var(--t-base);
}

.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.97); }

.btn:disabled,
.btn.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.btn--primary {
    background: var(--orange);
    color: var(--white);
    border-color: var(--orange);
    box-shadow: 0 4px 14px rgba(255, 107, 0, 0.35), 0 1px 3px rgba(255, 107, 0, 0.15);
}

.btn--primary:hover {
    background: var(--orange-hover);
    border-color: var(--orange-hover);
    box-shadow: 0 12px 36px rgba(255, 107, 0, 0.38);
    transform: translateY(-1px);
    color: var(--white);
}

.btn--indigo {
    background: var(--indigo);
    color: var(--white);
    border-color: var(--indigo);
    box-shadow: var(--shadow-indigo);
}

.btn--indigo:hover {
    background: var(--indigo-hover);
    border-color: var(--indigo-hover);
    transform: translateY(-1px);
    color: var(--white);
}

.btn--navy {
    background: var(--navy);
    color: var(--white);
    border-color: var(--navy);
}

.btn--navy:hover { background: var(--indigo-hover); border-color: var(--indigo-hover); color: var(--white); }

.btn--outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text-heading);
}

.btn--outline:hover { border-color: var(--navy); background: var(--indigo-pale); color: var(--navy); }

.btn--danger { background: var(--error); color: var(--white); border-color: var(--error); }
.btn--danger:hover { background: #a82626; border-color: #a82626; color: var(--white); }

.btn--sm { padding: var(--sp-2) var(--sp-3); font-size: var(--fs-xs); }
.btn--lg { padding: var(--sp-4) var(--sp-7); font-size: var(--fs-base); }
.btn--block { width: 100%; }

/* --- Cards ------------------------------------------------------------- */

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}

.card__head {
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
}

.card__title { font-size: var(--fs-md); font-weight: 700; }
.card__body { padding: var(--sp-6); }
.card__foot {
    padding: var(--sp-4) var(--sp-6);
    border-top: 1px solid var(--border-light);
    background: var(--bg);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* --- Forms ------------------------------------------------------------- */

.field { margin-bottom: var(--sp-5); }

.label {
    display: block;
    font-size: var(--fs-dense);
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: var(--sp-2);
}

.label__req { color: var(--error); margin-left: 2px; }

.input,
.select,
.textarea {
    width: 100%;
    padding: var(--sp-3) var(--sp-4);
    font-size: var(--fs-dense);
    color: var(--text-heading);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px var(--indigo-pale);
}

.input:disabled,
.select:disabled,
.textarea:disabled { background: var(--bg-alt); cursor: not-allowed; color: var(--text-muted); }

.textarea { min-height: 7rem; resize: vertical; }

.input.has-error,
.select.has-error,
.textarea.has-error { border-color: var(--error); }

.input.has-error:focus { box-shadow: 0 0 0 3px var(--error-pale); }

.field__hint { font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--sp-2); }
.field__error { font-size: var(--fs-xs); color: var(--error); margin-top: var(--sp-2); font-weight: 500; }

.form-row { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.form-row > * { flex: 1 1 14rem; }

/* Lays fields out in as many columns as fit, so a form fills the card width
   instead of a single stacked column with white space beside it. A field that
   needs the whole row (a textarea, an editor) carries .field--full. */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: var(--sp-2) var(--sp-5);
    align-items: start;
}

.form-grid > .field { margin-bottom: var(--sp-4); }
.form-grid > .field--full { grid-column: 1 / -1; }

/* Form cards fill their container; the old fixed max-width left a gutter. */
.form-card { width: 100%; max-width: none; }

/* --- Tables ------------------------------------------------------------ */

/* Wrap tables in .table-wrap so wide data scrolls inside the card instead of
   forcing the whole page to scroll sideways. */
.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: var(--fs-dense); }

.table th {
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--bg);
}

.table td {
    padding: var(--sp-4);
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--bg); }
.table tbody tr:last-child td { border-bottom: none; }

.table__num { text-align: right; font-variant-numeric: tabular-nums; }
.table__actions { text-align: right; white-space: nowrap; }

.table-empty {
    padding: var(--sp-12) var(--sp-6);
    text-align: center;
    color: var(--text-muted);
}

/* --- Icon buttons (table Actions) -------------------------------------- */

.table__actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--border-light);
    border-radius: var(--r-md);
    background: var(--white);
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--t-fast), border-color var(--t-fast),
                color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}

.icon-btn .material-symbols-outlined { font-size: 19px; }
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); text-decoration: none; }
.icon-btn:disabled, .icon-btn.is-disabled { opacity: 0.5; pointer-events: none; }

/* At rest the icon carries its colour; on hover it fills. */
.icon-btn--edit    { color: var(--indigo); }
.icon-btn--edit:hover    { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.icon-btn--view    { color: var(--navy); }
.icon-btn--view:hover    { background: var(--navy); border-color: var(--navy); color: #fff; }
.icon-btn--primary { color: var(--orange); }
.icon-btn--primary:hover { background: var(--orange); border-color: var(--orange); color: #fff; }
.icon-btn--delete  { color: var(--error); }
.icon-btn--delete:hover  { background: var(--error); border-color: var(--error); color: #fff; }
.icon-btn--success { color: var(--success); }
.icon-btn--success:hover { background: var(--success); border-color: var(--success); color: #fff; }
.icon-btn--info    { color: #0086b3; }
.icon-btn--info:hover    { background: #0086b3; border-color: #0086b3; color: #fff; }
.icon-btn--warning { color: var(--warning); }
.icon-btn--warning:hover { background: var(--warning); border-color: var(--warning); color: #fff; }

/* --- Settings tabs icons ----------------------------------------------- */

.tab-icon { display: inline-flex; align-items: center; }
.tab-glyph { width: 18px; height: 18px; display: block; }
.btn .tab-icon .material-symbols-outlined { font-size: 18px; }

/* --- Footer ------------------------------------------------------------ */

/* A sticky footer in the flex-column sense: pushed to the bottom when the page
   is short, pushed down when it is long. The content area is flex:1 above it. */
.app-footer {
    flex-shrink: 0;
    padding: var(--sp-4) var(--px);
    border-top: 1px solid var(--border-light);
    background: var(--white);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-align: center;
}

.app-footer a { color: var(--orange); font-weight: 600; }
.app-footer a:hover { color: var(--orange-hover); }

/* --- Badges ------------------------------------------------------------ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: var(--sp-1) var(--sp-3);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--r-full);
    line-height: 1.5;
    white-space: nowrap;
}

.badge--neutral { background: var(--bg-alt); color: var(--navy); }
.badge--success { background: var(--success-pale); color: var(--success); }
.badge--error   { background: var(--error-pale); color: var(--error); }
.badge--warning { background: var(--warning-pale); color: var(--warning); }
.badge--info    { background: var(--info-pale); color: var(--indigo); }
.badge--orange  { background: var(--orange-pale); color: var(--orange-hover); }
.badge--cyan    { background: var(--cyan-pale); color: #0086b3; }

/* Psychometric score bands. These carry meaning, so they are never signalled
   by colour alone — templates must also render the band text. */
.band--high   { background: var(--success-pale); color: var(--success); }
.band--medium { background: var(--warning-pale); color: var(--warning); }
.band--low    { background: var(--error-pale); color: var(--error); }

/* --- Alerts ------------------------------------------------------------ */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-radius: var(--r-md);
    border: 1px solid transparent;
    font-size: var(--fs-dense);
    margin-bottom: var(--sp-5);
}

.alert--success { background: var(--success-pale); border-color: rgba(13, 158, 99, 0.3); color: #08603c; }
.alert--error   { background: var(--error-pale); border-color: rgba(194, 46, 46, 0.3); color: #8c2020; }
.alert--warning { background: var(--warning-pale); border-color: rgba(178, 106, 0, 0.3); color: #7a4a00; }
.alert--info    { background: var(--info-pale); border-color: rgba(91, 79, 255, 0.3); color: #3a30b8; }

/* --- Stats ------------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    gap: var(--sp-5);
    margin-bottom: var(--sp-8);
}

.stat {
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--r-lg);
    padding: var(--sp-5) var(--sp-6);
    box-shadow: var(--shadow-sm);
}

.stat__label {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat__value {
    font-family: var(--font-display);
    font-size: var(--fs-2xl);
    font-weight: 800;
    color: var(--text-heading);
    line-height: 1.1;
    margin-top: var(--sp-2);
    font-variant-numeric: tabular-nums;
}

/* --- Utilities --------------------------------------------------------- */

.u-muted   { color: var(--text-muted); }
.u-subtle  { color: var(--text-subtle); }
.u-nowrap  { white-space: nowrap; }
.u-right   { text-align: right; }
.u-center  { text-align: center; }
.u-flex    { display: flex; }
.u-gap-2   { gap: var(--sp-2); }
.u-gap-3   { gap: var(--sp-3); }
.u-gap-4   { gap: var(--sp-4); }
.u-items-c { align-items: center; }
.u-between { justify-content: space-between; }
.u-mt-4    { margin-top: var(--sp-4); }
.u-mb-4    { margin-bottom: var(--sp-4); }
.u-mb-6    { margin-bottom: var(--sp-6); }

/* --- Responsive -------------------------------------------------------- */

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform var(--t-base);
        box-shadow: var(--shadow-xl);
    }

    .sidebar.is-open { transform: translateX(0); }

    .content { padding: var(--sp-5) var(--px-mob); }
    .topbar { padding: 0 var(--px-mob); }

    h1 { font-size: var(--fs-xl); }
}

@media (min-width: 901px) {
    .sidebar__toggle { display: none; }
}

/* --- Print ------------------------------------------------------------- */

/* Reports are rendered to PDF through a headless browser, so print rules are
   load-bearing rather than cosmetic: chrome must not appear in the output. */
@media print {
    .sidebar, .topbar, .btn, .no-print { display: none !important; }
    .app { display: block; }
    .content { padding: 0; }
    .card { box-shadow: none; border: 1px solid var(--border); break-inside: avoid; }
    body { background: var(--white); font-size: 11pt; }
}
