/* Веб-версия агрегатора. Один акцент (индиго/фиолетовый), тема
   переключается атрибутом data-theme на <html> (см. inline-скрипт в
   base.html, применяется до отрисовки - без мигания светлой темы при
   загрузке). Плотный дашборд-стиль, но с премиальной отделкой: собственный
   шрифт (self-hosted, см. /static/fonts - тот же принцип, что и у htmx/
   marked/chart.js в /static/vendor, без внешних запросов к Google Fonts),
   многослойные тени вместо плоских, мягкие полупрозрачные границы вместо
   сплошного серого, единая радиусная и переходная шкала. */

@font-face {
    font-family: 'Manrope';
    font-style: normal;
    font-weight: 400 800;
    font-display: swap;
    src: url('/static/fonts/manrope-cyrillic.woff2') format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
    font-family: 'Manrope';
    font-style: normal;
    font-weight: 400 800;
    font-display: swap;
    src: url('/static/fonts/manrope-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122;
}

:root {
    --bg: #eef0f6;
    --sidebar-bg: #fbfbfd;
    --card-bg: #ffffff;
    --card-border: rgba(21, 24, 43, 0.08);
    --text: #14162b;
    --text-muted: #6b7086;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-pressed: #3730a3;
    --accent-soft: #eeecfd;
    --accent-glow: rgba(79, 70, 229, 0.28);
    --input-bg: #f6f6fb;
    --input-border: rgba(21, 24, 43, 0.12);
    --error: #dc4966;
    --error-soft: #fdecef;
    --success: #1fa971;
    --warning: #d99a2b;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
    --shadow-sm: 0 1px 2px rgba(20, 24, 50, 0.05);
    --shadow: 0 1px 2px rgba(20, 24, 50, 0.04), 0 10px 28px -12px rgba(20, 24, 50, 0.16);
    --shadow-lg: 0 4px 10px rgba(20, 24, 50, 0.06), 0 20px 48px -16px rgba(20, 24, 50, 0.28);
}

[data-theme="dark"] {
    --bg: #0a0b12;
    --sidebar-bg: #0e0f18;
    --card-bg: #13141f;
    --card-border: rgba(255, 255, 255, 0.07);
    --text: #eef0fa;
    --text-muted: #8b90ac;
    --accent: #8377ff;
    --accent-hover: #9890ff;
    --accent-pressed: #6d61f2;
    --accent-soft: rgba(131, 119, 255, 0.16);
    --accent-glow: rgba(131, 119, 255, 0.35);
    --input-bg: #191b28;
    --input-border: rgba(255, 255, 255, 0.1);
    --error: #f0788e;
    --error-soft: #35202a;
    --success: #3fd39a;
    --warning: #f0bd63;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 14px 32px -14px rgba(0, 0, 0, 0.65);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.35), 0 24px 56px -20px rgba(0, 0, 0, 0.75);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Manrope', 'Segoe UI', Arial, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Тонкий скроллбар для плотных прокручиваемых списков - на голых системных
   скроллбарах (16px, квадратные) премиальный дашборд не соберёшь. */
* { scrollbar-width: thin; scrollbar-color: var(--card-border) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
}

/* --- Каркас: сайдбар слева + контент --- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 224px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    padding: 18px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
    font-weight: 800;
    font-size: 15px;
    letter-spacing: -0.01em;
    padding: 6px 10px 20px;
}
.sidebar .brand .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-hover), var(--accent));
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.sidebar-nav a svg { width: 17px; height: 17px; flex-shrink: 0; stroke: currentColor; }
.sidebar-nav a:hover { background: var(--input-bg); text-decoration: none; color: var(--text); }
.sidebar-nav a.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.10);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 12px;
    border-top: 1px solid var(--card-border);
}
.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.sidebar-footer a:hover { background: var(--input-bg); text-decoration: none; color: var(--text); }
.sidebar-footer a svg { width: 17px; height: 17px; flex-shrink: 0; stroke: currentColor; }

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    background: none;
    border: none;
    box-shadow: none;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.15s var(--ease);
}
.theme-toggle:hover { background: var(--input-bg); }
.theme-toggle .label { display: flex; align-items: center; gap: 10px; }
.theme-toggle svg { width: 17px; height: 17px; stroke: currentColor; }
.theme-toggle .switch {
    width: 32px; height: 18px; border-radius: 999px; background: var(--input-border);
    position: relative; flex-shrink: 0;
    transition: background-color 0.15s var(--ease);
}
.theme-toggle .switch .knob {
    position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
    background: #ffffff; transition: left 0.15s var(--ease);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
[data-theme="dark"] .theme-toggle .switch { background: var(--accent); }
[data-theme="dark"] .theme-toggle .switch .knob { left: 16px; }

.main { flex: 1; min-width: 0; }

/* Мобильная верхняя панель - скрыта на десктопе, см. responsive.css */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

/* --- Карточки --- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.page-title { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; color: var(--text); margin: 0 0 12px 0; }

/* --- Кнопки: primary (default) / secondary / danger, все с местом под иконку --- */
button, .btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: linear-gradient(180deg, var(--accent-hover), var(--accent));
    color: #ffffff;
    border: none;
    border-radius: 10px;
    padding: 9px 16px;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: -0.005em;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.2;
    box-shadow: 0 1px 2px rgba(20, 24, 50, 0.08), 0 6px 16px -6px var(--accent-glow);
    transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), background-color 0.15s var(--ease);
}
button svg, .btn svg { width: 15px; height: 15px; stroke: currentColor; flex-shrink: 0; }
button:hover, .btn:hover {
    text-decoration: none;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(20, 24, 50, 0.1), 0 10px 22px -6px var(--accent-glow);
}
button:active, .btn:active { transform: translateY(0); box-shadow: 0 1px 2px rgba(20, 24, 50, 0.08); }
button:disabled {
    background: var(--input-border);
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text);
    border: 1.5px solid var(--card-border);
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
    background: var(--input-bg);
    color: var(--text);
    border-color: var(--input-border);
    box-shadow: var(--shadow-sm);
}

.btn-danger {
    background: transparent;
    color: var(--error);
    border: 1.5px solid var(--error);
    box-shadow: none;
}
.btn-danger:hover { background: var(--error-soft); color: var(--error); box-shadow: none; }

/* Группировка действий в один ряд с видимым разделением смысловых блоков */
.action-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.action-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.action-divider { width: 1px; align-self: stretch; min-height: 24px; background: var(--card-border); margin: 0 2px; }

/* --- Поля ввода --- */
input[type="text"], input[type="password"], input[type="date"], select, textarea {
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 10px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input[type="text"]:focus, input[type="password"]:focus, input[type="date"]:focus,
select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

label { font-size: 13px; color: var(--text-muted); font-weight: 600; }

.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

/* --- Множественный выбор категорий ---
   Выпадающий блок с галочками: 12 категорий в ряд не помещаются, а
   обычный <select multiple> требует Ctrl-клика и занимает много места. */
.cat-picker { position: relative; }
.cat-picker > summary {
    cursor: pointer;
    list-style: none;
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    user-select: none;
    transition: border-color 0.15s var(--ease);
}
.cat-picker > summary::-webkit-details-marker { display: none; }
.cat-picker > summary::after { content: " ▾"; color: var(--text-muted); }
.cat-picker[open] > summary::after { content: " ▴"; }
.cat-picker[open] > summary { border-color: var(--accent); }
.cat-picker-body {
    position: absolute;
    z-index: 30;
    top: calc(100% + 6px);
    left: 0;
    min-width: 260px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 10px 12px;
    box-shadow: var(--shadow-lg);
}
.cat-picker-actions {
    display: flex;
    gap: 12px;
    padding-bottom: 8px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--card-border);
}
.cat-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    cursor: pointer;
    font-weight: normal;
}
.btn-link {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: 12px;
    color: var(--accent, #4a9eff);
    cursor: pointer;
    text-decoration: underline;
}

/* --- Список новостей --- */
.news-list {
    margin-bottom: 14px;
    max-height: 60vh;
    overflow-y: auto;
}
/* Панель просмотра новости стоит НАД списком и прилипает к верху окна:
   при прокрутке списка выбранная новость всегда остаётся перед глазами.
   Своя max-height со скроллом обязательна - без неё длинная статья
   заняла бы весь экран и список стал бы недоступен. Фон непрозрачный,
   иначе проезжающий под панелью список просвечивал бы сквозь неё. */
.news-detail {
    width: 100%;
    position: sticky;
    top: 0;
    z-index: 5;
    max-height: 55vh;
    overflow-y: auto;
    background: var(--card-bg);
}

.news-item {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-left: 3px solid transparent;
    border-radius: var(--radius);
    padding: 10px 13px;
    margin-bottom: 6px;
    cursor: pointer;
    color: var(--text);
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}
.news-item:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow-sm); }
.news-item.selected { border-color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); }
.news-item .badge { font-size: 11px; color: var(--text-muted); }
.news-item .title { font-weight: 700; margin: 3px 0; letter-spacing: -0.005em; }
.news-item .meta { font-size: 12px; color: var(--text-muted); }

.star { color: var(--warning); }

/* --- Статистика --- */
.stat-cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stat-card { flex: 1; min-width: 140px; padding: 14px 16px; }
.stat-card .label { font-size: 11px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; letter-spacing: 0.04em; }
.stat-card .value { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }

.charts-row { display: flex; gap: 14px; flex-wrap: wrap; }
.chart-card { flex: 1; min-width: 320px; padding: 14px 16px; }
.chart-card canvas { max-height: 280px; }

/* --- Календарь событий --- */
.calendar-item-date { font-weight: 700; color: var(--accent); font-size: 13px; margin-bottom: 4px; }
.calendar-item .title { font-weight: 700; margin: 2px 0 6px; letter-spacing: -0.005em; }
.calendar-item .meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.calendar-item-desc { color: var(--text); font-size: 13.5px; line-height: 1.5; margin: 0 0 8px; }

/* --- Прочее --- */
.hint { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.error { color: var(--error); font-weight: 600; }
.progress-wrap { background: var(--input-border); border-radius: 6px; height: 8px; overflow: hidden; margin: 10px 0; }
.progress-bar { background: var(--accent); height: 100%; width: 0%; transition: width 0.3s var(--ease); }

.qa-answer { line-height: 1.6; }
.qa-answer p { white-space: normal; margin: 0.5em 0; }
.qa-answer h1, .qa-answer h2, .qa-answer h3 { color: var(--text); margin: 0.6em 0 0.3em; }
.qa-answer ul, .qa-answer ol { margin: 0.3em 0; padding-left: 1.4em; }
.qa-answer li { margin: 0.2em 0; }
.qa-answer li p { margin: 0; display: inline; }

.history-list { max-height: 60vh; overflow-y: auto; }
.history-item {
    display: block;
    padding: 8px 10px;
    border-bottom: 1px solid var(--bg);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.15s var(--ease);
}
.history-item:hover { background: var(--input-bg); text-decoration: none; }

.checkbox-row { display: flex; align-items: center; gap: 6px; }

.site-toggle-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; }

.login-wrap {
    max-width: 380px;
    margin: 80px auto;
    text-align: center;
}
.login-wrap .card { text-align: left; }
.login-wrap h1 { color: var(--text); font-weight: 800; letter-spacing: -0.02em; }
.login-wrap input { width: 100%; margin-bottom: 12px; }
.login-wrap button { width: 100%; justify-content: center; }

/* Универсальный сброс отступов внутри отрендеренного markdown-ответа —
   не гадаем, какой именно тег даёт большой отступ, а жёстко всё выравниваем */
.qa-answer * { margin-top: 0; margin-bottom: 0.6em; }
.qa-answer *:last-child { margin-bottom: 0; }
.qa-answer h1, .qa-answer h2, .qa-answer h3, .qa-answer h4 { margin-top: 1em; }
.qa-answer h1:first-child, .qa-answer h2:first-child,
.qa-answer h3:first-child, .qa-answer h4:first-child { margin-top: 0; }
