/* =====================================================
   Мониторинг 1С — общие улучшения: темы, анимации
   ===================================================== */

/* ===== ТЁМНАЯ ТЕМА: переопределение переменных ===== */
/* Нейтрально-гармоничная тёмная палитра: мягкий графит с лёгким
   зелёным оттенком, приглушённые акценты — ничего резкого */
[data-theme="dark"] {
    --header-bg: #1a201d;
    --header-text: #8fbf9f;
    --nav-text: #93a89c;
    --nav-active: #a8d5b7;
    --nav-active-bg: #3a6b52;
    --nav-active-text: #f2f8f4;
    --body-bg: #131714;
    --card-bg: #1c231e;
    --primary: #6fae8c;
    --primary-light: #253029;
    --accent: #8fbf9f;
    --text-primary: #e3eae5;
    --text-secondary: #a3b5aa;
    --text-muted: #74847a;
    --border-color: #2c3730;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 10px 34px rgba(0, 0, 0, 0.42);
    --shadow-nav: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* Плавный переход цветов при смене темы */
body, .header, .card, .stat-card, .chart-card, .stock-card,
.table-container, .filters-container, .mobile-nav, .logout,
.header nav a, .filters-toggle-btn, th, td, .filter-input,
.status-check, .chart-tab, .btn-reset, .stock-table,
.details-subtable, .details-table-container, .details-table-title {
    transition: background-color 0.35s ease, color 0.35s ease,
                border-color 0.35s ease, box-shadow 0.35s ease !important;
}

/* ===== Тёмная тема: хардкод-цвета ===== */
[data-theme="dark"] .order-details { background-color: #181f1b; }
[data-theme="dark"] .details-subtable td { color: #cdd9d1; border-bottom-color: #28322c; }
[data-theme="dark"] .details-subtable tr:active td,
[data-theme="dark"] .details-subtable tr:hover td { background-color: #222b26 !important; }
[data-theme="dark"] .filters-toggle-btn:hover { background: rgba(111, 174, 140, 0.08); }
[data-theme="dark"] tbody tr:hover,
[data-theme="dark"] tbody tr:active { background-color: rgba(111, 174, 140, 0.07); }
[data-theme="dark"] .sortable:hover,
[data-theme="dark"] .sortable:active { background-color: #28322c; color: var(--accent); }
[data-theme="dark"] .btn-reset:hover { background: rgba(111, 174, 140, 0.08); }
[data-theme="dark"] .btn-apply:hover { background: #5d9a7a; }
[data-theme="dark"] .error-state { background-color: #33262a; color: #d9a9ad; }
[data-theme="dark"] .stock-qty { color: #d9a9ad; }
[data-theme="dark"] .filter-input { color-scheme: dark; }
[data-theme="dark"] .scroll-hint { color: #a8d5b7; }
[data-theme="dark"] .mobile-nav { background: #22302a; }

/* Статусные бейджи в тёмной теме: приглушённые, мягкие */
[data-theme="dark"] .status--new { background-color: rgba(111, 158, 206, 0.18); color: #9cc2e8; }
[data-theme="dark"] .status--in-progress { background-color: rgba(201, 162, 75, 0.16); color: #d4b877; }
[data-theme="dark"] .status--canceled { background-color: rgba(184, 106, 106, 0.16); color: #d39a9a; }
[data-theme="dark"] .status--success { background-color: rgba(111, 174, 140, 0.18); color: #93cba9; }
[data-theme="dark"] .status-check.status-new.active { background: rgba(111, 158, 206, 0.18); border-color: #9cc2e8; }
[data-theme="dark"] .status-check.status-progress.active { background: rgba(201, 162, 75, 0.16); border-color: #d4b877; }
[data-theme="dark"] .status-check.status-overdue.active { background: rgba(184, 106, 106, 0.16); border-color: #d39a9a; }
[data-theme="dark"] .status-check.status-done.active { background: rgba(111, 174, 140, 0.18); border-color: #93cba9; }

/* ===== Иконки с прозрачным фоном (WebP) ===== */
.dashboard-icon img,
.stat-card .icon img,
.chart-card h3 .icon img,
.stock-card h3 .icon img,
.section-title .icon img,
.details-table-title img {
    border-radius: 10px;
}
/* Тёмная тема: лёгкая инверсия штрихов, фон остаётся прозрачным */
[data-theme="dark"] .dashboard-icon img,
[data-theme="dark"] .stat-card .icon img,
[data-theme="dark"] .chart-card h3 .icon img,
[data-theme="dark"] .stock-card h3 .icon img,
[data-theme="dark"] .section-title .icon img,
[data-theme="dark"] .details-table-title img {
    filter: invert(0.88) hue-rotate(180deg) saturate(0.65) brightness(1.05);
}

/* ===== Кликабельный логотип «Мониторинг 1С» ===== */
.logo-link {
    text-decoration: none;
    color: inherit;
    display: inline-block;
    border-radius: 8px;
    transition: transform 0.25s ease, opacity 0.25s ease;
}
.logo-link:hover { opacity: 0.85; transform: translateY(-1px); }
.logo-link:active { transform: scale(0.97); }

/* ===== Кнопка переключения темы ===== */
.theme-toggle {
    background: var(--card-bg);
    border: 2px solid var(--primary);
    color: var(--primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
    box-shadow: 0 2px 6px rgba(27, 67, 50, 0.1);
    flex-shrink: 0;
    padding: 0;
}
.theme-toggle:hover { transform: rotate(20deg) scale(1.08); box-shadow: 0 8px 24px rgba(27, 67, 50, 0.35); }
.theme-toggle:active { transform: scale(0.92); }
.theme-toggle svg { width: 20px; height: 20px; transition: opacity 0.3s ease, transform 0.4s ease; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle { color: #d4b877; border-color: #d4b877; }

/* ===== Плавное появление блоков (scroll-reveal) ===== */
.reveal {
    opacity: 0;
    transform: translateY(26px);
    transition: opacity 0.6s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: opacity, transform;
}
.reveal.visible { opacity: 1; transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
    .reveal { opacity: 1 !important; transform: none !important; transition: none !important; }
}

/* ===== Анимации выпадающих списков ===== */
/* Панель фильтров: плавное раскрытие + каскад пунктов */
.filters-panel .filter-group,
.filters-panel .filter-actions {
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.filters-panel.open .filter-group,
.filters-panel.open .filter-actions {
    opacity: 1;
    transform: translateY(0);
}
.filters-panel.open .filters-content > *:nth-child(1) { transition-delay: 0.05s; }
.filters-panel.open .filters-content > *:nth-child(2) { transition-delay: 0.1s; }
.filters-panel.open .filters-content > *:nth-child(3) { transition-delay: 0.15s; }
.filters-panel.open .filters-content > *:nth-child(4) { transition-delay: 0.2s; }
.filters-panel.open .filters-content > *:nth-child(5) { transition-delay: 0.25s; }
.filters-panel.open .filters-content > *:nth-child(6) { transition-delay: 0.3s; }

.filters-toggle-btn::after { transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) !important; }

/* Раскрывающиеся строки таблицы */
.order-details.show > td > .details-wrapper,
.order-details.show > td > div {
    animation: detailsPop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes detailsPop {
    from { opacity: 0; transform: translateY(-12px) scale(0.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Мобильное меню: каскадное появление пунктов */
.mobile-nav a {
    opacity: 0;
    transform: translateX(-18px);
    transition: background-color 0.3s ease, color 0.3s ease,
                opacity 0.3s ease, transform 0.3s ease !important;
}
.mobile-nav.active a { opacity: 1; transform: translateX(0); }
.mobile-nav.active a:nth-child(2) { transition-delay: 0.06s; }
.mobile-nav.active a:nth-child(3) { transition-delay: 0.1s; }
.mobile-nav.active a:nth-child(4) { transition-delay: 0.14s; }
.mobile-nav.active a:nth-child(5) { transition-delay: 0.18s; }
.mobile-nav.active a:nth-child(6) { transition-delay: 0.22s; }
.mobile-nav.active a:nth-child(7) { transition-delay: 0.26s; }
.mobile-nav.active a:nth-child(8) { transition-delay: 0.3s; }

/* ===== Плавающая кнопка «Анализ» (FAB) ===== */
.fab-analytics {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1400;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 1.3rem;
    border: none;
    border-radius: 50px;
    background: linear-gradient(135deg, #2d6a4f, #40916c);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(27, 67, 50, 0.4);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    animation: fabIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.6s backwards;
}
@keyframes fabIn {
    from { opacity: 0; transform: translateY(30px) scale(0.8); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.fab-analytics:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 14px 34px rgba(27, 67, 50, 0.5); }
.fab-analytics:active { transform: scale(0.94); }
.fab-analytics svg { width: 20px; height: 20px; }
[data-theme="dark"] .fab-analytics { background: linear-gradient(135deg, #3a6b52, #5d9a7a); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); }

/* ===== Плавающий дашборд ===== */
.float-dash-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(5px);
    z-index: 1450;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}
.float-dash-overlay.open { opacity: 1; pointer-events: all; }

.float-dash {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1500;
    width: min(480px, calc(100vw - 2.5rem));
    max-height: min(640px, calc(100vh - 2.5rem));
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(40px) scale(0.92);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1),
                transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.float-dash.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }

/* Свободное окно: перетаскивание и закрепление */
.float-dash.floating {
    right: auto;
    bottom: auto;
    transform: none;
}
.float-dash.open.floating { transform: none; }
.float-dash.dragging {
    transition: none;
    user-select: none;
    box-shadow: 0 32px 90px rgba(0, 0, 0, 0.5);
}
.float-dash.pinned { border-color: var(--primary); }

.float-dash-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    gap: 0.75rem;
    flex-wrap: wrap;
    cursor: grab;
    touch-action: none;
}
.float-dash-header:active { cursor: grabbing; }
.float-dash-actions { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }

.float-dash-pin {
    background: var(--body-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
    flex-shrink: 0;
    padding: 0;
}
.float-dash-pin svg { width: 15px; height: 15px; }
.float-dash-pin:hover { color: var(--primary); transform: scale(1.08); }
.float-dash.pinned .float-dash-pin {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.float-dash-header h3 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--text-primary);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.float-dash-close {
    background: var(--body-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, background-color 0.25s ease, color 0.25s ease;
    flex-shrink: 0;
}
.float-dash-close:hover { transform: rotate(90deg); color: var(--primary); }

/* Табы плавающего дашборда */
.float-dash-tabs {
    display: flex;
    gap: 0.4rem;
    background: var(--body-bg);
    padding: 0.3rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}
.float-dash-tab {
    flex: 1;
    padding: 0.45rem 0.9rem;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    white-space: nowrap;
}
.float-dash-tab:active { transform: scale(0.95); }
.float-dash-tab.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(27, 67, 50, 0.25);
}

.float-dash-body {
    padding: 1.1rem 1.25rem 1.25rem;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

.float-view { display: none; }
.float-view.active { display: block; animation: floatViewIn 0.35s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes floatViewIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Мини-карточки внутри дашборда */
.fd-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    margin-bottom: 1rem;
}
.fd-mini {
    background: var(--body-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 0.75rem 0.85rem;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.fd-mini:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.fd-mini .fd-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.fd-mini .fd-value { font-size: 1.35rem; font-weight: 800; color: var(--text-primary); line-height: 1.2; }
.fd-mini .fd-sub { font-size: 0.72rem; color: var(--text-secondary); }

/* Полоса процента выполнения */
.fd-progress-wrap { margin-bottom: 1rem; }
.fd-progress-head {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}
.fd-progress-head strong { color: var(--primary); }
.fd-progress {
    height: 12px;
    background: var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}
.fd-progress-fill {
    height: 100%;
    width: 0;
    border-radius: 8px;
    background: linear-gradient(90deg, #6fae8c, #3a6b52);
    transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Процентные строки статусов внутри дашборда */
.fd-status-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.55rem;
}
.fd-status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.fd-status-name { font-size: 0.82rem; color: var(--text-secondary); min-width: 82px; font-weight: 600; }
.fd-status-bar { flex: 1; height: 9px; background: var(--border-color); border-radius: 6px; overflow: hidden; }
.fd-status-fill { height: 100%; width: 0; border-radius: 6px; transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1); }
.fd-status-num { font-size: 0.82rem; font-weight: 700; color: var(--text-primary); min-width: 52px; text-align: right; }

.fd-chart-box { position: relative; height: 220px; margin-bottom: 0.5rem; }
.fd-section-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0.9rem 0 0.6rem;
}
.fd-loading { text-align: center; color: var(--text-muted); padding: 2rem 0.5rem; font-size: 0.9rem; }

@media (max-width: 480px) {
    .fab-analytics span { display: none; }
    .fab-analytics { padding: 0.95rem; }
}

/* ===== МОБИЛЬНАЯ ВЕРСИЯ ===== */
/* Кнопка «Анализ» и плавающее окно — только для планшетов и ПК */
@media (max-width: 767px) {
    .fab-analytics,
    .float-dash,
    .float-dash-overlay { display: none !important; }
}

/* Мобильная шапка: только 3 полоски, значок темы и дверь выхода */
@media (max-width: 1023px) {
    .header h1 { display: none; }
    .header .container { justify-content: space-between; }
    .logout .logout-text { display: none; }
    .logout {
        padding: 0.5rem;
        border-radius: 50%;
        width: 40px;
        height: 40px;
        justify-content: center;
        gap: 0;
    }
    /* Переключатель темы в шапке не нужен — он в мобильном меню */
    .header .theme-toggle { display: none; }
}

/* Переключатель темы внутри мобильного меню, рядом с «Мониторинг 1С» */
.mobile-nav-header .theme-toggle {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.12);
    border-color: transparent;
    color: #fff;
    box-shadow: none;
    width: 36px;
    height: 36px;
}
.mobile-nav-header .theme-toggle:hover {
    box-shadow: none;
    background: rgba(255, 255, 255, 0.22);
}
.mobile-nav-header .theme-toggle svg { width: 18px; height: 18px; }
