/* ==========================================================================
   GPS Трекер — дизайн-система в стиле брендбука «Фаровон»
   Цвета, шрифты и формы кнопок взяты с job.farovon.tj
   ========================================================================== */

@font-face {
    font-family: InterVariable;
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('../fonts/InterVariable.woff2') format('woff2');
}
@font-face {
    font-family: 'Norms';
    src: url('../fonts/TTNormsPro-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Norms';
    src: url('../fonts/TTNormsPro-Medium.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Norms';
    src: url('../fonts/TTNormsPro-Bold.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --brand: #FF1F1F;
    --brand-600: #E60000;
    --brand-50: #FFF1F1;
    --brand-100: #FFE1E1;
    --ink: #161414;
    --ink-2: #444444;
    --muted: #7E828C;
    --muted-2: #666666;
    --line: #E4E7EF;
    --line-2: #EEF0F4;
    --surface: #FFFFFF;
    --panel: #F5F5F5;
    --panel-2: #F2F5F9;
    --success: #008A00;
    --success-50: #EAF7EA;
    --warning: #B45309;
    --warning-50: #FFF7E6;

    --radius-xs: 8px;
    --radius-sm: 12px;
    --radius: 16px;
    --radius-lg: 25px;
    --pill: 33px;

    --shadow-sm: 0 1px 2px rgba(22, 20, 20, .06);
    --shadow: 0 8px 24px rgba(22, 20, 20, .08);
    --shadow-lg: 0 24px 60px rgba(22, 20, 20, .18);

    --font: InterVariable, Norms, 'Inter var', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-head: Norms, InterVariable, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;

    --topbar-h: 72px;
}

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

html {
    font-family: var(--font);
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--surface);
    line-height: 1.45;
}

a { color: inherit; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

::selection { background: var(--brand-100); }

@media (min-width: 960px) {
    ::-webkit-scrollbar { width: 10px; height: 10px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: #C9CCD3; border-radius: 10px; border: 2px solid #fff; }
    ::-webkit-scrollbar-thumb:hover { background: #888; }
}

/* ---------- Типографика ---------- */

.h1, .h2, .h3 {
    font-family: var(--font-head);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .01em;
    margin: 0;
    line-height: 1.1;
}
.h1 { font-size: clamp(26px, 3.2vw, 40px); }
.h2 { font-size: 22px; }
.h3 { font-size: 16px; }

/* Заголовок раздела с фирменной «звездой» */
.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-head);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 15px;
    letter-spacing: .02em;
    margin: 0;
}
.section-title::before {
    content: "";
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    background: var(--brand);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0C12.6 6.6 17.4 11.4 24 12C17.4 12.6 12.6 17.4 12 24C11.4 17.4 6.6 12.6 0 12C6.6 11.4 11.4 6.6 12 0Z'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0C12.6 6.6 17.4 11.4 24 12C17.4 12.6 12.6 17.4 12 24C11.4 17.4 6.6 12.6 0 12C6.6 11.4 11.4 6.6 12 0Z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.section-title.lg { font-size: 24px; gap: 14px; }
.section-title.lg::before { width: 22px; height: 22px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ---------- Кнопки ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 9px 20px;
    border: 1px solid transparent;
    border-radius: var(--pill);
    background: transparent;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
    -webkit-user-select: none;
    user-select: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #fff; color: var(--brand); box-shadow: 0 0 10px rgba(255, 31, 31, .45); }

.btn-outline { background: #fff; border-color: var(--ink); color: var(--ink); }
.btn-outline:hover:not(:disabled) { background: var(--ink); color: #fff; }

.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover:not(:disabled) { background: #fff; color: var(--ink); }

.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--panel); color: var(--ink); }

.btn-danger { background: #fff; border-color: var(--line); color: var(--brand-600); }
.btn-danger:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-50); }

.btn-sm { min-height: 34px; padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.btn-icon {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.btn-icon:hover:not(:disabled) { border-color: var(--ink); }
.btn-icon:disabled { opacity: .4; cursor: default; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon.sm { width: 30px; height: 30px; }
.btn-icon.sm svg { width: 15px; height: 15px; }

/* ---------- Шапка ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 32px;
    padding: 0 28px;
    background: #fff;
    border-bottom: 1px solid var(--line-2);
}
.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
    flex: 0 0 auto;
}
.brand img { height: 26px; width: auto; display: block; }
.brand-product {
    padding-left: 14px;
    border-left: 1px solid var(--line);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    line-height: 1.1;
}
.nav { display: flex; align-items: center; gap: 4px; flex: 1 1 auto; min-width: 0; }
.nav a {
    position: relative;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 500;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--ink);
    border-radius: var(--pill);
    transition: color .15s, background .15s;
    white-space: nowrap;
}
.nav a:hover { color: var(--brand); }
.nav a.active { color: var(--brand); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--panel);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 14px;
    color: var(--ink);
    text-transform: uppercase;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 600; font-size: 14px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 12px; color: var(--muted); }

.nav-toggle { display: none; }

@media (max-width: 1100px) {
    .topbar { gap: 16px; padding: 0 16px; }
    .brand-product { display: none; }
    .user-meta { display: none; }
}
@media (max-width: 860px) {
    .nav-toggle { display: inline-grid; margin-left: auto; }
    .nav {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 8px 16px 16px;
        background: #fff;
        border-bottom: 1px solid var(--line);
        box-shadow: var(--shadow);
        transform: translateY(-8px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .15s, transform .15s;
    }
    .nav.open { opacity: 1; transform: none; pointer-events: auto; }
    .nav a { padding: 14px 8px; border-radius: 0; border-bottom: 1px solid var(--line-2); }
    .topbar-right .btn-logout span { display: none; }
    .topbar-right .btn-logout { padding: 9px 12px; }
}

/* ---------- Страница / карточки ---------- */

.page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 28px 64px;
}
@media (max-width: 640px) { .page { padding: 20px 16px 48px; } }

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.page-head p { margin: 8px 0 0; color: var(--muted); max-width: 640px; }

.hero {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--panel);
    padding: 32px 36px;
    margin-bottom: 28px;
}
.hero::after {
    content: "";
    position: absolute;
    right: -60px;
    top: -60px;
    width: 280px;
    height: 280px;
    background: #fff;
    opacity: .55;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0C12.6 6.6 17.4 11.4 24 12C17.4 12.6 12.6 17.4 12 24C11.4 17.4 6.6 12.6 0 12C6.6 11.4 11.4 6.6 12 0Z'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0C12.6 6.6 17.4 11.4 24 12C17.4 12.6 12.6 17.4 12 24C11.4 17.4 6.6 12.6 0 12C6.6 11.4 11.4 6.6 12 0Z'/%3E%3C/svg%3E") center / contain no-repeat;
    pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero p { margin: 12px 0 0; max-width: 620px; font-size: 15px; color: var(--ink-2); }
@media (max-width: 640px) { .hero { padding: 24px 20px; } }

.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 24px;
}
.card + .card { margin-top: 20px; }
@media (max-width: 640px) {
    .card { padding: 16px; border-radius: var(--radius); }
    .toolbar .input-search, .toolbar .select { max-width: none !important; flex: 1 1 100%; }
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

/* Сегментный переключатель (вкладки) */
.segmented {
    display: inline-flex;
    padding: 4px;
    gap: 4px;
    border-radius: var(--pill);
    background: var(--panel);
    max-width: 100%;
    overflow-x: auto;
}
.segmented button {
    border: 0;
    background: transparent;
    padding: 9px 18px;
    border-radius: var(--pill);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .02em;
    color: var(--ink-2);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: var(--ink); color: #fff; }
.segmented.sm button { padding: 6px 12px; font-size: 11.5px; }
.segmented.block { display: flex; }
.segmented.block button { flex: 1 1 0; }

/* ---------- Формы ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label, .label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}
.hint { font-size: 12px; color: var(--muted); }

.input, .select, textarea.input {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}
.input:hover, .select:hover { border-color: #C9CCD3; }
.input:focus, .select:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(22, 20, 20, .08);
}
.input[readonly] { background: var(--panel); color: var(--muted-2); }
.select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23161414' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    cursor: pointer;
}
.input-search {
    padding-left: 40px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237E828C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 14px center / 16px;
}

.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 0;
    cursor: pointer;
    font-size: 14px;
}
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--brand); flex: 0 0 auto; cursor: pointer; }
.check small { display: block; color: var(--muted); font-size: 12px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Таблицы ---------- */

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.toolbar .input-search { max-width: 340px; }
.toolbar .spacer { flex: 1 1 auto; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    position: sticky;
    top: 0;
    background: #FAFAFA;
    text-align: left;
    padding: 12px 16px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #FCFCFC; }
.table .actions { display: flex; gap: 8px; justify-content: flex-end; }
.table .num { color: var(--muted); font-variant-numeric: tabular-nums; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--pill);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    background: var(--panel);
    color: var(--ink-2);
}
.badge-admin { background: var(--brand-50); color: var(--brand-600); }
.badge-manager { background: var(--ink); color: #fff; }
.badge-user { background: var(--panel); color: var(--ink-2); }
.badge-count { background: var(--panel-2); color: var(--ink); font-variant-numeric: tabular-nums; }

.serial { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; font-weight: 600; letter-spacing: .01em; }

.empty {
    padding: 48px 16px;
    text-align: center;
    color: var(--muted);
}
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 6px; }

/* ---------- Модальные окна ---------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(22, 20, 20, .45);
    -webkit-backdrop-filter: blur(3px);
            backdrop-filter: blur(3px);
}
.modal.open { display: flex; }
.modal-dialog {
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    animation: modal-in .18s ease-out;
}
.modal-dialog.sm { max-width: 420px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.modal-head .h3 { font-size: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Уведомления ---------- */

.toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(420px, calc(100vw - 40px));
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    border-radius: var(--radius);
    background: var(--ink);
    color: #fff;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    animation: toast-in .2s ease-out;
}
.toast::before {
    content: "";
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    margin-top: 6px;
    border-radius: 50%;
    background: #3DDC84;
}
.toast.error::before { background: var(--brand); }
.toast.info::before { background: #9CA3AF; }
.toast.hide { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Загрузка ---------- */

.loader {
    width: 44px;
    height: 44px;
    border: 5px solid var(--brand);
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    animation: rotation 1s linear infinite;
}
.loader.sm { width: 18px; height: 18px; border-width: 3px; }
@keyframes rotation { to { transform: rotate(360deg); } }

.skeleton {
    display: inline-block;
    height: 12px;
    width: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, #F0F1F4 0%, #F7F8FA 50%, #F0F1F4 100%);
    background-size: 200% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.overlay-loading {
    position: absolute;
    inset: 0;
    z-index: 900;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(255, 255, 255, .6);
    -webkit-backdrop-filter: blur(3px);
            backdrop-filter: blur(3px);
    font-weight: 500;
}

/* ---------- Select2 в фирменном стиле ---------- */

.select2-container { width: 100% !important; }
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
}
.select2-container--default .select2-selection--single { display: flex; align-items: center; }
.select2-container--default .select2-selection--single .select2-selection__rendered { padding-left: 14px; padding-right: 40px; color: var(--ink); line-height: 42px; }
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 42px; right: 10px; }
.select2-container--default .select2-selection--single .select2-selection__placeholder { color: var(--muted); }
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(22, 20, 20, .08);
}
.select2-container--default .select2-selection--multiple .select2-selection__rendered { padding: 4px 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    display: inline-flex;
    align-items: center;
    margin: 0;
    padding: 4px 10px 4px 4px;
    border: 0;
    border-radius: var(--pill);
    background: var(--panel);
    color: var(--ink);
    font-size: 13px;
    font-weight: 500;
    max-width: 100%;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__display { padding: 0 0 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    position: static;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    color: var(--muted);
    font-size: 14px;
    line-height: 20px;
    padding: 0;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover { background: var(--brand); color: #fff; }
.select2-container--default .select2-search--inline .select2-search__field { margin: 0; height: 30px; padding-left: 6px; font-family: var(--font); font-size: 14px; }
.select2-container--default .select2-selection--multiple .select2-selection__clear { margin: 0; position: absolute; right: 12px; top: 10px; color: var(--muted); font-size: 18px; }
.select2-dropdown {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    overflow: hidden;
    z-index: 3500;
}
.select2-container--open .select2-dropdown--below { margin-top: 6px; border-radius: var(--radius-sm); }
.select2-container--open .select2-dropdown--above { margin-top: -6px; border-radius: var(--radius-sm); }
.select2-search--dropdown { padding: 10px; }
.select2-container--default .select2-search--dropdown .select2-search__field { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.select2-results__option { padding: 9px 14px; font-size: 14px; }
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable { background: var(--brand-50); color: var(--ink); }
.select2-container--default .select2-results__option--selected { background: var(--panel); font-weight: 600; }
.select2-results__message { color: var(--muted); }

/* ==========================================================================
   Страница входа
   ========================================================================== */

.auth-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 24px;
    background: #fff;
}
.auth-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 24px; }
.auth-top img { height: 30px; }
.auth-grid {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 24px;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
}
.auth-hero {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--panel);
    padding: 56px 52px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 420px;
}
.auth-hero .h1 { font-size: clamp(30px, 4vw, 52px); }
.auth-hero p { font-size: 16px; color: var(--ink-2); max-width: 460px; margin: 20px 0 0; }
.auth-hero .route-art { position: absolute; right: -10px; bottom: -10px; width: 62%; max-width: 440px; opacity: .95; pointer-events: none; }
.auth-hero > *:not(.route-art) { position: relative; z-index: 1; }
.auth-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 40px clamp(20px, 5vw, 64px);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}
.auth-card .h2 { font-size: 26px; margin-bottom: 8px; }
.auth-card .lead { color: var(--muted); margin: 0 0 28px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding-top: 20px; }

.alert {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 18px;
}
.alert-error { background: var(--brand-50); color: var(--brand-600); }
.alert-success { background: var(--success-50); color: var(--success); }
.alert-info { background: var(--panel-2); color: var(--ink-2); }
.alert-warning { background: var(--warning-50); color: var(--warning); }

@media (max-width: 900px) {
    .auth-page { padding: 16px; }
    .auth-grid { grid-template-columns: 1fr; }
    .auth-hero { min-height: 0; padding: 32px 24px 140px; }
    .auth-hero .route-art { width: 70%; }
    .auth-card { padding: 28px 20px; }
}

/* ==========================================================================
   Карта
   ========================================================================== */

body.page-map { position: fixed; inset: 0; overflow: hidden; display: flex; flex-direction: column; }

.page-map .topbar { flex: 0 0 auto; }
.map-layout {
    flex: 1 1 0;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: 360px minmax(0, 1fr) 400px;
    transition: grid-template-columns .2s ease;
}
.map-layout.hide-side { grid-template-columns: 0 minmax(0, 1fr) 400px; }
.map-layout.hide-hist { grid-template-columns: 360px minmax(0, 1fr) 0; }
.map-layout.hide-side.hide-hist { grid-template-columns: 0 minmax(0, 1fr) 0; }

.side {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid var(--line-2);
    background: #fff;
}
.side-inner { width: 360px; padding: 22px 20px 28px; }
.side-block { padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid var(--line-2); }
.side-block:last-child { border-bottom: 0; margin-bottom: 0; }
.side-block .section-title { margin-bottom: 14px; }

.collapse-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
    text-align: left;
}
.collapse-head .chev { transition: transform .15s; color: var(--muted); width: 18px; height: 18px; }
.collapse-head[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.collapse-head .section-title { margin: 0; }
.collapse-body { padding-top: 14px; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.chip {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: var(--pill);
    padding: 5px 12px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    color: var(--ink-2);
    transition: border-color .15s, color .15s, background .15s;
}
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.range-info {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border-radius: var(--radius-sm);
    background: var(--panel);
    font-size: 13px;
}
.range-info dt { color: var(--muted); }
.range-info dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.dt-row { display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: center; gap: 8px 10px; margin-bottom: 14px; }
.dt-row label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.dt-row .input { min-width: 0; min-height: 40px; padding: 7px 12px; font-size: 13.5px; }

.opt-grid { display: grid; gap: 14px; }
.opt-grid .field { margin: 0; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--panel);
}
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat-value { margin-top: 4px; font-family: var(--font-head); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value small { font-family: var(--font); font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 2px; }

.device-list { display: flex; flex-direction: column; gap: 6px; }
.device-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: border-color .15s, background .15s;
}
.device-row:hover { border-color: #C9CCD3; }
.device-row.active { border-color: var(--ink); background: var(--panel); }
.device-row .dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); }
.device-row .dname { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.device-row .dcount { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Карта */
.map-wrap { position: relative; min-width: 0; min-height: 0; background: #EEF0F2; }
#map { position: absolute; inset: 0; }

.map-fab {
    position: absolute;
    z-index: 800;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--pill);
    background: #fff;
    box-shadow: var(--shadow);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: var(--ink);
}
.map-fab:hover { color: var(--brand); }
.map-fab svg { width: 18px; height: 18px; }
.fab-side { top: 14px; left: 14px; }
.fab-hist { top: 14px; right: 14px; }
.map-layout:not(.hide-side) .fab-side .lbl-open,
.map-layout.hide-side .fab-side .lbl-close,
.map-layout:not(.hide-hist) .fab-hist .lbl-open,
.map-layout.hide-hist .fab-hist .lbl-close { display: none; }

.map-empty {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 700;
    width: min(420px, calc(100% - 32px));
    padding: 28px;
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, .96);
    box-shadow: var(--shadow);
    text-align: center;
}
.map-empty .section-title { justify-content: center; margin-bottom: 10px; }
.map-empty p { margin: 0; color: var(--muted); }

.map-notice {
    position: absolute;
    left: 50%;
    top: 14px;
    transform: translateX(-50%);
    z-index: 800;
    max-width: calc(100% - 320px);
    padding: 9px 16px;
    border-radius: var(--pill);
    background: var(--ink);
    color: #fff;
    font-size: 13px;
    box-shadow: var(--shadow);
    text-align: center;
}

.legend {
    position: absolute;
    left: 14px;
    bottom: 24px;
    z-index: 800;
    max-width: 280px;
    max-height: 40%;
    overflow: auto;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .96);
    box-shadow: var(--shadow);
    font-size: 12.5px;
}
.legend-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.legend-swatch { width: 22px; height: 6px; border-radius: 3px; flex: 0 0 auto; }
.legend-item span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Маркеры точек маршрута */
.pt-icon { background: none; border: 0; }
.pt {
    --c: var(--brand);
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    min-width: 24px;
    height: 24px;
    padding: 0 5px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: #fff;
    border: 2px solid var(--c);
    color: var(--ink);
    font: 700 11px/1 var(--font);
    font-variant-numeric: tabular-nums;
    box-shadow: 0 1px 4px rgba(22, 20, 20, .25);
    white-space: nowrap;
    transition: transform .12s;
}
.pt.start { background: var(--ink); border-color: var(--ink); color: #fff; }
.pt.end { background: var(--c); color: #fff; }
.pt.stop { border-radius: 6px; border-color: var(--ink); border-width: 2px; background: #FFF7E6; }
.pt.active {
    background: var(--brand);
    border-color: #fff;
    color: #fff;
    transform: translate(-50%, -50%) scale(1.3);
    box-shadow: 0 0 0 4px rgba(255, 31, 31, .28), 0 4px 10px rgba(22, 20, 20, .3);
    z-index: 10;
}
.pt-icon:hover .pt:not(.active) { transform: translate(-50%, -50%) scale(1.15); }

/* Много точек на мелком масштабе: обычные точки — маленькие кружки без номера */
.pts-compact .pt:not(.start):not(.end):not(.active) {
    min-width: 11px;
    width: 11px;
    height: 11px;
    padding: 0;
    border-width: 2px;
    font-size: 0;
    box-shadow: 0 0 0 1px #fff;
}
.pts-compact .pt.stop:not(.start):not(.end):not(.active) {
    border-radius: 3px;
    background: var(--ink);
    border-color: var(--ink);
}
.pts-compact .pt-icon:hover .pt:not(.active) { transform: translate(-50%, -50%) scale(1.6); }

.arrow-icon { background: none; border: 0; }
.arrow-icon svg { display: block; width: 16px; height: 16px; filter: drop-shadow(0 0 1px #fff) drop-shadow(0 0 1px #fff); }

.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper { border-radius: var(--radius); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 14px 16px; font-size: 13px; line-height: 1.45; min-width: 220px; }
.leaflet-tooltip { border-radius: 8px; border: 0; box-shadow: var(--shadow); font-size: 12px; }
.leaflet-bar a, .leaflet-control-layers { border-radius: 10px !important; }
.leaflet-control-zoom { border: 0 !important; box-shadow: var(--shadow) !important; border-radius: 12px !important; overflow: hidden; }
.leaflet-control-layers { border: 0 !important; box-shadow: var(--shadow) !important; }

.pop-num {
    display: inline-grid;
    place-items: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    border-radius: 12px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    margin-right: 8px;
}
.pop-head { display: flex; align-items: center; font-weight: 700; margin-bottom: 8px; }
.pop-addr { margin-bottom: 8px; }
.pop-row { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); }
.pop-row b { color: var(--ink); font-weight: 600; }
.pop-links { display: flex; gap: 12px; margin-top: 10px; }
.pop-links a { color: var(--brand); font-weight: 600; text-decoration: none; }
.pop-links a:hover { text-decoration: underline; }

/* История маршрута (правая панель) */
.hist {
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--line-2);
    background: #fff;
}
.hist-inner { width: 400px; min-height: 0; flex: 1 1 auto; display: flex; flex-direction: column; }
.hist-head { padding: 18px 18px 12px; border-bottom: 1px solid var(--line-2); }
.hist-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hist-device { margin-top: 12px; }
.hist-device .select { min-height: 40px; }

.days {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 10px;
    border-bottom: 1px solid var(--line-2);
}
.days-track {
    flex: 1 1 auto;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    padding: 2px;
}
.days-track::-webkit-scrollbar { display: none; }
.day {
    flex: 0 0 auto;
    width: 52px;
    padding: 6px 0 7px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    text-align: center;
    cursor: pointer;
    line-height: 1.1;
    transition: border-color .15s, background .15s, color .15s;
}
.day:hover { border-color: var(--ink); }
.day .dw { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.day .dd { display: block; font-family: var(--font-head); font-weight: 700; font-size: 17px; margin: 2px 0 1px; }
.day .dm { display: block; font-size: 10px; text-transform: uppercase; color: var(--muted); }
.day.all { width: auto; padding: 6px 12px; }
.day.all .dd { font-size: 12px; margin: 5px 0 4px; text-transform: uppercase; }
.day.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.day.active .dw, .day.active .dm { color: rgba(255, 255, 255, .85); }

.hist-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--line-2);
    border-bottom: 1px solid var(--line-2);
}
.hist-summary div { background: #fff; padding: 10px 12px; }
.hist-summary b { display: block; font-family: var(--font-head); font-size: 16px; font-variant-numeric: tabular-nums; }
.hist-summary span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }

.hist-datebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 8px 18px;
    background: var(--panel-2);
    font-size: 12px;
    font-weight: 700;
    color: var(--ink-2);
    text-transform: capitalize;
}
.hist-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; outline: none; }
.hist-item {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    padding: 12px 18px 12px 14px;
    border-bottom: 1px solid var(--line-2);
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: background .12s;
}
.hist-item:hover { background: #FAFAFA; }
.hist-item.active { background: var(--brand-50); border-left-color: var(--brand); }
.hist-num {
    position: relative;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    border: 2px solid var(--c, var(--brand));
    background: #fff;
    font-weight: 700;
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
    z-index: 1;
}
.hist-item.is-start .hist-num { background: var(--ink); border-color: var(--ink); color: #fff; }
.hist-item.is-end .hist-num { background: var(--c, var(--brand)); color: #fff; }
.hist-item.is-stop .hist-num { border-radius: 7px; border-color: var(--ink); background: #FFF7E6; }
.hist-item.active .hist-num { background: var(--brand); border-color: var(--brand); color: #fff; }
.hist-item::before {
    content: "";
    position: absolute;
    left: calc(14px + 13px);
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--line);
}
.hist-item:first-child::before { top: 26px; }
.hist-item:last-child::before { bottom: calc(100% - 26px); }
.hist-body { min-width: 0; }
.hist-addr { font-size: 13.5px; font-weight: 500; color: var(--ink); line-height: 1.35; word-wrap: break-word; }
.hist-addr .skeleton { width: 80%; height: 11px; margin: 4px 0; }
.hist-addr .noaddr { color: var(--muted); font-weight: 400; }
.hist-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.hist-coords { font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-time { font-weight: 700; color: var(--ink); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hist-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 2px 8px;
    border-radius: var(--pill);
    background: #FFF1D6;
    color: #92400E;
    font-size: 11.5px;
    font-weight: 600;
}
.hist-tag.move { background: var(--panel); color: var(--ink-2); }
.hist-more { padding: 14px; text-align: center; }
.hist-empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.hist-empty .section-title { justify-content: center; color: var(--ink); margin-bottom: 8px; }
.hist-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--line-2);
    font-size: 12px;
    color: var(--muted);
}
.hist-nav { display: flex; gap: 6px; }

@media (max-width: 1280px) {
    .map-layout { grid-template-columns: 320px minmax(0, 1fr) 360px; }
    .map-layout.hide-side { grid-template-columns: 0 minmax(0, 1fr) 360px; }
    .map-layout.hide-hist { grid-template-columns: 320px minmax(0, 1fr) 0; }
    .side-inner { width: 320px; }
    .hist-inner { width: 360px; }
}

/* Мобильная раскладка: панели становятся выезжающими */
@media (max-width: 1023px) {
    .map-layout,
    .map-layout.hide-side,
    .map-layout.hide-hist,
    .map-layout.hide-side.hide-hist { grid-template-columns: minmax(0, 1fr); }
    .map-wrap { grid-column: 1; grid-row: 1; }
    .side, .hist {
        position: fixed;
        z-index: 1500;
        background: #fff;
        box-shadow: var(--shadow-lg);
        transition: transform .22s ease;
    }
    .side {
        top: var(--topbar-h);
        bottom: 0;
        left: 0;
        width: min(360px, 92vw);
        border-right: 0;
    }
    .side-inner { width: auto; }
    .map-layout.hide-side .side { transform: translateX(-105%); }
    .hist {
        left: 0;
        right: 0;
        bottom: 0;
        height: 52vh;
        height: 52dvh;
        border-left: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    .hist-inner { width: auto; }
    .map-layout.hide-hist .hist { transform: translateY(105%); }
    .map-notice { max-width: calc(100% - 40px); top: 64px; }
    .legend { bottom: 16px; left: 10px; max-width: 220px; }
}
