/* style.css — исправленная и оптимизированная версия */

:root {
    --terminal-green:     #9fff9f;
    --terminal-green-dim: #40c940;
    --terminal-bg:        #0a1a0a;
    --text-muted:         #308030;
    --error-red:          #ff4040;
    --scanline:           rgba(0, 255, 0, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #000;
    color: var(--terminal-green);
    font-family: 'VT323', monospace;
    font-size: 1.35rem;           /* базовый чуть меньше */
    line-height: 1.4;
    height: 100vh;
    overflow: hidden;
    image-rendering: pixelated;
    background: radial-gradient(circle at center, #0f2f0f 0%, #000 82%);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(to bottom, transparent 0, var(--scanline) 1px, transparent 3px);
    pointer-events: none;
    z-index: 9999;
    animation: scan 10s linear infinite;
}

@keyframes scan {
    to { transform: translateY(100%); }
}

.crt-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 50% 50%, transparent 38%, rgba(0,0,0,0.65) 100%);
    box-shadow: inset 0 0 100px #000;
    z-index: 9998;
}

.container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1.2rem;
    max-width: 1280px;
    margin: 0 auto;
}

header {
    border-bottom: 1px solid var(--terminal-green-dim);
    padding-bottom: 0.6rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.9rem;            /* было ~2.6 → уменьшили почти в 1.4 раза */
    text-transform: uppercase;
    letter-spacing: 0.1em;
    animation: glitch 5s infinite;
    text-shadow: 0 0 5px var(--terminal-green-dim);
}

header p {
    color: var(--text-muted);
    font-size: 1.15rem;
}

.main {
    flex: 1;
    display: grid;
    grid-template-columns: 3fr 1fr;
    gap: 1.4rem;
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    background: rgba(3, 15, 3, 0.8);
    border: 1px solid var(--terminal-green-dim);
    box-shadow: 0 0 16px rgba(0, 255, 80, 0.1);
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    scrollbar-width: thin;
    scrollbar-color: var(--terminal-green-dim) #0003;
}

/* новый чат → сообщения снизу */
.messages:empty::before {
    content: "";
    flex: 1;
}

.messages > :first-child {
    margin-top: auto;
}

.messages::-webkit-scrollbar {
    width: 5px;
}
.messages::-webkit-scrollbar-track {
    background: #0003;
}
.messages::-webkit-scrollbar-thumb {
    background: var(--terminal-green-dim);
    border-radius: 2px;
}
.messages::-webkit-scrollbar-thumb:hover {
    background: #88ff88;
}

.input-area {
    display: flex;
    border-top: 1px solid var(--terminal-green-dim);
    padding: 0.8rem 1rem;
    background: rgba(0, 8, 0, 0.8);
    gap: 0.5rem;
    flex-shrink: 0;
}

#question-input {
    flex: 1;
    background: #0006;
    border: 1px solid var(--terminal-green-dim);
    color: inherit;
    font-family: inherit;
    font-size: 1.3rem;
    padding: 0.55rem 0.9rem;
    outline: none;
}

#question-input:focus {
    border-color: #99ff99;
    box-shadow: 0 0 7px #99ff9940;
}

#question-input::placeholder {
    color: #308030;
    opacity: 0.65;
}

#send-btn {
    background: transparent;
    border: 1px solid var(--terminal-green-dim);
    color: inherit;
    font-family: inherit;
    font-size: 1.25rem;
    padding: 0.55rem 1.2rem;
    cursor: pointer;
    white-space: nowrap;
    transition: 0.14s;
}

#send-btn:hover {
    background: var(--terminal-green-dim);
    color: #000;
    box-shadow: 0 0 12px var(--terminal-green);
}

/* Сообщения */
.message {
    animation: appear 0.35s forwards;
    padding: 0.45rem 0.9rem;
    border-left: 3px solid transparent;
    background: rgba(0, 18, 0, 0.35);
    max-width: 86%;
    word-break: break-word;
    opacity: 0;
}

.message.user {
    border-left-color: #99ff99;
    background: rgba(18, 55, 18, 0.5);
    align-self: flex-end;
    border-radius: 3px 0 0 3px;
}

.message.bot {
    border-left-color: var(--terminal-green);
    align-self: flex-start;
    border-radius: 0 3px 3px 0;
}

.source {
    font-size: 1rem;
    opacity: 50%;
}

@keyframes appear {
    to { opacity: 1; transform: translateY(0); }
}

/* Sidebar */
.sidebar {
    background: rgba(3, 15, 3, 0.8);
    border: 1px solid var(--terminal-green-dim);
    padding: 1rem;
    overflow-y: auto;
    box-shadow: 0 0 16px rgba(0, 255, 80, 0.09);
}

.sidebar h2 {
    font-size: 1.35rem;
    color: #88ff88;
    margin-bottom: 0.6rem;
    text-shadow: 0 0 5px #88ff88aa;
    border-bottom: 1px dashed var(--terminal-green-dim);
    padding-bottom: 0.3rem;
}

.sidebar h3 {
    font-size: 1.15rem;
    color: #77ff77;
    margin: 1.2rem 0 0.5rem;
}

.prompt-editor {
    width: 100%;
    min-height: 100px;
    background: #000;
    color: inherit;
    border: 1px solid var(--terminal-green-dim);
    font-family: inherit;
    font-size: 1.15rem;
    padding: 0.7rem;
    resize: vertical;
}

.save-prompt-btn, .action-btn {
    width: 100%;
    margin-top: 0.5rem;
    background: transparent;
    border: 1px solid var(--terminal-green-dim);
    color: inherit;
    padding: 0.55rem;
    font-size: 1.2rem;
    cursor: pointer;
}

.save-prompt-btn:hover, .action-btn:hover {
    background: rgba(100, 255, 100, 0.18);
}

/* мобильная адаптация */
/* Мобильные устройства — до 900px (планшеты вертикально и телефоны) */
@media (max-width: 900px) {
    body {
        font-size: 1.1rem;
    }

    header {
        border-bottom: 0px;
    }

    header h1 {
        font-size: 0.8rem;
    }

    header p {
        font-size: 0.5rem;
    }

    .main {
        display: block;
        height: 100%;
    }

    .container {
        height: 100vh;
        display: flex;
        flex-direction: column;
        padding: 1rem;
        max-width: 1280px;
        margin: 0 auto;
    }

    .chat-container {
        height: auto;
        min-height: calc(100vh - 160px);
        margin: 0;
        border-radius: 0;
    }

    .messages {
        padding: 0.8rem;
        min-height: calc(100% - 60px);
    }

    .message {
        max-width: 92%;
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .source {
        font-size: 0.6rem;
        opacity: 50%;
    }

    .input-area {
        position: sticky;
        bottom: 0;
        z-index: 5;
        background: rgba(0, 8, 0, 0.92);
    }

    #question-input {
        font-size: 0.7rem;
        padding: 0.2rem 0.3rem;
    }

    #send-btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.3rem;
    }

    .sidebar {
        display: none !important;
    }

    .sidebar h2 {
        font-size: 1.2rem;
    }

    .sidebar h3 {
        font-size: 1.05rem;
    }

    .prompt-editor {
        font-size: 1rem;
        min-height: 80px;
    }

    .save-prompt-btn, .action-btn {
        font-size: 1.05rem;
        padding: 0.5rem;
    }
}

/* ──────────────────────────────────────────────
   Мобильный статус-бар в правом верхнем углу
   ────────────────────────────────────────────── */

.mobile-status-bar {
    display: none;                    /* по умолчанию скрыт на десктопе */
}

/* Только на мобильных */
@media (max-width: 900px) {
    .mobile-status-bar {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 0.25rem;
        position: absolute;
        top: 0.8rem;
        right: 1rem;
        z-index: 10;
    }

    .status-column {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        color: #88ff88;
        font-size: 1rem;
        font-weight: bold;
        text-shadow: 0 0 4px #88ff88aa;
        white-space: nowrap;
    }

    .status-text {
        opacity: 0.85;
        font-size: 0.7rem;
    }

    .status-value {
        color: #99ff99;
        font-size: 0.7rem;
    }

    .action-btn {
        width: 90%;
        margin-top: 0.1rem;
        background: transparent;
        border: 1px solid var(--terminal-green-dim);
        color: inherit;
        padding: 0.1rem;
        font-size: 0.5rem;
        cursor: pointer;
    }
}

/* На десктопе полностью скрываем мобильный блок */
@media (min-width: 901px) {
    .mobile-status-bar {
        display: none !important;
    }
}