﻿/* ─────────────────────────────────────────────────────
   Глобальные CSS-переменные, сброс и базовый layout.
   Подключается первым в base.html.
───────────────────────────────────────────────────── */

/* ── Токены дизайн-системы ── */
:root {
    /* Цвета */
    --bg: #f6f7fb;
    --surface: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-interactive: #b0b7c3;  /* интерактивные контейнеры: кнопки, карточки маршрута, дропдауны */
    --border-input:       #a0a8b4;  /* поля ввода в покое */
    --border-input-hover: #8b94a6;  /* поля ввода при hover */
    --hover: #f8fafc;
    --hover-active: #eef6ff;

    /* Акцент */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;

    /* Деструктивные действия */
    --danger: #dc2626;
    --danger-hover: #b91c1c;

    /* Наложения и специальные поверхности */
    --modal-overlay:       rgba(0, 0, 0, 0.4);
    --surface-translucent: rgba(255, 255, 255, 0.92);
    --hover-inverse:       rgba(0, 0, 0, 0.05);
    --primary-ring:        rgba(37, 99, 235, 0.3);

    /* Типографика (шкала ×1.25 — major third) */
    --text-xs:   0.75rem;   /* 12px — бейджи, хедеры таблиц */
    --text-sm:   0.875rem;  /* 14px — метки форм, подписи, вспомогательный текст */
    --text-base: 1rem;      /* 16px — тело, значения, заголовки секций (через weight) */
    --text-lg:   1.25rem;   /* 20px — заголовки карточек / компонентов */
    --text-xl:   1.5rem;    /* 24px — заголовок страницы */

    /* Геометрия */
    --radius: 12px;
    --radius-sm: 10px;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    --container: 1200px;

    /* Z-index слои (не использовать магические числа) */
    --z-sticky-cell:      20;
    --z-sticky-header:    30;
    --z-sticky-actions:   40;
    --z-navbar:           50;
    --z-toast:            70;
    --z-inline-dropdown: 200;
    --z-modal:          1000;
    --z-autocomplete:   1100;
    --z-filter-dropdown:1200;
    --z-column-panel:   1300;
    --z-actions-menu:   1400;

    /* Семантические состояния */
    --success-text:   #16a34a;
    --success-bg:     #f0fdf4;
    --success-border: #bbf7d0;

    --warning-text:   #d97706;
    --warning-bg:     #fffbeb;
    --warning-border: #fde68a;

    --error-text:     #dc2626;
    --error-bg:       #fef2f2;
    --error-border:   #fecaca;

    --info-text:      #0e7490;
    --info-bg:        #ecfeff;
    --info-border:    #a5f3fc;

    --neutral-text:   #6b7280;
    --neutral-bg:     #f3f4f6;
    --neutral-border: #e5e7eb;
}

/* ── Сброс ── */
* {
    box-sizing: border-box;
}

/* Браузер не наследует font-family для form-элементов — фиксируем глобально */
button, input, select, textarea {
    font-family: inherit;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}

a {
    color: inherit;
    text-decoration: none;
}

/* ── Layout shell ── */
.app-shell {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

main {
    width: 100%;
    margin: 0;
    padding: 8px 8px 10px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ── Состояния фокуса (доступность) ── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--primary-ring);
    outline-offset: 1px;
}

/* ── Состояния валидации полей ── */
input.is-invalid,
select.is-invalid,
textarea.is-invalid,
input.is-invalid:focus,
select.is-invalid:focus,
textarea.is-invalid:focus {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12) !important;
}

/* Autocomplete: скрытый select.is-invalid → подсвечиваем видимый input */
.autocomplete-container:has(select.is-invalid) .autocomplete-input,
.autocomplete-container:has(select.is-invalid) .autocomplete-input:focus {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12) !important;
}

/* ── Модальное окно ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: 16px;
}

.modal-overlay[hidden] {
    display: none;
}

.modal-dialog {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    padding: 24px;
    max-width: 420px;
    width: 100%;
}

.modal-title {
    margin: 0 0 8px;
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text);
}

.modal-body {
    margin: 0 0 20px;
    font-size: var(--text-sm);
    color: var(--muted);
    line-height: 1.5;
}

.modal-dialog--wide {
    max-width: 520px;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

/* ── Поля формы внутри модалки ── */
.modal-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 16px;
}

.modal-field {
    min-width: 0;
}

.modal-field--full {
    grid-column: 1 / -1;
}

.modal-field-row {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.modal-field label {
    display: block;
    margin-bottom: 5px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text);
}

.modal-field input[type="text"],
.modal-field input[type="tel"],
.modal-field input[type="number"],
.modal-field select {
    width: 100%;
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    padding: 9px 12px;
    font-size: var(--text-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
}

.modal-field input:hover,
.modal-field select:hover {
    border-color: var(--border-input-hover);
}

.modal-field input:focus,
.modal-field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.modal-field input.is-invalid,
.modal-field select.is-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.modal-field-error {
    margin: 4px 0 0;
    font-size: var(--text-xs);
    color: var(--danger);
    line-height: 1.3;
}

.modal-field-hint {
    display: block;
    margin: 4px 0 0;
    font-size: var(--text-xs);
    color: var(--muted);
    line-height: 1.3;
}

/* ── Строка ИНН с кнопкой (в модалках и формах) ── */
.inn-row {
    display: flex;
    gap: 8px;
}

.inn-row input {
    flex: 1;
    min-width: 0;
}

.modal-form-errors {
    margin-bottom: 14px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--danger);
    font-size: var(--text-sm);
}

/* ── Suggest-дропдаун (автокомплит в модалках) ── */
.suggest-wrap {
    position: relative;
}

.suggest-wrap input {
    padding-right: 34px;
}

.suggest-spinner {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    pointer-events: none;
}

.suggest-spinner.active {
    display: block;
}

.suggest-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 3px);
    left: 0;
    right: 0;
    z-index: var(--z-inline-dropdown);
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.1);
    max-height: 230px;
    overflow-y: auto;
}

.suggest-dropdown.visible {
    display: block;
}

.suggest-item {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    cursor: pointer;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s ease;
}

.suggest-item:last-child {
    border-bottom: none;
}

.suggest-item:hover,
.suggest-item.is-active {
    background: var(--hover);
}

.suggest-item-title {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.suggest-item-sub {
    font-size: var(--text-xs);
    color: var(--muted);
}

/* ── Выбранное значение (автокомплит → selected row) ── */
.selected-row[hidden] {
    display: none;
}

.selected-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: var(--hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.selected-row-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.selected-row-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text);
}

.selected-row-sub {
    font-size: var(--text-xs);
    color: var(--muted);
}

.selected-row-action {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0;
    font-size: var(--text-xs);
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.15s ease;
}

.selected-row-action:hover {
    color: var(--primary-hover);
}

.selected-row--success {
    background: var(--success-bg);
    border-color: var(--success-border);
}

.selected-row--warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
}

.selected-row--success .selected-row-check {
    display: inline-flex;
}

.selected-row--warning .selected-row-check {
    display: none;
}

.selected-row-check {
    display: none;
    flex-shrink: 0;
}

/* ── Ссылка-кнопка «Ввести вручную» ── */
.suggest-manual-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: var(--text-xs);
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    transition: color 0.15s ease;
}

.suggest-manual-link:hover {
    color: var(--primary-hover);
}

@media (max-width: 560px) {
    main {
        padding: 10px 10px 16px;
    }

    .modal-fields {
        grid-template-columns: 1fr;
    }

    .modal-field-row {
        grid-template-columns: 1fr;
    }
}

/* ── Site footer ── */
.site-footer {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 24px 16px;
    font-size: var(--text-sm);
}

.site-footer a {
    color: var(--muted);
    text-decoration: none;
    transition: color 0.15s ease;
}

.site-footer a:hover {
    color: var(--text);
}

/* ─────────────────────────────────────────────────────────────────────
   Зоны тулбара списковых страниц (Pattern B: trips/invoicing/bank)

   Используется в парe с .list-toolbar (flex-контейнер, чьё определение
   остаётся в локальных CSS каждого списка, потому что Pattern A
   (contracts/organizations/persons/vehicles/waybills) использует другую
   раскладку .list-toolbar с .list-toolbar-left / .list-toolbar-right).

   Унификация Pattern A ↔ Pattern B — отдельный техдолг.
   ───────────────────────────────────────────────────────────────────── */
.toolbar-zone-title {
    flex-shrink: 0;
}

.toolbar-zone-filters {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-zone-filters > .active-filters {
    flex-basis: 100%;
}

.toolbar-zone-action {
    flex-shrink: 0;
    margin-left: auto;
}
