/* ====== TWIN APP — стиль ====== */
:root {
    --bg: #0f1219;
    --bg-2: #161b26;
    --bg-3: #1e2533;
    --border: #2a3344;
    --text: #e6e9ef;
    --text-2: #aab1c0;
    --text-3: #6b7384;
    --accent: #5b8def;
    --accent-2: #4570d4;
    --user: #2c5282;
    --bot: #1e2533;
    --ok: #48bb78;
    --warn: #ed8936;
    --err: #f56565;
    --radius: 10px;
    --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
                 "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    height: 100vh;
    overflow: hidden;
}

.app {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
}

.brand {
    display: flex; align-items: center; gap: 12px;
}
.brand-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #5b8def, #4570d4);
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
    flex-shrink: 0;
}
.brand-title { font-weight: 600; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.stat {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
}
.stat-num { display: block; font-size: 20px; font-weight: 600; color: var(--accent); }
.stat-lbl { display: block; font-size: 11px; color: var(--text-3); margin-top: 2px; }

.section { display: flex; flex-direction: column; gap: 8px; }
.section-title { font-size: 12px; text-transform: uppercase; color: var(--text-3); letter-spacing: 0.5px; }

.btn {
    border: 1px solid var(--border);
    background: var(--bg-3);
    color: var(--text);
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-ghost { background: transparent; }

.materials {
    display: flex; flex-direction: column; gap: 6px;
    max-height: 280px; overflow-y: auto;
}
.material {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    display: flex; justify-content: space-between; align-items: center;
    gap: 8px;
    font-size: 12px;
}
.material-name {
    flex: 1;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.material-meta { font-size: 10px; color: var(--text-3); }
.material-del {
    background: transparent; border: none; color: var(--err);
    cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.material-del:hover { background: rgba(245,101,101,0.15); }

.select, .input {
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    width: 100%;
}
.select:focus, .input:focus { outline: none; border-color: var(--accent); }

.checkbox { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); cursor: pointer; }
.checkbox input { margin: 0; }

.footer-info { margin-top: auto; }
.api-status {
    font-size: 11px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg-3);
    text-align: center;
    color: var(--text-3);
}
.api-status.ok { color: var(--ok); }
.api-status.warn { color: var(--warn); }

/* ===== Main ===== */
.main {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.topbar {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-2);
}
.topbar-title { font-weight: 600; }
.topbar-meta { font-size: 11px; color: var(--text-3); }

.chat {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex; flex-direction: column; gap: 16px;
    background: var(--bg);
}

.msg { display: flex; gap: 10px; max-width: 800px; }
.msg-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--bg-3);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
}
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-user .msg-avatar { background: var(--accent); }
.msg-user .msg-body { background: var(--user); }
.msg-bot .msg-body { background: var(--bot); }

.msg-body {
    border-radius: var(--radius);
    padding: 10px 14px;
    line-height: 1.55;
    border: 1px solid var(--border);
    max-width: 700px;
}
.msg-text { white-space: pre-wrap; word-wrap: break-word; }
.msg-text mark { background: rgba(91,141,239,0.25); color: var(--text); padding: 0 2px; border-radius: 2px; }
.msg-text code { background: var(--bg-3); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.msg-text pre { background: var(--bg-3); padding: 10px; border-radius: var(--radius-sm); overflow-x: auto; }
.msg-text pre code { background: transparent; padding: 0; }

.msg-actions {
    margin-top: 6px;
    display: flex; gap: 8px; align-items: center;
    font-size: 11px; color: var(--text-3);
}
.msg-action {
    background: transparent; border: none; color: var(--text-3);
    cursor: pointer; padding: 2px 6px; border-radius: 4px;
    display: flex; align-items: center; gap: 4px;
}
.msg-action:hover { background: var(--bg-3); color: var(--text); }
.msg-action:disabled { opacity: 0.4; cursor: not-allowed; }
.msg-action.playing { color: var(--accent); }

.msg-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    font-size: 11px;
    color: var(--text-3);
}
.msg-sources-title { margin-bottom: 4px; }
.msg-source {
    display: block;
    padding: 3px 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.msg-typing {
    display: flex; gap: 4px; padding: 6px 4px;
}
.msg-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text-3);
    animation: typing 1.2s infinite;
}
.msg-typing span:nth-child(2) { animation-delay: 0.15s; }
.msg-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* ===== Player ===== */
.player {
    padding: 8px 20px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
}
.player audio { flex: 1; height: 32px; }
.btn-icon {
    background: transparent; border: none; color: var(--text-2);
    cursor: pointer; font-size: 16px; padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.btn-icon:hover { background: var(--bg-3); }

/* ===== Composer ===== */
.composer {
    padding: 14px 20px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    display: flex; gap: 10px; align-items: flex-end;
}
.composer textarea {
    flex: 1;
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    max-height: 160px;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.btn-send {
    width: 44px; height: 44px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-2); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Modal ===== */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.modal[hidden] { display: none; }
.modal-inner {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 480px; max-width: 90vw;
    max-height: 90vh;
    display: flex; flex-direction: column;
}
.modal-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-title { font-weight: 600; }
.modal-body { padding: 18px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}

.hint { font-size: 12px; color: var(--text-3); margin: 0; }
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    display: block;
}
.dropzone:hover { border-color: var(--accent); background: var(--bg-3); }
.dropzone.dragover { border-color: var(--accent); background: rgba(91,141,239,0.1); }
.dropzone-text { color: var(--text-2); font-size: 13px; }
.dropzone-icon { font-size: 32px; margin-bottom: 8px; }
.dropzone-name { margin-top: 8px; font-size: 12px; color: var(--ok); }

.upload-progress { display: flex; flex-direction: column; gap: 4px; }
.bar { height: 6px; background: var(--bg-3); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.2s; }
.bar-text { font-size: 11px; color: var(--text-3); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-3); }


/* ===== Quick Questions ===== */
.quick-questions {
    padding: 10px 20px 0;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
}
.qq-title {
    font-size: 12px;
    color: var(--text-3);
    margin-bottom: 6px;
}
.qq-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.qq-chip {
    flex-shrink: 0;
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text-2);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.qq-chip:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}


/* ===== Audio Unlock Banner ===== */
.audio-banner {
    background: linear-gradient(135deg, rgba(91,141,239,0.15), rgba(91,141,239,0.05));
    border: 1px solid rgba(91,141,239,0.3);
    border-radius: var(--radius);
    margin: 20px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.audio-banner-icon {
    font-size: 32px;
    flex-shrink: 0;
}
.audio-banner-text { flex: 1; }
.audio-banner-title { font-weight: 600; margin-bottom: 2px; }
.audio-banner-sub { font-size: 12px; color: var(--text-3); }
.audio-banner.hidden { display: none; }


/* ===== Dev Banner ===== */
.dev-banner {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
    color: white;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.dev-banner-icon {
    font-size: 22px;
    flex-shrink: 0;
}
.dev-banner-text { text-align: left; }
.dev-banner-title {
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.3px;
}
.dev-banner-sub {
    font-size: 12px;
    opacity: 0.92;
    margin-top: 1px;
}


/* ===== Topbar actions ===== */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.btn-ghost-sm {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-2);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-ghost-sm:hover {
    background: var(--bg-3);
    border-color: var(--accent);
    color: var(--text);
}

/* ===== Instruction modal ===== */
.instruction-inner {
    width: 720px;
    max-width: 95vw;
    max-height: 90vh;
}
.instruction-body {
    max-height: calc(90vh - 110px);
    overflow-y: auto;
    line-height: 1.6;
}
.instruction-body h3 {
    margin-top: 18px;
    margin-bottom: 8px;
    font-size: 15px;
    color: var(--accent);
    font-weight: 600;
}
.instruction-body h3:first-child {
    margin-top: 0;
}
.instruction-body p, .instruction-body li {
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 6px;
}
.instruction-body ol, .instruction-body ul {
    padding-left: 22px;
}
.instruction-body b {
    color: var(--text);
}
.instruction-body .muted {
    color: var(--text-3);
    font-style: italic;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
