* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333;
}

.container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar h2 {
    margin-bottom: 30px;
    font-size: 24px;
}

.sidebar nav {
    margin-bottom: 30px;
}

.nav-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 16px;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateX(5px);
}

.nav-btn.active {
    background: rgba(255, 255, 255, 0.4);
    font-weight: bold;
    border-left: 4px solid white;
}

.status {
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 6px;
    font-size: 14px;
}

.status p {
    margin-bottom: 10px;
}

.status p:last-child {
    margin-bottom: 0;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
}

.main-content h1 {
    margin-bottom: 20px;
    color: #333;
}

.tab {
    display: none;
}

.tab.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Filters */
.filters {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filters input,
.filters select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.filters button {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.3s ease;
}

.filters button:hover {
    background: #764ba2;
}

/* Table */
.table-container {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead {
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
}

th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #495057;
}

td {
    padding: 12px;
    border-bottom: 1px solid #dee2e6;
}

tbody tr:hover {
    background: #f8f9fa;
}

/* Live Info */
.live-info {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.live-info h3 {
    margin-bottom: 15px;
    color: #333;
}

/* Report */
.report-section {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.report-section h3 {
    margin: 20px 0 10px 0;
    color: #333;
}

.checkpoint {
    background: #f8f9fa;
    padding: 12px;
    margin: 10px 0;
    border-radius: 6px;
    border-left: 3px solid #28a745;
}

.checkpoint.departure {
    border-left-color: #dc3545;
}

/* Settings */
.settings-form {
    background: white;
    padding: 20px;
    border-radius: 8px;
    max-width: 500px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.form-group small {
    display: block;
    margin-top: 4px;
    color: #999;
    font-size: 12px;
}

.settings-form button {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.3s ease;
}

.settings-form button:hover {
    background: #764ba2;
}

/* Скрытое остаётся скрытым, даже если у элемента свой display (flex у
   .money-bar): иначе форма смены пароля висела открытой постоянно. */
[hidden] { display: none !important; }

/* Status Indicators */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.status-badge.active {
    background: #d4edda;
    color: #155724;
}

.status-badge.completed {
    background: #cce5ff;
    color: #004085;
}

.status-badge.cancelled {
    background: #f8d7da;
    color: #721c24;
}

/* Action Buttons */
.action-btn {
    padding: 6px 12px;
    margin: 0 4px;
    border: none;
    background: #667eea;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s ease;
}

.action-btn:hover {
    background: #764ba2;
}

.actions-cell {
    white-space: nowrap;
}

/* Иконка карты: тот же размер, что у текстовых кнопок, но квадратная */
.action-btn.icon-btn {
    font-size: 15px;
    line-height: 1;
    padding: 6px 9px;
}

.action-btn.danger {
    background: #dc3545;
}

.action-btn.danger:hover {
    background: #c82333;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
    }

    .main-content {
        padding: 15px;
    }

    table {
        font-size: 12px;
    }

    th, td {
        padding: 8px;
    }
}

/* Loading state */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Success/Error messages */
/* Сообщения — поверх всего, включая карточку справа: иначе «Машина
   закреплена» пряталось под открытой панелью. */
.message {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2500;
    min-width: 280px;
    max-width: 90vw;
    padding: 12px 18px;
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
    animation: slideIn 0.3s ease;
}

.message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

@keyframes slideIn {
    from { transform: translate(-50%, -10px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* ================= Вход сотрудника ================= */

.login-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 1000;
}

.login-box {
    background: white;
    padding: 32px;
    border-radius: 10px;
    width: 320px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.login-box h2 { margin-bottom: 4px; }
.login-sub { color: #777; font-size: 13px; margin-bottom: 20px; }

.login-box input {
    width: 100%;
    padding: 11px;
    margin-bottom: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
}

.login-box button {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    cursor: pointer;
}

.login-box button:disabled { opacity: .6; cursor: default; }
.login-error { color: #dc3545; font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ================= Боковая панель ================= */

.user-box {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, .25);
    font-size: 13px;
}

.link-btn {
    background: none;
    border: none;
    color: white;
    text-decoration: underline;
    cursor: pointer;
    padding: 4px 0;
    font-size: 13px;
}

/* Счётчик новых анкет прямо в меню: диспетчер видит их, не заходя в раздел */
.badge {
    display: none;
    background: #dc3545;
    color: white;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 12px;
    margin-left: 6px;
}

/* ================= Карточка водителя ================= */

.driver-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .1);
}

.driver-card h4 { margin: 18px 0 8px; }

.driver-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 8px;
}

.driver-grid > div {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 6px;
    font-size: 13px;
}

.doc-thumbs { display: flex; flex-wrap: wrap; gap: 12px; }

.doc-thumb {
    margin: 0;
    width: 190px;
    text-align: center;
    font-size: 12px;
}

.doc-thumb img {
    width: 100%;
    height: 130px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: #f0f0f0;
    cursor: zoom-in;
}

.doc-thumb img:hover { opacity: .85; }

.history { font-size: 13px; }

.history-row {
    display: grid;
    grid-template-columns: 150px 200px 130px 1fr;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #eee;
}

.approve-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #eee;
    flex-wrap: wrap;
}

.approve-bar input {
    flex: 1;
    min-width: 200px;
    padding: 9px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.vehicle-row {
    padding: 8px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Статусы водителя — те же цвета, что у статусов рейса */
.status-badge.pending   { background: #fff3cd; color: #856404; }
.status-badge.approved  { background: #d4edda; color: #155724; }
.status-badge.rejected  { background: #f8d7da; color: #721c24; }
.status-badge.suspended { background: #e2e3e5; color: #383d41; }

/* Шапка карточки водителя: заголовок и кнопка закрытия по краям. */
.driver-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.driver-card-head h3 { margin: 0; }

/* Просмотр снимка документа во весь экран. */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, .85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    cursor: zoom-out;
}

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.lightbox-bar {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.lightbox-status { color: #fff; font-size: 14px; }

.lightbox-btn {
    padding: 8px 16px;
    border: 0;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 14px;
}

.lightbox-btn:disabled { opacity: .6; cursor: default; }

/* ---------------------------------------------------------------- рейсы */

/* Метка машины на карте: номер, красная — гружёная, зелёная — пустая. */
.truck-marker { background: transparent; border: 0; display: flex; justify-content: center; }
.truck-pin {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    border: 2px solid #fff;
    font: 700 12px/1.3 system-ui, sans-serif;
    color: #fff;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.truck-pin.loaded { background: #d62828; }
.truck-pin.empty  { background: #2a9d4a; }
.truck-pin.idle   { background: #6c757d; }
.truck-pin.inline { box-shadow: none; border: 0; margin-left: 8px; font-size: 11px; }

.map-legend { display: flex; gap: 6px; align-items: center; margin: -8px 0 18px; }

.status-badge.loaded { background: #f8d7da; color: #842029; }
.status-badge.empty  { background: #d1e7dd; color: #0f5132; }

.section-title { margin: 28px 0 12px; font-size: 18px; }

.money-bar,
.danger-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.danger-bar { border-top: 1px solid #eee; margin-top: 20px; padding-top: 14px; }

.warn-line { color: #842029; background: #f8d7da; padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.muted { color: #8a8f98; }

.routes-table th,
.routes-table td { padding: 6px 10px; }
.route-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
    margin-top: 12px;
    align-items: center;
}

/* ================= Карточка панелью справа ================= */

.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(900px, 100vw);
    overflow-y: auto;
    z-index: 1500;
    background: #f5f6fa;
    padding: 16px;
    box-shadow: -8px 0 30px rgba(0, 0, 0, .2);
    animation: panelIn .2s ease;
}

.panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1400;
    background: rgba(0, 0, 0, .35);
}

@keyframes panelIn {
    from { transform: translateX(40px); opacity: 0; }
    to { transform: none; opacity: 1; }
}

/* На белой карточке белая «ссылка» из боковой панели была не видна. */
.close-btn {
    border: 1px solid #ccc;
    background: white;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.close-btn:hover { background: #f0f0f0; }

tr.clickable, .vehicle-row.clickable { cursor: pointer; }
tr.clickable:hover td, .vehicle-row.clickable:hover { background: #f3f5ff; }

/* Статус в карточке — крупно: это первое, что ищет диспетчер. */
.status-badge.big {
    font-size: 15px;
    font-weight: 700;
    padding: 5px 12px;
}

.badge.money { background: #f0ad4e; }

.muted { color: #888; }
.ok-text { color: #198754; }
.warn-text { color: #dc3545; }

.hint-icon {
    display: inline-block;
    width: 15px;
    height: 15px;
    line-height: 15px;
    border-radius: 50%;
    background: #ccc;
    color: white;
    font-size: 11px;
    text-align: center;
    cursor: help;
}

/* ================= Смартфон водителя ================= */

.os-icon { vertical-align: -4px; margin-right: 4px; }
.device-cell { font-size: 12px; line-height: 1.4; }
.device-cell small { color: #777; }

.chip {
    display: inline-block;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 9px;
    margin: 3px 3px 0 0;
    white-space: nowrap;
}

.chip.warn { background: #f8d7da; color: #842029; }
.chip.ok { background: #d1e7dd; color: #0f5132; }

/* ================= Прежние снимки, выбор машины ================= */

details.prev-docs { margin-top: 12px; }
details.prev-docs summary { cursor: pointer; color: #667eea; margin-bottom: 10px; }

.vehicle-picker input {
    width: 100%;
    max-width: 380px;
    padding: 10px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 6px;
}

.vehicle-results {
    max-height: 380px;
    overflow-y: auto;
    margin-top: 6px;
    background: white;
    border-radius: 6px;
}

/* ================= Удаление ================= */

.doc-thumb { position: relative; }

.doc-del {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
    cursor: pointer;
    font-size: 14px;
}

.doc-del:hover { background: #f8d7da; }

.trash-thumbs { display: flex; gap: 4px; margin-bottom: 4px; }

.trash-thumbs img {
    width: 64px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    background: #eee;
}

.days-left.soon { color: #dc3545; font-weight: 600; }

/* ================= Подразделы, пользователи, роли ================= */

.subtabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 18px;
    border-bottom: 1px solid #e3e3e3;
}

.subtab {
    border: 0;
    border-bottom: 3px solid transparent;
    background: none;
    padding: 9px 14px;
    cursor: pointer;
    font-size: 14px;
    color: #666;
}

.subtab:hover { color: #333; }
.subtab.active { color: #333; font-weight: 600; border-bottom-color: #667eea; }

.role-card {
    background: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.role-card h3 { margin: 0 0 6px; }

.role-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }

.role-name {
    min-width: 240px;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 17px;
    font-weight: 600;
}

.perm-groups {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.perm-groups fieldset { border: 1px solid #e3e3e3; border-radius: 6px; padding: 8px 12px; }
.perm-groups legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
.perm-groups label { display: block; font-size: 13px; padding: 3px 0; cursor: pointer; }

/* ================= Заряд телефона ================= */

.battery { white-space: nowrap; font-size: 13px; }
.battery-icon { vertical-align: -2px; margin-right: 4px; }
.battery.low { color: #dc3545; font-weight: 700; }
.battery.stale { opacity: .55; }
.battery-line { margin: 4px 0; font-size: 13px; }
