/* ============================================================
   Root variables
   ============================================================ */
:root {
    --bg:      #1a1a2e;
    --surface: #16213e;
    --primary: #0f3460;
    --accent:  #e94560;
    --text:    #e0e0e0;
    --muted:   #888;
    --green:   #2ecc71;
    --amber:   #f39c12;
    --radius:  12px;
    --font:    system-ui, -apple-system, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ============================================================
   Kiosk — shared layout
   ============================================================ */
.kiosk-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    min-height: 100vh;
}

.kiosk-wrap {
    width: 100%;
    max-width: 480px;
    padding: 1.5rem 1rem 2.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

/* ============================================================
   PIN screen — clock header
   ============================================================ */
.kiosk-header { width: 100%; }

.kiosk-time {
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1.1;
}

.kiosk-date {
    font-size: clamp(0.85rem, 3vw, 1rem);
    color: var(--muted);
    margin-top: 0.25rem;
}

/* ============================================================
   PIN screen — dots display
   ============================================================ */
.pin-box { width: 100%; }

.pin-label {
    font-size: 1.1rem;
    color: var(--muted);
    margin-bottom: 0.75rem;
    min-height: 1.5rem;
    transition: color 0.2s;
}

.pin-dots {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    min-height: 2.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.pin-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--primary);
    transition: background 0.1s, border-color 0.1s, transform 0.1s;
}

.pin-dot--filled {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.15);
}

.pin-error {
    color: var(--accent);
    font-size: 0.95rem;
    margin-top: 0.6rem;
    min-height: 1.3rem;
    font-weight: 500;
}

/* ============================================================
   Keypad (PIN screen)
   ============================================================ */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;
    width: 100%;
    max-width: 320px;
}

.keypad-btn {
    aspect-ratio: 1;
    min-height: 80px;
    background: var(--surface);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1.6rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s, transform 0.05s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.keypad-btn:active:not(:disabled) {
    background: var(--primary);
    transform: scale(0.95);
}
.keypad-btn:hover:not(:active):not(:disabled) {
    background: color-mix(in srgb, var(--primary) 60%, transparent);
}
.keypad-btn--blank {
    background: transparent;
    border-color: transparent;
    cursor: default;
    pointer-events: none;
}
.keypad-btn--go {
    background: var(--accent);
    border-color: var(--accent);
    font-size: 1.4rem;
}
.keypad-btn--go:active:not(:disabled) {
    background: color-mix(in srgb, var(--accent) 80%, black);
}
.keypad-btn--del { font-size: 1.3rem; }

/* ============================================================
   Spinner (used on Go button while submitting)
   ============================================================ */
.spinner, .spinner-sm {
    display: inline-block;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    animation: spin 0.7s linear infinite;
}
.spinner    { width: 32px; height: 32px; }
.spinner-sm { width: 20px; height: 20px; border-width: 2px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Timeout progress bar
   Inserted / removed by x-if so the CSS animation restarts fresh.
   ============================================================ */
.timeout-bar {
    position: fixed;
    top: 0; left: 0;
    height: 4px;
    width: 100%;
    background: var(--accent);
    transform-origin: left center;
    animation: drain linear forwards;
    z-index: 200;
    pointer-events: none;
}

@keyframes drain {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ============================================================
   Punch screen — done confirmation overlay
   ============================================================ */
.done-overlay {
    position: fixed;
    inset: 0;
    background: color-mix(in srgb, var(--bg) 96%, transparent);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 100;
}

.done-icon {
    font-size: 5rem;
    color: var(--green);
    line-height: 1;
    animation: pop 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes pop {
    from { transform: scale(0.5); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.done-msg  { font-size: clamp(1.8rem, 6vw, 2.5rem); font-weight: 700; }
.done-name { font-size: 1.1rem; color: var(--muted); }

/* ============================================================
   Punch screen — loading state
   ============================================================ */
.punch-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40vh;
}

/* ============================================================
   Punch screen — main layout
   ============================================================ */
.punch-main {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.punch-header { width: 100%; }

.punch-error {
    width: 100%;
    padding: .75rem 1rem;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 6px;
    font-size: .95rem;
    text-align: center;
}

.punch-name {
    font-size: clamp(1.4rem, 5vw, 2rem);
    font-weight: 700;
    line-height: 1.2;
}

.punch-status {
    font-size: 0.95rem;
    margin-top: 0.3rem;
    font-weight: 500;
}

.punch-status--in  { color: var(--green); }
.punch-status--out { color: var(--muted); }

/* ============================================================
   Punch screen — department selector
   ============================================================ */
.dept-section { width: 100%; text-align: left; }

.section-label {
    display: block;
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.label-hint { font-size: 0.8rem; text-transform: none; letter-spacing: 0; }

.dept-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.dept-btn {
    padding: 0.65rem 1rem;
    min-height: 56px;
    min-width: 130px;
    background: var(--surface);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s, border-color 0.1s;
    flex: 1;
    max-width: 200px;
}

.dept-btn:active:not(:disabled) { transform: scale(0.97); }
.dept-btn:hover:not(.dept-btn--active) {
    background: color-mix(in srgb, var(--primary) 50%, transparent);
}
.dept-btn--active {
    background: var(--primary);
    border-color: var(--accent);
    font-weight: 600;
}

/* ============================================================
   Punch screen — notes field
   ============================================================ */
.notes-section { width: 100%; text-align: left; }

.notes-input {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: var(--surface);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s;
}

.notes-input::placeholder { color: var(--muted); }
.notes-input:focus { border-color: var(--accent); }

/* ============================================================
   Punch screen — action buttons
   ============================================================ */
.action-section { width: 100%; }

.action-row {
    display: flex;
    gap: 0.65rem;
    width: 100%;
    justify-content: center;
}

.action-row--center { justify-content: center; }

.action-btn {
    flex: 1;
    min-height: 88px;
    max-width: 150px;
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.1s, transform 0.05s;
}

.action-btn:active:not(:disabled) { transform: scale(0.96); }
.action-btn:disabled { cursor: not-allowed; }

/* Color variants */
.action-btn--green   { background: var(--green); }
.action-btn--red     { background: var(--accent); }
.action-btn--amber   { background: var(--amber); }

/* Dimmed = visible but clearly inactive (Transfer when not clocked in) */
.action-btn--dimmed  {
    background: var(--surface);
    border: 2px solid var(--primary);
    color: var(--muted);
    opacity: 0.45;
}

/* Secondary = available but not the recommended action */
.action-btn--secondary {
    background: var(--surface);
    border: 2px solid var(--primary);
    color: var(--text);
    opacity: 0.75;
}
.action-btn--secondary:active:not(:disabled) { opacity: 1; }

/* Event-based submit button gets more width */
.action-btn--wide {
    flex: none;
    min-width: 200px;
    max-width: 280px;
}

.cancel-btn {
    margin-top: 0.25rem;
    background: none;
    border: 1px solid var(--muted);
    border-radius: var(--radius);
    color: var(--muted);
    padding: 0.5rem 1.75rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.cancel-btn:hover:not(:disabled) { border-color: var(--text); color: var(--text); }
.cancel-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   Admin — Login
   ============================================================ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    min-height: 100vh;
}

.login-box {
    background: var(--surface);
    padding: 2.5rem;
    border-radius: var(--radius);
    width: min(360px, 90vw);
}

.login-box h1 {
    text-align: center;
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-box label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.875rem;
    color: var(--muted);
}

.login-box input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--primary);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s;
}

.login-box input:focus { border-color: var(--accent); }

.login-box button[type="submit"] {
    margin-top: 0.5rem;
    padding: 0.7rem;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.login-box button[type="submit"]:hover { opacity: 0.9; }

.error {
    color: var(--accent);
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    text-align: center;
}

/* ============================================================
   Admin — Shell layout
   ============================================================ */
.admin-page {
    background: #f4f6f8;
    color: #1a1a2e;
    min-height: 100vh;
}

.admin-nav {
    background: var(--primary);
    color: white;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    height: 54px;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-wrap: wrap;
}

.admin-nav a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.2rem 0;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.admin-nav a:hover,
.admin-nav a.nav-active { color: white; border-bottom-color: var(--accent); }

.nav-brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: white !important;
    border-bottom: none !important;
    margin-right: 0.5rem;
}

.btn-link {
    background: none;
    border: none;
    color: rgba(255,255,255,0.75);
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0;
    white-space: nowrap;
}

.btn-link:hover { color: white; }

.admin-main {
    padding: 2rem 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.admin-main h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: #1a1a2e;
}

/* Dashboard quick-access cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.dash-card {
    display: block;
    background: white;
    border: 1px solid #dde;
    border-radius: var(--radius);
    padding: 1.5rem;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s, transform 0.1s;
}

.dash-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.dash-card__title {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--primary);
    margin-bottom: 0.4rem;
}

.dash-card__desc { font-size: 0.875rem; color: var(--muted); }

/* ============================================================
   Admin — Timecards
   ============================================================ */

/* Toolbar: title + period nav */
.tc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.tc-toolbar h1 { margin-bottom: 0; }

.tc-period-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-period {
    display: inline-block;
    padding: 0.3rem 0.75rem;
    background: var(--primary);
    color: white;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.875rem;
    white-space: nowrap;
    transition: opacity 0.15s;
}
.btn-period:hover { opacity: 0.85; }

.period-label {
    font-weight: 600;
    font-size: 1rem;
    color: #1a1a2e;
    white-space: nowrap;
}
.period-relative-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

/* Needs Attention panel */
.tc-anomalies {
    background: #fff8e1;
    border: 1px solid #f39c12;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
}
.anomalies-title {
    font-weight: 700;
    color: #b7770d;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}
.anomaly-row {
    font-size: 0.875rem;
    padding: 0.15rem 0;
    color: #5a3e00;
}
.anomaly-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.anomaly-link:hover { opacity: 0.75; }

/* Cards container */
.tc-cards { display: flex; flex-direction: column; gap: 1.5rem; }
.tc-empty { color: var(--muted); font-style: italic; margin-top: 1rem; }

/* Employee card */
.emp-card {
    background: white;
    border: 1px solid #dde;
    border-radius: var(--radius);
    overflow: hidden;
}

.emp-card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.7rem 1rem;
    background: #f0f4f8;
    border-bottom: 1px solid #dde;
    flex-wrap: wrap;
}

.emp-name {
    font-weight: 700;
    font-size: 1rem;
    color: #1a1a2e;
    flex: 1;
    min-width: 160px;
}

.emp-totals {
    font-size: 0.875rem;
    color: #444;
    white-space: nowrap;
}

.ot-value { color: #c0392b; font-weight: 600; }

.emp-anomalies {
    padding: 0.4rem 1rem;
    background: #fff8e1;
    border-bottom: 1px solid #f39c12;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.anomaly-badge {
    font-size: 0.8rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    background: #f39c12;
    color: white;
    font-weight: 600;
}
.anomaly-badge.anomaly--open_shift { background: #e74c3c; }
.anomaly-badge.anomaly--consecutive_in { background: #8e44ad; }
.anomaly-badge.anomaly--orphan_out { background: #e67e22; }

/* Punch table */
.tc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.tc-table th {
    padding: 0.4rem 0.6rem;
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #666;
    background: #f8f9fa;
    border-bottom: 1px solid #dde;
    white-space: nowrap;
}

.tc-table td {
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid #eef;
    vertical-align: middle;
    white-space: nowrap;
}

.tc-table tr:last-child td { border-bottom: none; }

.day-header td {
    background: #e8ecf0;
    font-weight: 700;
    font-size: 0.8rem;
    color: #333;
    padding: 0.25rem 0.6rem;
    letter-spacing: 0.03em;
}
.day-total { font-weight: 600; font-size: 0.78rem; }

.row--deleted td { opacity: 0.45; text-decoration: line-through; }
.row--anomaly td:first-child { border-left: 3px solid #e74c3c; }
.row--phantom td {
    background: #fdf9f0;
    border-bottom: 1px dashed #e0d8c8;
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
}

.btn-suggest {
    background: transparent;
    border: 1px dashed #bbb;
    color: #999;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.1s, color 0.1s, background 0.1s;
}
.btn-suggest:hover {
    border-color: #3498db;
    color: #2980b9;
    background: #eaf4fd;
}

.text-muted { color: #aaa; }
.text-open { color: #e74c3c; font-weight: 600; font-size: 0.8rem; }
.edited-mark { color: #3498db; font-size: 0.7rem; vertical-align: super; }
.admin-added-mark { color: #27ae60; font-size: 0.7rem; vertical-align: super; font-weight: 700; }

.dir-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.dir-in  { background: #d5f5e3; color: #1a6b3c; }
.dir-out { background: #fde8e8; color: #922b21; }
.dir-evt { background: #e8eaf6; color: #283593; }

.col-notes { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.col-actions { width: 1px; } /* shrink-wrap */

/* Action buttons */
.punch-actions {
    white-space: nowrap;
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: wrap;
}

.btn-sm {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    border: none;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.1s;
}
.btn-sm:hover { opacity: 0.8; }
.btn-sm:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-edit    { background: #3498db; color: white; }
.btn-delete  { background: #e74c3c; color: white; }
.btn-restore { background: #27ae60; color: white; }
.btn-save    { background: #27ae60; color: white; }
.btn-cancel  { background: #95a5a6; color: white; }
.btn-add     { background: var(--primary); color: white; margin-left: auto; }

/* Inline edit / add forms */
.add-area { padding: 0 0 0.25rem; }

/* Inline edit row inside the punch table */
.row--editing > td {
    padding: 0.4rem 0.6rem;
    background: #eaf4ff;
    border-top: 2px solid #a8d1f0;
    border-bottom: 2px solid #a8d1f0;
}

.inline-edit-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.inline-edit-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #666;
    white-space: nowrap;
}

/* Stacked label+input for add form */
.inline-edit-row--add { align-items: flex-end; }
.inline-edit-field { display: flex; flex-direction: column; gap: 0.15rem; }
.inline-edit-field--notes { flex: 2; min-width: 120px; }
.inline-edit-field--actions .form-actions { margin-top: 0; }

/* Compact inputs for inline edit */
.input-date { width: 56px; }
.input-time { width: 62px; }
.input-dept { min-width: 110px; max-width: 180px; }
.input-dir  { width: 58px; }
.input-type { width: 96px; }
.input-dur  { width: 58px; }
.input-notes { flex: 2; min-width: 100px; }

.inline-form {
    background: #f0f8ff;
    border: 1px solid #b8d9f0;
    border-radius: 8px;
    padding: 0.9rem 1rem;
    margin-top: 0.5rem;
}

.inline-form-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: #1a5276;
    margin-bottom: 0.75rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.5rem 1rem;
}

.form-row { display: flex; flex-direction: column; gap: 0.2rem; }
.form-row--full { grid-column: 1 / -1; }

.form-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #555;
}

.form-input {
    padding: 0.35rem 0.5rem;
    border: 1px solid #c0cfe0;
    border-radius: 5px;
    font-size: 0.875rem;
    background: white;
    color: #1a1a2e;
    outline: none;
    transition: border-color 0.15s;
}
.form-input:focus { border-color: #3498db; }
.form-input--short { max-width: 100px; }
.form-input--muted { opacity: 0.45; background: #f5f5f5; }

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.emp-no-punches {
    padding: 0.75rem 1rem;
    color: #aaa;
    font-style: italic;
    font-size: 0.875rem;
}

/* ============================================================
   Admin — IIF Export
   ============================================================ */

.iif-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.btn-download {
    display: inline-block;
    padding: 0.55rem 1.4rem;
    background: #27ae60;
    color: white;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    transition: opacity 0.15s;
}
.btn-download:hover { opacity: 0.85; }

.iif-hint {
    font-size: 0.875rem;
    color: #666;
    font-style: italic;
}

.iif-warning {
    background: #fff3cd;
    border: 1px solid #f39c12;
    border-radius: 6px;
    padding: 0.6rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: #7a5800;
}
.iif-warning a { color: #7a5800; font-weight: 600; }

.iif-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid #dde;
    margin-bottom: 1.5rem;
}

.iif-table th {
    padding: 0.5rem 0.75rem;
    background: #f0f4f8;
    border-bottom: 1px solid #dde;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #555;
}

.iif-table td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid #eef;
    color: #222;
}

.iif-table tbody tr:last-child td { border-bottom: none; }

.iif-table tfoot td {
    border-top: 2px solid #dde;
    font-weight: 700;
    background: #f8f9fa;
}

.num-col { text-align: right; font-variant-numeric: tabular-nums; }

.iif-row--warn td { background: #fffbf0; }
.excluded-warn { color: #c0392b; font-weight: 600; }
.iif-emp-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.iif-emp-link:hover { opacity: 0.75; }

.iif-total-row td { padding: 0.45rem 0.75rem; }

.iif-legend {
    background: #f8f9fa;
    border: 1px solid #dde;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    font-size: 0.82rem;
    color: #555;
    line-height: 1.6;
}

.iif-legend p { margin-bottom: 0.3rem; }
.iif-legend p:last-child { margin-bottom: 0; }

/* ============================================================
   Admin — Generic table + form styles
   ============================================================ */

.page-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-toolbar h1 { margin-bottom: 0; }

/* Generic admin table */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid #dde;
    margin-bottom: 1.5rem;
}
.admin-table th {
    padding: 0.5rem 0.75rem;
    background: #f0f4f8;
    border-bottom: 1px solid #dde;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #555;
    text-align: left;
    white-space: nowrap;
}
.admin-table td {
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid #eef;
    color: #222;
    vertical-align: middle;
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table--muted tbody tr td { color: #888; }

.row--inactive { opacity: 0.65; }
.center-col { text-align: center; }
.mono { font-family: monospace; font-size: 0.9rem; }
.action-cell { white-space: nowrap; text-align: right; }
.section-title { font-size: 1rem; font-weight: 600; color: #555; margin: 1.5rem 0 0.75rem; }
.admin-empty { color: #888; font-style: italic; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge--green { background: #d4edda; color: #155724; }
.badge--muted { background: #e9ecef; color: #6c757d; }

/* Department type badge */
.dept-type-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.dept-type--time_based  { background: #cce5ff; color: #004085; }
.dept-type--event_based { background: #d4edda; color: #155724; }

/* Buttons */
.btn-primary {
    display: inline-block;
    padding: 0.45rem 1.1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
    display: inline-block;
    padding: 0.45rem 1.1rem;
    background: #e9ecef;
    color: #333;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}
.btn-secondary:hover { background: #dee2e6; }

.btn-warning { background: #e67e22; color: white; }
.btn-warning:hover { opacity: 0.85; }

/* Admin form layout */
.admin-form {
    max-width: 800px;
}

.form-section {
    border: 1px solid #dde;
    border-radius: var(--radius);
    padding: 1.25rem 1.25rem 0.75rem;
    margin-bottom: 1.25rem;
    background: white;
}

.form-section legend {
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #555;
    padding: 0 0.4rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem 1.25rem;
    margin-bottom: 0.75rem;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.form-field--short { max-width: 200px; }

.form-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #444;
    display: block;
    white-space: nowrap;
}

.form-field input[type="text"],
.form-field input[type="number"],
.form-field select {
    padding: 0.4rem 0.6rem;
    border: 1px solid #c0cfe0;
    border-radius: 5px;
    font-size: 0.9rem;
    color: #1a1a2e;
    background: white;
    outline: none;
    transition: border-color 0.15s;
}
.form-field input:focus,
.form-field select:focus { border-color: var(--primary); }

.req { color: #e74c3c; }

.field-hint {
    display: block;
    font-size: 0.72rem;
    font-weight: 400;
    color: #888;
    text-transform: none;
    letter-spacing: 0;
    white-space: normal;
}

/* Checkbox grids */
.checkbox-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    padding-bottom: 0.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.875rem;
    color: #333;
    cursor: pointer;
}
.checkbox-label input[type="checkbox"] { cursor: pointer; }

/* Error banner */
.form-error-banner {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    padding: 0.65rem 1rem;
    margin-bottom: 1rem;
    color: #721c24;
    font-size: 0.875rem;
    max-width: 800px;
}

/* Submit row */
.form-submit-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-bottom: 2rem;
}

/* ============================================================
   Settings page
   ============================================================ */

.settings-saved {
    background: #d1fae5;
    border: 1px solid #6ee7b7;
    color: #065f46;
    border-radius: 6px;
    padding: 0.6rem 1rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.settings-hints {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: #555;
}

.settings-hints p {
    margin: 0.25rem 0;
}

.settings-desc {
    font-size: 0.9rem;
    color: #444;
    margin-bottom: 0.75rem;
}

.api-key-display {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #f4f4f5;
    border: 1px solid #d4d4d8;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    word-break: break-all;
}

.api-key-display code {
    flex: 1;
    font-family: monospace;
    color: #1e293b;
}

.api-key-hint {
    font-size: 0.82rem;
    color: #666;
    margin-top: 0.5rem;
}

.api-key-hint code {
    background: #f1f5f9;
    padding: 0 3px;
    border-radius: 3px;
    font-size: 0.8rem;
}

/* ============================================================
   Dashboard
   ============================================================ */

/* Stats bar */
.dash-stats {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.dash-stat {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.9rem 1.4rem;
    min-width: 110px;
    text-align: center;
}

.dash-stat--active {
    background: #ecfdf5;
    border-color: #6ee7b7;
}

.dash-stat--warn {
    background: #fffbeb;
    border-color: #fcd34d;
}

.dash-stat__num {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    color: #1e293b;
}

.dash-stat__label {
    display: block;
    font-size: 0.78rem;
    color: #64748b;
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Sections */
.dash-section {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}

.dash-section--warn {
    border-color: #fcd34d;
    background: #fffdf0;
}

.dash-section__title {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 0.9rem 0;
}

.dash-section__sub {
    font-size: 0.8rem;
    font-weight: 400;
    color: #94a3b8;
}

.dash-section__desc {
    font-size: 0.875rem;
    color: #64748b;
    margin: -0.4rem 0 0.9rem 0;
}

.dash-empty {
    color: #94a3b8;
    font-size: 0.9rem;
    margin: 0;
}

.dash-warn-text {
    color: #b45309;
    font-weight: 600;
}

/* Sync stats mini-tiles */
.sync-stats {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.25rem;
}

.sync-stat {
    background: #f1f5f9;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    text-align: center;
    min-width: 80px;
}

.sync-stat--ok  { background: #ecfdf5; }
.sync-stat--warn { background: #fffbeb; }
.sync-stat--err  { background: #fef2f2; }

.sync-stat__num {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    color: #1e293b;
}

.sync-stat__label {
    display: block;
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.2rem;
}

/* Badge variants for sync statuses */
.badge--applied    { background: #d1fae5; color: #065f46; }
.badge--conflicted { background: #fef3c7; color: #92400e; }
.badge--rejected   { background: #fee2e2; color: #991b1b; }
.badge--pending    { background: #e9ecef; color: #6c757d; }
.badge--root       { background: #ede9fe; color: #5b21b6; }

/* Field hints */
.field-hint        { font-size: 0.8rem; color: #64748b; margin: 0.25rem 0 0; }
.field-hint-inline { font-size: 0.8rem; color: #94a3b8; font-weight: 400; }

/* ============================================================
   Audit Log
   ============================================================ */

.audit-filters {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

.audit-filter-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.audit-filter-row .form-field {
    margin: 0;
}

.form-field--btn {
    align-self: flex-end;
}

.audit-limit-note {
    font-size: 0.85rem;
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    padding: 0.5rem 0.875rem;
    margin-bottom: 0.75rem;
}

.audit-table .audit-when {
    white-space: nowrap;
    font-size: 0.85rem;
}

.audit-date {
    color: #94a3b8;
    font-size: 0.78rem;
}

.audit-row--undone td {
    opacity: 0.55;
}

.audit-detail {
    font-size: 0.875rem;
}

.audit-field {
    font-weight: 600;
    color: #1e293b;
    margin-right: 0.35rem;
}

.audit-old {
    color: #dc2626;
    text-decoration: line-through;
    margin-right: 0.25rem;
}

.audit-arrow {
    color: #94a3b8;
    margin-right: 0.25rem;
}

.audit-new {
    color: #16a34a;
    font-weight: 600;
}

/* Action badge colours */
.audit-badge--edit    { background: #eff6ff; color: #1d4ed8; }
.audit-badge--delete  { background: #fee2e2; color: #991b1b; }
.audit-badge--add     { background: #d1fae5; color: #065f46; }
.audit-badge--restore { background: #ede9fe; color: #5b21b6; }

.audit-empty {
    text-align: center;
    color: #94a3b8;
    padding: 3rem 0;
    font-size: 0.9rem;
}
