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

:root {
    --bg: #0a0e17;
    --surface: #111827;
    --surface-2: #1a2234;
    --border: #1e2d44;
    --text: #e2e8f0;
    --text-muted: #8896ab;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.1);
    --gold: #c9a84c;
    --success: #10b981;
    --danger: #ef4444;
    --radius: 12px;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --font-serif: 'DM Serif Display', Georgia, serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* --- Layout --- */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 900px;
    margin: 0 auto;
}

/* --- Header --- */
.header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--gold), #a07830);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.header h1 {
    font-family: var(--font-serif);
    font-size: 20px;
    font-weight: 400;
    letter-spacing: 0.02em;
    color: var(--text);
}

.header h1 span {
    color: var(--gold);
}

.header-nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s;
}

.header-nav a:hover {
    color: var(--text);
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* --- Chat Area --- */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--accent);
}

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--gold), #a07830);
}

.message-content {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.7;
}

.message.user .message-content {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 8px 0; padding-left: 20px; }
.message-content li { margin-bottom: 4px; }
.message-content strong { color: var(--gold); font-weight: 600; }
.message-content code {
    background: rgba(0,0,0,0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* --- Welcome --- */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 16px;
    padding: 40px;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--gold), #a07830);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 8px;
}

.welcome h2 {
    font-family: var(--font-serif);
    font-size: 24px;
    font-weight: 400;
    color: var(--text);
}

.welcome p {
    color: var(--text-muted);
    font-size: 14px;
    max-width: 420px;
}

.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    justify-content: center;
}

.suggestion-chip {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-chip:hover {
    border-color: var(--gold);
    color: var(--gold);
    background: rgba(201, 168, 76, 0.08);
}

/* --- Input Area --- */
.input-area {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 8px 8px 16px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 24px;
    padding: 4px 0;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- Typing Indicator --- */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Admin Page --- */
.admin-shell {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
}

.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.admin-section h2 {
    font-family: var(--font-serif);
    font-size: 18px;
    font-weight: 400;
    margin-bottom: 16px;
    color: var(--text);
}

/* Upload */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
    font-size: 14px;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--text);
}

.upload-zone input[type="file"] {
    display: none;
}

.upload-zone .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.upload-progress {
    margin-top: 16px;
    display: none;
}

.upload-progress.active { display: block; }

.progress-bar {
    height: 4px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
    width: 0%;
}

/* Document List */
.doc-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface-2);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.doc-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.doc-icon {
    width: 32px;
    height: 32px;
    background: rgba(201, 168, 76, 0.15);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.doc-name {
    font-size: 14px;
    color: var(--text);
}

.doc-chunks {
    font-size: 12px;
    color: var(--text-muted);
}

.doc-delete {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.doc-delete:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.stats-bar {
    display: flex;
    gap: 24px;
    padding: 12px 0;
    font-size: 13px;
    color: var(--text-muted);
}

.stats-bar strong {
    color: var(--gold);
    font-weight: 600;
}

.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Responsive */
@media (max-width: 640px) {
    .header { padding: 16px; }
    .chat-area { padding: 16px; }
    .input-area { padding: 12px 16px 16px; }
    .message { max-width: 95%; }
    .welcome-suggestions { flex-direction: column; }
    .admin-shell { padding: 16px; }
}
