/* ===== SARACEN – Employee Records System ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Colour theme — overridden per page via config/theme.php */
    --primary:       #1a4f7a;
    --primary-light: #2678b6;
    --accent:        #e8f2fb;
    --border:        #c5d5e4;

    /* Semantic tokens (light mode defaults) */
    --bg-page:   #f0f4f8;
    --bg-card:   #ffffff;
    --bg-input:  #ffffff;
    --text:      #222222;
    --muted:     #666666;
    --danger:    #c0392b;
    --success:   #27ae60;
    --radius:    6px;

    /* Header height used by sticky sub-nav offset */
    --header-h: 77px;
}

/* ── Dark mode overrides ── */
html[data-theme="dark"] {
    --bg-page:  #0d1b2a;
    --bg-card:  #132338;
    --bg-input: #1a2f44;
    --text:     #dce6f0;
    --muted:    #8aa8c0;
    --border:   #1e3a5a;
    --accent:   #1a2f44;
}

/* ═══════════════════════════════════════
   BASE
═══════════════════════════════════════ */
body {
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg-page);
    min-height: 100vh;
    transition: background .2s, color .2s;
}

/* ═══════════════════════════════════════
   FIXED HEADER + NAV — body compensation
═══════════════════════════════════════ */
:root {
    --header-h: 76px;
    --subnav-h: 43px;
}

/* Pages that have a fixed page-header */
body.has-header    { padding-top: var(--header-h); }
/* Pages that also have the admin sub-nav */
body.has-subnav    { padding-top: calc(var(--header-h) + var(--subnav-h)); }

/* ═══════════════════════════════════════
   PAGE HEADER (fixed)
═══════════════════════════════════════ */
.page-header {
    background: var(--primary);
    color: #fff;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    z-index: 200;
    box-shadow: 0 2px 8px rgba(0,0,0,.22);
}
.page-header img.logo   { height: 52px; border-radius: 4px; }
.page-header .title-block h1 { font-size: 18px; letter-spacing: .5px; }
.page-header .title-block p  { font-size: 12px; opacity: .8; }
.page-header .spacer    { flex: 1; }
.page-header a          { color: rgba(255,255,255,.75); font-size: 13px; text-decoration: none; }
.page-header a:hover    { color: #fff; text-decoration: underline; }

/* ── Mode toggle buttons ── */
.mode-toggle {
    display: flex;
    gap: 2px;
    background: rgba(0,0,0,.2);
    border-radius: 20px;
    padding: 3px;
}
.mode-toggle button {
    background: transparent;
    border: none;
    border-radius: 16px;
    color: rgba(255,255,255,.65);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 4px 7px;
    transition: background .15s, color .15s;
}
.mode-toggle button:hover     { color: #fff; }
.mode-toggle button.mode-active { background: rgba(255,255,255,.2); color: #fff; }

/* ═══════════════════════════════════════
   ADMIN NAV (fixed, below header)
═══════════════════════════════════════ */
.admin-nav {
    display: flex;
    gap: 4px;
    background: var(--primary);
    padding: 0 16px;
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0;
    height: var(--subnav-h);
    z-index: 199;
    box-shadow: 0 2px 6px rgba(0,0,0,.14);
    align-items: center;
}
.admin-nav a {
    display: inline-block;
    padding: 10px 18px;
    color: rgba(255,255,255,.7);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    transition: color .15s;
}
.admin-nav a:hover, .admin-nav a.active {
    color: #fff;
    border-bottom-color: #fff;
}

/* ═══════════════════════════════════════
   LAYOUT
═══════════════════════════════════════ */
.container {
    max-width: 960px;
    margin: 24px auto;
    padding: 0 16px;
}

/* ── Stats grid ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
@media (max-width: 500px) { .stats-grid { grid-template-columns: 1fr; } }

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    border-left: 4px solid var(--primary);
    transition: box-shadow .15s, background .2s;
}
.stat-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); }
.stat-card .stat-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    margin-bottom: 8px;
}
.stat-card .stat-value {
    font-size: 36px;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}
/* Gender split bar */
.gender-row {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}
.gender-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.gender-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.gender-dot.male   { background: #2678b6; }
.gender-dot.female { background: #e84393; }
.gender-bar-wrap {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}
.gender-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #2678b6 var(--male-pct), #e84393 var(--male-pct));
    border-radius: 3px;
    width: 100%;
}
/* Dept list */
.dept-list { list-style: none; margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.dept-list li { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text); }
.dept-list li .dept-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dept-list li .dept-bar-wrap { flex: 2; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.dept-list li .dept-bar-fill { height: 100%; background: var(--primary); border-radius: 3px; }
.dept-list li .dept-cnt { font-size: 11px; color: var(--muted); min-width: 20px; text-align: right; }

/* ═══════════════════════════════════════
   CARD
═══════════════════════════════════════ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
    transition: background .2s, border-color .2s;
}
.card-header {
    background: var(--primary);
    color: #fff;
    padding: 8px 16px;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: .4px;
}
.card-body { padding: 16px; }

/* ═══════════════════════════════════════
   FORM
═══════════════════════════════════════ */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px 20px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .3px;
}
.form-group input,
.form-group select,
.form-group textarea {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 7px 10px;
    font-size: 14px;
    width: 100%;
    background: var(--bg-input);
    color: var(--text);
    transition: border-color .15s, background .2s, color .2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(38,120,182,.12);
}
.form-group textarea { resize: vertical; min-height: 60px; }

/* ── Form actions bar ── */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 8px;
}

/* ═══════════════════════════════════════
   BUTTONS
═══════════════════════════════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, opacity .15s, filter .15s;
    font-family: inherit;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary {
    background: var(--accent);
    color: var(--primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { filter: brightness(.95); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ═══════════════════════════════════════
   CAMERA / PHOTO
═══════════════════════════════════════ */
.photo-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
#camera-preview, #photo-canvas {
    width: 150px;
    height: 190px;
    border-radius: 4px;
    object-fit: cover;
    border: 3px solid var(--border);
    background: #eee;
}
#photo-canvas { display: none; }
.photo-placeholder {
    width: 150px;
    height: 190px;
    border-radius: 4px;
    border: 3px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--muted);
    background: var(--bg-input);
}

/* ═══════════════════════════════════════
   DEPENDANTS TABLE
═══════════════════════════════════════ */
#dependants-section { display: none; }
.dep-table { width: 100%; border-collapse: collapse; }
.dep-table th, .dep-table td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    font-size: 13px;
}
.dep-table th { background: var(--accent); font-weight: 600; text-align: left; color: var(--text); }
.dep-table input, .dep-table select {
    border: none;
    background: transparent;
    width: 100%;
    padding: 2px 4px;
    font-size: 13px;
    color: var(--text);
}
.dep-table input:focus, .dep-table select:focus { outline: 1px solid var(--primary-light); }

#spouse-section { display: none; }

/* ═══════════════════════════════════════
   ALERTS
═══════════════════════════════════════ */
.alert {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}
.alert-success { background: #d5f5e3; border: 1px solid #a9dfbf; color: #1d6a3a; }
.alert-error   { background: #fde8e8; border: 1px solid #f5b7b1; color: #922b21; }

html[data-theme="dark"] .alert-success { background: #1a3a28; border-color: #27ae60; color: #6fcf97; }
html[data-theme="dark"] .alert-error   { background: #3a1a1a; border-color: #c0392b; color: #f1948a; }

/* ═══════════════════════════════════════
   DATA TABLE
═══════════════════════════════════════ */
/* ── Inline form tables (qualifications, position history, referees) ── */
.form-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.form-table th, .form-table td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    font-size: 13px;
}
.form-table th { background: var(--accent); font-weight: 600; text-align: left; color: var(--text); }
.form-table td.row-num { width: 32px; text-align: center; font-weight: 600; color: var(--muted); }
.form-table input, .form-table select {
    border: none;
    background: transparent;
    width: 100%;
    padding: 0;
    font-size: 13px;
    color: var(--text);
}
.form-table input:focus, .form-table select:focus { outline: 1px solid var(--primary-light); }
.form-table-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--primary);
    margin: 20px 0 6px;
}
html[data-theme="dark"] .form-table th { background: #1a2f44; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    font-size: 13px;
    text-align: left;
    color: var(--text);
}
.data-table th { background: var(--accent); font-weight: 600; }
.data-table tr:hover td { background: var(--accent); }
.data-table .actions { white-space: nowrap; }
.data-table .actions a { margin-right: 8px; font-size: 12px; color: var(--primary-light); }
.data-table .actions a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════
   SEARCH BAR
═══════════════════════════════════════ */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; }

/* ═══════════════════════════════════════
   COLOUR PALETTE PICKER (settings page)
═══════════════════════════════════════ */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-top: 10px;
    max-width: 420px;
}
.palette-swatch {
    position: relative;
    cursor: pointer;
}
.palette-swatch input[type="radio"] { display: none; }
.palette-swatch .sw {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    border: 3px solid transparent;
    transition: transform .15s, border-color .15s, box-shadow .15s;
    position: relative;
}
.palette-swatch .sw::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 6px;
    opacity: 0;
    transition: opacity .15s;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z'/%3E%3C/svg%3E") center/60% no-repeat;
}
.palette-swatch input:checked + .sw {
    border-color: var(--text);
    transform: scale(1.08);
    box-shadow: 0 3px 10px rgba(0,0,0,.3);
}
.palette-swatch input:checked + .sw::after { opacity: 1; }
.palette-swatch:hover .sw { transform: scale(1.05); }
.palette-swatch .sw-name {
    display: block;
    font-size: 9px;
    color: var(--muted);
    text-align: center;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ═══════════════════════════════════════
   FOOTER
═══════════════════════════════════════ */
.site-footer {
    text-align: center;
    padding: 20px 0 12px;
    color: var(--muted);
    font-size: 12px;
}
.site-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}
.site-footer a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════
   MISC
═══════════════════════════════════════ */
.text-muted  { color: var(--muted); font-size: 12px; }
.mt-1        { margin-top: 8px; }
.inline-flex { display: inline-flex; gap: 8px; align-items: center; }

/* ── Dark mode deep overrides ── */
html[data-theme="dark"] .card { background: var(--bg-card); }
html[data-theme="dark"] .form-group select option { background: var(--bg-input); }
html[data-theme="dark"] .dep-table select { background: var(--bg-input); }
html[data-theme="dark"] .dep-table select option { background: var(--bg-input); color: var(--text); }
html[data-theme="dark"] .form-table select { background: var(--bg-input); }
html[data-theme="dark"] .form-table select option { background: var(--bg-input); color: var(--text); }
html[data-theme="dark"] .data-table th { background: #1a2f44; }
html[data-theme="dark"] .data-table tr:hover td { background: #1a2f44; }
html[data-theme="dark"] .dep-table th { background: #1a2f44; }
html[data-theme="dark"] .btn-secondary { background: #1a2f44; color: var(--text); }
html[data-theme="dark"] .stat-card { background: var(--bg-card); }
html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }

/* ═══════════════════════════════════════
   RESPONSIVE — TABLET & MOBILE
═══════════════════════════════════════ */

/* ── Tablet / large phone (≤ 768px) ── */
@media (max-width: 768px) {
    :root { --header-h: 56px; --subnav-h: 40px; }

    /* ── Header: force single row, never wrap ── */
    .page-header {
        padding: 0 12px;
        gap: 8px;
        flex-wrap: nowrap;
        height: var(--header-h);
    }
    .page-header img.logo { height: 34px; flex-shrink: 0; }

    /* Title takes remaining space; text truncates with ellipsis */
    .page-header .title-block {
        flex: 1 1 0;
        min-width: 0;
        overflow: hidden;
    }
    .page-header .title-block h1 {
        font-size: 13px;
        letter-spacing: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .page-header .title-block p { display: none; }

    /* Remove spacer so title fills available space naturally */
    .page-header .spacer { display: none; }

    .page-header a { font-size: 11px; white-space: nowrap; flex-shrink: 0; }
    .mode-toggle   { flex-shrink: 0; }
    .mode-toggle button { font-size: 13px; padding: 4px 6px; }

    /* Admin sub-nav: horizontal scroll, hidden scrollbar */
    .admin-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 8px;
        gap: 0;
        scrollbar-width: none;
        height: var(--subnav-h);
    }
    .admin-nav::-webkit-scrollbar { display: none; }
    .admin-nav a { padding: 10px 14px; font-size: 12px; white-space: nowrap; }

    /* Layout */
    .container { padding: 0 10px; margin: 14px auto; }

    /* Cards: allow inner scroll; border-radius compensates on header */
    .card { overflow: visible; }
    .card-header { border-radius: var(--radius) var(--radius) 0 0; }
    .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Form: 2 columns on tablet */
    .form-grid { grid-template-columns: 1fr 1fr; gap: 10px 14px; }

    /* Palette: 4 columns */
    .palette-grid { grid-template-columns: repeat(4, 1fr); max-width: 100%; }

    /* Stats: 2 columns */
    .stats-grid { grid-template-columns: 1fr 1fr; }

    /* Action buttons: stacked full-width */
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; justify-content: center; }

    .photo-section { width: 100%; }
}

/* ── Mobile phone (≤ 480px) ── */
@media (max-width: 480px) {
    .page-header img.logo { height: 30px; }
    .page-header .title-block h1 { font-size: 12px; }
    .mode-toggle button { font-size: 12px; padding: 3px 5px; }
    .page-header a { font-size: 10px; }

    .container { padding: 0 8px; margin: 10px auto; }

    /* Single column */
    .form-grid  { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }

    /* Palette: 3 columns */
    .palette-grid { grid-template-columns: repeat(3, 1fr); }

    /* Smaller table cells */
    .data-table th, .data-table td { padding: 6px 8px; font-size: 12px; }
    .dep-table  th, .dep-table  td { padding: 4px 6px;  font-size: 12px; }

    /* Actions column: stack links */
    .data-table .actions { display: flex; flex-direction: column; gap: 4px; }
    .data-table .actions a { margin-right: 0; }

    /* Search form: stack vertically */
    .search-form-stack { flex-direction: column !important; }
    .search-form-stack > * { width: 100% !important; flex: none !important; }
}

/* ── Very small (≤ 360px — SE, Fold) ── */
@media (max-width: 360px) {
    .page-header img.logo { display: none; }
    .page-header .title-block h1 { font-size: 11px; }
}
