/* =========================================
   AI Cloud - Адаптивен CSS (Mistral версия)
   Тъмната тема и чат стиловете са от стария дизайн;
   нови са панелът с проекти/чатове, бутонът за търсене и редакторът на проект.
   ========================================= */

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    background-color: #121212;
    color: #e0e0e0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    height: var(--vh, 100vh);
    width: 100%;
    overflow: hidden;
    position: relative;
}

.container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    background: #1e1e1e;
    height: var(--vh, 100%);
    position: relative;
    overflow: hidden;
}

/* --- Хедър с лого --- */
header {
    padding: 10px 20px;
    background: #252525;
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.logo-container {
    display: flex;
    align-items: center;
    margin-right: auto;
}

.logo-img {
    height: 40px;
    width: auto;
    display: block;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #888;
    font-size: 0.9em;
}

#model-select {
    padding: 8px 12px;
    background: #333;
    color: white;
    border: 1px solid #444;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    font-size: 0.95em;
    max-width: 200px;
    text-overflow: ellipsis;
}

.icon-btn {
    background: none;
    border: none;
    color: #ccc;
    font-size: 1.3em;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
}

.icon-btn:hover {
    background: #333;
    color: #fff;
}

.icon-btn.small {
    font-size: 1em;
}

#menu-btn {
    display: none;
}

/* --- Основна подредба: панел + чат --- */
.layout {
    flex: 1;
    display: flex;
    min-height: 0;
    position: relative;
}

/* --- Панел с проекти и чатове --- */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    background: #1a1a1a;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.side-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px 0;
}

.side-projects {
    max-height: 40%;
    border-bottom: 1px solid #2c2c2c;
}

.side-chats {
    flex: 1;
}

.side-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 14px 8px 14px;
    color: #888;
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.side-add {
    background: none;
    border: 1px solid #3a3a3a;
    color: #007bff;
    border-radius: 14px;
    padding: 3px 10px;
    cursor: pointer;
    font-size: 1em;
    text-transform: none;
    letter-spacing: 0;
}

.side-add:hover {
    border-color: #007bff;
}

.side-add:disabled {
    color: #555;
    border-color: #2a2a2a;
    cursor: not-allowed;
}

.side-list {
    list-style: none;
    margin: 0;
    padding: 0 6px;
    overflow-y: auto;
    min-height: 0;
}

.side-list::-webkit-scrollbar { width: 6px; }
.side-list::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

.side-item {
    display: flex;
    align-items: center;
    border-radius: 8px;
    margin-bottom: 2px;
}

.side-item:hover {
    background: #252525;
}

.side-item.active {
    background: #0056b3;
}

.side-main {
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    color: #ddd;
    text-align: left;
    padding: 8px 10px;
    cursor: pointer;
    font: inherit;
    font-size: 0.9em;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.side-item.active .side-main {
    color: #fff;
}

.side-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-date {
    color: #777;
    font-size: 0.82em;
    flex-shrink: 0;
}

.side-item.active .side-date {
    color: #cfe2ff;
}

.side-act {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 6px 7px;
    border-radius: 6px;
    font-size: 0.85em;
    opacity: 0;
}

.side-item:hover .side-act,
.side-item.active .side-act,
.side-act:focus-visible {
    opacity: 1;
}

@media (hover: none) {
    .side-act { opacity: 1; }
}

.side-act:hover {
    color: #fff;
    background: #333;
}

.side-act.danger:hover {
    background: #5a2d2d;
}

.side-empty {
    color: #666;
    font-size: 0.85em;
    padding: 8px 12px;
    font-style: italic;
}

/* Докато AI отговаря, смяна на чат/проект е блокирана */
.sidebar.locked .side-list,
.sidebar.locked .side-add {
    pointer-events: none;
    opacity: 0.5;
}

/* --- Чат колона --- */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 20px;
    border-bottom: 1px solid #2c2c2c;
    color: #999;
    font-size: 0.85em;
    min-height: 38px;
}

#chat-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Чат зона (скролваща се) --- */
#chat-box {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 25px 30px 30px 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

#chat-box::-webkit-scrollbar { width: 8px; }
#chat-box::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.1); }
#chat-box::-webkit-scrollbar-thumb { background-color: #333; border-radius: 4px; }
#chat-box::-webkit-scrollbar-thumb:hover { background-color: #444; }

.empty-state {
    margin: auto;
    text-align: center;
    color: #777;
    padding: 20px;
}

.empty-title {
    font-size: 1.2em;
    color: #bbb;
    margin-bottom: 6px;
}

/* --- Съобщения --- */
.message {
    padding: 14px 18px;
    border-radius: 18px;
    max-width: 80%;
    line-height: 1.6;
    font-size: 0.95em;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.user {
    background: #0056b3;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.message.pending {
    opacity: 0.6;
}

.ai {
    background: #2d2d2d;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid #3a3a3a;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.ai-name {
    display: block;
    font-weight: bold;
    color: #007bff;
    margin-bottom: 6px;
    font-size: 0.85em;
    letter-spacing: 0.5px;
    white-space: normal;
}

.sources {
    white-space: normal;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #3a3a3a;
    font-size: 0.85em;
    color: #aaa;
}

.sources-title {
    font-weight: 600;
}

.sources ol {
    margin: 4px 0 0 0;
    padding-left: 22px;
}

.sources a {
    color: #6cb6ff;
    word-break: break-word;
}

.message.system {
    background: transparent;
    border: 1px dashed #444;
    color: #888;
    font-style: italic;
    opacity: 0.8;
    align-self: center;
    font-size: 0.85em;
}

.message.error {
    color: #ff6b6b;
    border-color: #5a2d2d;
    opacity: 1;
}

/* --- Индикатор "AI отговаря..." --- */
.typing-container {
    background: #37373d;
    padding: 12px 16px;
    border-radius: 15px;
    border-bottom-left-radius: 2px;
    width: fit-content;
    margin-right: auto;
    border: 1px solid #444;
    margin-bottom: 10px;
}

.typing-text {
    font-size: 0.85rem;
    color: #aaa;
    margin-bottom: 8px;
    font-style: italic;
}

.typing-dots {
    display: flex;
    gap: 5px;
    padding-left: 2px;
}

.dot {
    width: 6px;
    height: 6px;
    background: #007bff;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* --- Входна зона --- */
.input-area {
    background: #252525;
    border-top: 1px solid #333;
    z-index: 10;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 15px 25px 25px 25px;
    width: 100%;
}

#user-input {
    flex: 1;
    min-width: 0;
    background: #333;
    border: 1px solid #444;
    color: white;
    padding: 14px;
    border-radius: 10px;
    resize: none;
    font-family: inherit;
    font-size: 1.1rem;
    line-height: 1.4;
    min-height: 50px;
    max-height: 200px;
    outline: none;
}

#user-input:focus {
    border-color: #007bff;
}

.search-btn {
    position: relative;
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    color: #ccc;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.2em;
    transition: background 0.2s, border-color 0.2s;
}

.search-btn:hover:not(:disabled) {
    border-color: #555;
}

.search-btn.active {
    background: #0056b3;
    border-color: #007bff;
}

.search-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.badge {
    position: absolute;
    top: -7px;
    right: -7px;
    background: #007bff;
    color: #fff;
    font-size: 0.55em;
    font-weight: bold;
    border-radius: 10px;
    padding: 1px 6px;
    min-width: 18px;
    line-height: 1.5;
}

.badge:empty {
    display: none;
}

button#send-btn {
    flex-shrink: 0;
    background: #007bff;
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.95em;
    transition: background 0.2s;
    height: 50px;
}

button#send-btn:hover {
    background: #0069d9;
}

button#send-btn:disabled {
    background: #333;
    color: #555;
    cursor: not-allowed;
}

/* --- Редактор на проект --- */
.dialog {
    background: #1e1e1e;
    color: #e0e0e0;
    border: 1px solid #3a3a3a;
    border-radius: 12px;
    padding: 0;
    width: min(720px, 94vw);
    max-height: 92vh;
}

.dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}

.dialog-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
}

.dialog-form h2 {
    margin: 0 0 4px 0;
    font-size: 1.1em;
    color: #fff;
}

.dialog-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.85em;
    color: #aaa;
}

.dialog-form input,
.dialog-form textarea {
    background: #2a2a2a;
    border: 1px solid #444;
    color: #fff;
    border-radius: 8px;
    padding: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
}

.dialog-form textarea {
    min-height: 220px;
    resize: vertical;
    line-height: 1.45;
}

.dialog-form input:focus,
.dialog-form textarea:focus {
    border-color: #007bff;
}

.dialog-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.dialog-error {
    color: #ff6b6b;
    min-height: 1.2em;
    margin: 0;
    font-size: 0.85em;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.spacer {
    flex: 1;
}

.btn {
    background: #333;
    color: #ddd;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 9px 16px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9em;
}

.btn:hover {
    background: #3a3a3a;
}

.btn.primary {
    background: #007bff;
    border-color: #007bff;
    color: #fff;
    font-weight: bold;
}

.btn.primary:hover {
    background: #0069d9;
}

.btn.danger {
    background: transparent;
    color: #ff6b6b;
    border-color: #5a2d2d;
}

.btn.danger:hover {
    background: #5a2d2d;
    color: #fff;
}

/* --- Таблет и мобилен: панелът се отваря с ☰ --- */
@media (max-width: 900px) {
    #menu-btn {
        display: block;
    }

    .sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 30;
        width: min(85vw, 320px);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.4);
    }

    .sidebar.open {
        transform: none;
    }

    .overlay {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 20;
    }
}

@media (max-width: 600px) {
    .container {
        max-width: 100%;
    }

    header {
        padding: 8px 12px;
        gap: 8px;
    }

    .logo-img {
        height: 30px;
    }

    #model-select {
        padding: 6px 10px;
        max-width: 150px;
    }

    .chat-head {
        padding: 6px 15px;
    }

    #chat-box {
        padding: 15px 15px 25px 15px;
        gap: 15px;
    }

    .message {
        padding: 12px 14px;
        border-radius: 15px;
        max-width: 90%;
        font-size: 0.92em;
    }

    .input-row {
        padding: 10px 12px 20px 12px;
        gap: 8px;
    }

    #user-input {
        padding: 11px;
        border-radius: 8px;
        font-size: 16px; /* 16px, за да няма автоматичен зуум */
        min-height: 44px;
    }

    .search-btn {
        width: 44px;
        height: 44px;
        border-radius: 8px;
    }

    button#send-btn {
        padding: 11px 16px;
        border-radius: 8px;
        height: 44px;
        font-size: 0.9em;
    }

    .dialog-form {
        padding: 14px;
    }

    .dialog-grid {
        gap: 8px;
    }
}
