:root {
    --bg: #0f1117;
    --sidebar-bg: #171a23;
    --panel: #1e222d;
    --panel-2: #262b38;
    --border: #2c3242;
    --text: #e6e8ee;
    --text-dim: #9aa3b2;
    --primary: #4f7cff;
    --primary-hover: #3d6af0;
    --success: #37b26c;
    --danger: #e5484d;
    --warn: #d9a441;
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 15px;
}

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
}

.sidebar-header { margin-bottom: 20px; }
.logo { margin: 0; font-size: 20px; }
.tagline { margin: 4px 0 0; color: var(--text-dim); font-size: 13px; }

.upload-box { margin-bottom: 20px; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--text-dim); text-align: center; }

.doc-list-wrap { flex: 1; overflow-y: auto; }
.doc-list-title {
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .08em;
    color: var(--text-dim);
    margin-bottom: 10px;
}
.doc-list { list-style: none; margin: 0; padding: 0; }

.doc-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
}
.doc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.doc-name {
    font-size: 13px;
    font-weight: 600;
    word-break: break-word;
    line-height: 1.3;
}
.doc-meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

.doc-delete {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 6px;
}
.doc-delete:hover { color: var(--danger); background: var(--panel-2); }

.badge {
    display: inline-block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 2px 8px;
    border-radius: 999px;
    margin-top: 8px;
}
.badge-processing { background: rgba(217,164,65,.15); color: var(--warn); }
.badge-ready { background: rgba(55,178,108,.15); color: var(--success); }
.badge-failed { background: rgba(229,72,77,.15); color: var(--danger); }

.progress { margin-top: 8px; height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); width: 0; transition: width .3s ease; }
.doc-error { font-size: 11px; color: var(--danger); margin-top: 6px; }

.empty-state { color: var(--text-dim); font-size: 13px; text-align: center; margin-top: 24px; line-height: 1.5; }

/* ---------- Chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.messages { flex: 1; overflow-y: auto; padding: 28px 32px; }

.welcome { max-width: 560px; margin: 8vh auto 0; text-align: center; color: var(--text-dim); }
.welcome h2 { color: var(--text); font-weight: 600; }
.welcome p { line-height: 1.6; }

.msg { max-width: 760px; margin: 0 auto 18px; display: flex; }
.msg-user { justify-content: flex-end; }
.bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-width: 80%;
}
.msg-user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-bot .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.sources { margin-top: 10px; font-size: 12px; color: var(--text-dim); }
.source-chip {
    display: inline-block;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 8px;
    margin: 3px 4px 0 0;
}

.typing .bubble { color: var(--text-dim); font-style: italic; }

/* ---------- Composer ---------- */
.chat-form {
    display: flex;
    gap: 10px;
    padding: 16px 32px 22px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}
.question-input {
    flex: 1;
    resize: none;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 12px 14px;
    font: inherit;
    line-height: 1.4;
    max-height: 160px;
}
.question-input:focus { outline: none; border-color: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
    border: none;
    border-radius: var(--radius);
    padding: 11px 16px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { width: 100%; background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-send { background: var(--primary); color: #fff; align-self: flex-end; }
.btn-send:hover:not(:disabled) { background: var(--primary-hover); }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: #fff;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    z-index: 50;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

@media (max-width: 720px) {
    .app { flex-direction: column; }
    .sidebar { width: 100%; min-width: 0; height: 45vh; }
    .chat { height: 55vh; }
}

/* ---------- Sign in ----------
   Says nothing about what this is. An unauthenticated visitor gets a password
   box and no other information -- no product name, no description. */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 320px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px 24px;
}

.login-card label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-dim);
    margin-bottom: 7px;
}

.login-card input[type="password"] {
    width: 100%;
    padding: 11px 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.login-card input[type="password"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 124, 255, .15);
}

.login-btn {
    width: 100%;
    margin-top: 14px;
    padding: 11px;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
}
.login-btn:hover { background: var(--primary-hover); }

.login-error {
    background: rgba(229, 72, 77, .12);
    border-left: 3px solid var(--danger);
    border-radius: 7px;
    padding: 10px 12px;
    font-size: 14px;
    margin-bottom: 16px;
}

.login-locked {
    background: rgba(217, 164, 65, .10);
    border-left: 3px solid var(--warn);
    border-radius: 7px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.55;
}
.login-locked strong { display: block; margin-bottom: 3px; }
.login-locked p { margin: 0; color: var(--text-dim); font-size: 13px; }
