:root {
    --bg: #f3f4f8;
    --surface: #ffffff;
    --border: #e3e5ec;
    --text: #1c1e26;
    --text-muted: #6b7280;
    --primary: #262a52;
    --primary-hover: #363c74;
    --accent: #4f5fe0;
    --accent-hover: #3d4bcf;
    --danger: #b3261e;
    --danger-bg: #fdecea;
    --danger-border: #f4c6c2;
    --warning-text: #8a5a00;
    --warning-bg: #fdecc8;
    --success-text: #1e7a44;
    --success-bg: #e3f6ea;
    --info-text: #34399c;
    --info-bg: #ecedfb;
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(20, 21, 41, 0.05);
    --shadow-md: 0 6px 20px rgba(20, 21, 41, 0.08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font);
    margin: 0;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1 { font-size: 22px; font-weight: 650; margin: 0 0 20px; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 650; margin: 32px 0 12px; letter-spacing: -0.01em; }
p { line-height: 1.5; }
a { color: var(--accent); }

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 28px;
    background: var(--primary);
    color: #fff;
    flex-wrap: wrap;
    gap: 8px;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; row-gap: 8px; }
.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
}
.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--accent), var(--primary));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}
header nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-left: 20px;
    border-left: 1px solid rgba(255, 255, 255, 0.14);
}
@media (max-width: 480px) {
    header nav { padding-left: 0; border-left: none; margin-left: -12px; }
}
header nav a {
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    font-size: 14px;
    font-weight: 550;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: background 0.12s ease, color 0.12s ease;
}
header nav a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.user-info { font-size: 13px; color: rgba(255, 255, 255, 0.75); }
.user-info a { color: rgba(255, 255, 255, 0.9); text-decoration: none; }
.user-info a:hover { text-decoration: underline; }

main { padding: 28px; max-width: 1140px; margin: 0 auto; }

.welcome-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 28px 32px;
}
.welcome-card h1 { margin-bottom: 4px; }
.welcome-sub { color: var(--text-muted); margin: 0 0 22px; }
.quick-links { display: flex; flex-wrap: wrap; gap: 14px; }
.quick-link {
    flex: 1 1 200px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}
.quick-link:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}
.quick-link-title { font-weight: 650; font-size: 15px; }
.quick-link-desc { font-size: 13px; color: var(--text-muted); }
.welcome-note { margin: 22px 0 0; color: var(--text-muted); font-size: 13px; }

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
}
.empty-state p { margin: 0; }

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

table.trips, table.users {
    border-collapse: collapse;
    width: 100%;
    font-size: 14px;
}
table.trips { table-layout: fixed; min-width: 760px; }
table.trips th, table.trips td { white-space: nowrap; }
table.trips td.plate-cell { white-space: normal; }
table.trips th, table.trips td,
table.users th, table.users td {
    padding: 10px 14px;
    text-align: left;
}
table.users th, table.users td { border-bottom: 1px solid var(--border); }
/* Разделители в таблице рейсов -- целой линией только между днями.
   Построчный border-bottom здесь не годится: ячейки «Дата» и «За сутки»
   объединены rowspan на весь день и внутри него нижней границы не имеют,
   поэтому линия рвётся в этих двух колонках и читается как рамка вокруг
   части строк. Граница ставится сверху первой строки дня -- в ней обе
   объединённые ячейки присутствуют, линия выходит сплошной. */
table.trips tbody tr.day-start td { border-top: 1px solid var(--border); }
/* Выравнивание -- только классами: nth-child здесь считает ячейки строки,
   а из-за rowspan у первой строки дня их на две больше. */
table.trips .num { text-align: right; font-variant-numeric: tabular-nums; }
table.trips thead th, table.users thead th {
    background: #fafafd;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
table.users tbody tr:last-child td { border-bottom: none; }
table.trips tbody tr:hover, table.users tbody tr:hover { background: #fbfbfe; }
table.users { margin-bottom: 0; }
table.users form { display: inline-block; }

.users-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 20px;
    align-items: start;
}
@media (max-width: 900px) {
    .users-layout { grid-template-columns: 1fr; }
}
table.users th { white-space: nowrap; }
table.users .tg-id { color: var(--text-muted); font-variant-numeric: tabular-nums; }
table.users td.actions { text-align: right; white-space: nowrap; }
table.users td.actions form { margin-left: 6px; }
table.users td.actions button { padding: 5px 10px; font-size: 12px; }
.self-tag { color: var(--text-muted); font-size: 13px; }

.pagination { margin-top: 14px; display: flex; gap: 6px; }
.pagination a {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    background: var(--surface);
}
.pagination a:hover { border-color: var(--accent); color: var(--accent); }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

#filters {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: end;
    margin-bottom: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}
#filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--text-muted); gap: 5px; font-weight: 550; }
#filters a { font-size: 13px; align-self: center; text-decoration: none; }
#filters a:hover { text-decoration: underline; }

input, select, button {
    font-family: inherit;
    font-size: 14px;
}
input[type=text], input[type=number], input[type=date], select {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
}
input:focus, select:focus, button:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 95, 224, 0.15);
}

button, input[type=submit] {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-weight: 550;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}
button:hover { background: #f5f6fa; border-color: #d3d6e0; }

#filters button, #add-user-form button,
form[action*="create"] button {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
#filters button:hover, #add-user-form button:hover,
form[action*="create"] button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

table.users form[action*="deactivate"] button {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger);
}
table.users form[action*="deactivate"] button:hover { background: #fbdcd9; }
table.users form[action*="activate"]:not([action*="deactivate"]) button {
    background: var(--success-bg);
    border-color: #b9e5c8;
    color: var(--success-text);
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.status-new { background: #eef0f4; color: var(--text-muted); }
.status-priced { background: var(--info-bg); color: var(--info-text); }
.status-pending { background: var(--warning-bg); color: var(--warning-text); }
.status-approved { background: var(--success-bg); color: var(--success-text); }
.status-active { background: var(--success-bg); color: var(--success-text); }
.badge.unmatched { background: var(--warning-bg); color: var(--warning-text); margin-top: 4px; }
.status-inactive { background: #eef0f4; color: var(--text-muted); }

.totals {
    display: flex;
    flex-wrap: wrap;
    gap: 28px;
    margin-bottom: 18px;
    padding: 16px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    font-size: 13px;
    color: var(--text-muted);
}
.totals strong { display: block; font-size: 18px; color: var(--text); font-weight: 650; margin-top: 2px; }
.totals .unpriced { color: var(--warning-text); font-weight: 600; align-self: center; }

.audit-feed { display: flex; flex-direction: column; gap: 10px; }
.audit-entry {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
}
.audit-entry.self-approved, .audit-entry.reopened-multiple { border-left: 3px solid var(--warning-text); }
.audit-meta { color: var(--text-muted); font-size: 12px; }
.audit-action { margin-top: 3px; font-weight: 550; }
.audit-rates, .audit-comment { margin-top: 4px; color: var(--text); font-size: 13px; }
.audit-action .badge { margin-left: 8px; background: var(--warning-bg); color: var(--warning-text); }

#add-user-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
#add-user-form h2 { margin: 0 0 6px; font-size: 15px; }
#add-user-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--text-muted); gap: 5px; font-weight: 550; }
#add-user-form .hint { font-size: 12px; color: var(--text-muted); margin: 0; line-height: 1.4; }
#add-user-form .error { color: var(--danger); font-size: 13px; margin: 0; }
#add-user-form button { align-self: flex-start; margin-top: 4px; }

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    padding: 24px;
    background: linear-gradient(160deg, #f3f4f8 0%, #e8e9f5 100%);
}
.login-card {
    background: var(--surface);
    padding: 40px 40px 32px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    text-align: center;
    width: 340px;
    max-width: 100%;
}
.login-mark { width: 40px; height: 40px; border-radius: 11px; font-size: 18px; margin: 0 auto 14px; }
.login-card h1 { font-size: 20px; margin-bottom: 2px; }
.login-tagline { color: var(--text-muted); font-size: 13px; margin: 0 0 26px; }
.login-card .error {
    color: var(--danger);
    background: var(--danger-bg);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

.telegram-widget {
    display: flex;
    justify-content: center;
    min-height: 40px;
}
/* border: none обязателен -- без явного сброса некоторые браузеры (Safari
   iOS подтверждено) рисуют iframe без своих border/background дефолтной
   тёмной inset-рамкой, которая на телефоне читалась как чёрная плашка
   вокруг кнопки. Виджет из telegram.org (чужой origin, его внутреннее
   содержимое темизировать нашим CSS нельзя) сам рамку не ставит --
   значит рамку рисовал браузер, а не мы. */
.telegram-widget iframe {
    border: none;
    background: transparent;
}

.login-card .dev-form {
    margin-top: 26px;
    padding-top: 20px;
    border-top: 1px dashed var(--border);
    text-align: left;
}
.dev-form-label {
    margin: 0 0 10px;
    font-size: 11px;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}
.login-card .dev-form label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.dev-form-row { display: flex; gap: 8px; }
.dev-form-row input { flex: 1; padding: 7px 10px; font-size: 14px; min-width: 0; }
.dev-form-row button { padding: 7px 14px; font-size: 13px; }
