:root {
    --bg-0: #f4f7ff;
    --bg-1: #ecf2ff;
    --text-main: #1a2440;
    --text-muted: #6b7694;
    --primary: #4f6df5;
    --primary-2: #7f56d9;
    --success: #12b76a;
    --danger: #f04438;
    --surface: rgba(255, 255, 255, 0.78);
    --surface-stroke: rgba(95, 118, 255, 0.18);
    --shadow-soft: 0 16px 42px rgba(36, 50, 100, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text-main);
    background:
            radial-gradient(1000px 500px at 10% -10%, rgba(127, 86, 217, 0.17), transparent 60%),
            radial-gradient(900px 420px at 90% 0, rgba(79, 109, 245, 0.2), transparent 60%),
            linear-gradient(180deg, var(--bg-0), var(--bg-1));
    min-height: 100vh;
    font-family: Inter, "Segoe UI", Roboto, sans-serif;
}

.app-shell {
    max-width: 1200px;
}

.glass-card {
    border: 1px solid var(--surface-stroke);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(8px);
    border-radius: 20px;
}

.hero-card {
    background: linear-gradient(125deg, #4f6df5, #7f56d9);
    color: #fff;
    border-radius: 24px;
    box-shadow: 0 18px 45px rgba(79, 109, 245, 0.35);
}

.hero-muted {
    color: rgba(255, 255, 255, 0.9);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 22px;
}

.brand-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text-main);
    text-decoration: none;
}

.brand-chip .dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: linear-gradient(120deg, var(--primary), var(--primary-2));
    box-shadow: 0 0 0 6px rgba(79, 109, 245, 0.14);
}

.badge-soft {
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 0.74rem;
    font-weight: 600;
    color: #32426d;
    background: rgba(79, 109, 245, 0.1);
}

.btn-primary {
    border: none;
    border-radius: 12px;
    background: linear-gradient(120deg, var(--primary), var(--primary-2));
    box-shadow: 0 10px 20px rgba(79, 109, 245, 0.25);
}

.btn-primary:hover,
.btn-primary:focus {
    filter: brightness(1.03);
}

.btn-outline-secondary,
.btn-outline-primary,
.btn-outline-success {
    border-radius: 12px;
}

.form-control,
.form-select {
    border-radius: 12px;
    border-color: rgba(73, 93, 159, 0.2);
    padding: 0.62rem 0.78rem;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(79, 109, 245, 0.65);
    box-shadow: 0 0 0 0.2rem rgba(79, 109, 245, 0.16);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-border-color: rgba(92, 110, 170, 0.16);
    vertical-align: middle;
}

.table thead th {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-pill {
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.72rem;
    font-weight: 700;
}

.status-created { background: rgba(79, 109, 245, 0.12); color: #3d56c9; }
.status-assigned { background: rgba(2, 132, 199, 0.12); color: #0369a1; }
.status-transit { background: rgba(245, 158, 11, 0.14); color: #b45309; }
.status-done { background: rgba(18, 183, 106, 0.14); color: #067647; }

.metric {
    border-radius: 16px;
    padding: 14px 16px;
    background: rgba(79, 109, 245, 0.08);
    border: 1px solid rgba(79, 109, 245, 0.16);
}

.metric-title {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.metric-value {
    font-size: 1.4rem;
    font-weight: 700;
}

.muted-note {
    color: var(--text-muted);
}

.order-summary-table {
    table-layout: fixed;
    width: 100%;
}

.order-summary-table td,
.order-summary-table th {
    white-space: normal;
    word-break: break-word;
}

.ac-suggest {
    top: 100%;
    left: 0;
    max-height: 220px;
    overflow-y: auto;
    z-index: 25;
    box-shadow: var(--shadow-soft);
}

.driver-select-scroll {
    max-height: 11rem;
    overflow-y: auto;
}

.vehicle-removal-badge {
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: rgba(245, 158, 11, 0.22) !important;
    color: #92400e !important;
    border: 1px solid rgba(180, 83, 9, 0.35);
}

[data-create-order-drivers] .driver-select-row {
    cursor: pointer;
}

[data-create-order-drivers] .driver-select-row:hover {
    background-color: rgba(26, 36, 64, 0.04);
}

[data-create-order-drivers] .driver-select-row:last-of-type {
    border-bottom: 0 !important;
}

/* —— Manager shell (sidebar + main) —— */
.manager-body {
    margin: 0;
}

.manager-app {
    min-height: 100vh;
    align-items: stretch;
}

.manager-sidebar {
    width: 268px;
    flex-shrink: 0;
    background: linear-gradient(165deg, #0b1220 0%, #151e32 48%, #0f172a 100%);
    color: #cbd5e1;
    padding: 1.35rem 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    align-self: flex-start;
    min-height: 100vh;
    border-right: 1px solid rgba(148, 163, 184, 0.12);
    box-shadow: 8px 0 32px rgba(15, 23, 42, 0.12);
}

.manager-sidebar-brand {
    margin-bottom: 1.75rem;
    padding: 0 0.35rem;
}

.manager-sidebar-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    color: #f8fafc !important;
}

.manager-sidebar-dot {
    width: 11px;
    height: 11px;
    border-radius: 999px;
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    box-shadow: 0 0 0 5px rgba(129, 140, 248, 0.25);
}

.manager-sidebar-role {
    margin-top: 0.35rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(148, 163, 184, 0.85);
}

.manager-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.manager-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.72rem 0.9rem;
    border-radius: 12px;
    color: #94a3b8 !important;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
    border: 1px solid transparent;
}

.manager-nav-link i {
    font-size: 1.1rem;
    opacity: 0.9;
}

.manager-nav-link:hover {
    background: rgba(248, 250, 252, 0.06);
    color: #e2e8f0 !important;
}

.manager-nav-link.active {
    background: linear-gradient(125deg, rgba(79, 109, 245, 0.35), rgba(127, 86, 217, 0.28));
    border-color: rgba(129, 140, 248, 0.35);
    color: #f8fafc !important;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.35);
}

.manager-sidebar-footer {
    border-top: 1px solid rgba(148, 163, 184, 0.12);
    padding-top: 1rem;
}

.manager-sidebar-footer .btn-outline-light {
    border-color: rgba(248, 250, 252, 0.22);
    color: #e2e8f0;
    font-size: 0.88rem;
}

.manager-sidebar-footer .btn-outline-light:hover {
    background: rgba(248, 250, 252, 0.08);
    border-color: rgba(248, 250, 252, 0.35);
    color: #fff;
}

.manager-main {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 1400px;
}

.manager-page-header h1 {
    letter-spacing: -0.02em;
    font-weight: 700;
    color: var(--text-main);
}

.manager-metric-tile {
    display: block;
    text-decoration: none;
    color: inherit;
    border-radius: 18px;
    padding: 16px 18px;
    background: rgba(79, 109, 245, 0.08);
    border: 1px solid rgba(79, 109, 245, 0.16);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.manager-metric-tile:hover {
    transform: translateY(-2px);
    border-color: rgba(79, 109, 245, 0.35);
    box-shadow: 0 12px 28px rgba(36, 50, 100, 0.12);
    color: inherit;
}

.manager-metric-tile .metric-title {
    color: var(--text-muted);
}

.manager-metric-tile .metric-value {
    color: var(--text-main);
}

@media (max-width: 991.98px) {
    .manager-app {
        flex-direction: column;
    }

    .manager-sidebar {
        width: 100%;
        min-height: 0;
        position: relative;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 1rem;
    }

    .manager-sidebar-brand {
        margin-bottom: 0;
        flex: 1 1 auto;
    }

    .manager-sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
        margin-top: 0.75rem;
        gap: 0.5rem;
    }

    .manager-nav-link {
        flex: 1 1 auto;
        justify-content: center;
        min-width: 140px;
    }

    .manager-sidebar-footer {
        width: 100%;
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid rgba(148, 163, 184, 0.12);
    }
}

.manager-monitoring-embed {
    min-height: min(70vh, 720px);
    isolation: isolate;
}

.manager-monitoring-frame {
    min-height: min(70vh, 720px);
    height: 70vh;
    background: #fff;
}

/* —— Manager: новый заказ / список заказов —— */
.manager-order-create-hero .btn-outline-primary {
    border-color: rgba(79, 109, 245, 0.35);
    color: var(--primary);
}

.manager-order-create-hero .btn-outline-primary:hover {
    background: rgba(79, 109, 245, 0.08);
    color: #3d56c9;
}

.manager-order-create-page {
    max-width: 1180px;
    margin-inline: auto;
}

.manager-order-create-hero {
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(79, 109, 245, 0.07), rgba(127, 86, 217, 0.06));
    border-color: rgba(79, 109, 245, 0.2);
}

.order-create-kicker {
    letter-spacing: 0.08em;
    color: var(--primary);
    font-size: 0.72rem;
}

.order-create-lead {
    max-width: 46rem;
    line-height: 1.55;
}

.order-create-form .order-create-section {
    border-radius: 20px;
    /* overflow visible: иначе списки автодополнения контрагента/договора обрезаются */
    overflow: visible;
}

/*
 * Секции .glass-card с backdrop-filter создают свой stacking context.
 * Без поднятия блока контрагента следующая карточка («Комментарий») рисуется поверх выпадающего списка.
 */
.order-create-form [data-party-contract-scope] {
    position: relative;
    z-index: 30;
}

.order-create-form [data-party-contract-scope] .order-create-section-body {
    overflow: visible;
}

/* Подсказки поверх соседних секций и полей */
.order-create-form .ac-suggest {
    z-index: 50;
    max-height: min(16rem, 40vh);
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(36, 50, 100, 0.18);
    border-radius: 12px;
    border: 1px solid rgba(92, 110, 170, 0.14);
    background: #fff;
}

/* Открытый список — колонка выше соседней, иначе правая перекрывает подсказку слева */
.order-create-form .col-md-6.position-relative:has(.ac-suggest:not(.d-none)) {
    z-index: 5;
}

.order-create-section-head {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.15rem 1.35rem;
    background: linear-gradient(180deg, rgba(79, 109, 245, 0.06), transparent);
    border-bottom: 1px solid rgba(92, 110, 170, 0.1);
}

.order-create-section-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.15rem;
    color: var(--primary);
    background: rgba(79, 109, 245, 0.12);
    border: 1px solid rgba(79, 109, 245, 0.16);
}

.order-create-section-body {
    padding: 1.35rem 1.35rem 1.5rem;
}

.order-create-contact-stack .input-group .form-control {
    min-height: 2.75rem;
}

.order-create-vehicle-scroll {
    max-height: min(18rem, 42vh);
}

.order-create-actions {
    padding-bottom: 0.5rem;
}

.order-create-actions .btn-lg {
    font-weight: 600;
}

.manager-dashboard-actions {
    background: linear-gradient(135deg, rgba(79, 109, 245, 0.07), rgba(127, 86, 217, 0.06));
    border-color: rgba(79, 109, 245, 0.2);
}

.manager-orders-header .orders-total-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #32426d;
    background: rgba(79, 109, 245, 0.1);
    border: 1px solid rgba(79, 109, 245, 0.18);
}

.orders-toolbar .form-control,
.orders-toolbar .form-select,
.orders-toolbar .input-group-text {
    border-radius: 12px;
}

.orders-toolbar .input-group .form-control {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.orders-toolbar .input-group .input-group-text {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.orders-list-shell {
    box-shadow: var(--shadow-soft);
}

.orders-table-wrap {
    max-height: min(calc(100vh - 260px), 900px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.orders-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    font-size: 0.72rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.95));
    backdrop-filter: blur(8px);
    box-shadow: 0 1px 0 rgba(92, 110, 170, 0.12);
}

.orders-compact-table {
    font-size: 0.9rem;
}

.orders-compact-table tbody.order-group:nth-of-type(even) .order-row-summary td {
    background: rgba(79, 109, 245, 0.03);
}

.orders-col-id {
    width: 4.5rem;
}

.orders-col-date {
    width: 7rem;
}

.orders-col-expand {
    width: 3rem;
}

.order-row-summary .orders-expand-btn {
    padding: 0.25rem 0.45rem;
    line-height: 1;
}

.order-row-summary:hover .orders-expand-btn {
    background: rgba(79, 109, 245, 0.1) !important;
    border-color: rgba(79, 109, 245, 0.25) !important;
}

.orders-detail-panel {
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.65), rgba(255, 255, 255, 0.9));
}

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.orders-route-line {
    line-height: 1.25;
}

/* —— История рейсов (менеджер / водитель) —— */
.trip-history-details {
    border-radius: 12px;
    border: 1px solid rgba(92, 110, 170, 0.14);
    background: rgba(255, 255, 255, 0.92);
    overflow: hidden;
}

.trip-history-details > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #32426d;
    background: linear-gradient(180deg, rgba(79, 109, 245, 0.06), rgba(255, 255, 255, 0.4));
    user-select: none;
}

.trip-history-details > summary::-webkit-details-marker {
    display: none;
}

.trip-history-details > summary::after {
    content: "";
    width: 0.45rem;
    height: 0.45rem;
    border-right: 2px solid rgba(79, 109, 245, 0.55);
    border-bottom: 2px solid rgba(79, 109, 245, 0.55);
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-left: auto;
}

.trip-history-details[open] > summary::after {
    transform: rotate(-135deg);
    margin-top: 0.2rem;
}

.trip-history-details .trip-history-scroll {
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid rgba(92, 110, 170, 0.1);
    -webkit-overflow-scrolling: touch;
}

.trip-history-table {
    font-size: 0.8rem;
    margin-bottom: 0;
}

.trip-history-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #647196;
    background: linear-gradient(180deg, #f8fafc 96%, rgba(248, 250, 252, 0));
    border-bottom: 1px solid rgba(92, 110, 170, 0.12);
    white-space: nowrap;
    padding: 0.35rem 0.5rem;
}

.trip-history-table tbody td {
    padding: 0.4rem 0.5rem;
    vertical-align: middle;
    border-color: rgba(92, 110, 170, 0.08);
}

.trip-history-table .trip-history-actions .btn {
    padding: 0.12rem 0.45rem;
    font-size: 0.72rem;
}

.driver-trip-history-wrap {
    min-width: 0;
    max-width: 100%;
}

@media (max-width: 991.98px) {
    .orders-table-wrap {
        max-height: min(calc(100vh - 320px), 800px);
    }
}
