/* =============================================================================
   Reamind — xAI-inspired theme
   Stark monochrome, futuristic minimalism. Near-black canvas, white text,
   subtle borders, single neutral accent. ChatGPT-style structural layout.
   ========================================================================== */

/* -----------------------------------------------------------------------------
   Design Tokens
   -------------------------------------------------------------------------- */
:root {
    /* Surfaces */
    --bg-canvas: #000000;
    --bg-surface: #0A0A0A;
    --bg-elevated: #131313;
    --bg-hover: #1A1A1A;
    --bg-input: #0F0F0F;

    /* Borders */
    --border-subtle: #1A1A1A;
    --border-default: #262626;
    --border-strong: #3D3D3D;
    --border-focus: #FFFFFF;

    /* Text */
    --text-primary: #FFFFFF;
    --text-secondary: #A1A1A1;
    --text-tertiary: #6B6B6B;
    --text-disabled: #4A4A4A;
    --text-inverse: #000000;

    /* Status (used sparingly) */
    --color-danger: #EF4444;
    --color-danger-bg: rgba(239, 68, 68, 0.08);
    --color-success: #10B981;
    --color-success-bg: rgba(16, 185, 129, 0.08);
    --color-warning: #F59E0B;
    --color-warning-bg: rgba(245, 158, 11, 0.08);

    /* Typography */
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
    --fs-xs: 11px;
    --fs-sm: 13px;
    --fs-base: 14px;
    --fs-md: 15px;
    --fs-lg: 17px;
    --fs-xl: 20px;
    --fs-2xl: 24px;
    --fs-3xl: 32px;
    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --lh-tight: 1.25;
    --lh-normal: 1.5;
    --lh-relaxed: 1.65;

    /* Spacing scale */
    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 20px;
    --s-6: 24px;
    --s-8: 32px;
    --s-10: 40px;
    --s-12: 48px;
    --s-16: 64px;

    /* Radius */
    --r-sm: 4px;
    --r-md: 6px;
    --r-lg: 8px;
    --r-xl: 12px;
    --r-full: 999px;

    /* Layout */
    --sidebar-width: 260px;
    --composer-height: 96px;
    --max-content: 760px;

    /* Motion */
    --t-fast: 0.12s ease;
    --t-base: 0.18s ease;
}

/* -----------------------------------------------------------------------------
   Base reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg-canvas);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--text-primary);
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 3px;
    transition: text-decoration-color var(--t-fast);
}
a:hover { text-decoration-color: var(--text-primary); }

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    letter-spacing: -0.01em;
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }

p { margin: 0 0 var(--s-3); }

hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: var(--s-6) 0;
}

::selection { background: var(--text-primary); color: var(--text-inverse); }

/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* -----------------------------------------------------------------------------
   Typography utilities
   -------------------------------------------------------------------------- */
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-md { font-size: var(--fs-md); }
.text-lg { font-size: var(--fs-lg); }
.text-muted { color: var(--text-secondary); }
.text-dim { color: var(--text-tertiary); }
.text-mono { font-family: var(--font-mono); }
.text-uppercase { text-transform: uppercase; letter-spacing: 0.05em; }
.font-medium { font-weight: var(--fw-medium); }
.font-semibold { font-weight: var(--fw-semibold); }

/* -----------------------------------------------------------------------------
   Layout primitives
   -------------------------------------------------------------------------- */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--s-6);
}

.container-narrow {
    width: 100%;
    max-width: var(--max-content);
    margin: 0 auto;
    padding: 0 var(--s-6);
}

.stack { display: flex; flex-direction: column; }
.stack-2 > * + * { margin-top: var(--s-2); }
.stack-3 > * + * { margin-top: var(--s-3); }
.stack-4 > * + * { margin-top: var(--s-4); }
.stack-6 > * + * { margin-top: var(--s-6); }

.row { display: flex; align-items: center; gap: var(--s-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.row-wrap { flex-wrap: wrap; }

/* -----------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    line-height: 1;
    padding: 0 var(--s-4);
    height: 36px;
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
    white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn:disabled, .btn.is-disabled { opacity: 0.5; pointer-events: none; }

.btn-primary {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--text-inverse);
    font-weight: var(--fw-semibold);
}
.btn-primary:hover { background: #E5E5E5; border-color: #E5E5E5; }

.btn-ghost {
    background: transparent;
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-elevated); border-color: var(--border-default); }

.btn-muted { /* alias for default */ }

.btn-danger {
    background: transparent;
    border-color: var(--border-default);
    color: var(--color-danger);
}
.btn-danger:hover { background: var(--color-danger-bg); border-color: var(--color-danger); }

.btn-icon {
    width: 36px;
    padding: 0;
}

.btn-sm { height: 28px; padding: 0 var(--s-3); font-size: var(--fs-xs); }
.btn-lg { height: 44px; padding: 0 var(--s-5); font-size: var(--fs-md); }

.btn-block { width: 100%; }

/* Loading spinner inside button */
.btn .spinner {
    width: 12px;
    height: 12px;
    border-radius: var(--r-full);
    border: 2px solid currentColor;
    border-top-color: transparent;
    display: none;
    animation: spin 0.7s linear infinite;
}
.btn.is-loading .spinner { display: inline-block; }
.btn.is-loading { pointer-events: none; opacity: 0.7; }

@keyframes spin { to { transform: rotate(360deg); } }

/* -----------------------------------------------------------------------------
   Form controls
   -------------------------------------------------------------------------- */
label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    margin-bottom: var(--s-2);
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], input[type="tel"], input[type="date"],
input[type="datetime-local"], select, textarea {
    width: 100%;
    font-family: inherit;
    font-size: var(--fs-base);
    line-height: 1.4;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    padding: 10px 12px;
    transition: border-color var(--t-fast), background var(--t-fast);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-surface);
}

input::placeholder, textarea::placeholder { color: var(--text-tertiary); }

textarea { resize: vertical; min-height: 80px; }

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23A1A1A1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

input[type="checkbox"], input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--text-primary);
    margin: 0;
}

.form-field { margin-bottom: var(--s-4); }
.form-field-row { display: flex; gap: var(--s-3); }
.form-field-row > * { flex: 1; }

.form-help {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    margin-top: var(--s-2);
}

ul.errorlist {
    list-style: none;
    margin: var(--s-2) 0 0;
    padding: 0;
    color: var(--color-danger);
    font-size: var(--fs-xs);
}

.errornote, .alert-error {
    background: var(--color-danger-bg);
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
    border-radius: var(--r-lg);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
    font-size: var(--fs-sm);
}

.alert-info {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    border-radius: var(--r-lg);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
    font-size: var(--fs-sm);
}

.alert-success {
    background: var(--color-success-bg);
    border: 1px solid var(--color-success);
    color: var(--color-success);
    border-radius: var(--r-lg);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
    font-size: var(--fs-sm);
}

/* -----------------------------------------------------------------------------
   Cards / Panels
   -------------------------------------------------------------------------- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-6);
}
.card-elevated { background: var(--bg-elevated); }
.card-tight { padding: var(--s-4); }
.card-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); margin-bottom: var(--s-3); }
.card-subtitle { font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: var(--s-4); }

.panel { /* alias */
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-4);
}

/* -----------------------------------------------------------------------------
   Badges & chips
   -------------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    height: 22px;
    padding: 0 var(--s-2);
    border-radius: var(--r-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    line-height: 1;
    white-space: nowrap;
}
.badge-success { color: var(--color-success); border-color: var(--color-success); background: var(--color-success-bg); }
.badge-danger { color: var(--color-danger); border-color: var(--color-danger); background: var(--color-danger-bg); }
.badge-warning { color: var(--color-warning); border-color: var(--color-warning); background: var(--color-warning-bg); }

/* -----------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
}
.table th, .table td {
    text-align: left;
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
}
.table th {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-surface);
}
.table tbody tr:hover { background: var(--bg-surface); }
.table tbody tr:last-child td { border-bottom: none; }
.table-wrap {
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    overflow: hidden;
    background: var(--bg-canvas);
}

/* -----------------------------------------------------------------------------
   App shell (used for non-chat pages)
   -------------------------------------------------------------------------- */
.app-shell {
    width: min(1100px, 100%);
    margin: 0 auto;
    padding: var(--s-6) var(--s-4) var(--s-12);
}

.page-card { /* legacy alias used by some templates */
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-6);
}

.page-title {
    margin: 0 0 var(--s-2);
    font-size: var(--fs-2xl);
}

.top-links {
    display: flex;
    gap: var(--s-2);
    align-items: center;
    margin-bottom: var(--s-5);
    flex-wrap: wrap;
}

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

/* -----------------------------------------------------------------------------
   Auth pages — centered card on black canvas
   -------------------------------------------------------------------------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s-6);
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-8);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    margin-bottom: var(--s-6);
}
.auth-brand-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--r-md);
    background: var(--text-primary);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-semibold);
    font-size: var(--fs-lg);
}
.auth-brand-name {
    font-size: var(--fs-lg);
    font-weight: var(--fw-semibold);
}

.auth-title {
    font-size: var(--fs-2xl);
    margin-bottom: var(--s-2);
}
.auth-subtitle {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    margin-bottom: var(--s-6);
}

.auth-actions { margin-top: var(--s-6); }
.auth-footer {
    margin-top: var(--s-5);
    padding-top: var(--s-5);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    text-align: center;
}

/* -----------------------------------------------------------------------------
   Chat layout (ChatGPT-style)
   -------------------------------------------------------------------------- */
.chat-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transition: margin-left var(--t-base);
}

.chat-sidebar-header {
    padding: var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
}

.chat-sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    font-weight: var(--fw-semibold);
    font-size: var(--fs-md);
    margin-bottom: var(--s-4);
}
.chat-sidebar-brand .brand-mark {
    width: 28px;
    height: 28px;
    border-radius: var(--r-md);
    background: var(--text-primary);
    color: var(--text-inverse);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

.chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--s-2) var(--s-3);
}

.chat-sidebar-section-label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--s-3) var(--s-2) var(--s-2);
}

.chat-row {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background var(--t-fast);
    margin-bottom: 2px;
}
.chat-row:hover { background: var(--bg-elevated); }
.chat-row.active { background: var(--bg-elevated); }

.chat-row-link {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: left;
    font-size: var(--fs-sm);
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-row-delete {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    border-radius: var(--r-sm);
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--t-fast), color var(--t-fast);
}
.chat-row:hover .chat-row-delete { opacity: 1; }
.chat-row-delete:hover { color: var(--color-danger); background: var(--bg-hover); }

.chat-sidebar-footer {
    padding: var(--s-3) var(--s-4);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}
.user-chip-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--r-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-xs);
    color: var(--text-primary);
    font-weight: var(--fw-semibold);
    flex: 0 0 28px;
}

/* Main chat pane */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-canvas);
}

.chat-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-3) var(--s-5);
    border-bottom: 1px solid var(--border-subtle);
    min-height: 56px;
}
.chat-topbar-title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
}

.sidebar-toggle {
    display: none;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--r-md);
}
.sidebar-toggle:hover { background: var(--bg-elevated); }

.chat-feed {
    flex: 1;
    overflow-y: auto;
    padding: var(--s-6) var(--s-4) 160px;
}

.chat-feed-inner {
    max-width: var(--max-content);
    margin: 0 auto;
}

/* Empty state */
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 10vh var(--s-4) var(--s-8);
    color: var(--text-secondary);
}
.chat-empty-title {
    font-size: var(--fs-2xl);
    color: var(--text-primary);
    margin-bottom: var(--s-3);
}
.chat-empty-subtitle {
    font-size: var(--fs-sm);
    margin-bottom: var(--s-8);
    max-width: 480px;
}

.suggested-queries {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--s-3);
    width: 100%;
    max-width: 640px;
}
.suggested-query-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    padding: var(--s-3) var(--s-4);
    color: var(--text-primary);
    cursor: pointer;
    font-size: var(--fs-sm);
    text-align: left;
    transition: background var(--t-fast), border-color var(--t-fast);
    font-family: inherit;
}
.suggested-query-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--border-default);
}

/* Messages */
.message {
    margin-bottom: var(--s-6);
    display: flex;
}
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message .bubble {
    max-width: 90%;
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-xl);
    line-height: var(--lh-relaxed);
}

.message.user .bubble {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    border-bottom-right-radius: var(--r-sm);
}

.message.assistant .bubble {
    background: transparent;
    border: none;
    padding-left: 0;
    padding-right: 0;
    max-width: 100%;
    width: 100%;
    color: var(--text-primary);
}

.bubble .content {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: var(--fs-md);
}

/* Citation chip */
.citation-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin: 0 2px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--r-sm);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: var(--fw-semibold);
    text-decoration: none;
    line-height: 1;
    vertical-align: super;
    transition: background var(--t-fast), color var(--t-fast);
}
.citation-chip:hover {
    background: var(--text-primary);
    color: var(--text-inverse);
    border-color: var(--text-primary);
}

/* Result items (semantic search) */
.result-item {
    margin-bottom: var(--s-4);
    padding: var(--s-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
}
.result-item h3 { font-size: var(--fs-md); margin-bottom: var(--s-2); }
.result-item p { margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); line-height: var(--lh-relaxed); }

.chunks-link {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    margin-top: var(--s-3);
    padding: 6px var(--s-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    border-radius: var(--r-md);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    text-decoration: none;
}
.chunks-link:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.retry-note, .redo-filter {
    margin: var(--s-3) 0;
    padding: var(--s-3) var(--s-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}
.retry-note ul { margin: var(--s-2) 0 0 var(--s-4); padding: 0; }

.filter-applied-tag {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 var(--s-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--r-full);
    color: var(--text-primary);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
}

.scope-checkboxes {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--s-2);
    padding: var(--s-3);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
}
.scope-checkbox {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    color: var(--text-primary);
    font-size: var(--fs-sm);
    font-weight: var(--fw-regular);
    margin: 0;
}

.inline-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    margin-bottom: var(--s-3);
    flex-wrap: wrap;
}

.copy-status {
    color: var(--color-success);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
}

/* Composer */
.composer-shell {
    position: absolute;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    padding: var(--s-3) var(--s-4) var(--s-5);
    background: linear-gradient(to top, var(--bg-canvas) 60%, transparent);
    pointer-events: none;
}

.composer-wrap {
    max-width: var(--max-content);
    margin: 0 auto;
    pointer-events: auto;
}

.composer {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--r-xl);
    padding: var(--s-3);
    transition: border-color var(--t-fast);
}
.composer:focus-within { border-color: var(--border-strong); }
.composer form { margin: 0; }

.composer-main {
    display: flex;
    align-items: flex-end;
    gap: var(--s-2);
}

.composer-main textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: var(--s-2) var(--s-2);
    min-height: 28px;
    max-height: 200px;
    font-size: var(--fs-md);
    line-height: var(--lh-normal);
    resize: none;
}
.composer-main textarea:focus { background: transparent; border: none; }

.settings-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: var(--fs-lg);
    cursor: pointer;
    flex: 0 0 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--t-fast), color var(--t-fast);
}
.settings-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--text-inverse);
    border-radius: var(--r-md);
    font-weight: var(--fw-semibold);
}
.send-btn:hover { background: #E5E5E5; }
.send-btn .label { display: none; }
.send-btn::before {
    content: "↑";
    font-size: 18px;
    line-height: 1;
}
.send-btn.is-loading::before { content: ""; }

.settings-panel {
    display: none;
    margin-top: var(--s-3);
    padding-top: var(--s-3);
    border-top: 1px solid var(--border-subtle);
}
.settings-panel.open { display: block; }

.settings-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--s-3);
}
.settings-field label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--s-1);
}
.settings-field select {
    height: 32px;
    padding: 0 var(--s-3);
    font-size: var(--fs-sm);
}

/* -----------------------------------------------------------------------------
   Dashboard layout
   -------------------------------------------------------------------------- */
.dash-shell {
    display: flex;
    min-height: 100vh;
}

.dash-sidebar {
    flex: 0 0 240px;
    width: 240px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: var(--s-5) var(--s-3);
    display: flex;
    flex-direction: column;
}

.dash-sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--s-6);
    padding: 0 var(--s-3);
}

.dash-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.dash-nav-item {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--fs-sm);
    transition: background var(--t-fast), color var(--t-fast);
}
.dash-nav-item:hover { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }
.dash-nav-item.active { background: var(--bg-elevated); color: var(--text-primary); }
.dash-nav-section {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--s-4) var(--s-3) var(--s-1);
}

.dash-main {
    flex: 1;
    min-width: 0;
    padding: var(--s-8) var(--s-8);
    overflow-x: auto;
}
.dash-header {
    margin-bottom: var(--s-6);
}
.dash-header h1 {
    font-size: var(--fs-2xl);
    margin-bottom: var(--s-2);
}
.dash-header .muted { font-size: var(--fs-sm); }

.dash-section { margin-bottom: var(--s-8); }
.dash-section-title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--s-3);
}

/* Stats tile */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--s-4);
}
.stat-tile {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-5);
}
.stat-tile-label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--s-2);
}
.stat-tile-value {
    font-size: var(--fs-3xl);
    font-weight: var(--fw-semibold);
    line-height: 1;
}
.stat-tile-sub {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: var(--s-2);
}

/* -----------------------------------------------------------------------------
   Landing
   -------------------------------------------------------------------------- */
.landing-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s-8) var(--s-4);
}
.landing-card {
    max-width: 520px;
    width: 100%;
}
.landing-title {
    font-size: var(--fs-3xl);
    margin-bottom: var(--s-3);
}
.landing-tenant-list {
    list-style: none;
    padding: 0;
    margin: var(--s-5) 0 0;
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
}
.landing-tenant-list a {
    display: block;
    padding: var(--s-3) var(--s-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-lg);
    text-decoration: none;
    color: var(--text-primary);
    transition: background var(--t-fast), border-color var(--t-fast);
}
.landing-tenant-list a:hover {
    background: var(--bg-elevated);
    border-color: var(--border-default);
    text-decoration: none;
}

/* -----------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 880px) {
    :root { --sidebar-width: 240px; }

    .chat-shell { position: relative; }
    .chat-sidebar {
        position: fixed;
        top: 0; bottom: 0;
        left: 0;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform var(--t-base);
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
    }
    .chat-sidebar.open { transform: translateX(0); }
    .composer-shell { left: 0; }
    .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }

    .dash-sidebar { display: none; }
    .dash-main { padding: var(--s-5) var(--s-4); }
}

@media (max-width: 560px) {
    .settings-grid { grid-template-columns: 1fr; }
    .auth-card { padding: var(--s-6); }
}

/* -----------------------------------------------------------------------------
   Dashboard aliases (preserve existing class names used by dashboard subpages)
   -------------------------------------------------------------------------- */
.card-header {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: var(--s-3);
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-5);
}
.stat-card .stat-label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--s-2);
    font-weight: var(--fw-semibold);
}
.stat-card .stat-value {
    font-size: var(--fs-3xl);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    line-height: 1;
}
.stat-card .stat-sub {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: var(--s-2);
}

.form-group { margin-bottom: var(--s-4); }
.form-group label {
    display: block;
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    margin-bottom: var(--s-2);
}
.form-control {
    width: 100%;
    font-family: inherit;
    font-size: var(--fs-base);
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    padding: 10px 12px;
    transition: border-color var(--t-fast), background var(--t-fast);
}
.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-surface);
}
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23A1A1A1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}
textarea.form-control { resize: vertical; min-height: 80px; }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-1) 0;
    font-size: var(--fs-sm);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.filter-bar {
    display: flex;
    gap: var(--s-3);
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: var(--s-5);
    padding: var(--s-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
}
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }
.filter-bar .form-group label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; }

/* Django messages */
.messages { list-style: none; margin: 0 0 var(--s-4); padding: 0; }
.messages li {
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-lg);
    margin-bottom: var(--s-2);
    font-size: var(--fs-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    color: var(--text-primary);
}
.messages .success { background: var(--color-success-bg); border-color: var(--color-success); color: var(--color-success); }
.messages .error { background: var(--color-danger-bg); border-color: var(--color-danger); color: var(--color-danger); }
.messages .warning { background: var(--color-warning-bg); border-color: var(--color-warning); color: var(--color-warning); }

/* Color-named badges → map to neutral variants */
.badge-green { color: var(--color-success); border-color: var(--color-success); background: var(--color-success-bg); }
.badge-red { color: var(--color-danger); border-color: var(--color-danger); background: var(--color-danger-bg); }
.badge-yellow { color: var(--color-warning); border-color: var(--color-warning); background: var(--color-warning-bg); }
.badge-blue { color: var(--text-primary); border-color: var(--border-strong); background: var(--bg-elevated); }
.badge-gray { color: var(--text-secondary); border-color: var(--border-default); background: var(--bg-elevated); }

/* Match all old badges to the new badge shell */
.badge-green, .badge-red, .badge-yellow, .badge-blue, .badge-gray {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    height: 22px;
    padding: 0 var(--s-2);
    border-radius: var(--r-full);
    border: 1px solid;
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    line-height: 1;
    white-space: nowrap;
    text-transform: none;
    letter-spacing: 0;
}

/* -----------------------------------------------------------------------------
   Skeleton loaders
   -------------------------------------------------------------------------- */
@keyframes skeleton-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-elevated) 0%,
        var(--bg-hover) 50%,
        var(--bg-elevated) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--r-md);
    color: transparent;
    user-select: none;
    pointer-events: none;
}

.skeleton-line {
    display: block;
    height: 12px;
    border-radius: var(--r-sm);
    margin-bottom: var(--s-2);
}
.skeleton-line:last-child { margin-bottom: 0; }
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-75 { width: 75%; }
.skeleton-line.w-90 { width: 90%; }

.skeleton-block {
    width: 100%;
    height: 64px;
    border-radius: var(--r-lg);
    margin-bottom: var(--s-3);
}

.skeleton-circle {
    width: 32px;
    height: 32px;
    border-radius: var(--r-full);
    flex: 0 0 32px;
}

.skeleton-paragraph {
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    padding: var(--s-2) 0;
}
.skeleton-paragraph .skeleton-line { margin: 0; }

/* Initial page-load overlay — sits on top of the real DOM and fades out
   automatically. No JS dependency: if JS is slow or blocked, CSS animation
   still hides it. */
@keyframes skeleton-overlay-fade {
    0% { opacity: 1; visibility: visible; }
    85% { opacity: 1; visibility: visible; }
    100% { opacity: 0; visibility: hidden; }
}

.page-skeleton {
    position: fixed;
    inset: 0;
    background: var(--bg-canvas);
    z-index: 9999;
    pointer-events: none;
    animation: skeleton-overlay-fade 0.9s ease-out forwards;
}
.page-skeleton[data-hidden="true"] {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

/* Chat-page skeleton layout (matches .chat-shell structure) */
.page-skeleton-chat {
    display: flex;
    height: 100%;
}
.page-skeleton-chat .skel-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: var(--s-4);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}
.page-skeleton-chat .skel-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--s-6);
    gap: var(--s-4);
    align-items: center;
    justify-content: center;
}
.page-skeleton-chat .skel-main-inner {
    width: 100%;
    max-width: var(--max-content);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}

/* Dashboard-page skeleton layout */
.page-skeleton-dash {
    display: flex;
    height: 100%;
}
.page-skeleton-dash .skel-sidebar {
    width: 240px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: var(--s-5) var(--s-3);
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
}
.page-skeleton-dash .skel-main {
    flex: 1;
    padding: var(--s-8);
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
}

/* Auth-page skeleton */
.page-skeleton-auth {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--s-6);
}
.page-skeleton-auth .skel-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-xl);
    padding: var(--s-8);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}

@media (max-width: 880px) {
    .page-skeleton-chat .skel-sidebar { display: none; }
    .page-skeleton-dash .skel-sidebar { display: none; }
}
