:root {
    --primary: #2563eb;
    --sidebar: #172033;
    --background: #f3f6fb;
    --border: #e5e9f0;
    --text: #243047;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family: system-ui, -apple-system, sans-serif;
}

.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 245px;
    background: var(--sidebar);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
}

.sidebar-brand {
    font-size: 22px;
    font-weight: 700;
    padding: 25px 22px;
    border-bottom: 1px solid #ffffff15;
}

.sidebar-nav {
    padding: 18px 12px;
    flex: 1;
}

.sidebar-nav a {
    display: block;
    color: #cbd5e1;
    text-decoration: none;
    padding: 13px 16px;
    border-radius: 9px;
    margin-bottom: 5px;
    font-size: 15px;
}

.sidebar-nav a:hover {
    background: #ffffff15;
    color: white;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid #ffffff15;
}

.main-content {
    margin-left: 245px;
    width: calc(100% - 245px);
    min-width: 0;
}

.topbar {
    height: 76px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
}

.topbar-title {
    font-size: 21px;
    font-weight: 650;
}

.content-container {
    padding: 30px;
    max-width: 1600px;
    margin: auto;
}

.card {
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 3px 12px #15223808;
}

.stat-card {
    padding: 22px;
    background: white;
    border-radius: 14px;
    border: 1px solid var(--border);
}

.stat-label {
    color: #64748b;
    font-size: 14px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-top: 8px;
}

.table {
    vertical-align: middle;
}

.table th {
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
    background: #f8fafc;
}

.table td {
    padding-top: 14px;
    padding-bottom: 14px;
}

.btn {
    border-radius: 9px;
}

.btn-primary {
    background: var(--primary);
}

.form-control,
.form-select {
    border-radius: 9px;
    min-height: 42px;
}

.vehicle-photo {
    width: 100%;
    max-height: 320px;
    object-fit: cover;
    border-radius: 12px;
}

.mobile-nav {
    display: none;
}

@media (max-width: 850px) {

    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .topbar {
        height: 65px;
        padding: 0 16px;
    }

    .topbar-title {
        font-size: 18px;
    }

    .content-container {
        padding: 16px;
        padding-bottom: 95px;
    }

    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 70px;
        background: white;
        border-top: 1px solid var(--border);
        justify-content: space-around;
        align-items: center;
        z-index: 1000;
    }

    .mobile-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        color: #64748b;
        font-size: 19px;
        gap: 3px;
    }

    .mobile-nav span {
        font-size: 11px;
    }

    .stat-value {
        font-size: 23px;
    }

    .desktop-table {
        display: none;
    }
}

@media (min-width: 851px) {

    .mobile-cards {
        display: none;
    }
}

/* ================= Дополнения: формы и модальные окна ================= */

.sidebar-brand {
    display: block;
    color: #fff;
    text-decoration: none;
}

.sidebar-brand:hover {
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--primary);
    color: #fff;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    gap: 12px;
}

.topbar-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-actions {
    flex-shrink: 0;
}

.min-w-0 {
    min-width: 0;
}

.form-page {
    max-width: 900px;
    margin: 0 auto;
}

/* Форма внутри modal-content: прокручивается тело, шапка и кнопки на месте */
.modal-content > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

/* Подсветка полей с ошибками (Django 5 ставит aria-invalid) */
[aria-invalid="true"] {
    border-color: #dc3545 !important;
}

/* Виды работ «чипами» */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chips .btn {
    border-radius: 999px;
}

/* Tom Select под общий стиль */
.ts-wrapper .ts-control {
    min-height: 42px;
    border-radius: 9px;
}

.ts-dropdown {
    border-radius: 9px;
}

/* Файлы заказ-наряда */
.attachment-thumb {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 8px;
}

.attachment-file {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 2.5rem;
    text-decoration: none;
}

.toast-box {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1100;
}

.offcanvas-menu a {
    display: block;
    padding: 14px 4px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: 16px;
}

@media (max-width: 850px) {

    .mobile-nav button {
        display: flex;
        flex-direction: column;
        align-items: center;
        background: none;
        border: 0;
        color: #64748b;
        font-size: 19px;
        gap: 3px;
    }

    .toast-box {
        left: 16px;
        right: 16px;
        bottom: 86px;
    }

    .topbar .btn {
        padding: 6px 12px;
    }

    /* Кнопки «Сохранить» всегда видны внизу полноэкранной формы */
    .modal-fullscreen-md-down .modal-footer {
        position: sticky;
        bottom: 0;
        background: #fff;
    }
}