/* CRM Надежда — дизайн-токены (переменные) и стили вне Tailwind-билда.
   Значения — из redesign_plan/README.md «Дизайн-токены».
   Этот файл подключается в <head> рядом со static/tw.css. tw.css резолвит
   имена классов через Tailwind @apply, app.css задаёт переменные для них. */

:root {
    /* поверхности и текст (светлая тема) */
    --bg:        #eef1f6;
    --surface:   #ffffff;
    --surface-2: #f7f9fc;
    --ink:       #1a2233;
    --ink-2:     #55617a;
    --ink-3:     #8b96ad;
    --border:    #e2e7f0;
    --border-2:  #d3dae6;
    --accent:    #2563eb;   /* синий Надежды (НЕ кобальт источника) */
    --accent-ink:#1e40af;
    --accent-sf: #eff6ff;   /* мягкий фон акцента */
    /* сигнальные */
    --good: #12916a;
    --warn: #c9820f;
    --bad:  #d1495b;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg:        #0e131f;
    --surface:   #161d2c;
    --surface-2: #1b2233;
    --ink:       #e7ecf5;
    --ink-2:     #9aa6bd;
    --ink-3:     #6b7689;
    --border:    #232b3d;
    --border-2:  #2d3650;
    --accent:    #3b82f6;   /* светлее для контраста на тёмном */
    --accent-ink:#93c5fd;
    --accent-sf: #1e293b;
    --good: #3fbe93;
    --warn: #e0a53f;
    --bad:  #ec6c7d;
    color-scheme: dark;
}

/* ── Пилюли в тёмной теме: приглушённые фоны, чтобы не «горели» ── */
[data-theme="dark"] .pill-new        { background: #222b3c; }
[data-theme="dark"] .pill-in_progress{ background: #1a2947; }
[data-theme="dark"] .pill-done       { background: #0f3025; }
[data-theme="dark"] .pill-issued     { background: #241d3d; }
[data-theme="dark"] .pill-scheduled  { background: #1a2947; }
[data-theme="dark"] .pill-cancelled  { background: #361a20; }

/* ── Системные форм-контролы в тёмной теме: нативный appearance мешает ── */
[data-theme="dark"] input:not([type=submit]):not([type=button]):not([type=checkbox]):not([type=radio]):not([type=date]),
[data-theme="dark"] select, [data-theme="dark"] textarea {
    -webkit-appearance: none; appearance: none;
    background-color: #1b2233; color: #e7ecf5; border-color: #2d3650;
}
[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7689' d='M4 6l4 4 4-4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .6rem center; padding-right: 1.8rem;
}
[data-theme="dark"] input::placeholder, [data-theme="dark"] textarea::placeholder { color: #6b7689; opacity: 1; }

/* ── Скроллбары под тему ── */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 6px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-track { background: transparent; }

/* ── Sidebar scroll: flex-item default min-height:auto не даёт .side-nav
   сжаться ниже контента → overflow-y:auto не срабатывает, низ меню обрезается.
   min-height:0 + overflow-y:auto — меню скроллится, бренд/футер остаются на месте. */
.app-side {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}
.app-side .side-nav {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
@media (max-width: 980px) {
    .app-side .side-nav {
        flex: none;
        overflow: visible;
    }
}

/* ── Печать: скрываем sidebar/topbar, контент на всю ширину ── */
@media print {
    .app-side, .app-top, #toasts, #app-modal { display: none !important; }
    .app-grid { grid-template-columns: 1fr !important; }
    .app-main { max-width: 100% !important; padding: 0 !important; }
    body { background: #fff !important; color: #000 !important; }
}

/* ── Адаптив контентных сеток (без пересборки Tailwind) ──
   display:grid задаём здесь явно — не зависим от утилиты Tailwind .grid
   (иначе grid-template-columns без display:grid игнорируется → «лесенка»). */
[data-cols] { display: grid; gap: 16px; }
[data-cols] > * { min-width: 0; }
[data-cols="2-1"] { grid-template-columns: minmax(0, 1fr) minmax(240px, 320px); }
[data-cols="2-340"] { grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); }
[data-cols="1.6-1"] { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
[data-cols="form-3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
[data-cols="form-4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
[data-cols="kpi-4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.dash-kpi {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    align-items: stretch;
    margin-bottom: 20px;
}
.dash-kpi .kpi { height: 100%; }

.dash-mid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    gap: 20px;
    align-items: start;
    margin-bottom: 20px;
}

/* Chart-first дашборд — современная раскладка */
.dash { display: flex; flex-direction: column; gap: 18px; }
.dash-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 10px 16px;
}
.dash-range { margin: 0; font-size: 13px; color: var(--ink-3); }
.dash-period {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 1px 2px rgba(26, 34, 51, 0.04);
}
.dash-period-btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
    text-decoration: none;
    transition: background .15s, color .15s, box-shadow .15s;
}
.dash-period-btn:hover { color: var(--ink); background: var(--surface-2); }
.dash-period-btn.is-active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}
.dash-custom-range {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
}
.dash-date-lbl {
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-3);
}
.dash-date-inp {
    width: auto;
    min-width: 9.5rem;
    padding: 6px 10px;
    font-size: 13px;
}
.dash-metrics {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    align-items: stretch;
}
.dash-metric {
    display: grid;
    grid-template-rows: 1.25rem 2.75rem 1.2rem;
    row-gap: 6px;
    align-content: start;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(26, 34, 51, 0.04);
    min-width: 0;
    height: 100%;
    min-height: 108px;
    box-sizing: border-box;
}
.dash-metric-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--ink-3);
    text-transform: none;
    line-height: 1.25rem;
    height: 1.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.dash-metric-value {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    gap: 0;
    height: 2.75rem;
    min-height: 2.75rem;
    max-height: 2.75rem;
    font-size: 1.125rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    line-height: 1.35;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.dash-metric-hint {
    display: block;
    font-size: 11px;
    color: var(--ink-3);
    line-height: 1.2rem;
    height: 1.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.dash-metric-warn { color: var(--warn); }
.dash-metric-mix {
    font-size: 1.125rem;
    line-height: 1.35;
    white-space: normal;
}
.dash-metric-mix > span {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.dash-metric-split { display: none; }
.dash .card {
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(26, 34, 51, 0.04), 0 8px 24px rgba(26, 34, 51, 0.04);
}
.dash-hero-chart { margin: 0; }
.dash-charts-row {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 16px;
    align-items: stretch;
    margin: 0;
}
.dash-charts-row > * { min-width: 0; }
.dash-chart {
    position: relative;
    height: 280px;
    padding: 8px 16px 18px;
    background: linear-gradient(180deg, transparent 0%, var(--surface-2) 140%);
}
.dash-chart-lg { height: 360px; }
.dash-chart-doughnut { height: 280px; max-width: 440px; margin: 0 auto; }
.dash-funnel {
    min-height: 240px;
    justify-content: center;
    padding: 16px 18px 20px;
    gap: 10px;
}
.dash-funnel .frow {
    display: grid;
    grid-template-columns: 88px 1fr 28px;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 12px;
    transition: background .15s;
}
.dash-funnel .frow:hover { background: var(--surface-2); }
.dash-funnel .fbar {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

@media (max-width: 1200px) {
    .dash-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
    [data-cols="kpi-4"],
    .dash-kpi {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 980px) {
    [data-cols="2-340"],
    [data-cols="2-1"],
    [data-cols="1.6-1"],
    .dash-mid,
    .dash-charts-row {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}

@media (max-width: 640px) {
    [data-cols="kpi-4"],
    .dash-kpi {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    [data-cols="form-3"],
    [data-cols="form-4"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .dash-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dash-chart, .dash-chart-lg { height: 240px; }
    .dash-metric-value,
    .dash-metric-mix { font-size: 1.05rem; }
}

/* ── Сетки форм/выбора без зависимости от Tailwind .grid ── */
.app-main, .app-content, .space-y-4, .card, .card-pad { min-width: 0; max-width: 100%; }
.order-choose-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
    gap: 16px;
    align-items: stretch;
}
.order-choose-grid > * { min-width: 0; }
.form-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 16px;
}
.form-grid-2 > * { min-width: 0; }
@media (max-width: 640px) {
    .form-grid-2 { grid-template-columns: minmax(0, 1fr); }
}
.overflow-x-auto { max-width: 100%; }
.tbl { max-width: 100%; }

/* Печать записей — форма выбора даты в topbar */
.print-day-form {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
}
.print-day-form label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
}
.print-day-form .inp { width: auto; min-width: 9.5rem; padding: 6px 10px; font-size: 13px; }

/* Совладельцы авто */
.owners-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.owners-row {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface-2);
}
.owners-row .owners-name { font-weight: 600; }
.owners-badge {
    font-size: 11px; font-weight: 700; color: var(--accent-ink);
    background: var(--accent-sf); padding: 2px 8px; border-radius: 999px;
}
.owners-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-top: 10px; }
.owners-add .fld { flex: 1 1 180px; min-width: 0; margin: 0; }

/* ── Расходы: чипы получателей ── */
.exp-payee-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
button.exp-payee-chip {
    min-height: 34px;
    padding: 8px 14px;
    cursor: pointer;
    font: inherit;
    line-height: 1.2;
}
button.exp-payee-chip:hover {
    border-color: var(--accent);
    color: var(--accent-ink);
    background: var(--accent-sf);
}
.exp-form .fld { min-width: 0; }

/* ── Кликабельные строки списков ── */
tr.row-link,
tr.appt-row {
    cursor: pointer;
    transition: background .12s ease;
}
tr.row-link:hover,
tr.appt-row:hover {
    background: var(--accent-sf);
}
td.row-actions {
    text-align: center !important;
    vertical-align: middle;
}
.row-actions-inner {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    max-width: 100%;
}

/* ── Зарплата / выработка ── */
.pay-period {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 3px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
}
.pay-period a {
    display: inline-flex;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
    text-decoration: none;
}
.pay-period a.is-active {
    background: var(--accent);
    color: #fff;
}
.pay-debt-pos { color: var(--bad); font-weight: 700; }
.pay-debt-zero { color: var(--ink-3); }

/* ── Stepper статусов наряда (#status-bar) ── */
.order-status-bar { display: flex; flex-direction: column; gap: 12px; }
.status-stepper {
    display: flex; flex-wrap: wrap; align-items: center;
    list-style: none; margin: 0; padding: 0; gap: 0;
}
.status-step {
    display: inline-flex; align-items: center; gap: 8px;
}
.status-step-node {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 999px;
    font-size: 11px; font-weight: 700; line-height: 1;
    border: 1.5px solid var(--border-2);
    color: var(--ink-3); background: var(--surface-2);
    flex-shrink: 0;
}
.status-step.is-current .status-step-node {
    border-color: var(--accent); background: var(--accent); color: #fff;
}
.status-step.is-done .status-step-node {
    border-color: var(--good); background: var(--good); color: #fff;
}
.status-step-label {
    font-size: 13px; font-weight: 600; color: var(--ink);
    display: inline-flex; flex-direction: column; gap: 1px; line-height: 1.2;
}
.status-step.is-current .status-step-label { color: var(--accent-ink); }
.status-step-label.is-muted { color: var(--ink-3); font-weight: 500; }
.status-step-hint {
    font-size: 11px; font-weight: 500; color: var(--ink-3);
}
.status-step-sep {
    width: 20px; height: 2px; margin: 0 6px;
    background: var(--border-2); border-radius: 1px; flex-shrink: 0;
}
.status-step.is-done + .status-step .status-step-sep,
.status-step.is-done .status-step-sep { background: var(--good); opacity: .45; }
.status-step-btn { white-space: nowrap; }
.status-rollback {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    padding-top: 10px; border-top: 1px solid var(--border);
}
.status-rollback-label {
    font-size: 12px; font-weight: 600; color: var(--ink-3); margin-right: 2px;
}
