:root {
    /* Brand palette — churchquestions.org */
    --sky-light: #e8f6fd;
    --sky: #12aae1;
    --sky-dark: #0e8fbd;
    --navy-light: #e8f4f9;
    --navy: #0a2f4e;
    --navy-dark: #071f34;
    --slate-light: #f8fafc;
    --slate: #64748b;
    --slate-dark: #1e293b;

    /* Semantic roles mapped onto the palette */
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: var(--slate-light);
    --border: #e2e8f0;
    --text: var(--slate-dark);
    --text-soft: var(--slate);
    --primary: var(--sky);
    --primary-dark: var(--sky-dark);
    --primary-soft: var(--sky-light);
    --accent: var(--sky);
    --accent-soft: var(--sky-light);
    --danger: #b91c1c;

    --radius: 12px;
    --shadow: 0 1px 2px rgba(10, 47, 78, .05), 0 8px 24px rgba(10, 47, 78, .06);
    --font: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.55;
}

/* Header ------------------------------------------------------------------ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .9rem 1.5rem;
    background: var(--surface);
    color: var(--navy);
    border-bottom: 2px solid var(--accent);
    box-shadow: 0 1px 3px rgba(11, 28, 77, .04);
}
.brand { display: flex; align-items: center; }
.app-header h1 { font-size: 1.25rem; margin: 0; letter-spacing: .2px; }
.tagline { margin: 0; font-size: .82rem; color: #94a3b8; }

.status-badge {
    font-size: .75rem;
    font-weight: 600;
    padding: .35rem .7rem;
    border-radius: 999px;
    color: var(--navy);
    background: var(--surface-2);
    border: 1px solid var(--border);
    white-space: nowrap;
}
.status-badge.live { color: #047857; background: #ecfdf5; border-color: #a7f3d0; }
.status-badge.demo { color: var(--navy); background: var(--sky-light); border-color: #bae6fd; }

/* Layout ------------------------------------------------------------------ */
.layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.25rem;
    max-width: 1200px;
    margin: 1.25rem auto;
    padding: 0 1.25rem;
    align-items: start;
}

.sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    border-left: 3px solid var(--sky);
    box-shadow: var(--shadow);
    position: sticky;
    top: 1.25rem;
}
.sidebar-intro {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-soft);
    margin-bottom: .6rem;
}

.feature-nav { display: flex; flex-direction: column; gap: .25rem; }
.nav-group-label {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--navy);
    margin: .75rem .25rem .25rem;
}
.feature-btn {
    display: flex;
    align-items: flex-start;
    text-align: left;
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 10px;
    padding: .6rem .65rem;
    cursor: pointer;
    font: inherit;
    color: var(--text);
    transition: background .15s, border-color .15s;
}
.feature-btn:hover { background: var(--surface-2); }
.feature-btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--navy); }
.feature-btn .meta { display: flex; flex-direction: column; }
.feature-btn .meta strong { font-size: .9rem; }
.feature-btn .meta span { font-size: .76rem; color: var(--text-soft); }

/* Workspace --------------------------------------------------------------- */
.workspace { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }

.empty-state {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-soft);
}
.empty-state h2 { color: var(--navy); margin: .5rem 0; }

.feature-form, .result-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    border-left: 3px solid var(--sky);
    box-shadow: var(--shadow);
}
.form-head h2 { color: var(--navy); margin: 0 0 .25rem; }
.form-desc { margin: 0 0 1.25rem; color: var(--text-soft); }

.form-fields { display: flex; flex-direction: column; gap: 1rem; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.field .req { color: var(--danger); margin-left: .15rem; }
.field .help { font-weight: 400; font-size: .78rem; color: var(--text-soft); margin-top: .2rem; }
.field input, .field select, .field textarea {
    width: 100%;
    padding: .65rem .7rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
    transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(18, 170, 225, .16);
    background: #fff;
}

.form-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1.4rem; }
.form-hint { font-size: .82rem; color: var(--danger); }

.btn {
    font: inherit;
    font-weight: 600;
    border-radius: 9px;
    padding: .6rem 1.1rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, opacity .15s;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.primary:disabled { opacity: .6; cursor: progress; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }

/* Result ------------------------------------------------------------------ */
.result-panel { position: relative; }
.result-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.result-head h3 { color: var(--navy); margin: 0; }
.result-tools { display: flex; gap: .5rem; }

.result-content {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem 1.4rem;
    overflow-x: auto;
}
.result-content h1, .result-content h2, .result-content h3 { margin-top: 1.1em; }
.result-content h1:first-child, .result-content h2:first-child { margin-top: 0; }
.result-content table { border-collapse: collapse; width: 100%; margin: .75rem 0; }
.result-content th, .result-content td { border: 1px solid var(--border); padding: .45rem .6rem; text-align: left; }
.result-content th { background: var(--primary-soft); }
.result-content a { color: var(--sky-dark); text-decoration: underline; }
.result-content code { background: #f1f5f9; padding: .1rem .35rem; border-radius: 5px; font-size: .9em; }
.result-content pre { background: var(--navy); color: #f8fafc; padding: 1rem; border-radius: 8px; overflow-x: auto; }
.result-content pre code { background: transparent; color: inherit; }
.result-content blockquote {
    border-left: 4px solid var(--accent);
    margin: .75rem 0;
    padding: .25rem 1rem;
    color: var(--text-soft);
    background: var(--accent-soft);
    border-radius: 0 8px 8px 0;
}

/* While streaming we show raw text; preserve line breaks and hint a caret. */
.result-content.streaming {
    white-space: pre-wrap;
    word-break: break-word;
}
.result-content.streaming::after {
    content: "▍";
    color: var(--primary);
    animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.disclaimer { font-size: .78rem; color: var(--text-soft); margin: 1rem 0 0; font-style: italic; }

/* Generating overlay ------------------------------------------------------ */
.generating-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 2rem;
    border-radius: var(--radius);
    z-index: 10;
}
.generating-overlay[hidden] { display: none; }
.generating-banner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
    width: 260px;
}
.generating-message {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--navy);
    background: var(--surface);
    padding: .75rem 1.5rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 3px;
    transition: width .3s ease;
}

/* Spinner ----------------------------------------------------------------- */
.spinner {
    display: inline-block;
    width: 1em; height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: -2px;
    margin-right: .4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive -------------------------------------------------------------- */
@media (max-width: 820px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: static; }
}

@media (max-width: 480px) {
    .app-header { align-items: flex-start; flex-direction: column; }
    .status-badge { max-width: 100%; white-space: normal; }
}
