
/* Podstawowe style i reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, html {
    height: 100%;
    height: 100dvh;
    font-family: Arial, sans-serif;
    background-color: #f4f6f9;
    color: #333;
    overflow: hidden;
}

/* Główny kontener aplikacji */
.app-container {
    display: flex;
    height: 100%;
    width: 100vw;
    position: relative;
    overflow: hidden;
}

/* Panele boczne (wspólne style) */
.sidebar {
    width: 280px;
    background-color: #ffffff;
    border-color: #e2e8f0;
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 10;
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.sidebar-left {
    left: 0;
    border-right: 1px solid #e2e8f0;
    transform: translateX(-100%);
}

.sidebar-left.open {
    transform: translateX(0);
}

.sidebar-right {
    right: 0;
    border-left: 1px solid #e2e8f0;
    transform: translateX(100%);
}

.sidebar-right.open {
    transform: translateX(0);
}

.sidebar-header {
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #edf2f7;
}

/* Styl dla listy chatów w lewym panelu */
.chat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    flex: 1;
    margin-top: 10px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 12px;
    background-color: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #4a5568;
    transition: background-color 0.2s, border-color 0.2s;
}

.chat-item-title {
    flex: 1;
    min-width: 0;
    padding: 6px 0;
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-menu-btn {
    flex: none;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #718096;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}
.chat-menu-btn:hover { background-color: #e2e8f0; color: #2d3748; }

.chat-menu {
    position: fixed;
    z-index: 1000;
    min-width: 170px;
    padding: 4px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
}
.chat-menu[hidden] { display: none; }
.chat-menu a, .chat-menu button {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #2d3748;
    font-size: 0.9rem;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.chat-menu a:hover, .chat-menu button:hover { background-color: #edf2f7; }
.chat-menu .danger { color: #c53030; }
.chat-menu .danger:hover { background-color: #fff5f5; }

.chat-item:hover {
    background-color: #edf2f7;
    border-color: #cbd5e0;
    color: #2d3748;
}

.chat-item.active {
    background-color: #ebf8ff;
    border-color: #3182ce;
    color: #2b6cb0;
    font-weight: bold;
}

/* Centralny obszar roboczy - dynamicznie zmienia szerokość na desktopie */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: #f7fafc;
    padding: 20px;
    margin-left: 0;
    margin-right: 0;
    transition: margin 0.3s ease-in-out;
    min-width: 0;
}

.app-container.left-open .workspace {
    margin-left: 280px;
}

.app-container.right-open .workspace {
    margin-right: 280px;
}

/* Statyczne przyciski przełączania wewnątrz belki */
.toggle-btn {
    background-color: #ffffff;
    border: 1px solid #cbd5e0;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toggle-btn:hover {
    background-color: #edf2f7;
}

/* Obszar tytułowy (góra workspace) */
.workspace-header {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 15px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    gap: 15px;
    flex-shrink: 0;
}

.workspace-header-center {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    min-width: 0;
}

.assistant-selector-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    font-weight: bold;
    color: #4a5568;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.assistant-selector-wrapper select {
    padding: 6px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    background-color: #fff;
    color: #2d3748;
    cursor: pointer;
    transition: border-color 0.2s;
    max-width: 100%;
}

.assistant-selector-wrapper select:focus {
    border-color: #3182ce;
}

/* Górny wiersz: Rozmowa */
.chat-container {
    flex: 1;
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 15px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
    min-height: 0;
}

/* Style wiadomości w dialogu */
.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.4;
}

.message.user {
    align-self: flex-start;
    background-color: #ebf8ff;
    color: #2b6cb0;
    border-left: 4px solid #3182ce;
}

.message.thinking {
    align-self: center;
    background-color: #fffaf0;
    color: #c05621;
    border: 1px dashed #ed8936;
    text-align: center;
    font-style: italic;
    font-size: 0.85rem;
    max-width: 60%;
}

.message.assistant {
    align-self: flex-end;
    background-color: #f0fff4;
    color: #276749;
    border-right: 4px solid #38a169;
}

/* Dolny wiersz: Pole wpisywania promptu */
.prompt-container {
    min-height: 70px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
}

.think-selector-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-self: flex-end;
}

.think-selector-group label {
    font-size: 0.75rem;
    font-weight: bold;
    color: #718096;
    text-transform: uppercase;
}

.think-selector-group select {
    padding: 8px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 0.85rem;
    outline: none;
    background-color: #fff;
    color: #4a5568;
    cursor: pointer;
    height: 42px;
}

.prompt-container textarea {
    flex: 1;
    resize: none;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    padding: 12px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    height: 42px;
    max-height: 150px;
    overflow-y: hidden;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.prompt-container textarea:focus {
    border-color: #3182ce;
}

.prompt-container button {
    padding: 0 20px;
    background-color: #3182ce;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    height: 42px;
    transition: background-color 0.2s;
    align-self: flex-end;
    flex-shrink: 0;
}

.prompt-container button:hover {
    background-color: #2b6cb0;
}

.prompt-container button.stop-btn {
    background-color: #e53e3e;
}

.prompt-container button.stop-btn:hover {
    background-color: #c53030;
}

.prompt-container button:disabled {
    background-color: #e2e8f0;
    color: #a0aec0;
    cursor: not-allowed;
    border: 1px solid #cbd5e0;
}

/* --- STYLY DEDYKOWANE DLA URZĄDZEN MOBILNYCH --- */
@media (max-width: 768px) {
    .workspace {
        padding: 10px;
    }

    .workspace-header {
        padding: 8px 10px;
        gap: 8px;
    }

    .workspace-header-center > div:last-child {
        display: none; 
    }

    .prompt-container button {
        padding: 0 12px;
        font-size: 0.85rem;
    }

    .assistant-selector-wrapper {
        font-size: 0.85rem;
    }
}

/* --- STYLY DLA FORMULARZA KONFIGURACJI CHATU --- */
.config-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 30px;
}

.config-section {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.config-section-title {
    font-size: 1rem;
    font-weight: bold;
    color: #2d3748;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #edf2f7;
    display: flex;
    align-items: center;
    gap: 8px;
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: bold;
    color: #4a5568;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    padding: 10px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    background-color: #fff;
    color: #2d3748;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    width: 100%;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: #3182ce;
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 90px;
}

.form-group.checkbox-group {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding-top: 5px;
}

.form-group.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #3182ce;
    cursor: pointer;
}

/* Lista narzędzi przypisanych do chatu */
.tools-checklist {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}

.tool-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background-color: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #4a5568;
}

/* Pasek akcji na dole */
.config-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
}

.btn-primary {
    padding: 10px 20px;
    background-color: #3182ce;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: #2b6cb0;
}

.btn-secondary {
    padding: 10px 20px;
    background-color: #e2e8f0;
    color: #4a5568;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-secondary:hover {
    background-color: #cbd5e0;
}

/* --- Uzupełnienia formularza konfiguracji chatu --- */
.form-group .hint,
.config-note .hint,
.hint {
    font-size: 0.75rem;
    color: #718096;
    font-weight: normal;
}

.config-note {
    margin-top: 12px;
    font-size: 0.85rem;
    color: #718096;
}

.cap-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 4px;
}

.cap-chip {
    padding: 3px 10px;
    background-color: #ebf8ff;
    border: 1px solid #bee3f8;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    color: #2b6cb0;
}

.flash {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 4px;
    flex-shrink: 0;
}

.flash-success {
    background-color: #f0fff4;
    border: 1px solid #9ae6b4;
    color: #276749;
}

.flash-warning {
    background-color: #fffaf0;
    border: 1px solid #fbd38d;
    color: #c05621;
    margin-top: 8px;
}

.flash-error {
    background-color: #fff5f5;
    border: 1px solid #feb2b2;
    color: #c53030;
}

/* Błędy walidacji Symfony (ul/li) */
.form-group ul,
.flash-error ul {
    list-style: none;
    font-size: 0.8rem;
    color: #c53030;
}

.tool-item label {
    font-weight: normal;
    cursor: pointer;
}

.tool-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #3182ce;
    cursor: pointer;
}

/* --- WIDOK CZATU: strumieniowanie odpowiedzi --- */
.message { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }

.chat-empty {
    margin: auto;
    color: #a0aec0;
    font-size: 0.95rem;
}

/* Porcje odpowiedzi pojawiają się płynnie */
.chunk { animation: chunkIn 0.35s ease-out; }
@keyframes chunkIn {
    from { opacity: 0; transform: translateY(3px); filter: blur(2px); }
    to   { opacity: 1; transform: none; filter: none; }
}

.caret {
    display: inline-block;
    width: 7px;
    height: 1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background-color: #38a169;
    border-radius: 1px;
    animation: caretBlink 1s steps(2, start) infinite;
}
@keyframes caretBlink { to { visibility: hidden; } }

.reply-time {
    display: inline-block;
    margin-left: 8px;
    color: #a0aec0;
    font-size: 0.75rem;
    white-space: nowrap;
    cursor: help;
}

.aborted-tag {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    border-radius: 10px;
    background-color: #fed7d7;
    color: #c53030;
    font-size: 0.75rem;
    font-weight: bold;
    white-space: nowrap;
}

/* Myślenie maszyny: pulsujący bąbel ze strumieniem myśli, znika po zakończeniu kanału thinking */
.message.thinking-live {
    align-self: center;
    width: 60%;
    max-width: 60%;
    background: linear-gradient(110deg, #fffaf0 30%, #feebc8 50%, #fffaf0 70%);
    background-size: 200% 100%;
    color: #c05621;
    border: 1px dashed #ed8936;
    font-size: 0.85rem;
    animation: thinkShimmer 2.4s linear infinite, thinkIn 0.3s ease-out;
    white-space: normal;
}
@keyframes thinkShimmer { to { background-position: -200% 0; } }
@keyframes thinkIn {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: none; }
}
.message.thinking-live.leaving {
    animation: thinkOut 0.3s ease-in forwards;
    pointer-events: none;
}
@keyframes thinkOut {
    from { opacity: 1; transform: none; max-height: 300px; }
    to   { opacity: 0; transform: scale(0.9); max-height: 0; padding-top: 0; padding-bottom: 0; margin-top: -15px; }
}

.thinking-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    margin-bottom: 6px;
}
.thinking-brain { display: inline-block; animation: brainPulse 1.2s ease-in-out infinite; }
@keyframes brainPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.25); }
}
.thinking-dots { display: inline-flex; gap: 3px; }
.thinking-dots i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: #ed8936;
    animation: dotBounce 1.2s ease-in-out infinite;
}
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}
.thinking-stream {
    max-height: 5.5em;
    overflow-y: auto;
    font-style: italic;
    white-space: pre-wrap;
    opacity: 0.85;
    line-height: 1.35;
}

/* Statusy (kompresja, przerwanie) */
.status-pill {
    align-self: center;
    padding: 4px 14px;
    border-radius: 14px;
    background-color: #edf2f7;
    color: #4a5568;
    font-size: 0.8rem;
    animation: thinkIn 0.3s ease-out, pillPulse 1.6s ease-in-out infinite;
}
.status-pill.leaving { animation: pillOut 0.3s ease-in forwards; }
@keyframes pillOut { to { opacity: 0; transform: scale(0.9); } }
.status-pill.aborted { background-color: #fed7d7; color: #c53030; animation: thinkIn 0.3s ease-out; }
@keyframes pillPulse { 50% { opacity: 0.55; } }

/* Karty narzędzi w agentowej pętli */
.tool-card {
    align-self: flex-end;
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 8px;
    background-color: #f7fafc;
    border: 1px solid #e2e8f0;
    border-left: 4px solid #a0aec0;
    font-size: 0.82rem;
    color: #4a5568;
    animation: thinkIn 0.3s ease-out;
}
.tool-card.running { border-left-color: #ed8936; }
.tool-card.done { border-left-color: #38a169; }
.tool-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.tool-card code {
    font-size: 0.78rem;
    color: #718096;
    word-break: break-all;
}
.tool-card-result { margin-top: 4px; }
.tool-card-result summary { cursor: pointer; color: #3182ce; }
.tool-card-result pre {
    margin: 4px 0 0;
    max-height: 200px;
    overflow: auto;
    padding: 6px 8px;
    background-color: #edf2f7;
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 0.78rem;
}
.tool-card-note { margin-top: 4px; font-size: 0.75rem; color: #c53030; }
.tool-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid #fbd38d;
    border-top-color: #ed8936;
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Miernik okna kontekstowego w prawym panelu */
.ctx-meter { font-size: 0.85rem; color: #4a5568; }
.ctx-meter-label { font-size: 0.75rem; font-weight: bold; color: #718096; text-transform: uppercase; margin-bottom: 4px; }
.ctx-meter-bar { height: 10px; background-color: #e2e8f0; border-radius: 5px; overflow: hidden; }
.ctx-meter-fill { height: 100%; background-color: #3182ce; border-radius: 5px; transition: width 0.6s ease; }
.ctx-meter-value { margin-top: 4px; }

@media (max-width: 768px) {
    .message.thinking-live { width: 90%; max-width: 90%; }
    .tool-card { max-width: 95%; }
}

/* Markdown w odpowiedziach modelu */
.md-body { white-space: normal; }
.md-body > :first-child { margin-top: 0; }
.md-body > :last-child { margin-bottom: 0; }
.md-body p { margin: 0 0 0.7em; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 { margin: 0.9em 0 0.4em; line-height: 1.25; }
.md-body h1 { font-size: 1.35rem; }
.md-body h2 { font-size: 1.2rem; }
.md-body h3 { font-size: 1.08rem; }
.md-body h4, .md-body h5, .md-body h6 { font-size: 1rem; }
.md-body ul, .md-body ol { margin: 0 0 0.7em; padding-left: 1.5em; }
.md-body li { margin: 0.15em 0; }
.md-body li > p { margin: 0.3em 0; }
.md-body blockquote { margin: 0 0 0.7em; padding: 2px 12px; border-left: 3px solid #a0aec0; color: #4a5568; }
.md-body hr { border: none; border-top: 1px solid #cbd5e0; margin: 1em 0; }
.md-body a { color: #2b6cb0; }
.md-body code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88em;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.07);
}
.md-body .code-block {
    margin: 0.2em 0 0.8em;
    border-radius: 8px;
    overflow: hidden;
    background: #1a202c;
    color: #e2e8f0;
    white-space: normal;
}
.md-body .code-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 10px;
    background: #2d3748;
    font-size: 0.75rem;
    color: #a0aec0;
}
.md-body .code-copy {
    padding: 2px 8px;
    border: 1px solid #4a5568;
    border-radius: 4px;
    background: transparent;
    color: #e2e8f0;
    font-size: 0.75rem;
    cursor: pointer;
}
.md-body .code-copy:hover { background: #4a5568; }
.md-body .code-block pre { margin: 0; padding: 10px 12px; overflow-x: auto; white-space: pre; }
.md-body .code-block code { padding: 0; background: none; font-size: 0.85rem; line-height: 1.45; color: inherit; }
.md-body .hl-c { color: #8fa1b3; font-style: italic; }
.md-body .hl-s { color: #9ae6b4; }
.md-body .hl-v { color: #fbd38d; }
.md-body .hl-n { color: #f6ad55; }
.md-body .hl-k { color: #90cdf4; font-weight: 600; }
.md-body .md-table { overflow-x: auto; margin: 0 0 0.8em; }
.md-body table { border-collapse: collapse; font-size: 0.9em; }
.md-body th, .md-body td { border: 1px solid #cbd5e0; padding: 4px 10px; }
.md-body th { background: rgba(0, 0, 0, 0.05); }
.message.assistant { max-width: min(85%, 900px); }

/* Kopiowanie bloków rozmowy */
.message.user, .message.assistant { position: relative; }
.msg-copy {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.9);
    color: #4a5568;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}
.message:hover .msg-copy, .msg-copy:focus-visible { opacity: 1; }
.msg-copy:hover { background: #fff; color: #2b6cb0; }
.message.assistant { padding-right: 42px; }
.message.user { padding-right: 42px; }

/* Dymek "Skopiowano" */
.copy-toast {
    position: fixed;
    left: 50%;
    bottom: 90px;
    transform: translateX(-50%);
    padding: 8px 18px;
    border-radius: 18px;
    background: rgba(26, 32, 44, 0.92);
    color: #fff;
    font-size: 0.85rem;
    pointer-events: none;
    opacity: 0;
    z-index: 2000;
}
.copy-toast.show { animation: toastInOut 1.6s ease-out forwards; }
@keyframes toastInOut {
    0%   { opacity: 0; transform: translate(-50%, 8px); }
    12%  { opacity: 1; transform: translate(-50%, 0); }
    55%  { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -6px); }
}

/* Stopka lewego panelu */
.sidebar-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #edf2f7;
    font-size: 0.9rem;
}
.sidebar-footer a { color: #4a5568; text-decoration: none; }
.sidebar-footer a:hover { color: #2b6cb0; }

/* Strona ustawień: menu sekcji po lewej, przewijane pola po prawej */
.settings-layout {
    flex: 1;
    min-height: 0;
    display: flex;
    gap: 16px;
}
.settings-nav {
    flex: none;
    width: 220px;
    align-self: flex-start;
    padding: 8px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}
.settings-nav ul { list-style: none; }
.settings-nav-item a {
    display: block;
    padding: 10px 12px;
    border-radius: 6px;
    color: #4a5568;
    text-decoration: none;
    font-size: 0.95rem;
    border-left: 3px solid transparent;
}
.settings-nav-item a:hover { background: #edf2f7; }
.settings-nav-item.active a {
    background: #ebf8ff;
    color: #2b6cb0;
    font-weight: bold;
    border-left-color: #3182ce;
}
.settings-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding-right: 4px;
}
.settings-section {
    margin-bottom: 20px;
    padding: 18px 20px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}
.settings-section h2 {
    font-size: 1.1rem;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #edf2f7;
}
.settings-spacer { height: 30vh; } /* pozwala ostatniej sekcji dojechać do góry obszaru */
.setting-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.4fr);
    gap: 8px 24px;
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
}
.setting-row:last-child { border-bottom: none; }
.setting-label { display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; }
.setting-label label, .setting-title { font-weight: 600; color: #2d3748; }
.setting-control input[type="text"],
.setting-control input[type="number"],
.setting-control select,
.setting-control textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font: inherit;
    font-size: 0.92rem;
    background: #fff;
}
.setting-control input:focus, .setting-control select:focus, .setting-control textarea:focus {
    outline: none;
    border-color: #3182ce;
    box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.2);
}
.setting-number { display: flex; align-items: center; gap: 8px; }
.setting-number input { max-width: 160px; }
.setting-unit { color: #718096; font-size: 0.85rem; }
.setting-options { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; }
.setting-options label, .setting-switch { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.92rem; }
.setting-row.has-error .setting-control input, .setting-row.has-error .setting-control select, .setting-row.has-error .setting-control textarea { border-color: #e53e3e; }
.setting-error { margin-top: 4px; color: #c53030; font-size: 0.85rem; }
.settings-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 10px;
    padding: 12px 0;
    background: linear-gradient(to top, #f7fafc 70%, rgba(247, 250, 252, 0));
}
@media (max-width: 800px) {
    .settings-layout { flex-direction: column; }
    .settings-nav { width: 100%; }
    .settings-nav ul { display: flex; overflow-x: auto; }
    .settings-nav-item a { white-space: nowrap; }
    .setting-row { grid-template-columns: 1fr; }
}
.setting-scope { color: #805ad5; font-size: 0.75rem; }

/* Sekcja „Asystenci” na stronie ustawień */
.assistant-toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.assistant-toolbar .hint { max-width: 560px; }
.assistant-add { text-decoration: none; white-space: nowrap; }
.assistant-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
    border-top: 1px solid #f1f5f9;
}
.assistant-name { font-weight: 600; color: #2d3748; }
.assistant-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 3px 0 6px; font-size: 0.82rem; color: #718096; }
.assistant-model { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: #4a5568; }
.assistant-actions { display: flex; gap: 8px; flex: none; }
.assistant-actions .btn-secondary { padding: 7px 12px; font-size: 0.85rem; text-decoration: none; }
.assistant-actions .btn-secondary[disabled] { opacity: 0.5; cursor: not-allowed; }
.model-info { font-size: 0.85rem; color: #4a5568; display: flex; flex-direction: column; gap: 4px; }
.model-info:empty { display: none; }
.model-info-strong { font-weight: 600; color: #2b6cb0; }
.model-info-error { color: #c53030; }
.use-safe-ctx { align-self: flex-start; padding: 5px 10px; font-size: 0.8rem; }
.use-safe-ctx[hidden] { display: none; }
@media (max-width: 800px) { .assistant-row, .assistant-toolbar { flex-direction: column; align-items: stretch; } }

/* Grupy czatów według asystenta */
.chat-group { display: flex; flex-direction: column; gap: 6px; }
.chat-group-head { display: flex; align-items: center; gap: 6px; padding: 4px 4px; cursor: pointer; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #718096; list-style: none; }
.chat-group-head::-webkit-details-marker { display: none; }
.chat-group-head::before { content: '▾'; font-size: 0.8rem; }
.chat-group:not([open]) > .chat-group-head::before { content: '▸'; }
.chat-group-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-group-count { font-weight: 400; }
.chat-group-delete { background: none; border: 0; cursor: pointer; opacity: 0; font-size: 0.85rem; padding: 2px 4px; border-radius: 4px; }
.chat-group-head:hover .chat-group-delete, .chat-group-delete:focus { opacity: 1; }
.chat-group-delete:hover { background: #fed7d7; }
@media (hover: none) { .chat-group-delete { opacity: .7; } }

/* Globalny odnośnik do strony głównej (nagłówek lewego panelu) i przycisk zamknięcia ustawień */
.sidebar-header .home-link { color: inherit; text-decoration: none; display: block; }
.sidebar-header .home-link:hover { color: #2b6cb0; }
.header-close {
    padding: 6px 12px; border: 1px solid #e2e8f0; border-radius: 6px; background: #fff;
    color: #4a5568; text-decoration: none; font-size: 0.85rem; white-space: nowrap; flex-shrink: 0;
}
.header-close:hover { background: #edf2f7; color: #2d3748; }
a.home-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* --- Strona logowania --- */
.login-page {
    min-height: 100%;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 28px 28px 24px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.login-brand { text-align: center; margin-bottom: 4px; }
.login-logo { font-size: 2.4rem; line-height: 1; margin-bottom: 8px; }
.login-brand h1 { font-size: 1.2rem; color: #2d3748; }
.login-brand p { font-size: 0.85rem; color: #718096; margin-top: 4px; }
.login-card .form-group { display: flex; flex-direction: column; gap: 6px; }
.login-card .form-group label { font-size: 0.85rem; font-weight: bold; color: #4a5568; }
.login-card .form-group input[type="email"],
.login-card .form-group input[type="password"] {
    padding: 10px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 0.95rem;
    outline: none;
    font-family: inherit;
    color: #2d3748;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.login-card .form-group input:focus { border-color: #3182ce; box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1); }
.login-remember { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: #4a5568; cursor: pointer; }
.login-submit { width: 100%; padding: 11px 20px; font-size: 0.95rem; }
.login-card .flash { margin: 0; }
.login-card .flash a { color: inherit; font-weight: bold; }
a.logout-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.sidebar-footer { display: flex; justify-content: space-between; gap: 10px; }

/* --- PANEL KODU (prawa kolumna czatu) --- */
.code-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 22px; font-size: 0.85rem; color: #4a5568; }
.code-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.code-icon-btn { border: 1px solid #e2e8f0; background: #fff; border-radius: 6px; width: 28px; height: 28px; cursor: pointer; color: #4a5568; font-size: 0.95rem; line-height: 1; }
.code-icon-btn:hover { background: #edf2f7; color: #2b6cb0; }
.code-icon-btn:disabled { cursor: wait; opacity: 0.6; }
.code-icon-btn.spinning { animation: code-spin 0.9s linear infinite; }
@keyframes code-spin { to { transform: rotate(360deg); } }
.code-project { width: 100%; margin-bottom: 6px; padding: 5px; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 0.8rem; }
.code-status { font-size: 0.72rem; color: #718096; margin-bottom: 8px; }
.code-search input { width: 100%; padding: 7px 9px; border: 1px solid #cbd5e0; border-radius: 6px; font-size: 0.82rem; }
.code-search input:focus { outline: none; border-color: #3182ce; box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.15); }
.code-nav { margin-top: 6px; }
.code-link-btn { background: none; border: none; padding: 0; color: #3182ce; cursor: pointer; font-size: 0.78rem; text-align: left; }
.code-link-btn:hover { text-decoration: underline; }
.code-view { flex: 1; min-height: 0; overflow-y: auto; margin-top: 8px; padding-right: 2px; }
.code-hint, .code-loading { color: #718096; font-size: 0.78rem; line-height: 1.45; }
.code-hint code { background: #edf2f7; padding: 0 3px; border-radius: 3px; font-size: 0.75rem; }
.code-error { color: #c53030; background: #fff5f5; border: 1px solid #fed7d7; border-radius: 6px; padding: 6px 8px; font-size: 0.78rem; word-break: break-word; }
.code-head { margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1px solid #edf2f7; }
.code-head-title { font-weight: bold; color: #2d3748; word-break: break-all; }
.code-head-sub { font-size: 0.72rem; color: #718096; word-break: break-all; }
.code-item { display: block; width: 100%; text-align: left; background: none; border: none; border-radius: 5px; padding: 5px 6px; cursor: pointer; color: inherit; font: inherit; }
.code-item:hover { background: #edf2f7; }
.code-item-row { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.code-item-main { font-family: Consolas, "DejaVu Sans Mono", monospace; font-size: 0.75rem; color: #2d3748; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.code-item-side { flex-shrink: 0; font-size: 0.68rem; color: #a0aec0; }
.code-item-sub { font-size: 0.7rem; color: #718096; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-kind-class .code-item-main, .code-kind-interface .code-item-main, .code-kind-trait .code-item-main, .code-kind-enum .code-item-main { font-weight: bold; color: #2b6cb0; }
.code-kind-property .code-item-main, .code-kind-const .code-item-main, .code-kind-enum_case .code-item-main { color: #718096; }
.code-approx .code-item-main { color: #a0aec0; }
.code-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.code-action { border: 1px solid #e2e8f0; background: #f7fafc; border-radius: 5px; padding: 3px 7px; font-size: 0.72rem; color: #4a5568; cursor: pointer; }
.code-action:hover { background: #ebf8ff; border-color: #bee3f8; color: #2b6cb0; }
.code-pre { background: #1a202c; color: #e2e8f0; border-radius: 6px; padding: 8px; font-family: Consolas, "DejaVu Sans Mono", monospace; font-size: 0.72rem; line-height: 1.45; overflow: auto; white-space: pre; tab-size: 4; }
.code-dialog { margin: auto; width: min(1100px, 94vw); max-height: 88vh; border: none; border-radius: 10px; padding: 0; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); }
.code-dialog::backdrop { background: rgba(26, 32, 44, 0.55); }
.code-dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #e2e8f0; font-size: 0.85rem; font-weight: bold; color: #2d3748; word-break: break-all; }
.code-dialog-pre { margin: 0; border-radius: 0 0 10px 10px; max-height: calc(88vh - 52px); font-size: 0.8rem; padding: 14px; }

/* --- Bazy wiedzy (karta /knowledge) --- */
.kb-page { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding-bottom: 30px; }
.kb-page > .flash { margin: 0; }
.kb-crumbs { font-size: 0.9rem; font-weight: bold; color: #2d3748; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-crumbs a { color: inherit; text-decoration: none; }
.kb-crumbs a:hover { color: #2b6cb0; }
.kb-crumb-current { color: #3182ce; }
.kb-worker { font-size: 0.78rem; color: #718096; background: #f7fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 3px 10px; white-space: nowrap; flex-shrink: 0; }
.kb-worker.running { color: #276749; background: #f0fff4; border-color: #9ae6b4; }
.kb-worker:empty { display: none; }
.kb-filter { width: 100%; padding: 8px 12px; border: 1px solid #cbd5e0; border-radius: 6px; font-size: 0.9rem; margin: 4px 0 8px; }
.kb-filter[hidden], .kb-row[hidden] { display: none; }
.kb-link { color: #2d3748; text-decoration: none; }
.kb-link:hover { color: #2b6cb0; text-decoration: underline; }
.kb-desc { font-size: 0.85rem; color: #4a5568; margin-top: 2px; }
.kb-chip { padding: 2px 8px; border-radius: 10px; font-size: 0.72rem; font-weight: 600; background: #edf2f7; color: #4a5568; border: 1px solid #e2e8f0; white-space: nowrap; }
.kb-chip.ready { background: #f0fff4; color: #276749; border-color: #c6f6d5; }
.kb-chip.working { background: #fffaf0; color: #c05621; border-color: #feebc8; }
.kb-chip.failed { background: #fff5f5; color: #c53030; border-color: #fed7d7; }
.kb-chip.off { color: #a0aec0; font-weight: 400; }
.kb-gap { margin-top: 14px; }
.kb-radios { display: flex; flex-direction: column; gap: 6px; }
.kb-radios .tool-item { cursor: pointer; }
.kb-note-top { margin: 0 0 14px; color: #c05621; }
.kb-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.kb-title { font-size: 1.1rem; }
.kb-danger:hover { background: #fed7d7; color: #c53030; }
.kb-rebuild-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid #edf2f7; font-size: 0.85rem; color: #4a5568; }
.kb-rebuild-bar select, .kb-drive-bar select, .kb-search-bar select, .kb-doc-actions select { padding: 7px 10px; border: 1px solid #cbd5e0; border-radius: 6px; font-size: 0.85rem; background: #fff; color: #2d3748; }
.kb-rebuild-bar .btn-secondary, .kb-small { padding: 7px 12px; font-size: 0.85rem; }
.kb-rebuild-bar .hint { flex-basis: 100%; }
.kb-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.kb-tab { padding: 7px 14px; border: 1px solid #e2e8f0; border-radius: 6px; background: #f7fafc; color: #4a5568; cursor: pointer; font-size: 0.85rem; }
.kb-tab.active { background: #ebf8ff; border-color: #90cdf4; color: #2b6cb0; font-weight: 600; }
.kb-tab[disabled] { opacity: 0.5; cursor: not-allowed; }
.kb-drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 16px; border: 2px dashed #cbd5e0; border-radius: 8px; background: #f7fafc; cursor: pointer; text-align: center; color: #4a5568; transition: border-color .2s, background .2s; }
.kb-drop:hover, .kb-drop.over { border-color: #3182ce; background: #ebf8ff; }
.kb-drop input { display: none; }
.kb-progress { position: relative; margin-top: 10px; height: 22px; background: #edf2f7; border-radius: 6px; overflow: hidden; }
.kb-progress[hidden] { display: none; }
.kb-progress-fill { height: 100%; width: 0; background: #90cdf4; transition: width .2s; }
.kb-progress span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.78rem; color: #2d3748; }
.kb-drive-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kb-drive-path { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; color: #4a5568; overflow-wrap: anywhere; }
.kb-drive-list { margin-top: 10px; max-height: 320px; overflow-y: auto; border: 1px solid #e2e8f0; border-radius: 6px; background: #fff; }
.kb-drive-list .config-note { margin: 10px 12px; }
.kb-drive-item { display: flex; align-items: center; gap: 6px; padding: 6px 12px; font-size: 0.88rem; color: #2d3748; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.kb-drive-item:hover { background: #f7fafc; }
.kb-drive-item.file small { margin-left: auto; }
.kb-drive-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 10px; }
.kb-drive-actions .btn-primary, .kb-drive-actions .btn-secondary { padding: 8px 14px; font-size: 0.85rem; }
.kb-drive-actions .btn-primary[disabled] { opacity: 0.5; cursor: not-allowed; }
.kb-drive-actions .hint { flex-basis: 100%; }
.kb-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: #4a5568; }
.kb-results { list-style: none; margin-top: 12px; display: flex; flex-direction: column; gap: 3px; font-size: 0.85rem; max-height: 240px; overflow-y: auto; }
.kb-results[hidden] { display: none; }
.kb-results li.ok { color: #276749; }
.kb-results li.error { color: #c53030; }
.kb-count { font-weight: 400; color: #718096; }
.kb-doc { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding: 10px 0; border-top: 1px solid #f1f5f9; }
.kb-doc:first-child { border-top: 0; }
.kb-doc-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.kb-doc-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kb-doc-file { font-weight: 600; color: #2d3748; overflow-wrap: anywhere; }
.kb-doc-meta { font-size: 0.8rem; color: #718096; }
.kb-doc-error { font-size: 0.82rem; color: #c53030; overflow-wrap: anywhere; }
.kb-doc-wait { font-size: 0.82rem; color: #c05621; overflow-wrap: anywhere; }
.kb-doc-note { font-size: 0.8rem; color: #c05621; }
.kb-doc-actions { display: flex; gap: 6px; flex: none; align-items: center; }
.kb-doc-actions select { max-width: 190px; }
.kb-badge { font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: #fffaf0; color: #c05621; border: 1px solid #feebc8; }
.kb-badge.ready { background: #f0fff4; color: #276749; border-color: #c6f6d5; }
.kb-badge.failed { background: #fff5f5; color: #c53030; border-color: #fed7d7; }
.kb-badge.queued { background: #edf2f7; color: #4a5568; border-color: #e2e8f0; }
.kb-stages { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; max-width: 640px; }
.kb-stage { position: relative; height: 18px; border-radius: 4px; background: #edf2f7; overflow: hidden; }
.kb-stage-fill { position: absolute; inset: 0 auto 0 0; background: #90cdf4; transition: width .4s; }
.kb-stage.done .kb-stage-fill { background: #9ae6b4; }
.kb-stage-label { position: relative; display: block; padding: 0 6px; font-size: 0.68rem; line-height: 18px; color: #2d3748; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-stage.pending .kb-stage-label { color: #a0aec0; }
.kb-search-bar { display: flex; gap: 8px; margin-bottom: 6px; }
.kb-search-bar input { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid #cbd5e0; border-radius: 6px; font-size: 0.9rem; }
.kb-search-bar .btn-primary { padding: 9px 16px; }
#kb-search-results .config-note { margin: 10px 0 4px; }
.kb-hit { margin-top: 10px; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 6px; background: #fff; }
.kb-hit-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.kb-hit-rank { font-weight: 700; color: #3182ce; }
.kb-hit-source { font-weight: 600; color: #2d3748; margin-right: 4px; overflow-wrap: anywhere; }
.kb-hit-path { font-size: 0.8rem; color: #718096; margin: 4px 0; overflow-wrap: anywhere; }
.kb-hit-text { white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; color: #2d3748; background: #f7fafc; border-radius: 4px; padding: 8px; margin: 0; }
.kb-hit-text.collapsed { max-height: 9.5em; overflow: hidden; }
.kb-link-btn { background: none; border: 0; color: #3182ce; cursor: pointer; font-size: 0.8rem; padding: 4px 0; }
@media (max-width: 800px) {
    .kb-head, .kb-doc { flex-direction: column; align-items: stretch; }
    .kb-stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kb-search-bar { flex-wrap: wrap; }
    .workspace-header .kb-worker { display: none; }
}

/* Numer wersji aplikacji (subtelnie, w stopce lewego panelu i na stronie logowania) */
.app-version { font-size: 0.7rem; color: #a0aec0; text-align: center; margin-top: 8px; user-select: all; }
.sidebar-footer { flex-wrap: wrap; justify-content: flex-start; gap: 6px 14px; }


/* ===================== Narzędzie imageCreate: robot malarz, obraz w czacie, powrót do rozmowy ===================== */
/* Faza 1: robot malarz, dopóki działa narzędzie */
.tool-painting { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.tool-painting svg { width: 260px; max-width: 100%; height: auto; display: block; overflow: visible; }
.tool-status { font-size: 0.85rem; color: #276749; }
.tool-status b { font-variant-numeric: tabular-nums; }
.tool-status .hint { color: #4a7c59; opacity: 0.85; }

.painter * { transform-box: view-box; }

/* Co 6 s robot wychyla się zza płótna i zerka na nas (malowany portret) */
.peek { transform-origin: 144px 64px; animation: peek 6s ease-in-out infinite; }
@keyframes peek {
    0%, 68%, 100% { transform: none; }
    76%, 90% { transform: translate(-16px, -3px) rotate(-8deg); }
}
.pupils { animation: look 6s ease-in-out infinite; }
/* Domyślnie wzrok w dół, na płótno; przy wychyleniu na wprost, na nas */
@keyframes look {
    0%, 68%, 100% { transform: translate(0, 3.5px); }
    76%, 90% { transform: translate(0, 0); }
}
.bob { animation: bob 0.36s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(1.5px); } }

.tongue { transform-origin: 151px 60px; animation: tongue 0.5s ease-in-out infinite alternate; }
@keyframes tongue { to { transform: rotate(14deg); } }
.led { animation: led 0.7s steps(2, jump-none) infinite; }
@keyframes led { 0% { fill: #f56565; } 100% { fill: #fbd38d; } }

/* Energiczne malowanie: ramię w barku, pędzel w nadgarstku */
.arm { transform-origin: 172px 94px; animation: arm 0.34s ease-in-out infinite alternate; }
@keyframes arm { from { transform: rotate(-8deg); } to { transform: rotate(9deg); } }
.brush { transform-origin: 230px 55px; animation: flick 0.21s ease-in-out infinite alternate; }
@keyframes flick { from { transform: rotate(-20deg); } to { transform: rotate(16deg); } }
.tip { animation: tip 2.4s steps(1) infinite; }
@keyframes tip { 0% { fill: #3182ce; } 25% { fill: #e53e3e; } 50% { fill: #ecc94b; } 75% { fill: #38a169; } }
.whoosh { animation: whoosh 0.34s steps(2, jump-none) infinite; }
@keyframes whoosh { 0% { opacity: 0.9; } 100% { opacity: 0.15; } }

/* Rozpryski farby lecące łukiem */
.drop { animation: fly 0.9s ease-out infinite; opacity: 0; }
@keyframes fly {
    0% { transform: translate(0, 0); opacity: 0; }
    10% { opacity: 1; }
    50% { transform: translate(var(--mx), var(--my)); opacity: 1; }
    100% { transform: translate(var(--ex), var(--ey)); opacity: 0; }
}
/* Kleksy na podłodze, głowie i farba ściekająca przez krawędź płótna: narastają, potem cykl od nowa */
.splat { transform-origin: center; transform-box: fill-box; animation: splat 9s ease-out infinite; opacity: 0; }
@keyframes splat { 0% { opacity: 0; transform: scale(0.2); } 6%, 92% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1); } }
.drip { transform-origin: top; transform-box: fill-box; animation: drip 9s ease-in infinite; transform: scaleY(0); }
@keyframes drip { 0% { transform: scaleY(0); } 30%, 92% { transform: scaleY(1); opacity: 1; } 100% { transform: scaleY(1); opacity: 0; } }

/* Obraz wygenerowany w czacie */
.message.chat-image { display: flex; flex-direction: column; gap: 4px; }
.message.chat-image img { display: block; max-width: 100%; width: 512px; height: auto; border-radius: 6px; border: 1px solid #c6f6d5; }
.chat-image-caption { font-size: 0.8rem; color: #4a7c59; }
.chat-image-caption a { color: inherit; }

/* Faza 2: obraz gotowy, model wczytuje się z powrotem do VRAM */
.returning {
    align-self: center; width: 60%; max-width: 60%; text-align: center; font-size: 0.85rem; font-style: italic;
    background: linear-gradient(110deg, #fffaf0 30%, #feebc8 50%, #fffaf0 70%); background-size: 200% 100%;
    color: #c05621; border: 1px dashed #ed8936; border-radius: 8px; padding: 10px 14px;
    animation: shimmer 2.4s linear infinite;
}
.returning b { font-variant-numeric: tabular-nums; font-style: normal; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
    .painter *, .returning { animation: none !important; }
    .drop { opacity: 0; }
    .splat, .drip { opacity: 1; transform: none; }
}
@media (max-width: 600px) {
    .returning { width: 90%; max-width: 90%; }
}

/* --- Galeria obrazów czatu (chat/_gallery.html.twig) --- */
.gallery-dialog { margin: auto; width: min(1000px, 94vw); height: min(780px, 90vh); border: none; border-radius: 10px; padding: 0; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); }
.gallery-dialog[open] { display: flex; flex-direction: column; }
.gallery-dialog::backdrop { background: rgba(26, 32, 44, 0.6); }
.gallery-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #e2e8f0; }
.gallery-title { flex: 1; font-weight: bold; color: #2d3748; }
.gallery-btn { padding: 5px 12px; background: #e2e8f0; color: #4a5568; border: none; border-radius: 6px; font-size: 0.85rem; font-weight: bold; cursor: pointer; text-decoration: none; white-space: nowrap; }
.gallery-btn:hover { background: #cbd5e0; }
.gallery-btn.danger.confirm, .gallery-icon-btn.confirm { background: #e53e3e; color: #fff; }
.gallery-add { background: #3182ce; color: #fff; }
.gallery-add:hover { background: #2b6cb0; }
.gallery-msg { padding: 0 14px; font-size: 0.85rem; color: #276749; min-height: 0; }
.gallery-msg:not(:empty) { padding: 6px 14px; }
.gallery-msg.error { color: #c53030; }
.gallery-grid { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; align-content: start; }
.gallery-grid[hidden], .gallery-viewer[hidden] { display: none; }
.gallery-empty { grid-column: 1 / -1; text-align: center; color: #718096; padding: 40px 0; }
.gallery-tile { border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; background: #f7fafc; display: flex; flex-direction: column; }
.gallery-tile img { width: 100%; aspect-ratio: 1; object-fit: cover; cursor: zoom-in; display: block; background: #edf2f7; }
.gallery-tile-foot { display: flex; align-items: center; gap: 6px; padding: 5px 8px; font-size: 0.75rem; color: #4a5568; }
.gallery-tile-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold; }
.gallery-tile-size { color: #718096; white-space: nowrap; }
.gallery-icon-btn { border: none; background: none; cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 0.8rem; white-space: nowrap; }
.gallery-icon-btn:hover { background: #fed7d7; }
.gallery-viewer { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #1a202c; }
.gallery-viewer img { max-width: 100%; max-height: calc(100% - 52px); object-fit: contain; cursor: pointer; }
.gallery-nav { position: absolute; top: calc(50% - 26px); transform: translateY(-50%); width: 44px; height: 64px; border: none; border-radius: 6px; background: rgba(0, 0, 0, 0.35); color: #fff; font-size: 2rem; cursor: pointer; z-index: 1; }
.gallery-nav:hover { background: rgba(0, 0, 0, 0.6); }
.gallery-nav.prev { left: 10px; }
.gallery-nav.next { right: 10px; }
.gallery-viewer-bar { position: absolute; bottom: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #2d3748; color: #e2e8f0; font-size: 0.85rem; }
.gallery-viewer-bar span { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-image-gone { font-size: 0.85rem; color: #718096; font-style: italic; }

/* --- Załączniki do wiadomości (spinacz) --- */
.prompt-field { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.prompt-field textarea { flex: none; width: 100%; box-sizing: border-box; }
.prompt-container .attach-btn { height: 42px; padding: 0 12px; background: #e2e8f0; color: #4a5568; font-size: 1.1rem; }
.prompt-container .attach-btn:hover:not(:disabled) { background: #cbd5e0; }
.attach-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.attach-chips[hidden] { display: none; }
.attach-chip { position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; border: 1px solid #cbd5e0; background: #edf2f7; }
.attach-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prompt-container .attach-chip button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; padding: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.7rem; line-height: 20px; }
.user-images { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.user-images img { display: block; max-width: 180px; max-height: 180px; border-radius: 6px; border: 1px solid #bee3f8; }
.upload-note { align-self: center; font-size: 0.85rem; color: #276749; background: #f0fff4; border: 1px solid #c6f6d5; border-radius: 12px; padding: 4px 12px; }
.upload-note.error { color: #c53030; background: #fff5f5; border-color: #fed7d7; }

/* --- Pasek etapów rysowania (robot malarz i „Wracam do rozmowy”) --- */
.stage-strip { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 8px; font-style: normal; }
.stage-icons { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.stage-icon { position: relative; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; font-size: 0.9rem; border-radius: 6px; background: #edf2f7; opacity: 0.35; filter: grayscale(1); cursor: default; transition: opacity 0.2s; }
.stage-icon.current { opacity: 1; filter: none; background: #feebc8; box-shadow: 0 0 0 2px #ed8936; animation: stage-pulse 1.2s ease-in-out infinite; }
.stage-icon.done { opacity: 1; filter: none; background: #c6f6d5; }
.stage-icon.done::after { content: '✓'; position: absolute; right: -3px; bottom: -4px; font-size: 0.6rem; font-weight: bold; color: #fff; background: #38a169; border-radius: 50%; width: 12px; height: 12px; line-height: 12px; text-align: center; }
.stage-label { font-size: 0.78rem; color: #744210; min-height: 1em; font-variant-numeric: tabular-nums; }
@keyframes stage-pulse { 50% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { .stage-icon.current { animation: none; } }
.stage-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 0.75rem; color: #4a7c59; padding-top: 4px; border-top: 1px dashed #c6f6d5; margin-top: 2px; }
.stage-summary-item { white-space: nowrap; font-variant-numeric: tabular-nums; cursor: default; }
.stage-summary-total { white-space: nowrap; font-weight: bold; margin-left: auto; }

/* --- Tryb głosowy (public/js/chat-voice.js) --- */
.prompt-attach { display: flex; flex-direction: row; align-items: center; gap: 6px; }
.prompt-container .voice-btn.active { background: #fed7d7; box-shadow: 0 0 0 2px #e53e3e; }
.prompt-container .voice-btn[data-state="hearing"] { background: #e53e3e; color: #fff; animation: voice-pulse 1s ease-in-out infinite; }
.prompt-container .voice-btn[data-state="speaking"] { background: #c6f6d5; box-shadow: 0 0 0 2px #38a169; }
@keyframes voice-pulse { 50% { transform: scale(1.08); } }
.voice-status { font-size: 0.85rem; color: #2c5282; background: #ebf8ff; border: 1px solid #bee3f8; border-radius: 6px; padding: 4px 10px; }
.voice-status[hidden] { display: none; }
.voice-status.hearing { color: #c53030; background: #fff5f5; border-color: #fed7d7; }
.voice-status.speaking { color: #276749; background: #f0fff4; border-color: #c6f6d5; }
.voice-status.error { color: #c53030; background: #fff5f5; border-color: #fed7d7; }
@media (prefers-reduced-motion: reduce) { .prompt-container .voice-btn[data-state="hearing"] { animation: none; } }

/* Wąski ekran (telefon, mały tablet): pole wiadomości na całą szerokość na górze, przyciski w rzędzie pod nim. */
@media (max-width: 700px) {
    .prompt-container { flex-wrap: wrap; align-items: flex-end; }
    .prompt-container .prompt-field { order: -1; flex: 1 1 100%; }
    .prompt-container #send-btn { margin-left: auto; }
}
@media (max-width: 480px) {
    .prompt-container { gap: 6px; }
    .think-selector-group select { width: 96px; padding: 8px 6px; }
    .prompt-container #stop-btn, .prompt-container #send-btn { padding-left: 12px; padding-right: 12px; }
}
.voice-field { display: flex; flex-direction: column; gap: 6px; }
.voice-field .voice-preview { align-self: flex-start; padding: 6px 12px; font-size: 0.85rem; }
.voice-preview-msg { font-size: 0.8rem; color: #c53030; }

/* --- Belka czatu: możliwości modelu i zapełnienie okna --- */
.header-info { display: flex; align-items: center; gap: 12px; min-width: 0; margin: 0 12px; flex: 0 1 auto; }
.header-caps { display: flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; min-width: 0; }
.header-caps .cap-chip { padding: 1px 8px; font-size: 0.7rem; white-space: nowrap; }
.header-ctx { display: flex; align-items: center; gap: 6px; flex-shrink: 0; cursor: default; }
.header-ctx-bar { width: 90px; height: 8px; background-color: #e2e8f0; border-radius: 4px; overflow: hidden; }
.header-ctx-fill { height: 100%; background-color: #3182ce; border-radius: 4px; transition: width 0.6s ease; }
.header-ctx-value { font-size: 0.75rem; font-weight: bold; color: #4a5568; font-variant-numeric: tabular-nums; min-width: 2.6em; }
/* tytuł czatu w jednej linii (wielokropek zamiast łamania belki) */
.workspace-header-center > div:last-child { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* za mało miejsca na etykietki obok nazwy i tytułu: zostaje sam pasek */
@media (max-width: 1250px) { .header-caps { display: none; } }
@media (max-width: 480px) {
    .assistant-selector-wrapper label { display: none; }
    .header-info { margin: 0 4px; gap: 4px; }
    .header-ctx { gap: 4px; }
    .header-ctx-bar { width: 40px; }
    .header-ctx-value { min-width: 0; }
}

/* --- Ręczne wywołanie narzędzi (prawa kolumna + okno) --- */
.manual-tools { margin-top: 18px; }
.manual-tools-list { display: flex; flex-direction: column; gap: 6px; }
.manual-tool-btn { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; padding: 6px 10px; border: 1px solid #cbd5e0; border-radius: 6px; background: #fff; cursor: pointer; text-align: left; font-size: 0.85rem; color: #2d3748; }
.manual-tool-btn:hover { background: #ebf8ff; border-color: #90cdf4; }
.manual-tool-label { font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manual-tool-name { font-family: monospace; font-size: 0.75rem; color: #718096; white-space: nowrap; }
.manual-tools-hint { margin-top: 6px; font-size: 0.75rem; }
.tool-dialog { margin: auto; width: min(640px, 94vw); max-height: 88vh; border: none; border-radius: 10px; padding: 0; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); }
.tool-dialog::backdrop { background: rgba(26, 32, 44, 0.55); }
.tool-dialog form { display: flex; flex-direction: column; max-height: 88vh; }
.tool-dialog-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid #e2e8f0; }
.tool-dialog-title { flex: 1; font-weight: bold; color: #2d3748; }
.tool-dialog-body { padding: 12px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.tool-dialog-desc { font-size: 0.85rem; color: #4a5568; background: #f7fafc; border-left: 3px solid #90cdf4; padding: 6px 10px; border-radius: 4px; }
.tool-field { display: flex; flex-direction: column; gap: 4px; }
.tool-field label { font-weight: bold; font-size: 0.85rem; color: #2d3748; font-family: monospace; }
.tool-field-prompt label { font-family: inherit; }
.tool-field input, .tool-field textarea, .tool-field select { width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid #cbd5e0; border-radius: 6px; font: inherit; font-size: 0.9rem; }
.tool-field textarea { resize: vertical; }
.tool-required { color: #e53e3e; }
.tool-type { font-weight: normal; color: #a0aec0; font-size: 0.75rem; }
.tool-field-prompt { border-top: 1px dashed #e2e8f0; padding-top: 10px; }
.tool-dialog-msg { color: #c53030; font-size: 0.85rem; min-height: 1em; }
.tool-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid #e2e8f0; }
#tool-dialog-fields { display: flex; flex-direction: column; gap: 14px; }
