/* Шапка страницы (на всех страницах) и кнопки в ней: меню, уведомления, пользователь.
   Цвета - переменные --au-* из automation.css, поэтому светлая и тёмная тема - одни и те же правила.
   Подключается в base.html последним, чтобы перекрыть старые правила шапки в main.css / main-mobile.css. */

:is(body, body.dark-theme) .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 14px;
    min-height: 72px;
    margin-bottom: 20px;
    padding: 14px 20px;
    background: var(--au-card);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid var(--au-line);
    border-radius: var(--au-radius);
    box-shadow: var(--au-shadow);
    color: var(--au-text);
}

:is(body, body.dark-theme):not(.dark-theme) .header { border-color: transparent; }

:is(body, body.dark-theme) .header-left {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

:is(body, body.dark-theme) .header-right {
    display: flex;
    flex: none;
    align-items: center;
    gap: 10px;
}

/* Значок раздела */
:is(body, body.dark-theme) .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: var(--au-grad);
    color: #fff;
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.32);
}

:is(body, body.dark-theme) .logo svg { width: 22px; height: 22px; }

/* Заголовок */
:is(body, body.dark-theme) .header-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

:is(body, body.dark-theme) .header-title {
    overflow: hidden;
    background: none;
    color: var(--au-text);
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.3px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
    -webkit-background-clip: border-box;
    background-clip: border-box;
    -webkit-text-fill-color: currentColor;
}

:is(body, body.dark-theme) .header-subtitle {
    overflow: hidden;
    color: var(--au-muted);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Кнопка меню (телефон) */
:is(body, body.dark-theme) .hamburger-btn {
    flex: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 0;
    background: var(--au-surface-2) !important;
    border: 1px solid var(--au-line) !important;
    border-radius: 13px;
    cursor: pointer;
    transform: none;
    transition: background 0.15s, border-color 0.15s;
}

:is(body, body.dark-theme) .hamburger-btn:hover { background: var(--au-accent-soft) !important; border-color: var(--au-accent-line) !important; transform: none; }
:is(body, body.dark-theme) .hamburger-btn:focus-visible { outline: 3px solid var(--au-focus); outline-offset: 2px; }
:is(body, body.dark-theme) .hamburger-btn span { display: block; width: 19px; height: 2px; border-radius: 2px; background: var(--au-text-2) !important; }
:is(body, body.dark-theme) .hamburger-btn span:nth-child(2) { width: 13px; align-self: flex-start; margin-left: 12px; }

/* Уведомления (колокольчик) */
:is(body, body.dark-theme) .global-notify-wrap { margin-right: 0; }

:is(body, body.dark-theme) .global-notify-btn {
    width: 44px;
    height: 44px;
    background: var(--au-surface-2);
    border: 1px solid var(--au-line);
    border-radius: 50%;
    box-shadow: none;
    color: var(--au-text-2);
    transform: none;
}

:is(body, body.dark-theme) .global-notify-btn:hover { background: var(--au-accent-soft); border-color: var(--au-accent-line); color: var(--au-accent-ink); box-shadow: none; transform: none; }
:is(body, body.dark-theme) .global-notify-btn:focus-visible { outline: 3px solid var(--au-focus); outline-offset: 2px; }
:is(body, body.dark-theme) .global-notify-badge { top: -4px; right: -4px; background: var(--au-err); box-shadow: 0 0 0 2px var(--au-card-solid); }

/* Пользователь: «таблетка» с аватаром */
:is(body, body.dark-theme) .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 14px 4px 4px;
    background: var(--au-surface-2) !important;
    border: 1px solid var(--au-line);
    border-radius: 999px;
    box-shadow: none !important;
    cursor: pointer;
    filter: none;
    transform: none;
    transition: background 0.15s, border-color 0.15s;
}

:is(body, body.dark-theme) .user-info:hover { background: var(--au-accent-soft) !important; border-color: var(--au-accent-line); filter: none; transform: none; }
:is(body, body.dark-theme) .user-info.active { background: var(--au-accent-soft) !important; border-color: var(--au-accent); box-shadow: 0 0 0 3px var(--au-focus) !important; }

:is(body, body.dark-theme) .user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 36px;
    height: 36px;
    background: var(--au-grad) !important;
    border-radius: 50%;
    color: #fff;
    backdrop-filter: none;
}

:is(body, body.dark-theme) .user-name {
    max-width: 160px;
    overflow: hidden;
    color: var(--au-text) !important;
    font-size: 14px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

:is(body, body.dark-theme) .user-info::after {
    content: '';
    flex: none;
    width: 7px;
    height: 7px;
    margin: -3px 2px 0 0;
    border-right: 2px solid var(--au-muted);
    border-bottom: 2px solid var(--au-muted);
    transform: rotate(45deg);
    transition: transform 0.2s;
}

:is(body, body.dark-theme) .user-info.active::after { margin-top: 3px; transform: rotate(225deg); }

/* Кнопка выхода, если страница её рисует */
:is(body, body.dark-theme) .logout-btn { border-radius: 12px; }

/* ── Тёмная полоса прокрутки: страница, меню, окна, таблицы ───── */
html:has(body.dark-theme) { color-scheme: dark; scrollbar-color: #4b5563 #1a1a1a; }
html:has(body:not(.dark-theme)) { scrollbar-color: #cbd5e1 transparent; }
body:not(.dark-theme), body:not(.dark-theme) * { scrollbar-color: #cbd5e1 transparent; }

/* ── Уведомления: кнопка ─────────────────────────────────────── */
:is(body, body.dark-theme) .global-notify-btn.has-unread { background: var(--au-accent-soft); border-color: var(--au-accent-line); color: var(--au-accent-ink); }

/* ── Уведомления: окно ───────────────────────────────────────── */
:is(body, body.dark-theme) .global-notify-overlay { background: var(--au-scrim); }

:is(body, body.dark-theme) .global-notify-panel {
    width: 392px;
    max-height: min(580px, calc(100vh - 100px));
    background: var(--au-card-solid);
    border: 1px solid var(--au-line);
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    color: var(--au-text);
}

:is(body, body.dark-theme) .global-notify-head { padding: 16px 18px 12px; border-bottom: 0; }
:is(body, body.dark-theme) .global-notify-head-title { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 800; color: var(--au-text); }
:is(body, body.dark-theme) .global-notify-head-title::before {
    content: '';
    width: 34px; height: 34px; flex: none; border-radius: 11px;
    background: center / 18px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8.5a6 6 0 0 1 12 0c0 6.2 2.5 7.7 2.5 7.7h-17S6 14.7 6 8.5z'/%3E%3Cpath d='M10 19.5a2.2 2.2 0 0 0 4 0'/%3E%3C/svg%3E"), var(--au-grad);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
:is(body, body.dark-theme) .global-notify-close { width: 34px; height: 34px; border-radius: 10px; background: var(--au-surface-2); color: var(--au-muted); font-size: 20px; }
:is(body, body.dark-theme) .global-notify-close:hover { background: var(--au-err-soft); color: var(--au-err); }
:is(body, body.dark-theme) .global-notify-handle { background: var(--au-line-strong); }

:is(body, body.dark-theme) .global-notify-tabs { gap: 4px; margin: 0 16px 6px; padding: 4px; background: var(--au-surface-2); border: 0; border-radius: 13px; }
:is(body, body.dark-theme) .global-notify-tab {
    position: relative; padding: 8px 4px; background: transparent; border: 0; border-radius: 10px;
    color: var(--au-muted); font-size: 12.5px; font-weight: 700; transition: background 0.15s, color 0.15s;
}
:is(body, body.dark-theme) .global-notify-tab:hover { color: var(--au-text); }
:is(body, body.dark-theme) .global-notify-tab.active { background: var(--au-card-solid); color: var(--au-accent-ink); box-shadow: 0 2px 8px rgba(102, 126, 234, 0.25); }
:is(body, body.dark-theme) .global-notify-tab-dot { background: var(--au-err); }

:is(body, body.dark-theme) .global-notify-body { padding: 4px 12px 14px; scrollbar-width: thin; }
:is(body, body.dark-theme) .global-notify-day-header { top: 0; padding: 10px 4px 6px; background: var(--au-card-solid); color: var(--au-faint); font-size: 11px; font-weight: 800; letter-spacing: 0.06em; }
:is(body, body.dark-theme) .global-notify-item {
    margin: 0 0 8px; padding: 12px 14px; background: var(--au-surface); border: 1px solid var(--au-line); border-radius: 14px;
    transition: border-color 0.15s;
}
:is(body, body.dark-theme) .global-notify-item:hover { border-color: var(--au-accent-line); }
:is(body, body.dark-theme) .global-notify-title { font-size: 13.5px; font-weight: 800; line-height: 1.35; color: var(--au-text); }
:is(body, body.dark-theme) .global-notify-dates { margin-top: 8px; gap: 4px 16px; }
:is(body, body.dark-theme) .global-notify-meta { font-size: 12px; color: var(--au-text-2); }
:is(body, body.dark-theme) .global-notify-meta-label { color: var(--au-faint); }
:is(body, body.dark-theme) .global-notify-sum { display: flex; align-items: center; gap: 5px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--au-line); font-size: 12.5px; color: var(--au-text-2); }
:is(body, body.dark-theme) .global-notify-sum b { color: var(--au-ok); font-weight: 800; }
:is(body, body.dark-theme) .global-notify-products { margin-top: 6px; font-size: 11.5px; line-height: 1.45; color: var(--au-muted); }
:is(body, body.dark-theme) .global-notify-empty { color: var(--au-muted); }
:is(body, body.dark-theme) .global-notify-body .au-state { padding: 34px 16px; }

/* ── AI-ассистент: кнопка ────────────────────────────────────── */
:is(body, body.dark-theme) #ai-fab {
    width: 54px; height: 54px; background: var(--au-grad);
    box-shadow: 0 10px 26px rgba(102, 126, 234, 0.45);
}
:is(body, body.dark-theme) #ai-fab:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(102, 126, 234, 0.55); }
:is(body, body.dark-theme) #ai-fab:focus-visible { outline: 3px solid var(--au-focus); outline-offset: 3px; }

/* ── AI-ассистент: окно ──────────────────────────────────────── */
:is(body, body.dark-theme) #ai-chat-window {
    right: 24px; bottom: 90px; width: 384px; height: min(580px, calc(100vh - 120px)); max-height: none;
    background: var(--au-card-solid); color: var(--au-text); border: 1px solid var(--au-line); border-radius: 22px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.32); animation: ai-pop 0.2s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes ai-pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }

:is(body, body.dark-theme) #ai-chat-header {
    gap: 12px; padding: 14px 16px; background: var(--au-card-solid); color: var(--au-text);
    border-bottom: 1px solid var(--au-line); font-size: 15px;
}
:is(body, body.dark-theme) .ai-head-ico { display: flex; align-items: center; justify-content: center; flex: none; width: 40px; height: 40px; border-radius: 13px; background: var(--au-grad); color: #fff; box-shadow: 0 4px 12px rgba(102, 126, 234, 0.32); }
:is(body, body.dark-theme) .ai-head-txt { display: flex; flex: 1; flex-direction: column; min-width: 0; }
:is(body, body.dark-theme) .ai-head-title { font-size: 15px; font-weight: 800; line-height: 1.2; color: var(--au-text); }
:is(body, body.dark-theme) .ai-head-sub { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--au-muted); }
:is(body, body.dark-theme) .ai-head-sub::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--au-ok); }
:is(body, body.dark-theme) #ai-chat-header .ai-head-btn,
:is(body, body.dark-theme) #ai-chat-close {
    display: flex; align-items: center; justify-content: center; flex: none; width: 34px; height: 34px; padding: 0;
    background: var(--au-surface-2); border: 0; border-radius: 10px; color: var(--au-muted); opacity: 1; cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
:is(body, body.dark-theme) #ai-chat-header .ai-head-btn:hover { background: var(--au-accent-soft); color: var(--au-accent-ink); }
:is(body, body.dark-theme) #ai-chat-close:hover { background: var(--au-err-soft); color: var(--au-err); }

:is(body, body.dark-theme) #ai-chat-messages { gap: 12px; padding: 16px; background: var(--au-surface); scrollbar-width: thin; }
:is(body, body.dark-theme) .ai-msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06); }
:is(body, body.dark-theme) .ai-msg.user { background: var(--au-grad); color: #fff; border-bottom-right-radius: 5px; box-shadow: 0 4px 12px rgba(102, 126, 234, 0.28); }
:is(body, body.dark-theme) .ai-msg.bot { background: var(--au-card-solid); color: var(--au-text); border: 1px solid var(--au-line); border-bottom-left-radius: 5px; }
:is(body, body.dark-theme) .ai-msg.bot.typing { color: var(--au-faint); animation: ai-typing 1.2s ease-in-out infinite; }
@keyframes ai-typing { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }
:is(body, body.dark-theme) .ai-msg a { color: var(--au-accent-ink); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
:is(body, body.dark-theme) .ai-msg.user a { color: #fff; }
:is(body, body.dark-theme) .ai-msg strong { font-weight: 800; }
:is(body, body.dark-theme) .ai-msg.bot { white-space: pre-wrap; }
:is(body, body.dark-theme) .ai-action-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
:is(body, body.dark-theme) .ai-action-controls button { border: 1px solid var(--au-line); border-radius: 10px; padding: 8px 10px; cursor: pointer; font: inherit; font-weight: 700; }
:is(body, body.dark-theme) .ai-action-apply { background: var(--au-accent); color: #fff; }
:is(body, body.dark-theme) .ai-action-cancel { background: var(--au-card-solid); color: var(--au-text); }
:is(body, body.dark-theme) .ai-action-controls button:disabled { opacity: .55; cursor: default; }

:is(body, body.dark-theme) #ai-chat-input-row { gap: 10px; padding: 12px 14px; background: var(--au-card-solid); border-top: 1px solid var(--au-line); align-items: flex-end; }
:is(body, body.dark-theme) #ai-chat-input {
    min-height: 44px; padding: 11px 14px; background: var(--au-surface); color: var(--au-text);
    border: 1.5px solid var(--au-line-strong); border-radius: 14px; font-size: 14.5px; line-height: 1.35; transition: border-color 0.15s, box-shadow 0.15s;
}
:is(body, body.dark-theme) #ai-chat-input::placeholder { color: var(--au-faint); }
:is(body, body.dark-theme) #ai-chat-input:focus { border-color: var(--au-accent); box-shadow: 0 0 0 4px var(--au-focus); }
:is(body, body.dark-theme) #ai-chat-send { width: 44px; height: 44px; background: var(--au-grad); border-radius: 14px; box-shadow: 0 6px 16px rgba(102, 126, 234, 0.3); transition: transform 0.15s, box-shadow 0.15s; }
:is(body, body.dark-theme) #ai-chat-send:hover { background: var(--au-grad); transform: translateY(-1px); box-shadow: 0 8px 20px rgba(102, 126, 234, 0.42); }
:is(body, body.dark-theme) #ai-chat-send:focus-visible { outline: 3px solid var(--au-focus); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    :is(body, body.dark-theme) #ai-chat-window { animation: none; }
    :is(body, body.dark-theme) .ai-msg.bot.typing { animation: none; }
}

/* Короткий заголовок страницы в шапке: <span class="hdr-desk">полный</span><span class="hdr-mob">короткий</span> */
.hdr-mob { display: none; }

/* Затемнение под AI-ассистентом - только на телефоне (правила в shell-mobile.css) */
.ai-chat-overlay { display: none; }
