:root {
    --primary: #1e3a8a;
    --primary-hover: #1e40af;
    --accent: #2563eb;
    --success: #059669;
    --success-light: #ecfdf5;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Навигация */
.top-nav {
    background: #0f274a;
    color: #fff;
    padding: 10px 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}
.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.brand-section {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-badge {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    padding: 4px 8px;
    border-radius: 6px;
    text-transform: uppercase;
}
.brand-title .main-title {
    display: block;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.5px;
}
.brand-title .sub-title {
    display: block;
    font-size: 11px;
    color: #94a3b8;
}

.nav-links {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.nav-item {
    color: #cbd5e1;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 8px;
    transition: all 0.2s;
}
.nav-item:hover, .nav-item.active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.user-block {
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-meta {
    text-align: right;
    font-size: 12px;
}
.user-name {
    display: block;
    font-weight: 700;
    color: #fff;
}
.user-role {
    color: #93c5fd;
    font-size: 11px;
}
.btn-logout {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.4);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    text-decoration: none;
    font-weight: 600;
}
.btn-logout:hover { background: #dc2626; color: #fff; }

/* Контейнер */
.main-container {
    max-width: 1400px;
    width: 100%;
    margin: 16px auto;
    padding: 0 16px;
    flex: 1;
}

/* Кнопки */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    min-height: 42px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline-success { background: #fff; border: 1.5px solid #10b981; color: #065f46; }
.btn-outline-success:hover { background: #ecfdf5; }
.btn-block { width: 100%; }
.btn-lg { font-size: 15px; padding: 12px 22px; font-weight: 700; }
.btn-sm { font-size: 12px; padding: 6px 12px; border-radius: 6px; min-height: 32px; }

/* Карточки */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.card-header {
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

/* Формы */
.form-group, .form-row { margin-bottom: 14px; }
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 6px;
}
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=tel], select {
    width: 100%;
    font-size: 15px;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text-main);
    font-family: inherit;
    min-height: 46px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.form-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}
.help-text {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Логин */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 180px);
}
.login-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 30px 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}
.login-header { text-align: center; margin-bottom: 22px; }
.login-icon { font-size: 36px; margin-bottom: 6px; }
.login-header h2 { font-size: 19px; font-weight: 800; color: #0f274a; }
.login-header p { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.login-footer {
    margin-top: 22px;
    font-size: 11px;
    color: #94a3b8;
    text-align: center;
    line-height: 1.4;
    border-top: 1px solid #f1f5f9;
    padding-top: 12px;
}

/* Алерт */
.alert {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13.5px;
    margin-bottom: 14px;
}
.alert-error { background: var(--danger-light); border: 1px solid #fca5a5; color: #991b1b; }
.alert-success { background: var(--success-light); border: 1px solid #a7f3d0; color: #065f46; }

/* Панель управления */
.control-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}
.panel-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.station-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}
.st-icon { font-size: 22px; }
.st-name { display: block; font-size: 14.5px; color: #0f274a; }
.st-details { font-size: 12px; color: var(--text-muted); }

.date-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.date-group input[type=date] { width: auto; font-weight: 700; min-height: 40px; }
.quick-dates { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-chip {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #334155;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    min-height: 34px;
}
.btn-chip:hover { background: #e2e8f0; }
.btn-chip-highlight {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
    font-weight: 700;
}

/* Баннер правил */
.rule-banner {
    background: #eff6ff;
    border: 1.5px solid #bfdbfe;
    border-left: 5px solid var(--accent);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 13px;
}
.rule-icon { font-size: 20px; flex-shrink: 0; }
.rule-text ul { margin-left: 18px; margin-top: 4px; }
.rule-text li { margin-bottom: 3px; }

/* Статистика */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.stat-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}
.stat-num {
    display: block;
    font-size: 24px;
    font-weight: 800;
    color: #0f172a;
}
.stat-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); }
.stat-primary .stat-num { color: var(--accent); }
.stat-repeat .stat-num { color: #8b5cf6; }
.stat-free .stat-num { color: var(--success); }
.stat-danger .stat-num { color: var(--danger); }

/* Сетка слотов */
.schedule-section {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 22px;
    box-shadow: var(--shadow);
}
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}
.section-header h3 { font-size: 16px; font-weight: 700; color: #0f274a; }
.legend { display: flex; gap: 12px; font-size: 12px; color: #475569; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.box { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.box-free { background: #ecfdf5; border: 1.5px solid #10b981; }
.box-booked { background: #eff6ff; border: 1.5px solid #3b82f6; }
.box-repeat { background: #f5f3ff; border: 1.5px solid #8b5cf6; }

.slots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}
.slot-card {
    border-radius: 10px;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.slot-card.free { background: #fafafa; border-style: dashed; }
.slot-card.booked {
    background: #ffffff;
    border-color: #93c5fd;
    border-left: 4px solid var(--accent);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.08);
}
.slot-card.repeat-border { border-left-color: #8b5cf6; }
.slot-time { font-size: 17px; font-weight: 800; color: #0f274a; margin-bottom: 6px; }
.vehicle-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.plate-number {
    font-size: 14.5px;
    font-weight: 800;
    letter-spacing: 1px;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
}
.cat-badge { font-size: 11px; font-weight: 700; padding: 2px 5px; border-radius: 4px; }
.cat-M3 { background: #fef3c7; color: #92400e; }
.cat-M2 { background: #e0e7ff; color: #3730a3; }
.badge { font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 4px; }
.badge-primary { background: #dbeafe; color: #1e40af; }
.badge-repeat { background: #ede9fe; color: #6d28d9; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-error { background: #fee2e2; color: #991b1b; }

.vehicle-model { font-size: 13.5px; font-weight: 600; color: #1e293b; margin-bottom: 2px; }
.vehicle-vin { font-size: 11.5px; color: var(--text-muted); margin-bottom: 6px; }
.vehicle-vin code { background: #f1f5f9; padding: 1px 4px; border-radius: 4px; }
.applicant-info { font-size: 12px; color: #334155; margin-bottom: 6px; }
.slot-station { font-size: 11px; color: #64748b; margin-bottom: 6px; }
.slot-empty { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.slot-actions { display: flex; justify-content: flex-end; border-top: 1px solid #f1f5f9; padding-top: 6px; margin-top: 4px; }
.btn-action-cancel { background: none; border: none; color: #dc2626; font-size: 12px; font-weight: 600; cursor: pointer; padding: 4px 0; }

/* Поиск */
.search-section {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.search-bar { display: flex; gap: 8px; margin-top: 10px; }
.search-bar input { flex: 1; }

/* Таблицы */
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; margin-top: 10px; min-width: 650px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; text-align: left; }
.table th { background: #f8fafc; font-weight: 600; color: #475569; }

/* Модальные окна */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 12px;
}
.modal-overlay.active { display: flex; }
.modal-card {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 680px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    position: relative;
}
.modal-card form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.modal-header {
    background: #0f274a;
    color: #fff;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.modal-header h3 { font-size: 15.5px; font-weight: 700; }
.btn-close { background: none; border: none; color: #cbd5e1; font-size: 22px; cursor: pointer; padding: 4px; line-height: 1; }
.btn-close:hover { color: #fff; }
.modal-body {
    padding: 18px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
    min-height: 0;
}
.modal-footer {
    background: #f8fafc;
    border-top: 1.5px solid var(--border);
    padding: 14px 18px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 20;
    box-shadow: 0 -3px 10px rgba(0,0,0,0.04);
}

.btn-action-edit {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    font-size: 11.5px;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.btn-action-edit:hover {
    background: #dbeafe;
    border-color: #93c5fd;
}
.checkbox-highlight {
    background: #f8fafc;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
}
.date-validation-hint { font-size: 12px; margin-top: 4px; font-weight: 600; }
.date-validation-hint.valid { color: #059669; }
.date-validation-hint.invalid { color: #dc2626; }

/* Подвал */
.footer {
    background: #0f274a;
    color: #94a3b8;
    font-size: 11.5px;
    padding: 14px 16px;
    margin-top: 25px;
}
.footer-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

/* --- АДАПТАЦИЯ ПОД ТЕЛЕФОНЫ И ПЛАНШЕТЫ --- */
@media (max-width: 768px) {
    .main-container { padding: 0 10px; margin: 10px auto; }
    .control-panel { padding: 12px; flex-direction: column; align-items: stretch; gap: 12px; }
    .panel-left { flex-direction: column; align-items: stretch; gap: 12px; }
    .date-group { flex-direction: column; align-items: stretch; }
    .date-group input[type=date] { width: 100%; }
    .quick-dates { overflow-x: auto; padding-bottom: 4px; }
    .btn-mobile-block { width: 100%; }
    .slots-grid { grid-template-columns: 1fr; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; gap: 0; }
    .modal-card { max-height: 96vh; }
    .modal-body { padding: 14px; }
    .nav-container { flex-direction: column; align-items: stretch; gap: 10px; }
    .nav-links { justify-content: space-between; width: 100%; }
    .nav-item { flex: 1; text-align: center; padding: 8px 4px; font-size: 12px; }
    .user-block { justify-content: space-between; width: 100%; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 8px; }
}

/* Стилизация обеденного перерыва и раздельных периодов */
.lunch-break-divider {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 1.5px dashed #f59e0b;
    border-radius: 10px;
    padding: 12px 16px;
    margin: 16px 0;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 1px 3px rgba(245, 158, 11, 0.1);
}
.lunch-break-divider .lunch-icon {
    font-size: 26px;
    line-height: 1;
}
.lunch-break-divider .lunch-title {
    font-size: 13.5px;
    font-weight: 800;
    color: #92400e;
    letter-spacing: 0.2px;
}
.lunch-break-divider .lunch-desc {
    font-size: 12px;
    color: #b45309;
    margin-top: 2px;
}
.period-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 6px;
}
.period-header h4 {
    font-size: 14.5px;
    font-weight: 800;
    color: #1e3a8a;
    display: flex;
    align-items: center;
    gap: 6px;
}
.empty-period-note {
    text-align: center;
    padding: 18px 12px;
    background: #f8fafc;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: #64748b;
    font-size: 13px;
    font-style: italic;
}

/* Стилизация выбора рабочих дней станции */
.day-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    color: #1e293b;
    transition: all 0.15s ease;
}
.day-chip input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}
.day-chip:hover {
    border-color: #94a3b8;
    background: #f8fafc;
}

/* Поля с кнопкой быстрого поиска / декодера */
.input-with-btn {
    display: flex;
    gap: 6px;
    align-items: stretch;
}
.input-with-btn input {
    flex: 1;
    min-width: 0;
}
.btn-side {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #0f274a;
    color: #ffffff;
    border: 1px solid #1e3a5f;
    border-radius: 6px;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}
.btn-side:hover {
    background: #1e3a5f;
    color: #ffffff;
}
.btn-side:active {
    transform: scale(0.97);
}
