/* Base */
:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #1f2933;
    --muted: #6b7785;
    --border: #d8dee4;
    --primary: #1d5fbf;
    --primary-dark: #174c99;
    --danger: #c0392b;
    --success-bg: #e6f4ea;
    --success-text: #1e6b34;
    --error-bg: #fdecea;
    --error-text: #9b2c20;
    --warning-bg: #fff6e0;
    --warning-text: #7a5a00;
    --deleted-bg: #eceff2;
    --faulty-bg: #fde3e0;
    --faulty-hover-bg: #fbd5d1;
    --radius: 6px;
}

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

html { font-size: 15px; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; padding-top: 20px; padding-bottom: 32px; }

.container { width: 100%; max-width: 1400px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }

a { color: var(--primary); }

.muted, .link-muted { color: var(--muted); }
.hint { display: block; color: var(--muted); font-size: .85rem; margin-top: 2px; }

/* Header */
.topbar { background: #1f2d3d; color: #fff; }
.topbar-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; padding-top: 10px; padding-bottom: 10px; }
.brand { color: #fff; font-weight: 600; text-decoration: none; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; flex: 1; }
.nav > a, .dropdown > summary { color: #d6e0ea; text-decoration: none; padding: 6px 10px; border-radius: var(--radius); }
.nav > a:hover, .nav > a.active, .dropdown > summary:hover, .dropdown > summary.active, .dropdown[open] > summary {
    background: rgba(255, 255, 255, .12); color: #fff;
}

/* Menu groups and the user menu: <details>, so they open without JavaScript too. */
.dropdown { position: relative; }
.dropdown > summary { display: block; cursor: pointer; list-style: none; user-select: none; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown > summary::after { content: ""; display: inline-block; margin-left: 6px; vertical-align: 3px;
    border: 4px solid transparent; border-top-color: currentColor; border-bottom-width: 0; }
.dropdown-menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; min-width: 220px; padding: 6px 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(0, 0, 0, .15); }
.dropdown-menu-right { left: auto; right: 0; }
.dropdown-menu a, .dropdown-menu button { display: block; width: 100%; padding: 8px 14px; color: var(--text); text-decoration: none;
    text-align: left; font: inherit; background: none; border: 0; cursor: pointer; white-space: nowrap; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: #eef2f6; }
.dropdown-menu a.active { font-weight: 600; color: var(--primary); }
.dropdown-menu form { margin: 0; border-top: 1px solid var(--border); }
.dropdown-note { display: block; padding: 4px 14px 8px; color: var(--muted); font-size: .85rem; }
.user-menu { font-size: .9rem; }
.user-role { color: #b8c4d0; }

.footer { color: var(--muted); font-size: .85rem; padding: 16px 0; border-top: 1px solid var(--border); background: var(--surface); }

/* Alerts */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: #b7dfc3; }
.alert-error { background: var(--error-bg); color: var(--error-text); border-color: #f3c2bc; }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border-color: #f0dc9f; }

/* Buttons */
.btn {
    display: inline-block; padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text); font: inherit; text-decoration: none; cursor: pointer; line-height: 1.2;
}
.btn:hover { background: #eef1f4; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-small { padding: 4px 10px; font-size: .85rem; }
.btn-block { display: block; width: 100%; }
.topbar .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .35); }

form.inline { display: inline; }

/* Forms */
.form label { display: block; font-weight: 500; margin: 12px 0 4px; }
.form input[type=text], .form input[type=tel], .form input[type=password], .form input[type=number],
.form input[type=datetime-local], .form input[type=date], .form select, .filters input:not([type=checkbox]), .filters select {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
    font: inherit; background: #fff; color: var(--text);
}
.form input:focus, .form select:focus, .filters input:focus, .filters select:focus { outline: 2px solid #9cc2f5; border-color: var(--primary); }
.form input[readonly] { background: #f0f2f4; }
.form-narrow { max-width: 460px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 24px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.field-error { color: var(--error-text); font-size: .85rem; margin-top: 4px; }
/* A field with a button beside it (car form: driver + "new driver"); wraps on a phone. */
.input-row { display: flex; flex-wrap: wrap; gap: 8px; }
.form .input-row select { flex: 1 1 200px; width: auto; min-width: 0; }
.input-row .btn { white-space: nowrap; }
/* Modal dialog (<dialog>, opened by app.js). */
.dialog { width: min(420px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text); box-shadow: 0 12px 32px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(15, 23, 32, .45); }
.dialog h2 { margin: 0 0 8px; font-size: 1.15rem; }
.dialog .alert { margin: 8px 0 0; }
/* Searchable select: a text filter and a listbox over a visually hidden native <select>. */
.combobox { position: relative; }
.combobox-native {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip-path: inset(50%); border: 0;
}
.combobox-list {
    position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin: 2px 0 0; padding: 4px 0;
    max-height: 240px; overflow-y: auto; list-style: none;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 6px 16px rgba(31, 41, 51, .18);
}
.combobox-option { padding: 7px 10px; cursor: pointer; }
.combobox-option.is-active { background: #eaf1fc; }
.combobox-option[aria-selected=true] { font-weight: 600; }
.combobox-empty { padding: 7px 10px; color: var(--muted); }


.autofill-window { margin-bottom: 16px; }
.autofill-window label:first-child { margin-top: 0; }

.radio-group { display: flex; gap: 16px; padding: 6px 0; }
.radio-group label, .checkbox { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; margin: 0; cursor: pointer; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }

/* Login */
.auth-card { max-width: 380px; margin: 40px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.auth-card h1 { font-size: 1.15rem; text-align: center; }
.auth-card h2 { font-size: 1rem; text-align: center; color: var(--muted); font-weight: normal; }
.auth-divider { text-align: center; color: var(--muted); font-size: .85rem; margin: 18px 0 0; }
.btn-telegram { background: #2aabee; border-color: #2aabee; color: #fff; text-align: center; margin-top: 16px; }
.btn-telegram:hover { background: #229ed9; color: #fff; }
.icon { width: 1.1em; height: 1.1em; vertical-align: -.2em; margin-right: 6px; }
.auth-card .btn-block { margin-top: 20px; }

/* Page header with actions */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 16px; }
.filters .field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; flex: 1 1 150px; max-width: 260px; }
.filters .field label { font-size: .85rem; color: var(--muted); }
.filters .actions { display: flex; gap: 8px; align-items: center; }
/* As tall as the inputs, so the checkbox and its text line up with them. */
.filters .checkbox { min-height: 38px; white-space: nowrap; }
/* The text search gets more room than a select. */
.filters .field.field-wide { flex: 2 1 240px; max-width: 360px; }

/* Tables: horizontal scroll on small screens */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #eef1f4; font-weight: 600; font-size: .85rem; white-space: nowrap; }
tbody tr:hover { background: #f8fafc; }
/* Sortable headers: the whole label is the link; ▲/▼ marks the current order. */
.sort-link { color: inherit; text-decoration: none; display: inline-flex; align-items: baseline; gap: 4px; }
.sort-link:hover { color: var(--primary); }
.sort-icon { font-size: .7rem; color: var(--muted); opacity: .5; }
.sort-link.is-sorted .sort-icon { color: var(--primary); opacity: 1; }
/* A failed review (faulty car, unhealthy driver) is red; a deleted row grey, whatever else it is. */
tr.is-faulty { background: var(--faulty-bg); print-color-adjust: exact; -webkit-print-color-adjust: exact; }
tr.is-faulty:hover { background: var(--faulty-hover-bg); }
tr.is-deleted, tr.is-deleted:hover { background: var(--deleted-bg); color: var(--muted); }
td.nowrap, .nowrap { white-space: nowrap; }
td.actions { white-space: nowrap; }
td.actions .btn, td.actions form { margin-right: 4px; }
.table-empty { padding: 20px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .8rem; background: #e5e9ee; white-space: nowrap; }
.badge-ok { background: var(--success-bg); color: var(--success-text); }
.badge-bad { background: var(--error-bg); color: var(--error-text); }
.badge-deleted { background: var(--deleted-bg); color: var(--danger); }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-top: 12px; }
.pagination-top { margin: 0 0 8px; }
.pagination-summary { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.pager-item, .pager-gap { min-width: 34px; height: 34px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius); font-variant-numeric: tabular-nums; }
.pager-item { border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; }
a.pager-item:hover { border-color: var(--primary); color: var(--primary); }
.pager-item.current { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pager-item.disabled { color: var(--border); }
.pager-gap { color: var(--muted); min-width: 20px; padding: 0; }
.per-page { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--muted); font-size: .9rem; }
.per-page select { padding: 4px 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font: inherit; color: var(--text); }

/* Error and confirm pages */
.error-page { text-align: center; padding: 48px 16px; }
.error-page h1 { font-size: 3rem; color: var(--muted); margin-bottom: 4px; }
.confirm { max-width: 560px; }
.confirm-subject { font-weight: 600; }

@media (max-width: 700px) {
    html { font-size: 14px; }
    .nav { order: 3; flex-basis: 100%; }
    /* On a phone an open group spans the whole menu row, so it never runs off the screen. */
    .nav { position: relative; }
    .nav .dropdown { position: static; }
    .nav .dropdown-menu { right: 0; min-width: 0; }
    .filters .field { max-width: none; }
    .pager-item.far { display: none; }
}

@media print {
    .topbar, .footer, .filters, .pagination, .actions, .btn { display: none !important; }
    body { background: #fff; }
}
.section-title { margin-top: 24px; }
.radio-field { border: 0; padding: 0; margin: 12px 0 0; min-width: 0; }
.radio-field legend { font-weight: 500; padding: 0; margin-bottom: 2px; }
/* Staff checklist of the bulk pages (views/partials/staff_checklist.php); wraps on a phone. */
.staff-list { display: flex; flex-wrap: wrap; gap: 6px 20px; padding: 6px 0; }
.form .staff-list label { display: inline-flex; font-weight: normal; margin: 0; }
.confirm-check { margin-top: 8px; font-weight: 600; }
.form-actions.no-margin { margin-top: 0; }
table.journal th { white-space: normal; min-width: 80px; vertical-align: bottom; }
.setup { max-width: 720px; margin: 40px auto; } .setup li { margin-bottom: 6px; }

/* Database backup progress (views/backup/index.php) */
.backup-progress { margin-top: 16px; }
.backup-progress progress { width: 100%; height: 14px; accent-color: var(--primary); }
.backup-progress-text { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: .9rem; }
.backup-progress-text.is-error { color: var(--error-text); }
