/**
 * BeeOS Studio — skórka pełnej strony Agenta (/agent) i logowania.
 * Aktywacja: html.agent-studio (globalne ustawienie firmy `ui_skin` ≠ classic).
 * Warianty: html.agent-studio (jasny Studio) / html.agent-studio.dark (ciemny Studio).
 * Tokeny 1:1 z cms-theme-studio.css (CMS Studio) — jeden wygląd całego BeeOS.
 * UWAGA: KAŻDA reguła musi być scoped pod `html.agent-studio`
 * (strażnik tests/test_menus_products_agent_nov2026.py). Klasy semantyczne
 * `.agent-*` żyją w <style> szablonu index.html (fallback = skórka klasyczna).
 */

/* ═══ 1. TOKENY — STUDIO JASNY (CMS: body.light.theme-studio) ═══ */
html.agent-studio {
    color-scheme: light;

    --bg-root: #f4f6fc;
    --bg-sidebar: #ffffff;
    --bg-topbar: rgba(255, 255, 255, 0.86);
    --bg-card: #ffffff;
    --bg-card-hover: #f7f8fd;
    --bg-surface: #f8f9fd;
    --bg-input: #ffffff;
    --bg-hover: #edf0f9;
    --bg-active: #e6e9f6;

    --border: #d7dceb;
    --border-light: #e6e9f2;
    --border-strong: #c3c9da;

    --text-primary: #0f121a;
    --text-secondary: #4b5468;
    --text-muted: #6d7689;

    --primary: #4f46e5;
    --primary-hover: #6d28d9;
    --primary-soft: rgba(79, 70, 229, 0.10);
    --accent: #4f46e5;
    --accent-hover: #4338ca;

    --danger: #dc2626;
    --warning: #d97706;
    --success: #059669;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 10px 30px rgba(16, 24, 40, 0.10);
    --shadow-lg: 0 24px 48px rgba(16, 24, 40, 0.16);

    /* Aliasy zgodności ze starymi stylami tej strony (styles.css) */
    --bg-primary: #f4f6fc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fd;
    --border-color: #d7dceb;
    --text: #0f121a;
    --chat-user-bg: var(--primary-soft);
    --chat-agent-bg: transparent;
    --input-bg: #ffffff;
    --glass-bg: rgba(255, 255, 255, 0.86);
    --glass-border: #e6e9f2;
    --scrollbar-thumb: #c8cdd6;
    --scrollbar-thumb-hover: #94a3b8;
}

/* ═══ 2. TOKENY — STUDIO CIEMNY (CMS: body.theme-studio) ═══ */
html.agent-studio.dark {
    color-scheme: dark;

    --bg-root: #090a0f;
    --bg-sidebar: #0a0b12;
    --bg-topbar: rgba(9, 10, 15, 0.82);
    --bg-card: #12141f;
    --bg-card-hover: #181b2a;
    --bg-surface: #0f1119;
    --bg-input: #0d0f17;
    --bg-hover: #191c2a;
    --bg-active: #20243a;

    --border: rgba(255, 255, 255, 0.10);
    --border-light: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.14);

    --text-primary: #e8eaf3;
    --text-secondary: #a9b0c3;
    --text-muted: #717890;

    --primary: #6366f1;
    --primary-hover: #8b5cf6;
    --primary-soft: rgba(99, 102, 241, 0.15);
    --accent: #6366f1;
    --accent-hover: #818cf8;

    --danger: #f87171;
    --warning: #f59e0b;
    --success: #34d399;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.55);

    --bg-primary: #090a0f;
    --bg-secondary: #12141f;
    --bg-tertiary: #0f1119;
    --border-color: rgba(255, 255, 255, 0.10);
    --text: #e8eaf3;
    --chat-user-bg: var(--primary-soft);
    --chat-agent-bg: transparent;
    --input-bg: #0d0f17;
    --glass-bg: rgba(9, 10, 15, 0.82);
    --glass-border: rgba(255, 255, 255, 0.08);
    --scrollbar-thumb: #262a3a;
    --scrollbar-thumb-hover: #343a50;
}

/* ═══ 3. POWIERZCHNIE GŁÓWNE ═══ */
html.agent-studio body {
    background-color: var(--bg-root);
    color: var(--text-primary);
}

html.agent-studio #sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
}

html.agent-studio #top-bar {
    background: var(--bg-root);
    border-bottom: 1px solid var(--border-light);
}

html.agent-studio #main-area,
html.agent-studio #chat-body {
    background: var(--bg-root);
}

/* Separatory sidebaru */
html.agent-studio #sidebar > div {
    border-color: var(--border-light);
}

/* ═══ 4. POLE WIADOMOŚCI ═══ */
html.agent-studio #input-wrapper {
    background: var(--bg-root);
    border: none;
}

html.agent-studio #input-wrapper > div:first-child {
    background: var(--bg-card);
    border-color: var(--border);
}

html.agent-studio #message-input {
    background: transparent;
    color: var(--text-primary);
}

html.agent-studio #message-input::placeholder {
    color: var(--text-muted);
}

html.agent-studio #input-toolbar {
    border-color: var(--border-light);
}

html.agent-studio #file-chips > div {
    background: var(--bg-surface);
    color: var(--text-secondary);
}

/* ═══ 5. PRZYCISKI SIDEBARU / TOPBARU ═══ */
html.agent-studio #new-chat-btn {
    background: var(--primary);
    border: 1px solid transparent;
    color: #ffffff;
}

html.agent-studio #new-chat-btn:hover {
    background: var(--primary-hover);
    color: #ffffff;
}

html.agent-studio #send-btn {
    background: var(--primary);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

html.agent-studio #send-btn:hover {
    background: var(--primary-hover);
    color: #ffffff;
}

/* Spinner w przycisku Wyślij (ikona strzałki znika, przycisk stałej szerokości) */
html.agent-studio #send-btn.sending svg,
html.agent-studio #send-btn.sending .lucide {
    display: none;
}

html.agent-studio #send-btn.sending::before {
    content: '';
    width: 14px;
    height: 14px;
    margin: 0;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: agentSendSpin 0.7s linear infinite;
}

@keyframes agentSendSpin {
    to { transform: rotate(360deg); }
}

/* Zdjęcia w czacie /agent — zawsze obrazy, nigdy linki */
html.agent-studio .ap-chat-img,
html.agent-studio .agent-chat-img {
    max-width: 100%;
    max-height: 280px;
    border-radius: 10px;
    margin: 4px 0;
    display: block;
}

html.agent-studio .ap-chat-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 4px;
    margin: 4px 0;
}

html.agent-studio .ap-chat-gallery .ap-chat-img {
    margin: 0;
    width: 100%;
    height: auto;
}

html.agent-studio .ap-chat-prodname {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 2px 0;
}

html.agent-studio .ap-chat-note {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

/* ═══ 6. LISTA SESJI ═══ */
html.agent-studio #sessions-list button {
    color: var(--text-secondary);
}

html.agent-studio #sessions-list .sess-btn {
    color: var(--text-secondary);
}

html.agent-studio #sessions-list button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

html.agent-studio .sess-row .sess-pin,
html.agent-studio .sess-row .sess-menu-icon {
    color: var(--text-muted);
}

html.agent-studio .sess-row:hover .sess-menu-icon {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

html.agent-studio .sess-row .sess-menu-icon:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

html.agent-studio .sess-dropdown {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: var(--shadow-md);
}

html.agent-studio .sess-dropdown button {
    color: var(--text-secondary);
}

html.agent-studio .sess-dropdown button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

html.agent-studio .sess-dropdown button.danger:hover {
    background: rgba(239, 68, 68, 0.14);
    color: var(--danger);
}

/* ═══ 7. PROFIL (sidebar) ═══ */
html.agent-studio #profile-btn:hover {
    background: var(--bg-hover);
}

/* ═══ 8. WIADOMOŚCI CZATU ═══ */
html.agent-studio .msg-user {
    background: var(--primary-soft);
    color: var(--text-primary);
}

html.agent-studio .msg-assistant {
    color: var(--text-primary);
}

html.agent-studio .msg-assistant .bee-card {
    background: var(--bg-card);
    border-color: var(--border);
}

html.agent-studio .msg-assistant .bee-card-body {
    color: var(--text-secondary);
}

html.agent-studio .msg-assistant td {
    border-bottom-color: var(--border-light);
}

html.agent-studio .msg-assistant img {
    border-color: var(--border);
}

/* Kropki „pisze…” (dynamiczny #typing-indicator w chat.js) */
html.agent-studio #typing-indicator span {
    background: var(--text-muted);
}

/* ═══ 9. POWIADOMIENIA ═══ */
html.agent-studio #notif-dropdown,
html.agent-studio .glass-panel {
    background: var(--bg-card);
    border-color: var(--border);
}

/* ═══ 10. LOGOWANIE ═══ */
html.agent-studio #login-overlay {
    background: var(--bg-root);
}

html.agent-studio #login-overlay > div {
    background: var(--bg-card);
    border-color: var(--border);
}

html.agent-studio #login-username,
html.agent-studio #login-password,
html.agent-studio #login-2fa {
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-primary);
}

html.agent-studio #login-username:focus,
html.agent-studio #login-password:focus,
html.agent-studio #login-2fa:focus {
    border-color: var(--primary);
}

html.agent-studio #login-btn {
    background: var(--primary);
    color: #ffffff;
}

html.agent-studio #login-btn:hover {
    background: var(--primary-hover);
    color: #ffffff;
}

/* ═══ 11. MODALE (Panel Admina / Profil / Zmiana nazwy / Usuwanie) ═══ */
html.agent-studio #admin-modal-overlay > div,
html.agent-studio #profile-modal-overlay > div,
html.agent-studio #rename-modal-overlay > div,
html.agent-studio #delete-modal-overlay > div {
    background: var(--bg-card);
    border-color: var(--border);
}

html.agent-studio #admin-modal-overlay div.border-b,
html.agent-studio #profile-modal-overlay div.border-b,
html.agent-studio #rename-modal-overlay div.border-b,
html.agent-studio #delete-modal-overlay div.border-t {
    border-color: var(--border-light);
}

html.agent-studio #admin-modal-overlay select,
html.agent-studio #profile-name-input,
html.agent-studio #rename-input {
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-primary);
}

html.agent-studio #admin-modal-overlay select:focus,
html.agent-studio #profile-name-input:focus,
html.agent-studio #rename-input:focus {
    border-color: var(--primary);
    outline: none;
}

html.agent-studio #profile-save-btn,
html.agent-studio #rename-save-btn {
    background: var(--primary);
    color: #ffffff;
}

html.agent-studio #profile-save-btn:hover,
html.agent-studio #rename-save-btn:hover {
    background: var(--primary-hover);
    color: #ffffff;
}

html.agent-studio #rename-cancel-btn,
html.agent-studio #delete-cancel-btn {
    color: var(--text-secondary);
}

html.agent-studio #rename-cancel-btn:hover,
html.agent-studio #delete-cancel-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

html.agent-studio #rag-reindex-btn {
    background: var(--bg-surface);
    color: var(--text-secondary);
}

html.agent-studio #rag-reindex-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Modal „Master Prompt" tworzony dynamicznie w chat.js (overlay bez ID) */
html.agent-studio div[class*="z-[200]"] > div {
    background: var(--bg-card);
    border-color: var(--border);
}

html.agent-studio #prompt-modal-text {
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-primary);
}

html.agent-studio #prompt-modal-text:focus {
    border-color: var(--primary);
}

html.agent-studio #prompt-modal-cancel {
    color: var(--text-secondary);
}

html.agent-studio #prompt-modal-cancel:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

html.agent-studio #prompt-modal-save {
    background: var(--primary);
    color: #ffffff;
}

html.agent-studio #prompt-modal-save:hover {
    background: var(--primary-hover);
    color: #ffffff;
}

/* ═══ 12. GALERIA ═══ */
html.agent-studio #gallery-content {
    background: var(--bg-card);
    border-left-color: var(--border);
}

html.agent-studio #gallery-trigger {
    background: var(--bg-card);
    border-color: var(--border);
}

html.agent-studio #gallery-trigger:hover {
    background: var(--bg-hover);
}

html.agent-studio #gallery-user-select {
    background: var(--bg-input);
    border-color: var(--border);
    color: var(--text-primary);
}

/* ═══ 13. DOLNY PASEK (mobile) ═══ */
html.agent-studio #bottom-bar {
    background: var(--bg-sidebar);
    border-top-color: var(--border-light);
}

/* ═══ 14. AWATARY — akcent Studio ═══ */
html.agent-studio #user-avatar,
html.agent-studio #profile-avatar-preview,
html.agent-studio #bottom-avatar {
    background-image: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #ffffff;
}

/* ═══ 15. LOGO — czytelne tło w jasnym Studio ═══ */
html.agent-studio:not(.dark) .logo-wrap {
    background: rgba(15, 18, 26, 0.04);
}

/* ═══ 16. SCROLLBARY ═══ */
html.agent-studio * {
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

html.agent-studio ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
}

html.agent-studio ::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

html.agent-studio #chat-box::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
}

/* ═══ Poprawki layoutu (2026-11-15) ═══ */
/* Lista rozmów musi się kurczyć (flex-1 + min-height:0), inaczej stopka
   profilu wychodzi poza ekran przy długiej liście sesji. */
html.agent-studio #sessions-list { min-height: 0; }
html.agent-studio #sessions-scroll { height: 100%; overflow-y: auto; }

/* Uchwyt galerii — pełna szerokość i spójny wygląd (nie „ucięty pasek") */
html.agent-studio #gallery-trigger {
    width: 30px; height: 64px; border-radius: 8px 0 0 8px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-right: none; color: var(--text-secondary);
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.18);
}
html.agent-studio #gallery-trigger:hover { color: var(--primary); }

/* ═══ 17. TRYB LIVE + BeeAgent (2026-11-24) ═══ */
html.agent-studio .agent-suggest-list {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    margin-top: 18px; max-width: 640px; margin-left: auto; margin-right: auto;
}
html.agent-studio .agent-suggest {
    text-align: left; font-size: 12px; line-height: 1.4; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
    background: var(--bg-card); color: var(--text-secondary);
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
html.agent-studio .agent-suggest:hover {
    background: var(--bg-hover); color: var(--text-primary);
    border-color: var(--primary);
}
html.agent-studio .agent-voice-status {
    padding: 2px 8px; font-size: 11px; color: var(--text-muted);
    white-space: nowrap;
}
html.agent-studio .agent-live-on {
    color: var(--primary); background: var(--bg-hover);
    border: 1px solid var(--primary);
}
html.agent-studio .agent-live-btn {
    transition: color 0.12s, background 0.12s, border-color 0.12s;
}
html.agent-studio .agent-live-btn:hover {
    color: var(--primary); background: var(--bg-hover);
}
html.agent-studio #agent-live-btn.agent-live-on {
    color: var(--primary); background: var(--bg-hover);
    border: 1px solid var(--primary);
}
@media (max-width: 768px) {
    html.agent-studio .agent-suggest-list {
        grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 12px;
    }
    html.agent-studio .agent-suggest { padding: 8px 10px; }
}
