/* Promo CRM — тема веб-панели: читаемость, тёмная тема, меню на телефоне.

   Подключается ПОСЛЕ tailwind-built.css. Tailwind здесь собран заранее
   (не JIT), и шаблонов больше пятидесяти — поэтому тёмная тема сделана не
   через dark:-варианты в каждом шаблоне, а переопределением тех цветовых
   классов, которые реально используются (список собран по шаблонам).
   Тему выставляет скрипт в <head> (templates/partials/theme_head.html):
   html[data-theme="dark"] — тёмная, иначе светлая; по умолчанию — как в
   системе, выбор пользователя запоминается. */

/* ================= Читаемость (обе темы) ================= */

/* Серый #9ca3af на белом — контраст ~2.5:1, подсказки и вторичный текст
   читались с трудом. Чуть темнее — уже ~4.5:1. */
.text-gray-400 { color: #6f7280; }
.text-gray-300 { color: #a0a4ae; }
/* Заголовки таблиц были 11px — мелко для рабочих экранов. */
.text-\[11px\] { font-size: 12px; }
.text-\[10px\] { font-size: 11px; }

/* Видимая рамка фокуса при работе с клавиатуры (Tab) — раньше не было видно,
   на какой кнопке сейчас фокус. */
:focus-visible {
    outline: 2px solid var(--accent, #5D4CDE);
    outline-offset: 2px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }

/* Длинные названия в таблицах переносятся, а не уезжают за край. */
td { overflow-wrap: anywhere; }

/* ================= Переключатель темы и меню на телефоне ================= */
.theme-toggle, .menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 999px;
    background: #fff; border: 1px solid #F0F0F4; color: #6B6B76;
    box-shadow: 0 1px 2px rgba(30,27,75,0.04);
    cursor: pointer; flex-shrink: 0;
}
.theme-toggle:hover, .menu-toggle:hover { background: #F5F5FA; color: #2B2A33; }
.theme-toggle svg, .menu-toggle svg { width: 18px; height: 18px; }
.menu-toggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 1023px) {
    .menu-toggle { display: inline-flex; }
    .app-sidebar {
        position: fixed; top: 0; bottom: 0; left: 0; z-index: 70;
        width: 280px; max-width: 85vw;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 10px 40px rgba(0,0,0,.25);
    }
    body.sidebar-open .app-sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop {
        display: block; position: fixed; inset: 0; z-index: 65; background: rgba(17, 17, 26, .45);
    }
    .app-header { padding-left: 12px !important; padding-right: 12px !important; gap: 8px; }
    .app-header-title h1 { font-size: 17px; }
    .app-main { padding: 14px !important; }
}
/* Таблицы на телефоне: прокрутка вбок вместо сжатия колонок до нечитаемых
   (в «Задачах проекта» колонки налезали друг на друга). */
@media (max-width: 1023px) {
    .overflow-x-auto > table { min-width: 720px; }
    .overflow-x-auto > table.table-fixed { min-width: 900px; }
}
@media (max-width: 639px) {
    .header-clock { display: none !important; }
    .app-header-actions { gap: 6px !important; }
    .app-header-actions select { max-width: 130px; }
}

/* ================= ТЁМНАЯ ТЕМА ================= */
html[data-theme="dark"] { color-scheme: dark; --accent-tint: #2c2750; }
html[data-theme="dark"] body,
html[data-theme="dark"] [style*="#F5F5FA"],
html[data-theme="dark"] [style*="#f5f5fa"] { background: #121218 !important; color: #e4e4ea; }

/* Поверхности */
html[data-theme="dark"] .bg-white { background-color: #1b1b24 !important; }
html[data-theme="dark"] .bg-gray-50 { background-color: #20202b !important; }
html[data-theme="dark"] .bg-gray-50\/50 { background-color: rgba(255,255,255,.025) !important; }
html[data-theme="dark"] .even\:bg-gray-50\/50:nth-child(even) { background-color: rgba(255,255,255,.03) !important; }
html[data-theme="dark"] .bg-gray-100 { background-color: #262632 !important; }
html[data-theme="dark"] .bg-gray-200 { background-color: #2f2f3c !important; }
html[data-theme="dark"] .bg-gray-300 { background-color: #3a3a48 !important; }
html[data-theme="dark"] .hover\:bg-gray-50:hover,
html[data-theme="dark"] .hover\:bg-gray-100:hover { background-color: #2a2a36 !important; }
html[data-theme="dark"] .hover\:bg-gray-200:hover,
html[data-theme="dark"] .hover\:bg-gray-300:hover { background-color: #34343f !important; }

/* Текст */
html[data-theme="dark"] .text-gray-900,
html[data-theme="dark"] .text-gray-800 { color: #ececf2 !important; }
html[data-theme="dark"] .text-gray-700 { color: #d6d6de !important; }
html[data-theme="dark"] .text-gray-600 { color: #bcbcc8 !important; }
html[data-theme="dark"] .text-gray-500 { color: #a2a2b0 !important; }
html[data-theme="dark"] .text-gray-400 { color: #8c8c9a !important; }
html[data-theme="dark"] .text-gray-300 { color: #6c6c7a !important; }
html[data-theme="dark"] .hover\:text-gray-800:hover,
html[data-theme="dark"] .hover\:text-gray-700:hover,
html[data-theme="dark"] .hover\:text-gray-600:hover { color: #f0f0f5 !important; }

/* Рамки и разделители */
html[data-theme="dark"] .border-gray-100 { border-color: #2a2a35 !important; }
html[data-theme="dark"] .border-gray-200 { border-color: #33333f !important; }
html[data-theme="dark"] .border-gray-300 { border-color: #3d3d4b !important; }
html[data-theme="dark"] .divide-gray-50 > :not([hidden]) ~ :not([hidden]),
html[data-theme="dark"] .divide-gray-100 > :not([hidden]) ~ :not([hidden]),
html[data-theme="dark"] .divide-gray-200 > :not([hidden]) ~ :not([hidden]) { border-color: #2c2c37 !important; }

/* Цветные подложки (плашки, сообщения, предупреждения) — приглушённые */
html[data-theme="dark"] .bg-red-50, html[data-theme="dark"] .bg-red-100 { background-color: rgba(239, 68, 68, .14) !important; }
html[data-theme="dark"] .bg-green-50, html[data-theme="dark"] .bg-green-100 { background-color: rgba(34, 197, 94, .14) !important; }
html[data-theme="dark"] .bg-blue-50, html[data-theme="dark"] .bg-blue-100 { background-color: rgba(59, 130, 246, .15) !important; }
html[data-theme="dark"] .bg-amber-50, html[data-theme="dark"] .bg-amber-100,
html[data-theme="dark"] .bg-yellow-50, html[data-theme="dark"] .bg-yellow-100 { background-color: rgba(245, 158, 11, .14) !important; }
html[data-theme="dark"] .bg-indigo-50, html[data-theme="dark"] .bg-indigo-100,
html[data-theme="dark"] .bg-purple-50, html[data-theme="dark"] .bg-purple-100 { background-color: rgba(129, 115, 245, .16) !important; }
html[data-theme="dark"] .border-red-100, html[data-theme="dark"] .border-red-200 { border-color: rgba(239, 68, 68, .3) !important; }
html[data-theme="dark"] .border-green-100, html[data-theme="dark"] .border-green-200 { border-color: rgba(34, 197, 94, .3) !important; }
html[data-theme="dark"] .border-blue-100 { border-color: rgba(59, 130, 246, .3) !important; }
html[data-theme="dark"] .border-amber-100, html[data-theme="dark"] .border-amber-200,
html[data-theme="dark"] .border-yellow-100 { border-color: rgba(245, 158, 11, .3) !important; }
html[data-theme="dark"] .border-indigo-100, html[data-theme="dark"] .border-indigo-200 { border-color: rgba(129, 115, 245, .35) !important; }

/* Цветной текст — светлее, чтобы читался на тёмном */
html[data-theme="dark"] .text-red-500, html[data-theme="dark"] .text-red-600,
html[data-theme="dark"] .text-red-700, html[data-theme="dark"] .text-red-800 { color: #fca5a5 !important; }
html[data-theme="dark"] .text-green-600, html[data-theme="dark"] .text-green-700,
html[data-theme="dark"] .text-green-800 { color: #86efac !important; }
html[data-theme="dark"] .text-blue-600, html[data-theme="dark"] .text-blue-700,
html[data-theme="dark"] .text-blue-800, html[data-theme="dark"] .text-sky-700 { color: #93c5fd !important; }
html[data-theme="dark"] .text-amber-600, html[data-theme="dark"] .text-amber-700,
html[data-theme="dark"] .text-amber-800, html[data-theme="dark"] .text-yellow-800,
html[data-theme="dark"] .text-yellow-900 { color: #fcd34d !important; }
html[data-theme="dark"] .text-indigo-600, html[data-theme="dark"] .text-indigo-700,
html[data-theme="dark"] .text-purple-600, html[data-theme="dark"] .text-purple-700,
html[data-theme="dark"] .text-purple-800 { color: #c4b5fd !important; }

/* Поля ввода */
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background-color: #16161e !important;
    color: #ececf2 !important;
    border-color: #3a3a47 !important;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #767684 !important; }
html[data-theme="dark"] input[readonly], html[data-theme="dark"] input:disabled,
html[data-theme="dark"] select:disabled { background-color: #22222c !important; color: #9a9aa8 !important; }

/* Тени — мягче и темнее */
html[data-theme="dark"] .shadow, html[data-theme="dark"] .shadow-sm, html[data-theme="dark"] .shadow-md,
html[data-theme="dark"] .shadow-lg, html[data-theme="dark"] .shadow-xl, html[data-theme="dark"] .shadow-2xl {
    box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 24px -12px rgba(0,0,0,.6) !important;
}

/* Боковое меню и элементы из base.html */
html[data-theme="dark"] .sidebar-link { color: #a8a8b6; }
html[data-theme="dark"] .sidebar-link:hover { background: #242430; color: #f0f0f5; }
html[data-theme="dark"] .sidebar-link.active { background: var(--accent-tint); color: #c9c1ff; }
html[data-theme="dark"] .sidebar-scroll { scrollbar-color: #3a3a47 transparent; }
html[data-theme="dark"] ::selection { background: #3d3480; color: #fff; }
html[data-theme="dark"] .theme-toggle, html[data-theme="dark"] .menu-toggle {
    background: #1b1b24; border-color: #2c2c37; color: #b8b8c6;
}
html[data-theme="dark"] .theme-toggle:hover, html[data-theme="dark"] .menu-toggle:hover { background: #262632; color: #fff; }

/* Пастельные кнопки-иконки в таблицах (переопределения из base.html) */
html[data-theme="dark"] a[class~="rounded"][class*="bg-yellow"], html[data-theme="dark"] button[class~="rounded"][class*="bg-yellow"],
html[data-theme="dark"] a[class~="rounded"][class*="bg-amber"], html[data-theme="dark"] button[class~="rounded"][class*="bg-amber"] { background: rgba(245,158,11,.18) !important; }
html[data-theme="dark"] a[class~="rounded"][class*="bg-red"], html[data-theme="dark"] button[class~="rounded"][class*="bg-red"] { background: rgba(239,68,68,.18) !important; }
html[data-theme="dark"] a[class~="rounded"][class*="bg-green"], html[data-theme="dark"] button[class~="rounded"][class*="bg-green"],
html[data-theme="dark"] a[class~="rounded"][class*="bg-emerald"], html[data-theme="dark"] button[class~="rounded"][class*="bg-emerald"] { background: rgba(34,197,94,.18) !important; }
html[data-theme="dark"] a[class~="rounded"][class*="bg-blue"], html[data-theme="dark"] button[class~="rounded"][class*="bg-blue"],
html[data-theme="dark"] a[class~="rounded"][class*="bg-indigo"], html[data-theme="dark"] button[class~="rounded"][class*="bg-indigo"],
html[data-theme="dark"] a[class~="rounded"][class*="bg-purple"], html[data-theme="dark"] button[class~="rounded"][class*="bg-purple"] { background: rgba(129,115,245,.2) !important; }
html[data-theme="dark"] a[class~="rounded"][class*="bg-gray"], html[data-theme="dark"] button[class~="rounded"][class*="bg-gray"] { background: #2a2a36 !important; }
/* Иконки-картинки в этих кнопках цветные — на тёмном фоне чуть ярче, без перекраски */
html[data-theme="dark"] a[class~="rounded"] img[src*="/icons/"], html[data-theme="dark"] button[class~="rounded"] img[src*="/icons/"] {
    filter: brightness(1.15) saturate(1.1);
}
/* Второстепенные белые кнопки с рамкой */
html[data-theme="dark"] a[class*="border-gray"][class*="rounded"]:hover,
html[data-theme="dark"] button[class*="border-gray"][class*="rounded"]:hover { color: #c9c1ff !important; }

/* Всплывающие окна интерактивного тура */
html[data-theme="dark"] .site-tour-tooltip { background: #1f1f29; }
html[data-theme="dark"] .site-tour-tooltip h4 { color: #f0f0f5; }
html[data-theme="dark"] .site-tour-tooltip p { color: #b8b8c6; }
html[data-theme="dark"] .site-tour-prev { background: #2c2c38; color: #e0e0e8; }

/* Карты (Leaflet): тёмная подложка без перекраски меток и фото */
/* Тёмная подложка карт — в static/js/map-tiles.js (плитки перекрашиваются один раз при загрузке). CSS-фильтр — только запасной вариант для браузеров без фильтров в canvas: на весь слой он пересчитывался на каждом кадре и карта подлагивала. */
html[data-theme="dark"] .promo-tiles-css-dark { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.8); }
html[data-theme="dark"] .leaflet-container { background: #1a1a22; }
html[data-theme="dark"] .leaflet-popup-content-wrapper, html[data-theme="dark"] .leaflet-popup-tip {
    background: #1f1f29; color: #e8e8ee;
}
html[data-theme="dark"] .leaflet-bar a { background: #1f1f29; color: #e8e8ee; border-color: #33333f; }
html[data-theme="dark"] .leaflet-control-attribution { background: rgba(20,20,26,.8) !important; color: #9a9aa8; }
html[data-theme="dark"] .leaflet-control-attribution a { color: #b7aefc; }

/* Логотип в меню — белая картинка, в тёмной теме хотя бы со скруглением */
html[data-theme="dark"] .app-sidebar img[src*="logo"] { border-radius: 6px; }

