/* ==================================================================
   Header (промпт 09: единый хедер на всех страницах)
   Подключается во все страницы через <link rel="stylesheet" href="/static/css/header.css">
   в <head> и <script src="/static/js/header.js"> перед </body>.
================================================================== */

/* --- Кнопка «Помощь разработчику» под логотипом (донаты) --- */
.donate-btn-wrap {
    margin: 0 0 12px;
}
.donate-btn {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 9px 14px;
    background: #922b21;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease;
}
.donate-btn:hover {
    background: #a93226;
}
.donate-btn:active {
    background: #7f1d1d;
}

/* --- Основной хедер (промпт 19, задача D: теперь ВНУТРИ левой колонки) --- */
#csg-header {
    background: #fafbfc;
    border: 1px solid #e8edf2;
    border-radius: 8px;
    padding: 12px 12px;
    margin-bottom: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.header-inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

/* --- Бренд-строка: логотип в «кубике» слева от «Калькулятор КСГ» --- */
h2.app-brand,
.app-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 10px;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
    color: #fff;
}

.app-logo-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.app-logo-box img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* --- Строка пользователя (аватар, имя, «>», выход) --- */
.header-user-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.header-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* --- Левая часть --- */
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #2c3e50;
    text-decoration: none;
    white-space: nowrap;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #ecf0f1;
    flex-shrink: 0;
}

.header-name {
    font-size: 0.85rem;
    color: #2c3e50;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Кнопка « > » (промпт 19, задачи D3/J1) --- */
.admin-link,
.profile-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #ecf0f1;
    color: #2c3e50;
    font-size: 1rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    flex-shrink: 0;
    border: 1px solid #d5dde5;
    line-height: 1;
}

.admin-link:hover,
.profile-link:hover {
    background: #3498db;
    color: #fff;
}

/* --- Иконка выхода больше не показывается (выход — через контекстное меню) --- */
#header-logout-btn {
    display: none !important;
}

/* --- Контекстное меню пользователя (промпт 19) --- */
.csg-user-menu {
    position: fixed;
    z-index: 4000;
    background: #ffffff;
    border: 1px solid #e8edf2;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    min-width: 230px;
    padding: 6px;
}
.csg-user-menu a,
.csg-user-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    border: none;
    background: none;
    color: #2c3e50;
    font-size: 0.92rem;
    text-decoration: none;
    cursor: pointer;
    border-radius: 6px;
    box-sizing: border-box;
}
.csg-user-menu a:hover,
.csg-user-menu button:hover {
    background: #f0f4f7;
}
.csg-user-menu button:last-child {
    color: #c0392b;
    border-top: 1px solid #eef1f5;
    margin-top: 4px;
}

/* --- Плашка trial --- */
#trial-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    display: none;
}

#trial-badge.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

#trial-badge.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

#trial-badge.info {
    background: #d1ecf1;
    color: #0c5176;
    border: 1px solid #bee5eb;
}

/* --- Правая часть (кнопка выхода) --- */
.header-right {
    display: flex;
    align-items: center;
}

/* --- Простая двухколоночная раскладка (страницы без сайдбара) --- */
.app-layout { display: flex; gap: 20px; padding: 20px; align-items: flex-start; }
.app-sidebar { width: 240px; flex-shrink: 0; }
.app-main { flex: 1; min-width: 0; }
.app-nav { margin-top: 12px; }
.app-nav a {
    display: block;
    padding: 8px 10px;
    margin-bottom: 6px;
    background: #ecf0f1;
    color: #2c3e50;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.9rem;
}
.app-nav a:hover { background: #d5dbdb; }

.exit-icon {
    width: 28px;
    height: 28px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.exit-icon:hover {
    opacity: 1;
    filter: invert(32%) sepia(15%) saturate(150%) hue-rotate(340deg);
}

/* --- Диалог выхода --- */
.logout-dialog-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.logout-dialog-overlay.show {
    display: flex;
}

.logout-dialog {
    background: #ffffff;
    border-radius: 8px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.logout-text {
    font-size: 1rem;
    color: #333;
    margin-bottom: 20px;
}

.logout-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn-confirm {
    padding: 10px 20px;
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-confirm:hover {
    background: #c0392b;
}

.btn-cancel {
    padding: 10px 20px;
    background: #ecf0f1;
    color: #333;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-cancel:hover {
    background: #d5dbdb;
}

/* --- Кнопка «Войти» под логотипом (промпт 19, задача A2) --- */
.login-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 9px 12px;
    background: #2c3e50;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    text-align: center;
}

.login-btn:hover {
    background: #34495e;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Адаптивность --- */
@media (max-width: 1024px) {
    .app-title {
        font-size: 1rem;
    }
    .header-avatar {
        width: 32px;
        height: 32px;
    }
    .header-name {
        font-size: 0.8rem;
    }
}

@media (max-width: 768px) {
    .header-inner {
        padding: 0 12px;
    }
    .header-avatar {
        width: 28px;
        height: 28px;
    }
    .header-name {
        font-size: 0.75rem;
    }
    .app-title {
        font-size: 0.95rem;
    }
}
/* ==================================================================
   ЕДИНЫЙ САЙДБАР (все страницы приложения)
   Шаблон разметки (рендерит static/js/sidebar.js):
       <aside class="sidebar">
           <div id="sidebar-top"></div>
           <script src="/static/js/sidebar.js"></script>
           <nav class="sidebar-menu" id="sidebar-menu"></nav>
           ... секции страницы ...
       </aside>
   Кнопки меню: без заливки, серый текст, активная — белая + жирная
   зелёная полоса слева, наведение — серый фон + зелёная полоса.
================================================================== */

/* Раскладка страницы (страницы с единым сайдбаром могут не грузить main.css) */
.container {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    min-width: 0;
    padding: 20px;
    margin-left: 260px;
    width: calc(100vw - 260px);
    box-sizing: border-box;
}

/* Сам сайдбар: 260px — минимально под фильтры главной + блок пользователя */
.sidebar {
    width: 260px;
    min-width: 260px;
    background-color: #2c3e50;
    color: #ecf0f1;
    padding: 18px;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    box-sizing: border-box;
}

/* Бренд-строка в сайдбаре (снимаем унаследованные стили h2 предыдущих версий) */
.sidebar h2.app-brand {
    margin: 0 0 12px;
    padding: 0;
    border-bottom: none;
    position: static;
    background: transparent;
    top: auto;
    z-index: auto;
}

.sidebar-menu {
    margin-top: 8px;
}

/* --- Кнопки навигации (единый вид на всех страницах) --- */
.sidebar .nav-btn,
.sidebar-menu .nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    margin: 0;
    background: transparent;
    color: #96a6b5;
    border: none;
    border-left: 4px solid transparent;
    border-radius: 0;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1.2;
    text-align: left;
    text-decoration: none;
    box-sizing: border-box;
    font-family: inherit;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.sidebar .nav-btn .nav-icon,
.sidebar-menu .nav-btn .nav-icon {
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.sidebar .nav-btn .nav-label,
.sidebar-menu .nav-btn .nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Наведение: более яркий серый фон + зелёная полоса слева */
.sidebar .nav-btn:hover,
.sidebar-menu .nav-btn:hover {
    background: #3a5268;
    color: #f5f7fa;
    border-left-color: #2ecc71;
}

/* Активная (окно, в котором находимся): белый жирный текст + жирная
   зелёная полоса слева (постоянно) */
.sidebar .nav-btn.active,
.sidebar-menu .nav-btn.active {
    background: transparent;
    color: #fff;
    font-weight: 700;
    border-left-color: #27ae60;
}

/* Запрещённые по правам пункты: блокировка классом (без inline-стилей,
   чтобы при загрузке/переходах не было мерцания) */
.nav-denied {
    opacity: 0.45;
    pointer-events: none;
}

/* --- Подменю «Закупки» → «Закупки GOV» / «Анализ СВ цены» (Task 15 §C.1) --- */
.nav-group {
    position: relative;
}

.nav-btn.nav-parent {
    background: transparent;
    color: #96a6b5;
}

.nav-btn.nav-parent:hover {
    background: #3a5268;
    color: #f5f7fa;
    border-left-color: #2ecc71;
}

.nav-chevron {
    margin-left: auto;
    font-size: 0.75rem;
    opacity: 0.7;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.nav-group.open .nav-chevron {
    transform: rotate(180deg);
}

.nav-submenu {
    display: none;
    padding: 2px 0 6px 22px;
}

.nav-group.open .nav-submenu {
    display: block;
}

.nav-submenu .nav-btn {
    padding: 7px 12px;
    font-size: 0.9rem;
    border-left-width: 2px;
}

.nav-submenu .nav-btn.active {
    font-weight: 700;
    color: #fff;
    border-left-color: #27ae60;
}

/* Адаптивность: на узких экранах сайдбар раскрывается сверху */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }
    .layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        max-height: none;
        position: relative;
        left: auto;
        top: auto;
    }
    .main-content {
        margin-left: 0;
        width: 100%;
    }
}

