/* ==========================================================================
   StaffRegistry — design tokens
   Palette: navy ink + paper background + brass accent, evoking an official
   document registry (fitting for a system built around IDs, passports,
   permits). Serif (Fraunces) for headings, Inter for UI/body, IBM Plex Mono
   for ID numbers and dates — those are literal codes, not decoration.
   ========================================================================== */
:root {
    --paper: #FAF8F3;
    --paper-raised: #FFFFFF;
    --ink: #1C2321;
    --ink-soft: #5B6460;
    --navy: #1D3557;
    --navy-dark: #14263F;
    --navy-tint: #E9EEF3;
    --brass: #A9834B;
    --brass-dark: #8C6B39;
    --brass-tint: #F3EBDA;
    --sage: #3E7A55;
    --sage-tint: #E6F0E9;
    --amber: #B4711F;
    --amber-tint: #FBEEDB;
    --rust: #AA3A2A;
    --rust-tint: #FBE7E3;
    --line: #E3DDD0;
    --line-strong: #CFC7B6;
    --shadow: 0 1px 2px rgba(28, 35, 33, 0.06), 0 4px 16px rgba(28, 35, 33, 0.05);
    --radius: 8px;
    --radius-sm: 5px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

h1, h2, h3, .brand-name {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 600;
    color: var(--navy);
    margin: 0;
}

a { color: var(--navy); text-decoration: none; }
a:hover { color: var(--brass-dark); }

.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- Layout shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--navy);
    color: #EAF0F5;
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 7px;
    background: var(--brass);
    color: var(--navy-dark);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Fraunces', serif; font-weight: 700; font-size: 14px;
}
.brand-name { color: #fff; font-size: 17px; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #C6D3DE;
    font-size: 14px; font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--brass); color: var(--navy-dark); font-weight: 600; }
.nav-link .icon { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.12); padding-top: 16px; margin-top: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brass-tint); color: var(--navy-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-family: 'Fraunces', serif; flex-shrink: 0;
}
.user-chip-name { font-size: 13.5px; font-weight: 600; color: #fff; }
.user-chip-role { font-size: 12px; color: #A9BACA; }
.text-link { display: block; font-size: 13px; color: #A9BACA; padding: 4px 0; }
.text-link:hover { color: #fff; }
.text-link.logout { color: #E3B3A8; }
.text-link.logout:hover { color: #fff; }

.main { flex: 1; min-width: 0; }
.topbar {
    padding: 24px 40px;
    border-bottom: 1px solid var(--line);
    background: var(--paper-raised);
}
.topbar h1 { font-size: 24px; }
.content { padding: 32px 40px 60px; }

/* ---------- Auth (login) screen ---------- */
.auth-shell { background: var(--navy); }
.auth-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.auth-card {
    background: var(--paper-raised);
    width: 100%; max-width: 380px;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    padding: 40px 36px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.auth-brand .brand-mark { background: var(--brass); }
.auth-brand span.title { font-family: 'Fraunces', serif; font-size: 19px; font-weight: 600; color: var(--navy); }
.auth-card h2 { font-size: 20px; margin-bottom: 4px; }
.auth-sub { color: var(--ink-soft); font-size: 13.5px; margin-bottom: 24px; }
.auth-hint {
    margin-top: 20px; padding: 12px 14px;
    background: var(--brass-tint); border-radius: var(--radius-sm);
    font-size: 12.5px; color: var(--brass-dark); line-height: 1.6;
}

/* ---------- Forms ---------- */
.field { margin-bottom: 18px; }
.field label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--navy); margin-bottom: 6px;
}
.field .hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
input[type=text], input[type=password], input[type=date], input[type=tel],
input[type=email], input[type=search], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--paper-raised);
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--navy);
    box-shadow: 0 0 0 3px var(--navy-tint);
}
input[type=file] {
    width: 100%;
    padding: 9px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--paper);
    font-size: 13px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.form-grid .field.full { grid-column: 1 / -1; }
.form-section {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px 28px;
    margin-bottom: 20px;
}
.form-section h3 {
    font-size: 15px; padding-bottom: 12px; margin-bottom: 18px;
    border-bottom: 1px solid var(--line);
}
.radio-row { display: flex; gap: 18px; margin-bottom: 6px; }
.radio-option { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); color: #fff; }
.btn-brass { background: var(--brass); color: var(--navy-dark); }
.btn-brass:hover { background: var(--brass-dark); color: #fff; }
.btn-outline { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-outline:hover { border-color: var(--navy); color: var(--navy); }
.btn-danger { background: transparent; border-color: var(--rust); color: var(--rust); }
.btn-danger:hover { background: var(--rust); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.alert-success { background: var(--sage-tint); color: #245536; border-color: #BFDCC9; }
.alert-error { background: var(--rust-tint); color: #7A2A1E; border-color: #EFC1B7; }
.alert-info { background: var(--navy-tint); color: var(--navy-dark); border-color: #C9D8E5; }

/* ---------- Pills / badges ---------- */
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11.5px; font-weight: 600;
}
.pill-ok { background: var(--sage-tint); color: #245536; }
.pill-warning { background: var(--amber-tint); color: var(--amber); }
.pill-danger { background: var(--rust-tint); color: var(--rust); }
.pill-neutral { background: var(--navy-tint); color: var(--navy); }
.role-pill-super_admin { background: var(--brass-tint); color: var(--brass-dark); }
.role-pill-admin { background: var(--navy-tint); color: var(--navy); }
.role-pill-user { background: #EEECE6; color: var(--ink-soft); }

/* ---------- Dashboard stat row ---------- */
.stat-row {
    display: flex;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper-raised);
    margin-bottom: 28px;
    overflow: hidden;
}
.stat {
    flex: 1;
    padding: 20px 26px;
    border-right: 1px solid var(--line);
}
.stat:last-child { border-right: none; }
.stat .num { font-family: 'Fraunces', serif; font-size: 30px; font-weight: 600; color: var(--navy); line-height: 1; }
.stat .label { font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; }
.stat.warn .num { color: var(--amber); }
.stat.danger .num { color: var(--rust); }

.section-title {
    font-size: 13px; font-weight: 700; color: var(--navy);
    text-transform: uppercase; letter-spacing: 0.04em;
    margin: 32px 0 12px;
}
.section-title:first-child { margin-top: 0; }

/* ---------- Ledger table ---------- */
.table-wrap {
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    font-size: 11.5px; font-weight: 700; color: var(--ink-soft);
    text-transform: uppercase; letter-spacing: 0.03em;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
}
tbody td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    font-size: 13.5px;
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--paper); }
.row-name { font-weight: 600; color: var(--ink); }
.row-sub { font-size: 12px; color: var(--ink-soft); }
.cell-actions { display: flex; gap: 8px; justify-content: flex-end; }
.thumb {
    width: 38px; height: 38px; border-radius: 50%;
    object-fit: cover; border: 1px solid var(--line);
    background: var(--navy-tint);
}
.thumb-placeholder {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--navy-tint); color: var(--navy);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Fraunces', serif; font-weight: 600; font-size: 14px;
}
.empty-state {
    text-align: center; padding: 60px 20px; color: var(--ink-soft);
}
.empty-state h3 { color: var(--ink-soft); margin-bottom: 8px; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar-search { display: flex; gap: 10px; flex: 1; max-width: 420px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-chip {
    padding: 6px 13px; border-radius: 100px; border: 1px solid var(--line-strong);
    font-size: 12.5px; font-weight: 500; color: var(--ink-soft); background: var(--paper-raised);
}
.filter-chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }

/* ---------- Staff detail view ---------- */
.profile-header { display: flex; gap: 20px; align-items: center; margin-bottom: 24px; }
.profile-photo {
    width: 88px; height: 88px; border-radius: 50%; object-fit: cover;
    border: 3px solid var(--paper-raised); box-shadow: var(--shadow);
}
.profile-photo-placeholder {
    width: 88px; height: 88px; border-radius: 50%;
    background: var(--navy-tint); color: var(--navy);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Fraunces', serif; font-weight: 600; font-size: 30px;
    border: 3px solid var(--paper-raised); box-shadow: var(--shadow);
}
.profile-header h2 { font-size: 22px; }
.profile-header .row-sub { font-size: 13px; margin-top: 4px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 32px; }
.detail-item .k { font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 3px; }
.detail-item .v { font-size: 14.5px; color: var(--ink); font-weight: 500; }
.doc-card {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    margin-bottom: 10px;
}
.doc-card .doc-name { font-weight: 600; font-size: 13.5px; }
.doc-card .doc-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* ---------- Misc ---------- */
.page-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; }
.back-link:hover { color: var(--navy); }
.card-actions { display: flex; gap: 10px; margin-top: 24px; }
.helper-note { background: var(--navy-tint); color: var(--navy-dark); padding: 12px 16px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 20px; }

/* ---------- Document viewer modal ---------- */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(20, 38, 63, 0.55);
    z-index: 1000;
    align-items: center; justify-content: center;
    padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal-box {
    position: relative;
    background: var(--paper-raised);
    border-radius: var(--radius);
    width: 100%; max-width: 780px;
    max-height: 88vh;
    display: flex; flex-direction: column;
    box-shadow: 0 24px 70px rgba(0,0,0,0.4);
    overflow: hidden;
}
.modal-title {
    padding: 16px 52px 14px 22px;
    font-family: 'Fraunces', serif; font-weight: 600; font-size: 16px;
    color: var(--navy);
    border-bottom: 1px solid var(--line);
}
.modal-close {
    position: absolute; top: 12px; right: 12px;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    background: var(--paper); border: 1px solid var(--line-strong);
    border-radius: 50%;
    color: var(--ink);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    z-index: 1;
}
.modal-close:hover { background: var(--rust); border-color: var(--rust); color: #fff; }
.modal-close svg { fill: currentColor; }
.modal-body {
    flex: 1;
    overflow: auto;
    background: var(--paper);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-img { max-width: 100%; max-height: 74vh; border-radius: 4px; box-shadow: var(--shadow); }
.modal-iframe { width: 100%; height: 74vh; border: none; background: #fff; border-radius: 4px; }

/* ---------- Staff card grid ---------- */
.staff-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.staff-card {
    position: relative;
    background: var(--paper-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.staff-card:hover { box-shadow: var(--shadow); border-color: var(--line-strong); }
.card-stretched-link { position: absolute; inset: 0; z-index: 1; border-radius: inherit; }
.staff-card-top { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; padding-right: 74px; }
.staff-card-photo, .staff-card-photo-placeholder { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.staff-card-photo-placeholder { background: var(--navy-tint); color: var(--navy); display: flex; align-items: center; justify-content: center; font-family: 'Fraunces', serif; font-weight: 600; font-size: 16px; }
.staff-card-name { font-weight: 600; font-size: 14.5px; color: var(--ink); line-height: 1.35; }
.staff-card-id { font-size: 12px; color: var(--ink-soft); margin-top: 3px; display: flex; align-items: center; gap: 5px; }
.staff-card-id .icon-sm { width: 12px; height: 12px; fill: currentColor; flex-shrink: 0; }
.staff-card-badge { position: absolute; top: 18px; right: 20px; z-index: 2; }
.staff-card-expiry-row { display: flex; gap: 10px; margin-bottom: 14px; }
.expiry-block { flex: 1; min-width: 0; background: var(--paper); border-radius: var(--radius-sm); padding: 8px 10px; }
.expiry-block .eb-label { font-size: 11px; color: var(--ink-soft); display: flex; align-items: center; gap: 4px; margin-bottom: 3px; }
.expiry-block .eb-label .icon-sm { width: 11px; height: 11px; fill: currentColor; flex-shrink: 0; }
.expiry-block .eb-date { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.expiry-block .eb-days { font-size: 11px; font-weight: 600; margin-left: 4px; }
.eb-days.left { color: var(--sage); }
.eb-days.ago { color: var(--rust); }
.staff-card-docs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; position: relative; z-index: 2; }
.doc-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px 7px 7px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper-raised);
    text-decoration: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.doc-btn:hover { border-color: var(--line-strong); background: var(--paper); }
.doc-btn-icon {
    width: 30px; height: 30px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.doc-btn-icon svg { width: 15px; height: 15px; fill: currentColor; }
.doc-btn-label { font-size: 12.5px; font-weight: 600; color: var(--ink); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-btn-download { width: 14px; height: 14px; fill: var(--ink-soft); flex-shrink: 0; }
.doc-tint-navy { background: var(--navy-tint); color: var(--navy); }
.doc-tint-rust { background: var(--rust-tint); color: var(--rust); }
.doc-tint-sage { background: var(--sage-tint); color: var(--sage); }
.doc-tint-brass { background: var(--brass-tint); color: var(--brass-dark); }
.staff-card-footer {
    border-top: 1px solid var(--line); padding-top: 10px;
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--ink-soft);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.staff-card-footer .icon-sm { width: 12px; height: 12px; fill: currentColor; flex-shrink: 0; }

@media (max-width: 900px) {
    .shell { flex-direction: column; }
    .sidebar { position: relative; width: 100%; height: auto; }
    .content, .topbar { padding-left: 20px; padding-right: 20px; }
    .form-grid, .detail-grid { grid-template-columns: 1fr; }
    .staff-grid { grid-template-columns: 1fr; }
    .stat-row { flex-wrap: wrap; }
    .stat { flex: 1 1 50%; border-bottom: 1px solid var(--line); }
}

@media (min-width: 901px) and (max-width: 1300px) {
    .staff-grid { grid-template-columns: repeat(2, 1fr); }
}
