/* ============================================
   ГЛАВНАЯ И ГЛОБАЛЬНЫЙ ПОИСК
   ============================================ */

/* ---------- Большая строка поиска ---------- */
.search-vin {
    margin-bottom: 24px;
}
.crm-hero .search-vin {
    flex: 1 1 520px;
    max-width: 640px;
    margin: 0;
}
.search-vin form {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 860px;
}
.search-vin .search-icon {
    position: absolute;
    left: 16px;
    font-size: 22px;
    color: var(--crm-faint);
    pointer-events: none;
    transition: color var(--crm-fast) ease, transform var(--crm-mid) var(--crm-ease);
}
.search-vin input[type="text"] {
    flex: 1;
    min-width: 0;
    min-height: 52px;
    padding: 12px 16px 12px 48px;
    background: var(--crm-input-bg);
    border: 1px solid var(--crm-border);
    border-radius: 12px;
    font-size: 15px;
}
.search-vin input[type="text"]:focus {
    background: rgba(6, 9, 18, 0.75);
}
.search-vin form:focus-within .search-icon {
    color: var(--crm-accent);
    transform: scale(1.1);
}
.search-vin button {
    min-height: 52px;
    padding: 0 28px;
    border: none;
    border-radius: 12px;
    background: var(--crm-btn-gradient);
    color: #fff;
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--crm-btn-shadow);
    transition: background var(--crm-fast) ease, transform var(--crm-fast) ease, box-shadow var(--crm-mid) var(--crm-ease);
}
.search-vin button:hover {
    background: var(--crm-btn-gradient-hover);
    transform: translateY(-1px);
    box-shadow: var(--crm-btn-shadow-hover);
}

/* ---------- Шапка главной: плата с током, как сводка в админке сайта ---------- */
.crm-hero {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px 28px;
    margin-bottom: 18px;
    padding: 24px 26px;
    border-radius: 20px;
    border: 1px solid var(--crm-border-soft);
    background:
        radial-gradient(600px 260px at 85% 0%, rgba(74, 144, 217, 0.16), transparent 70%),
        var(--crm-panel);
    animation: crm-rise 0.4s var(--crm-ease) both;
}
.crm-hero-board {
    position: absolute;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* под текстом слева плата гаснет, чтобы не мешать читать */
    -webkit-mask: linear-gradient(90deg, rgba(0, 0, 0, 0.25) 0%, #000 55%);
    mask: linear-gradient(90deg, rgba(0, 0, 0, 0.25) 0%, #000 55%);
}
.crm-hero h1 {
    margin: 10px 0 0;
    color: var(--crm-strong);
    font-size: clamp(1.7rem, 1.3rem + 1.2vw, 2.4rem);
    line-height: 1.1;
}
.crm-hero h1 span {
    color: var(--crm-accent);
}
.crm-hero-lead {
    margin: 10px 0 0;
    color: #9DB3C8;
    font-size: 15px;
}
/* Надпись над заголовком — как .eyebrow сайта: моноширинный шрифт, черта со свечением */
.crm-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font: 500 11px/1 var(--crm-font-mono);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #8FA2B8;
}
.crm-eyebrow::before {
    content: "";
    width: 30px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--crm-accent));
}
.crm-eyebrow::first-letter {
    text-transform: uppercase;
}
.search-vin button:active {
    transform: scale(0.97);
}

/* ---------- Карточки с цифрами ---------- */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card,
a.stat-card:link,
a.stat-card:visited {
    --tone: var(--crm-accent);
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    padding: 18px;
    background: var(--crm-panel);
    border: 1px solid var(--crm-border-soft);
    border-radius: var(--crm-radius-lg);
    box-shadow: var(--crm-shadow);
    color: inherit;
    overflow: hidden;
    animation: crm-rise 0.45s var(--crm-ease) both;
    transition: transform var(--crm-mid) var(--crm-ease), border-color var(--crm-mid) ease,
                box-shadow var(--crm-mid) var(--crm-ease);
}
.stat-card::before,
.stat-card::after {
    /* нижняя полоска цвета карточки, по ней бежит блик — как на сводке админки сайта */
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    pointer-events: none;
}
.stat-card::before {
    background: linear-gradient(90deg, transparent, var(--tone), transparent);
    opacity: 0.45;
}
.stat-card::after {
    background: linear-gradient(90deg, transparent 0%, var(--tone) 45%, #fff 50%, var(--tone) 55%, transparent 100%);
    background-size: 40% 100%;
    background-repeat: no-repeat;
    filter: drop-shadow(0 0 4px var(--tone));
    animation: crm-flow 3.6s cubic-bezier(0.45, 0, 0.25, 1) infinite;
}
.dashboard-stats > :nth-child(2)::after { animation-delay: 0.6s; }
.dashboard-stats > :nth-child(3)::after { animation-delay: 1.2s; }
.dashboard-stats > :nth-child(4)::after { animation-delay: 1.8s; }
.dashboard-stats > :nth-child(5)::after { animation-delay: 2.4s; }
.dashboard-stats > :nth-child(6)::after { animation-delay: 3s; }
.stat-card:hover {
    transform: translateY(-1px);
    border-color: rgba(74, 144, 217, 0.5);
}
@keyframes crm-flow {
    0% { background-position: -60% 0; }
    70%, 100% { background-position: 160% 0; }
}

.stat-card .stat-icon {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid color-mix(in srgb, var(--tone) 32%, transparent);
    background: color-mix(in srgb, var(--tone) 12%, transparent);
    color: var(--tone);
    font-size: 22px;
}
.stat-card .stat-body {
    min-width: 0;
}
.stat-card .stat-label {
    color: var(--crm-muted);
    font-family: var(--crm-font-mono);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.35;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.stat-card .stat-number {
    margin-top: 4px;
    color: var(--crm-strong);
    font-family: var(--crm-font-display);
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.1;
    white-space: nowrap;
}
a.stat-card .stat-label::after {
    content: " →";
    opacity: 0;
    transition: opacity var(--crm-fast) ease;
}
a.stat-card:hover .stat-label::after {
    opacity: 1;
}

/* a.stat-card:link весит больше, чем .stat-card.green, — повторяем цвет и для ссылок */
.stat-card.blue, a.stat-card.blue:link, a.stat-card.blue:visited { --tone: #4a90d9; }
.stat-card.green, a.stat-card.green:link, a.stat-card.green:visited { --tone: #5fbf8f; }
.stat-card.orange, a.stat-card.orange:link, a.stat-card.orange:visited { --tone: #d9b25a; }
.stat-card.purple, a.stat-card.purple:link, a.stat-card.purple:visited { --tone: #a48cf0; }
.stat-card.red, a.stat-card.red:link, a.stat-card.red:visited { --tone: #e07a7a; }

/* Старая форма заказов: итоги над фильтром */
.legacy-totals {
    margin: 0 0 18px;
}
/* вкладки «Все / Geely / RAV4» слева, кнопка «Показать скрытые заказы» справа; под ними — подпись и карточки */
.legacy-totals-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin-bottom: 14px;
}
.legacy-totals > .crm-eyebrow {
    margin-bottom: 10px;
}
.legacy-tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--crm-border);
    border-radius: 12px;
    background: var(--crm-input-bg);
}
.legacy-tabs a:link,
.legacy-tabs a:visited {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 6px 20px;
    border-radius: 9px;
    color: var(--crm-text-2);
    font-size: 14px;
    font-weight: 500;
    transition: background var(--crm-fast) ease, color var(--crm-fast) ease;
}
.legacy-tabs a:hover {
    background: var(--crm-surface-2);
    color: var(--crm-text);
}
.legacy-tabs a.active {
    background: var(--crm-accent-soft);
    color: var(--crm-text);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(74, 144, 217, 0.45);
}
.legacy-hidden-toggle.button {
    min-height: 34px;
    padding: 5px 14px;
    font-size: 13px;
}
.legacy-hidden-toggle .material-icons {
    font-size: 18px;
}
/* шесть карточек: по три в ряд (суммы в миллионы не помещаются в шестую часть строки), на широком — все в ряд */
.legacy-totals .dashboard-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 0;
}
@media (min-width: 1900px) {
    .legacy-totals .dashboard-stats {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}
@media (max-width: 767px) {
    .legacy-totals .dashboard-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Карточки появляются по очереди */
.dashboard-stats > :nth-child(2) { animation-delay: 0.04s; }
.dashboard-stats > :nth-child(3) { animation-delay: 0.08s; }
.dashboard-stats > :nth-child(4) { animation-delay: 0.12s; }
.dashboard-stats > :nth-child(5) { animation-delay: 0.16s; }
.dashboard-stats > :nth-child(6) { animation-delay: 0.20s; }

/* ---------- Напоминания (заявки, склад) ---------- */
.dashboard-alerts {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}
.crm-alert,
a.crm-alert:link,
a.crm-alert:visited {
    --tone: var(--crm-accent);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px 8px 10px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--tone) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--tone) 32%, transparent);
    color: var(--tone);
    font-size: 13px;
    font-weight: 600;
    animation: crm-rise 0.45s var(--crm-ease) 0.2s both;
    transition: background var(--crm-fast) ease, transform var(--crm-fast) ease;
}
.crm-alert .material-icons {
    font-size: 18px;
}
a.crm-alert:hover {
    background: color-mix(in srgb, var(--tone) 22%, transparent);
    color: var(--tone);
    transform: translateY(-1px);
}
.crm-alert.green,
a.crm-alert.green:link,
a.crm-alert.green:visited { --tone: #5fbf8f; }
.crm-alert.red,
a.crm-alert.red:link,
a.crm-alert.red:visited { --tone: #e07a7a; }

/* ---------- Последние заказы и клиенты ---------- */
.dashboard-recent {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 20px;
    margin-bottom: 20px;
}
.dashboard-recent .module {
    margin: 0;
    animation: crm-rise 0.5s var(--crm-ease) 0.15s both;
}
.dashboard-recent .module + .module {
    animation-delay: 0.22s;
}
.dashboard-recent .module h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}
.dashboard-recent .module h2 .material-icons {
    font-size: 20px;
    color: var(--crm-accent);
}
.dashboard-recent table {
    width: 100%;
}
.dashboard-recent th,
.dashboard-recent td {
    padding: 11px 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}
.dashboard-recent td.num,
.dashboard-recent th.num {
    text-align: right;
}
.dashboard-recent tbody tr:last-child td {
    border-bottom: none;
}
.crm-empty {
    padding: 28px 20px;
    color: var(--crm-muted);
    text-align: center;
}

/* ---------- Выручка за 12 месяцев ---------- */
.crm-dash-revenue {
    margin: 0 0 20px;
    animation: crm-rise 0.5s var(--crm-ease) 0.1s both;
}
.crm-dash-revenue h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}
.crm-dash-revenue h2 .material-icons {
    font-size: 20px;
    color: var(--crm-accent);
}
.crm-dash-total {
    margin-left: auto;
    color: var(--crm-strong);
    font-variant-numeric: tabular-nums;
}
.crm-dash-revenue .crm-chart {
    margin: 12px 16px 4px;
}

.module-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--crm-border-soft);
}
.module-footer a:link,
.module-footer a:visited {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    transition: background var(--crm-fast) ease, gap var(--crm-mid) var(--crm-ease);
}
.module-footer a:hover {
    background: var(--crm-accent-soft);
    gap: 8px;
}

/* ---------- Адаптивность ---------- */
@media (max-width: 1100px) {
    .dashboard-recent {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 767px) {
    .dashboard-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
    .stat-card,
    a.stat-card:link,
    a.stat-card:visited {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 14px;
    }
    .stat-card .stat-number {
        font-size: 21px;
    }
    .search-vin form {
        flex-wrap: wrap;
    }
    .search-vin button {
        width: 100%;
    }
    .search-vin .search-icon {
        top: 15px;
    }
    .crm-hero {
        padding: 18px 16px;
    }
}
