:root {
    --bg: #f3f6fb;
    --bg-soft: #eef2f8;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --ink: #0f172a;
    --ink-soft: #1e293b;
    --muted: #64748b;
    --muted-soft: #94a3b8;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;

    --brand: #2563eb;
    --brand-strong: #1d4ed8;
    --brand-soft: #dbeafe;
    --navy: #1e3a8a;
    --accent: #0ea5e9;

    --success: #16a34a;
    --success-soft: #dcfce7;
    --success-ink: #166534;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --warning-ink: #92400e;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --danger-ink: #991b1b;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --info-ink: #075985;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 10px 20px -4px rgba(15, 23, 42, 0.08), 0 4px 8px -2px rgba(15, 23, 42, 0.04);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

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

html,
body {
    margin: 0;
    min-height: 100%;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body {
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    color: var(--brand-strong);
}

img {
    display: block;
    max-width: 100%;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

h1,
h2,
h3,
h4 {
    margin: 0;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.01em;
}

h1 { font-size: 1.75rem; line-height: 1.2; }
h2 { font-size: 1.2rem; line-height: 1.3; }
h3 { font-size: 1rem; line-height: 1.4; }

.page-backdrop { display: none; }

/* ---------- Top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 2.3rem;
    height: 2.3rem;
    border-radius: 10px;
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.06em;
    background: linear-gradient(135deg, var(--brand), var(--navy));
    box-shadow: var(--shadow-sm);
}

.brand strong {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
}

.brand small {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
}

.topnav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topnav a {
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--muted);
}

.topnav a:hover {
    background: var(--bg-soft);
    color: var(--ink);
}

/* ---------- Layout ---------- */

.page-frame {
    width: min(1360px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.5rem 0 3rem;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
}

.panel + .panel {
    margin-top: 1rem;
}

.card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.card-heading h2,
.card-heading h3 {
    margin-bottom: 0.25rem;
}

.card-heading p,
.subtle,
.muted-note {
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
}

.eyebrow {
    display: inline-block;
    margin: 0 0 0.5rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--navy);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}

/* ---------- App shell: sidebar + main ---------- */

.chat-layout {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

.side-rail {
    display: grid;
    gap: 1rem;
    position: sticky;
    top: 4.5rem;
}

.rail-section {
    padding: 1.15rem;
}

.rail-section h2 {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 0.8rem;
}

.chat-stage {
    display: grid;
    grid-template-rows: auto minmax(320px, 1fr) auto;
    min-height: calc(100vh - 8rem);
    padding: 1.5rem;
}

.chat-stage__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
}

.chat-stage__header h1 {
    font-size: 1.4rem;
}

.chat-stage__header p {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.preview-meta,
.stats-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.preview-meta span,
.stats-strip span {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 0.8rem;
    font-weight: 500;
}

/* ---------- Status banners (info / success / warning / danger) ---------- */

.status-banner {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.92rem;
    line-height: 1.45;
}

.status-banner__icon {
    display: grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    flex: 0 0 1.6rem;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.9rem;
}

.status-banner__text strong {
    display: block;
    font-weight: 600;
}

.status-banner--success {
    background: var(--success-soft);
    border-color: color-mix(in srgb, var(--success) 25%, transparent);
    color: var(--success-ink);
}

.status-banner--success .status-banner__icon {
    background: var(--success);
    color: white;
}

.status-banner--info {
    background: var(--info-soft);
    border-color: color-mix(in srgb, var(--info) 25%, transparent);
    color: var(--info-ink);
}

.status-banner--info .status-banner__icon {
    background: var(--info);
    color: white;
}

.status-banner--warning {
    background: var(--warning-soft);
    border-color: color-mix(in srgb, var(--warning) 30%, transparent);
    color: var(--warning-ink);
}

.status-banner--warning .status-banner__icon {
    background: var(--warning);
    color: white;
}

.status-banner--danger {
    background: var(--danger-soft);
    border-color: color-mix(in srgb, var(--danger) 30%, transparent);
    color: var(--danger-ink);
}

.status-banner--danger .status-banner__icon {
    background: var(--danger);
    color: white;
}

.status-stack {
    display: grid;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

/* ---------- Hero block ---------- */

.hero {
    text-align: center;
    padding: 1rem 0 1.5rem;
}

.hero h1 {
    font-size: 1.75rem;
    margin: 0 0 0.5rem;
}

.hero p {
    margin: 0;
    color: var(--muted);
    font-size: 1rem;
}

/* ---------- Metric hero cards ---------- */

.metric-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.9rem;
    margin: 0.25rem 0 1.25rem;
}

.metric-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 1.15rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    transition: box-shadow 0.18s ease, transform 0.18s ease;
}

.metric-tile::before {
    content: "";
    position: absolute;
    left: 0;
    top: 12%;
    bottom: 12%;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
}

.metric-tile--success::before { background: var(--success); }
.metric-tile--accent::before { background: var(--accent); }

.metric-tile:hover {
    box-shadow: var(--shadow-md);
}

.metric-tile span {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 500;
}

.metric-tile strong {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.metric-tile__icon {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.2rem;
    opacity: 0.55;
}

/* ---------- Chart gallery ---------- */

.chart-gallery,
.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
}

.chart-card {
    margin: 0;
    padding: 0.85rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.18s ease, transform 0.18s ease;
}

.chart-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.chart-card img {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    background: var(--surface-alt);
}

.chart-card figcaption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.65rem 0.4rem 0.2rem;
    font-size: 0.88rem;
    color: var(--ink-soft);
    font-weight: 500;
}

.chart-card figcaption a {
    font-size: 0.82rem;
    font-weight: 500;
}

/* ---------- Download row ---------- */

.download-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.8rem;
}

.download-stack {
    display: grid;
    gap: 0.6rem;
}

.download-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.download-card:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
    color: var(--ink);
}

.download-card > div {
    display: grid;
    gap: 0.2rem;
}

.download-card strong {
    font-size: 0.94rem;
    font-weight: 600;
}

.download-card span {
    font-size: 0.8rem;
    color: var(--muted);
}

.download-card--cta {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem 1.25rem;
    text-align: center;
    background: var(--brand);
    border-color: var(--brand);
    color: white;
    font-weight: 600;
}

.download-card--cta:hover {
    background: var(--brand-strong);
    border-color: var(--brand-strong);
    color: white;
}

.download-card--cta strong {
    color: white;
    font-size: 1rem;
}

.download-card--cta span {
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.82rem;
}

/* ---------- Buttons ---------- */

button,
.primary-btn,
.secondary-btn,
.ghost-btn,
.cta-btn {
    appearance: none;
    cursor: pointer;
    font-weight: 500;
    border-radius: var(--radius);
    padding: 0.7rem 1rem;
    border: 1px solid transparent;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease, color 0.18s ease;
    font-size: 0.92rem;
}

button:active,
.primary-btn:active,
.secondary-btn:active,
.ghost-btn:active,
.cta-btn:active {
    transform: translateY(1px);
}

.primary-btn {
    background: var(--brand);
    color: white;
    box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
    background: var(--brand-strong);
}

.secondary-btn {
    background: var(--navy);
    color: white;
}

.secondary-btn:hover {
    background: #17306b;
}

.ghost-btn {
    background: var(--surface);
    color: var(--ink-soft);
    border-color: var(--line);
}

.ghost-btn:hover {
    background: var(--bg-soft);
    border-color: var(--line-strong);
    color: var(--ink);
}

.cta-btn {
    padding: 0.95rem 1.2rem;
    background: linear-gradient(135deg, var(--brand), var(--navy));
    color: white;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: var(--shadow-md);
    letter-spacing: 0.01em;
}

.cta-btn:hover {
    background: linear-gradient(135deg, var(--brand-strong), var(--navy));
    box-shadow: var(--shadow-lg);
}

.wide-btn {
    width: 100%;
}

.primary-btn:disabled,
.secondary-btn:disabled,
.ghost-btn:disabled,
.cta-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- Action forms ---------- */

.action-form {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 0.7rem;
}

.action-form label {
    display: grid;
    gap: 0.25rem;
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 500;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin: 0.7rem 0 0.3rem;
}

.action-grid form {
    width: 100%;
    margin: 0;
}

/* ---------- Inputs ---------- */

input[type="text"],
input[type="number"],
input[type="file"],
textarea,
select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

textarea {
    min-height: 54px;
    max-height: 240px;
    resize: vertical;
    padding: 0.75rem 0.9rem;
    line-height: 1.5;
}

select {
    cursor: pointer;
}

/* ---------- Chat thread ---------- */

.chat-thread {
    display: grid;
    gap: 1rem;
    padding: 0.5rem 0;
    overflow: auto;
    scroll-behavior: smooth;
}

.message {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 0.75rem;
    align-items: start;
}

.message__avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-weight: 600;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
}

.message--assistant .message__avatar {
    background: var(--brand);
    color: white;
}

.message--user .message__avatar {
    background: var(--bg-soft);
    color: var(--ink-soft);
    border: 1px solid var(--line);
}

.message__body {
    display: grid;
    gap: 0.7rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--line);
}

.message--user .message__body {
    background: var(--bg-soft);
    border-color: var(--line);
}

.message__meta {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.82rem;
}

.message__meta strong {
    color: var(--ink);
    font-weight: 600;
}

.message__meta span {
    color: var(--muted);
}

.message-text {
    white-space: pre-line;
    line-height: 1.6;
    color: var(--ink);
}

.message-preview-image {
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface-alt);
}

/* ---------- Artifact cards (chat attachments) ---------- */

.artifact-stack {
    display: grid;
    gap: 0.55rem;
}

.artifact-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius);
    background: var(--surface-alt);
    border: 1px solid var(--line);
}

.artifact-card strong {
    display: block;
    font-weight: 600;
    color: var(--ink);
    font-size: 0.93rem;
}

.artifact-card__name {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.1rem;
}

.artifact-card p {
    margin: 0.3rem 0 0;
    font-size: 0.82rem;
    color: var(--muted);
}

.artifact-card__actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.artifact-card__actions .ghost-btn,
.artifact-card__actions .secondary-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.82rem;
}

/* ---------- Tables ---------- */

.table-wrap {
    overflow: auto;
    border-radius: var(--radius);
    border: 1px solid var(--line);
}

table {
    width: 100%;
    min-width: 480px;
    border-collapse: collapse;
    background: var(--surface);
}

th,
td {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 0.9rem;
}

th {
    position: sticky;
    top: 0;
    background: var(--surface-alt);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ---------- Composer ---------- */

.composer {
    display: grid;
    gap: 0.7rem;
    margin-top: 1rem;
    padding: 0.9rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
}

.composer__top,
.composer__bottom {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.composer__actions {
    display: flex;
    gap: 0.4rem;
    margin-left: auto;
}

.attach-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.85rem;
    border-radius: var(--radius);
    border: 1px dashed var(--line-strong);
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 0.88rem;
    cursor: pointer;
    transition: border-color 0.18s ease, color 0.18s ease;
}

.attach-btn:hover {
    border-color: var(--brand);
    color: var(--brand);
}

.attach-btn input {
    display: none;
}

.selected-file-pill {
    padding: 0.4rem 0.7rem;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--navy);
    font-size: 0.82rem;
    font-weight: 500;
}

/* ---------- Sidebar sections ---------- */

.context-card,
.empty-card {
    display: grid;
    gap: 0.6rem;
    padding: 0.9rem;
    border-radius: var(--radius);
    background: var(--surface-alt);
    border: 1px solid var(--line);
}

.context-card__title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.context-card__title strong {
    font-weight: 600;
    color: var(--ink);
    word-break: break-word;
}

.context-card__title span {
    font-size: 0.76rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--navy);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.empty-card strong {
    color: var(--ink);
}

.empty-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.file-list,
.artifact-list,
.quick-grid,
.insight-list {
    display: grid;
    gap: 0.5rem;
}

.file-chip-form {
    margin: 0;
}

.file-chip {
    display: grid;
    gap: 0.2rem;
    width: 100%;
    padding: 0.7rem 0.85rem;
    text-align: left;
    cursor: pointer;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: var(--radius);
    color: var(--ink);
    transition: border-color 0.18s ease, background 0.18s ease;
}

.file-chip:hover {
    border-color: var(--brand);
    background: var(--brand-soft);
}

.file-chip strong {
    font-weight: 600;
    font-size: 0.9rem;
    word-break: break-word;
}

.file-chip span {
    font-size: 0.78rem;
    color: var(--muted);
}

.file-chip.is-active {
    border-color: var(--brand);
    background: var(--brand-soft);
}

.file-chip.is-active strong {
    color: var(--navy);
}

/* ---------- Analysis / preview ---------- */

.analysis-card,
.preview-card {
    display: grid;
    gap: 0.7rem;
    padding: 0.9rem;
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.insight-item {
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius);
    background: var(--brand-soft);
    border: 1px solid color-mix(in srgb, var(--brand) 18%, transparent);
    color: var(--info-ink);
    font-size: 0.9rem;
    line-height: 1.5;
}

.mini-table {
    display: grid;
    gap: 0.35rem;
    padding: 0.8rem;
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.mini-table h3 {
    margin: 0 0 0.3rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
}

.mini-row {
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    padding: 0.35rem 0;
    border-bottom: 1px dashed var(--line);
    font-size: 0.9rem;
}

.mini-row:last-child { border-bottom: none; }

/* ---------- Result grid ---------- */

.result-stack {
    display: grid;
    gap: 1rem;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1rem;
}

.empty-state {
    display: grid;
    place-items: center;
    gap: 0.4rem;
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--line-strong);
    background: var(--surface-alt);
}

.empty-state h2 {
    color: var(--ink);
}

/* ---------- Column profile ---------- */

.column-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.5rem;
}

.column-card {
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface-alt);
}

.column-card strong {
    display: block;
    font-size: 0.9rem;
    color: var(--ink);
    word-break: break-word;
}

.column-card span {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

/* ---------- Alerts ---------- */

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--success-soft);
    color: var(--success-ink);
    border-color: color-mix(in srgb, var(--success) 25%, transparent);
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger-ink);
    border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

/* ---------- Loader overlay ---------- */

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(3px);
    animation: fadeIn 0.18s ease-out;
}

.loading-overlay.is-active {
    display: flex;
}

.loading-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--line);
    min-width: min(420px, calc(100% - 2rem));
}

.loading-card > div {
    display: grid;
    gap: 0.2rem;
}

.loading-card strong {
    display: block;
    font-weight: 600;
    color: var(--ink);
    font-size: 1rem;
}

.loading-card span {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
}

.loader-ring {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid rgba(37, 99, 235, 0.2);
    border-top-color: var(--brand);
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

.loader-ring--lg {
    width: 2.25rem;
    height: 2.25rem;
    border-width: 3px;
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---------- Button loading state ---------- */

button.htmx-request,
.primary-btn.htmx-request,
.secondary-btn.htmx-request,
.cta-btn.htmx-request,
.ghost-btn.htmx-request {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

button.htmx-request::after,
.primary-btn.htmx-request::after,
.secondary-btn.htmx-request::after,
.cta-btn.htmx-request::after,
.ghost-btn.htmx-request::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 1rem;
    height: 1rem;
    margin: -0.5rem 0 0 -0.5rem;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: white;
    animation: spin 0.7s linear infinite;
}

.ghost-btn.htmx-request::after {
    border-color: rgba(37, 99, 235, 0.25);
    border-top-color: var(--brand);
}

/* Form wrapping a submitting button also gets visual feedback */
form.htmx-request button {
    opacity: 0.85;
}

/* ---------- Primary accent rail section ---------- */

.rail-section--primary {
    border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.04), rgba(14, 165, 233, 0.04));
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.04);
}

.rail-section--primary h2 {
    color: var(--navy);
}

details summary {
    cursor: pointer;
    padding: 0.5rem 0;
    font-weight: 500;
    color: var(--brand);
    font-size: 0.9rem;
    list-style: none;
}

details summary::-webkit-details-marker { display: none; }

details summary::before {
    content: "▸ ";
    display: inline-block;
    transition: transform 0.18s ease;
}

details[open] summary::before {
    transform: rotate(90deg);
}

/* ---------- Landing page (index) ---------- */

.page-stack {
    display: grid;
    gap: 1.25rem;
}

.page-grid {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    gap: 1.25rem;
    align-items: start;
}

.hero-card {
    padding: 2rem 2rem 1.75rem;
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #0ea5e9 100%);
    color: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    display: grid;
    gap: 1rem;
}

.hero-card .eyebrow {
    background: rgba(255, 255, 255, 0.18);
    color: white;
}

.hero-card h1 {
    color: white;
    font-size: 1.85rem;
    line-height: 1.25;
}

.hero-card .hero-text {
    margin: 0;
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.98rem;
    line-height: 1.55;
}

.hero-points {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.3rem;
}

.hero-points span {
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    color: white;
    font-size: 0.82rem;
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.upload-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    padding: 1.75rem;
    box-shadow: var(--shadow-sm);
    display: grid;
    gap: 1rem;
}

.upload-form {
    display: grid;
    gap: 0.8rem;
}

.dropzone {
    position: relative;
    display: grid;
    justify-items: center;
    gap: 0.5rem;
    padding: 2.25rem 1.5rem;
    border-radius: var(--radius-lg);
    border: 2px dashed var(--line-strong);
    background: var(--surface-alt);
    cursor: pointer;
    text-align: center;
    transition: border-color 0.18s ease, background 0.18s ease;
}

.dropzone:hover {
    border-color: var(--brand);
    background: var(--brand-soft);
}

.dropzone input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.dropzone-badge {
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: var(--brand);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.dropzone strong {
    font-size: 1rem;
    color: var(--ink);
    font-weight: 600;
}

.dropzone small {
    color: var(--muted);
    font-size: 0.82rem;
}

.support-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.support-grid article {
    padding: 0.85rem 0.95rem;
    border-radius: var(--radius);
    background: var(--surface-alt);
    border: 1px solid var(--line);
}

.support-grid h3 {
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
    color: var(--navy);
}

.support-grid p {
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.45;
}

/* ---------- Preview + Actions layout ---------- */

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.9fr);
    gap: 1.25rem;
    align-items: start;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0.25rem 0;
}

.section-head h1 {
    font-size: 1.55rem;
    word-break: break-word;
}

.head-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.preview-panel,
.action-panel {
    display: grid;
    gap: 1rem;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.55rem;
}

.profile-card {
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface-alt);
}

.profile-card strong {
    display: block;
    font-size: 0.9rem;
    color: var(--ink);
    font-weight: 600;
    word-break: break-word;
}

.profile-card span,
.profile-card small {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.2rem;
}

.image-preview {
    display: grid;
    gap: 0.75rem;
}

.image-preview img {
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface-alt);
}

.image-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.image-meta span {
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    font-size: 0.8rem;
    color: var(--ink-soft);
}

/* ---------- Responsive ---------- */

@media (max-width: 1120px) {
    .chat-layout,
    .page-grid,
    .workspace-grid {
        grid-template-columns: 1fr;
    }

    .side-rail {
        position: static;
    }

    .chat-stage {
        min-height: auto;
    }

    .support-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 720px) {
    .page-frame {
        width: min(100% - 1rem, 100%);
        padding-top: 1rem;
    }

    .topbar {
        padding: 0.7rem 1rem;
    }

    .chat-stage,
    .panel,
    .rail-section {
        padding: 1rem;
    }

    .chat-stage__header,
    .composer__bottom {
        flex-direction: column;
        align-items: stretch;
    }

    .composer__actions {
        margin-left: 0;
    }

    .action-grid {
        grid-template-columns: 1fr;
    }

    .message {
        grid-template-columns: 1fr;
    }

    .hero-card {
        padding: 1.5rem 1.25rem;
    }

    .support-grid {
        grid-template-columns: 1fr;
    }

    .section-head {
        flex-direction: column;
    }
}
