/* Lume Chat — design tokens (claude-inspired palette). Light & dark themes share variable names. */
:root {
    --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.18);
    --shadow-lg: 0 18px 60px rgba(0, 0, 0, 0.32);
    --transition-fast: 120ms ease;
    --transition-med: 220ms ease;
    --sidebar-width: 280px;
    --topbar-height: 60px;
    --max-thread-width: 760px;
}

[data-theme="dark"] {
    --bg-app: #1f1c18;          /* warm near-black, like claude.ai */
    --bg-panel: #2a2622;
    --bg-panel-2: #322d28;
    --bg-elevated: #3a3530;
    --bg-input: #2a2622;
    --bg-hover: #3a3530;
    --bg-bubble-user: #d97757;  /* signature claude orange */
    --bg-bubble-asst: #2a2622;

    --text-primary: #f5f1eb;
    --text-secondary: #c9c1b6;
    --text-muted: #948b80;
    --text-on-accent: #ffffff;

    --border: #3d3934;
    --border-strong: #524d47;

    --accent: #d97757;          /* primary action / claude orange */
    --accent-hover: #c2664a;
    --accent-soft: rgba(217, 119, 87, 0.16);

    --danger: #e26666;
    --success: #6cbf86;
    --info: #6aa9e9;
}

[data-theme="light"] {
    --bg-app: #faf9f5;
    --bg-panel: #f0ece4;
    --bg-panel-2: #ebe6dc;
    --bg-elevated: #ffffff;
    --bg-input: #ffffff;
    --bg-hover: #ebe6dc;
    --bg-bubble-user: #d97757;
    --bg-bubble-asst: #ffffff;

    --text-primary: #29251f;
    --text-secondary: #4f4a42;
    --text-muted: #7a7368;
    --text-on-accent: #ffffff;

    --border: #d8d2c5;
    --border-strong: #b9b1a1;

    --accent: #c2664a;
    --accent-hover: #a85335;
    --accent-soft: rgba(194, 102, 74, 0.14);

    --danger: #c0392b;
    --success: #3a8a5a;
    --info: #2c6fb5;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body { min-height: 100vh; min-height: 100dvh; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    font-family: var(--font-mono);
    background: var(--bg-panel-2);
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 0.92em;
}

.visually-hidden {
    position: absolute !important;
    clip: rect(0 0 0 0); width: 1px; height: 1px;
    overflow: hidden; white-space: nowrap;
}

.muted { color: var(--text-muted); }

/* ---------- Buttons & form controls ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; padding: 10px 16px;
    font: inherit; font-weight: 500;
    background: var(--bg-elevated); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    cursor: pointer; transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
    text-decoration: none;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--text-on-accent); border-color: transparent; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: rgba(226, 102, 102, 0.12); }
.btn-block { width: 100%; }
.btn-small { padding: 6px 10px; font-size: 0.88rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    background: transparent; color: var(--text-secondary);
    border: 1px solid transparent; border-radius: 10px;
    cursor: pointer; transition: background var(--transition-fast), color var(--transition-fast);
    font-size: 1rem;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.form-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-input-narrow { width: 84px; }

.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 0.82rem; color: var(--text-secondary); font-weight: 500; }
.form-hint { font-size: 0.78rem; color: var(--text-tertiary, var(--text-secondary)); }
.form-stack { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.form-stack .btn { align-self: flex-start; }
.form-inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.form-grid {
    display: grid; gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.form-grid-end { align-items: end; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-toggle { flex-direction: row; align-items: center; gap: 10px; }
.form-toggle input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

.alert {
    padding: 12px 14px; border-radius: var(--radius-md);
    border: 1px solid var(--border); margin-bottom: 14px;
    background: var(--bg-panel-2);
}
.alert-error { border-color: rgba(226, 102, 102, 0.5); background: rgba(226, 102, 102, 0.10); }
.alert-info { border-color: rgba(106, 169, 233, 0.5); background: rgba(106, 169, 233, 0.10); }
.alert-success { border-color: rgba(108, 191, 134, 0.5); background: rgba(108, 191, 134, 0.10); }

/* ---------- Auth screen ---------- */
.auth-body { background: radial-gradient(1200px 600px at 80% -10%, var(--accent-soft), transparent 60%), var(--bg-app); }
.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: 32px 16px; }
.auth-card {
    width: 100%; max-width: 420px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-md);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 22px; }
.auth-logo {
    width: 56px; height: 56px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent); color: var(--text-on-accent);
    font-size: 1.5rem; box-shadow: var(--shadow-md);
}
.auth-card h1 { margin: 6px 0 0; font-size: 1.6rem; }
.auth-tagline { color: var(--text-muted); margin: 0; text-align: center; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-divider { text-align: center; color: var(--text-muted); margin: 18px 0; position: relative; }
.auth-divider::before, .auth-divider::after {
    content: ""; position: absolute; top: 50%; width: 36%; height: 1px; background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }
.auth-divider span { background: var(--bg-panel); padding: 0 10px; font-size: 0.85rem; }
.auth-hint { color: var(--text-muted); font-size: 0.86rem; margin: 8px 0 0; text-align: center; }
.auth-switch { text-align: center; color: var(--text-muted); margin-top: 18px; }
.theme-toggle-floating { position: fixed; top: 18px; right: 18px; }

/* ---------- App shell / sidebar ---------- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100dvh;
}

.sidebar {
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 14px;
    height: 100dvh; position: sticky; top: 0;
    z-index: 30;
}
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
}
.brand {
    display: inline-flex; align-items: center; gap: 10px;
    color: var(--text-primary); font-weight: 600;
    text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--accent); color: var(--text-on-accent);
    display: grid; place-items: center; font-size: 0.95rem;
}
.brand-text { font-size: 1.05rem; }
.sidebar-close { display: none; }

.new-chat-btn { width: 100%; justify-content: center; margin-bottom: 14px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.sidebar-link {
    color: var(--text-secondary); padding: 8px 10px; border-radius: var(--radius-sm);
    text-decoration: none; font-size: 0.95rem;
}
.sidebar-link:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }
.sidebar-link.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-section-title {
    font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-muted); padding: 0 10px; margin: 6px 0;
}

.chat-list { flex: 1; overflow-y: auto; list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-list-empty { color: var(--text-muted); padding: 8px 10px; font-size: 0.9rem; }
.chat-list-item {
    display: flex; align-items: center; gap: 4px;
    border-radius: var(--radius-sm);
}
.chat-list-item:hover { background: var(--bg-hover); }
.chat-list-item.active { background: var(--accent-soft); }
.chat-list-item.active .chat-list-link { color: var(--accent); }
.chat-list-link {
    flex: 1; min-width: 0;
    padding: 8px 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.93rem;
}
.chat-list-link:hover { text-decoration: none; color: var(--text-primary); }
.chat-list-title {
    display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-list-delete {
    width: 28px; height: 28px; opacity: 0; transition: opacity var(--transition-fast);
}
.chat-list-item:hover .chat-list-delete,
.chat-list-item:focus-within .chat-list-delete { opacity: 1; }

.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.user-card { display: flex; gap: 10px; align-items: center; }
.user-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--text-on-accent);
    display: grid; place-items: center; font-weight: 600;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-weight: 600; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; max-width: 160px; }
.user-role { font-size: 0.78rem; color: var(--text-muted); }
.usage-bar {
    position: relative; height: 22px; border-radius: 999px;
    background: var(--bg-panel-2); overflow: hidden; border: 1px solid var(--border);
}
.usage-bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); opacity: 0.6; }
.usage-bar-text {
    position: relative; display: block; text-align: center; line-height: 22px;
    font-size: 0.78rem; color: var(--text-primary);
}
.sidebar-footer-actions { display: flex; gap: 8px; align-items: center; }
.logout-form { margin-left: auto; }

.sidebar-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.45); z-index: 25;
}

/* ---------- Chat main ---------- */
.chat-main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.chat-topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 18px; min-height: var(--topbar-height);
    border-bottom: 1px solid var(--border); background: var(--bg-app);
    position: sticky; top: 0; z-index: 10;
}
.sidebar-toggle { display: none; }
.chat-title-wrap { flex: 1; min-width: 0; }
.chat-title {
    font-size: 1rem; font-weight: 600; margin: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.model-picker { display: flex; align-items: center; gap: 8px; }
.model-select {
    appearance: none; -webkit-appearance: none;
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 32px 8px 12px;
    color: var(--text-primary); font: inherit;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23999' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
    cursor: pointer;
    max-width: 280px;
}
.model-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.banner {
    margin: 12px 18px 0; padding: 12px 16px; border-radius: var(--radius-md);
    background: var(--accent-soft); border: 1px solid rgba(217, 119, 87, 0.4);
    display: flex; align-items: center; gap: 12px;
}
.banner-info { background: rgba(106, 169, 233, 0.12); border-color: rgba(106, 169, 233, 0.4); }
.banner-close { margin-left: auto; background: transparent; border: 0; color: inherit; cursor: pointer; font-size: 1rem; }

.chat-thread {
    flex: 1; overflow-y: auto;
    padding: 24px 16px 120px;
    display: flex; flex-direction: column; gap: 20px;
}
.empty-state {
    margin: auto; max-width: 560px; text-align: center; padding: 32px 16px;
}
.empty-mark {
    width: 64px; height: 64px; margin: 0 auto 16px;
    border-radius: 50%; background: var(--accent); color: var(--text-on-accent);
    display: grid; place-items: center; font-size: 1.5rem; box-shadow: var(--shadow-md);
}
.empty-state h2 { margin: 0 0 6px; font-size: 1.6rem; }
.empty-state p { color: var(--text-secondary); margin: 0 0 20px; }
.prompt-suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.prompt-chip {
    padding: 10px 14px;
    border-radius: 999px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font: inherit; cursor: pointer; transition: background var(--transition-fast);
}
.prompt-chip:hover { background: var(--bg-hover); color: var(--text-primary); }

.message {
    display: flex; gap: 14px;
    width: 100%;
    max-width: var(--max-thread-width);
    margin: 0 auto;
}
.message-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--bg-panel-2); color: var(--text-secondary);
    display: grid; place-items: center;
    font-size: 0.75rem; font-weight: 600;
    flex-shrink: 0;
}
.message-user .message-avatar { background: var(--accent); color: var(--text-on-accent); }
.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    background: var(--bg-bubble-asst);
    border: 1px solid var(--border);
    max-width: 100%;
    overflow-wrap: anywhere;
}
.message-user .message-bubble { background: var(--bg-bubble-user); color: var(--text-on-accent); border-color: transparent; }
.message-content { white-space: pre-wrap; }
.message-content p { margin: 0 0 0.6em; }
.message-content p:last-child { margin-bottom: 0; }

.typing-dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.typing-dots span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--text-muted); display: inline-block;
    animation: typing-bounce 1.1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.composer {
    position: sticky; bottom: 0; left: 0; right: 0;
    padding: 14px 16px;
    background: linear-gradient(to top, var(--bg-app) 70%, transparent);
}
.composer-inner {
    max-width: var(--max-thread-width);
    margin: 0 auto;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex; align-items: flex-end; gap: 8px;
    padding: 8px 8px 8px 14px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.composer-inner:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-md); }
.composer-input {
    flex: 1; resize: none;
    background: transparent; border: 0; outline: none;
    color: var(--text-primary); font: inherit;
    line-height: 1.5; max-height: 220px; padding: 8px 0;
}
.composer-send {
    align-self: flex-end;
    padding: 10px 18px;
    height: 40px;
}
.composer-send-icon { display: none; }
.composer-meta {
    max-width: var(--max-thread-width);
    margin: 6px auto 0; padding: 0 4px;
    text-align: right; font-size: 0.78rem; color: var(--text-muted);
}

/* ---------- Generic page content (settings, admin) ---------- */
.page-content {
    flex: 1; padding: 24px clamp(16px, 4vw, 36px); max-width: 1100px; margin: 0 auto; width: 100%;
    display: flex; flex-direction: column; gap: 18px;
    overflow-y: auto;
}
.card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    display: flex; flex-direction: column; gap: 14px;
}
.card-title { margin: 0; font-size: 1.1rem; }
.subtle-heading { margin: 14px 0 6px; font-size: 0.95rem; color: var(--text-secondary); }

.kv-grid {
    display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px;
    margin: 0;
}
.kv-grid dt { color: var(--text-muted); }
.kv-grid dd { margin: 0; }

.stat-grid {
    display: grid; gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.stat-card {
    display: flex; flex-direction: column; gap: 6px;
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px;
}
.stat-value { font-size: 1.8rem; font-weight: 600; color: var(--text-primary); }
.stat-label { color: var(--text-muted); font-size: 0.9rem; }

.badge {
    display: inline-flex; align-items: center; padding: 2px 8px;
    border-radius: 999px; font-size: 0.78rem;
    background: var(--bg-panel-2); color: var(--text-secondary);
    border: 1px solid var(--border);
}
.badge-success { background: rgba(108, 191, 134, 0.15); color: var(--success); border-color: rgba(108, 191, 134, 0.4); }
.badge-muted { background: var(--bg-panel-2); color: var(--text-muted); }

.provider-card { gap: 18px; }
.provider-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%; border-collapse: collapse; font-size: 0.92rem;
}
.data-table th, .data-table td {
    text-align: left; padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table th { color: var(--text-muted); font-weight: 500; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions form { margin: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 880px) {
    :root { --sidebar-width: 290px; }
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0;
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform var(--transition-med);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: inline-flex; }
    .sidebar-toggle { display: inline-flex; }
    .sidebar-backdrop.show { display: block; }
}

@media (max-width: 480px) {
    .composer-send-label { display: none; }
    .composer-send-icon { display: inline; }
    .model-select { max-width: 160px; font-size: 0.88rem; }
    .chat-thread { padding: 18px 10px 110px; }
    .composer { padding: 10px; }
    .auth-card { padding: 24px 18px; }
    .stat-value { font-size: 1.5rem; }
}

/* Smooth scroll for all scrollable containers */
.chat-thread, .chat-list, .page-content { scrollbar-width: thin; }
.chat-thread::-webkit-scrollbar, .chat-list::-webkit-scrollbar, .page-content::-webkit-scrollbar { width: 8px; }
.chat-thread::-webkit-scrollbar-thumb, .chat-list::-webkit-scrollbar-thumb, .page-content::-webkit-scrollbar-thumb {
    background: var(--border-strong); border-radius: 999px;
}
