/* --- Reset & base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #F0F4F5;
    --surface: #FFFFFF;
    --surface-2: #FAFCFC;
    --ink: #0F172A;
    --ink-soft: #475569;
    --ink-faint: #94A3B8;
    --accent: #0F766E;
    --accent-hover: #0D5E58;
    --on-accent: #F0FDFA;
    --border: #DDE3E7;
    --border-focus: #CBD5DC;
    --error-bg: #FEF2F2;
    --error-border: #DC2626;
    --error-text: #991B1B;
    --radius: 6px;
    --font-serif: 'Newsreader', Georgia, serif;
    --font-sans: 'DM Sans', system-ui, sans-serif;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0E1419;
    --surface: #161D24;
    --surface-2: #1C242C;
    --ink: #E6EDF3;
    --ink-soft: #A4B2BE;
    --ink-faint: #6E7E8B;
    --accent: #2DD4BF;
    --accent-hover: #5EEAD4;
    --on-accent: #06302C;
    --border: #2A343D;
    --border-focus: #3D4A55;
    --error-bg: #2A1416;
    --error-border: #F87171;
    --error-text: #FCA5A5;
    color-scheme: dark;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* subtle paper grain */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    opacity: 0.3;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    background-size: 256px 256px;
}

/* --- Layout ---
   Two states: default (form centered, no result) and body.bbo-focus
   (form collapsed into a left drawer behind the rail; output full width). */
.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 2rem 4rem;
    position: relative;
}

.col-input {
    max-width: 600px;
    margin: 0 auto;
}

.input-panel-head {
    display: none;
}

.focus-rail {
    display: none;
}

body.bbo-focus .focus-rail {
    position: fixed;
    top: 5.25rem;
    right: 1rem;
    z-index: 25;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
    padding: 0.5rem 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.rail-btn {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.28rem;
    width: 54px;
    padding: 0.5rem 0.15rem 0.45rem;
    border: none;
    border-radius: 10px;
    background: none;
    color: var(--ink-soft);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.rail-btn:hover {
    background: var(--surface-2);
    color: var(--accent);
}

.rail-label {
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1;
}

.rail-div {
    width: 26px;
    height: 1px;
    background: var(--border);
    margin: 0.1rem auto;
}

/* Form as drawer in focus mode; right-anchored like the rail that opens it */
body.bbo-focus .col-input {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 30;
    width: min(440px, 100vw);
    max-width: none;
    height: 100vh;
    margin: 0;
    padding: 0 1.25rem 1.25rem;
    overflow-y: auto;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -20px 0 60px rgba(15, 23, 42, 0.14);
    transform: translateX(100%);
    transition: transform 0.2s ease;
}

body.bbo-focus .col-input.is-open {
    transform: translateX(0);
}

body.bbo-focus .input-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

.input-panel-title {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 600;
}

body.bbo-focus .records-toggle {
    display: none;
}

.col-output {
    max-width: 880px;
    margin: 0 auto;
}

.col-output:empty {
    display: none;
}

/* --- Header --- */
header {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Top-right corner with the Arkiv toggle. Anchored to the page, not the
   viewport: it scrolls away with the header instead of floating over content. */
.theme-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    color: var(--ink-soft);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.theme-toggle:hover {
    color: var(--accent);
    border-color: var(--border-focus);
}

.theme-toggle .ti { display: none; }

:root[data-theme-pref="system"] .ti-system,
:root[data-theme-pref="light"] .ti-light,
:root[data-theme-pref="dark"] .ti-dark {
    display: block;
}

:root:not([data-theme-pref]) .ti-system { display: block; }

/* The logo is the "start over" affordance — same behavior as the Ny button.
   z-index keeps it clickable when focus mode pulls main up over the header. */
.logo {
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: 2.4rem;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--ink);
    text-decoration: none;
    position: relative;
    z-index: 20;
    transition: color 0.15s ease;
}

.logo:hover {
    color: var(--accent);
}

.records-toggle {
    position: absolute;
    top: 1rem;
    right: 4rem;
    z-index: 20;
    height: 2.25rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--accent);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.records-panel {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 30;
    width: min(380px, 100vw);
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -20px 0 60px rgba(15, 23, 42, 0.14);
    transform: translateX(0);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
}

.records-panel.is-closed {
    transform: translateX(100%);
}

.records-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.records-header h2 {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    font-weight: 600;
}

.records-close {
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
}

.records-list {
    overflow: auto;
    padding: 0.75rem;
}

.records-empty {
    color: var(--ink-soft);
    font-size: 0.875rem;
    padding: 1rem 0.25rem;
}

.record-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    background: var(--surface-2);
}

.record-item summary {
    cursor: pointer;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.75rem;
    list-style: none;
}

.record-item summary::-webkit-details-marker {
    display: none;
}

.record-title {
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.3;
}

.record-time,
.record-source,
.record-preview {
    color: var(--ink-soft);
    font-size: 0.75rem;
}

.record-source,
.record-preview,
.record-actions {
    padding: 0 0.75rem 0.75rem;
}

.record-preview {
    line-height: 1.45;
}

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

.record-actions button {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--accent);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.35rem 0.6rem;
    cursor: pointer;
}

/* --- Form --- */
.draft-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-soft);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.label-hint {
    text-transform: none;
    font-weight: 400;
    color: var(--ink-faint);
}

textarea,
input[type="text"],
.edit-input,
.edit-textarea {
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
    resize: vertical;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    line-height: 1.45;
}

input[type="text"] {
    resize: none;
}

textarea::placeholder,
input[type="text"]::placeholder,
.edit-input::placeholder,
.edit-textarea::placeholder {
    color: var(--ink-faint);
}

textarea:focus,
input[type="text"]:focus,
.edit-input:focus,
.edit-textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(28, 25, 23, 0.06);
}

/* hidden native file input */
input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.file-upload {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: none;
    color: var(--ink-soft);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
    width: fit-content;
}

.file-upload:hover {
    border-color: var(--ink-faint);
    color: var(--ink);
}

.file-names {
    font-size: 0.8125rem;
    color: var(--ink-soft);
    font-style: italic;
}

/* --- Source parse status --- */
#url-status,
#file-status {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.url-indicator {
    font-size: 0.75rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.url-ok { color: var(--accent); }
.url-err { color: var(--error-text); }
.url-pending { color: var(--ink-faint); }

.url-spinner-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ink-faint);
    animation: pulse 1.2s ease-in-out infinite;
    vertical-align: middle;
}

/* --- Start screen: mode choice ---
   Two equal cards; the source form only appears after picking the auto mode
   (or via the drawer once a BBO is on stage). */
.mode-choice {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.mode-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.55rem;
    padding: 1.4rem 1.3rem 1.5rem;
    text-align: left;
    font-family: var(--font-sans);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.mode-card:hover {
    border-color: var(--accent);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

.mode-icon {
    color: var(--accent);
    margin-bottom: 0.2rem;
}

.mode-title {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.25;
}

.mode-desc {
    font-size: 0.8125rem;
    color: var(--ink-soft);
    line-height: 1.5;
}

body.mode-auto .mode-choice,
body.bbo-focus .mode-choice {
    display: none;
}

#bbo-form {
    display: none;
}

body.mode-auto #bbo-form,
body.bbo-focus #bbo-form {
    display: flex;
}

/* Back to the mode choice; hidden in the drawer, which has its own header */
.form-back-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.form-back {
    flex: none;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}

.form-back:hover {
    color: var(--accent);
    border-color: var(--border-focus);
}

.form-mode-title {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 600;
}

body.bbo-focus .form-back-row {
    display: none;
}

/* --- Button --- */
.form-actions {
    padding-top: 0.5rem;
}

.btn-draft {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--on-accent);
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    padding: 0.75rem 1.6rem;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    width: 100%;
    justify-content: center;
}

.btn-draft:hover {
    background: var(--accent-hover);
}

.btn-draft:active {
    transform: scale(0.985);
}

.btn-draft:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-arrow {
    transition: transform 0.2s ease;
}

.btn-draft:hover .btn-arrow {
    transform: translateX(3px);
}

/* --- Spinner --- */
.spinner-hidden {
    display: none;
}

.spinner-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem 0;
    color: var(--ink-soft);
    font-size: 0.875rem;
}

/* A 3x3 grid whose lit cell sweeps left->right as a chevron wavefront. The
   650ms cycle is shorter than the 270ms stagger + cycle, so two fronts are
   always in flight — the grid never reads as empty mid-loop. */
.pixel-grid {
    display: grid;
    grid-template-columns: repeat(3, 8px);
    gap: 3px;
    flex: none;
}

.pixel-grid span {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--ink);
    opacity: 0.12;
    animation: pixel-on 650ms ease-in-out infinite;
}

/* Delay per cell = (column + |row - 1|) * 90ms, which tilts the column front
   into a chevron. Hand-expanded here because the markup is static. */
.pixel-grid span:nth-child(4) { animation-delay: 0ms; }
.pixel-grid span:nth-child(1),
.pixel-grid span:nth-child(5),
.pixel-grid span:nth-child(7) { animation-delay: 90ms; }
.pixel-grid span:nth-child(2),
.pixel-grid span:nth-child(6),
.pixel-grid span:nth-child(8) { animation-delay: 180ms; }
.pixel-grid span:nth-child(3),
.pixel-grid span:nth-child(9) { animation-delay: 270ms; }

@keyframes pixel-on {
    0%, 100% { background-color: var(--ink); opacity: 0.12; }
    50% { background-color: var(--accent); opacity: 0.95; }
}

.spinner-label {
    margin: 0;
    color: var(--ink-soft);
}

/* Gated: without background-clip the transparent fill would erase the label
   outright, so the shimmer only applies where it can actually render. */
@supports (background-clip: text) or (-webkit-background-clip: text) {
    .spinner-label {
        /* Base is --ink-soft, the label's own colour: an --ink-faint base made
           the shimmering label lighter than the static one it replaced. */
        background-image: linear-gradient(
            90deg,
            var(--ink-soft) 35%,
            var(--ink) 50%,
            var(--ink-soft) 65%
        );
        background-size: 200% 100%;
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
        animation: shimmer-text 1.4s linear infinite;
    }
}

@keyframes shimmer-text {
    from { background-position: 100% 0; }
    to { background-position: 0% 0; }
}

.spinner-elapsed {
    font-family: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    color: var(--ink-faint);
}

/* Freeze the grid dim and drop the sweep; the timer keeps ticking, since it
   carries information rather than motion. Scoped to the loader so the app's
   other transitions are left alone. */
@media (prefers-reduced-motion: reduce) {
    .pixel-grid span {
        animation: none;
    }

    .spinner-label {
        animation: none;
        background-image: none;
        color: var(--ink-soft);
        -webkit-text-fill-color: var(--ink-soft);
    }
}

.btn-cancel {
    margin-left: auto;
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--ink-soft);
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-style: normal;
    padding: 0.25rem 0.75rem;
    cursor: pointer;
}

.btn-cancel:hover {
    color: var(--ink);
    border-color: var(--ink-faint);
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1); }
}

/* --- Progress card (speaker extraction / bio fetching) --- */
.progress-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    animation: fadeUp 0.35s ease-out;
}

.progress-title {
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--ink-soft);
    margin-bottom: 0.75rem;
}

.progress-item {
    font-size: 0.9375rem;
    padding: 0.35rem 0;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.progress-icon {
    font-size: 0.875rem;
    width: 1.2em;
    text-align: center;
}

.progress-icon.bio-ok { color: var(--accent); }
.progress-icon.bio-fail { color: var(--error-text); }

/* --- BBO result preview --- */
.bbo-wrapper {
    animation: fadeUp 0.35s ease-out;
}

.bbo-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
    max-width: 45rem;
    margin: 0 auto 0.7rem;
}

.bbo-actions .save-status {
    margin-right: auto;
    order: -1;
}

/* The editor is a page: readable measure, centered on the desk */
.bbo-preview {
    max-width: 45rem;
    margin: 0 auto;
    padding: 2.6rem 3rem 2.9rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.bbo-editor .edit-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--ink-faint);
    letter-spacing: 0.1em;
    margin: 0 0 0.35rem;
}

/* Colophon line above the title: context left, responsible person right */
.doc-folio {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 1.1rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.folio-mark {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
    white-space: nowrap;
}

.folio-ansv {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.55rem;
}

.folio-ansv .edit-label {
    margin: 0;
    white-space: nowrap;
}

.bbo-editor .edit-ansvarlig {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    background: none;
    border: none;
    border-bottom: 1px dashed var(--ink-faint);
    border-radius: 0;
    padding: 0.05rem 0.1rem 0.2rem;
    width: 11rem;
}

.bbo-editor .edit-ansvarlig:focus {
    border-bottom: 1px solid var(--accent);
    box-shadow: none;
}

.bbo-editor .edit-ansvarlig[aria-invalid="true"] {
    border-bottom-color: var(--error-text);
}

.field-error-message {
    flex-basis: 100%;
    color: var(--error-text);
    font-size: 0.72rem;
    font-weight: 600;
    text-align: right;
}

/* The headline owns the page; its underline only appears on hover/focus.
   It is a textarea so long titles wrap — autoGrow keeps it at content height. */
.bbo-editor .edit-title {
    display: block;
    width: 100%;
    font-family: var(--font-serif);
    font-size: 2.2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--ink);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 0.1rem 0 0.35rem;
    min-height: 0;
    resize: none;
    overflow: hidden;
}

.bbo-editor .edit-title:hover {
    border-bottom-color: var(--border);
}

.bbo-editor .edit-title:focus {
    border-bottom-color: var(--accent);
    box-shadow: none;
}

.omtale-block {
    margin-top: 1.7rem;
}

/* Seamless body text; the field reveals itself as a soft block on hover/focus.
   autoGrow sizes these to their content, so the manual resize grip is noise. */
.bbo-editor .edit-omtale {
    font-family: var(--font-serif);
    font-size: 1.0625rem;
    line-height: 1.72;
    min-height: 8rem;
    background: none;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    margin: 0 -0.6rem;
    width: calc(100% + 1.2rem);
    resize: none;
}

.bbo-editor .edit-omtale:hover {
    background: var(--surface-2);
}

.bbo-editor .edit-omtale:focus {
    background: var(--surface-2);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.bbo-field {
    margin-bottom: 1rem;
    font-family: var(--font-serif);
    font-size: 1.0625rem;
    line-height: 1.65;
    color: var(--ink);
}

.bbo-field-label {
    font-weight: 600;
}

.bbo-title-field {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.3;
}

.bbo-title-value {
    font-weight: 600;
}

.bbo-omtale {
    margin-top: 0.35rem;
    font-family: var(--font-serif);
    font-size: 1.0625rem;
    line-height: 1.7;
}

/* --- Speakers: part of the document, separated by a hairline --- */
.speakers-block {
    margin-top: 2.4rem;
    padding-top: 1.7rem;
    border-top: 1px solid var(--border);
}

.speaker-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.8rem 2rem;
    margin-top: 1.1rem;
}

.bbo-speaker-editor {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

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

/* The name is a skrivelinje: a visible line to fill in, like a paper form */
.speaker-head .edit-input {
    flex: 1;
    min-width: 0;
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
    background: none;
    border: none;
    border-bottom: 1px solid var(--ink-faint);
    border-radius: 0;
    padding: 0.15rem 0 0.3rem;
    margin: 0;
}

.speaker-head .edit-input::placeholder {
    font-style: italic;
    font-weight: 400;
}

.speaker-head .edit-input:focus {
    border-bottom: 2px solid var(--accent);
    padding-bottom: calc(0.3rem - 1px);
    box-shadow: none;
}

.btn-remove-speaker {
    border: none;
    background: none;
    color: var(--ink-faint);
    font-size: 1rem;
    line-height: 1;
    padding: 0.25rem;
    cursor: pointer;
}

.btn-remove-speaker:hover {
    color: var(--error-text);
}

.speaker-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.75rem;
}

/* No warnings before any information exists: hide the status chip on untouched
   cards. The chip (and its checkbox) stays in the DOM so archive lookups and
   autosave keep working unchanged. */
.bbo-speaker-editor.is-pristine .chip-state {
    display: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    padding: 0.16rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-soft);
    cursor: pointer;
    white-space: nowrap;
}

.chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.chip input[type="checkbox"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.chip.is-on {
    border-color: var(--accent);
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

/* Explicit negative state: image not uploaded and not in the archive */
.chip.chip-warn {
    border-color: color-mix(in srgb, var(--error-border) 40%, var(--border));
    color: var(--error-text);
}

.chip.chip-warn:hover {
    border-color: var(--error-border);
    color: var(--error-text);
}

.chip-status {
    cursor: default;
}

.chip-upload svg {
    flex: none;
}

.chip-static {
    cursor: default;
}

.chip-static:hover {
    border-color: var(--border);
    color: var(--ink-soft);
}

.btn-remove-image {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--ink-faint);
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
}

.btn-remove-image:hover {
    color: var(--error-text);
}

.speaker-bio-field {
    margin-top: 1.05rem;
}

/* Bio reads as document text, like the omtale — field reveals on hover/focus */
.speaker-bio-field .edit-textarea {
    font-family: var(--font-serif);
    font-size: 0.95rem;
    line-height: 1.62;
    min-height: 3.6rem;
    background: none;
    border: none;
    border-radius: 6px;
    padding: 0.3rem 0.5rem;
    margin: 0 -0.5rem;
    width: calc(100% + 1rem);
    resize: none;
}

.speaker-bio-field .edit-textarea::placeholder {
    font-style: italic;
}

.speaker-bio-field .edit-textarea:hover {
    background: var(--surface-2);
}

.speaker-bio-field .edit-textarea:focus {
    background: var(--surface-2);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

/* Big add tile: same grid footprint as a speaker, like the original design */
.btn-add-speaker {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: 9rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink-soft);
    background: none;
    border: 1.5px dashed var(--border-focus);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-add-speaker .add-plus {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--ink-faint);
    transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-add-speaker:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.btn-add-speaker:hover .add-plus {
    color: var(--accent);
    border-color: var(--accent);
}

.bio-source-suffix {
    text-transform: none;
    font-weight: 400;
    color: var(--ink-soft);
}

.bio-source-suffix a {
    color: var(--accent);
    text-decoration: none;
}

.bio-source-suffix a:hover {
    text-decoration: underline;
}

.image-upload-status {
    color: var(--ink-soft);
    font-size: 0.7rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.image-upload-status:empty {
    display: none;
}

.bbo-missing {
    color: var(--error-text);
    font-weight: 500;
}

/* Google Docs button */
.btn-gdocs {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--on-accent);
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background 0.15s ease;
    white-space: nowrap;
}

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

.btn-save-bbo {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--accent);
    background: var(--bg);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.4rem 0.85rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.btn-save-bbo:hover {
    background: var(--accent);
    color: var(--on-accent);
}

.btn-save-bbo:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Quiet ghost variant for secondary actions (Kopier / Slett / Vis PDF) */
.btn-copy-bbo {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-soft);
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.4rem 0.7rem;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-copy-bbo:hover {
    border-color: var(--border);
    color: var(--accent);
}

/* --- Error --- */
.error-box {
    margin-top: 1.5rem;
    padding: 0.875rem 1.25rem;
    background: var(--error-bg);
    border-left: 3px solid var(--error-border);
    border-radius: var(--radius);
    color: var(--error-text);
    font-size: 0.875rem;
    animation: fadeUp 0.3s ease-out;
}

.error-label {
    font-weight: 500;
    margin-right: 0.35rem;
}

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

/* --- PDF link button --- */
.btn-pdf {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-soft);
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.4rem 0.7rem;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-pdf:hover {
    border-color: var(--border);
    color: var(--accent);
}

/* Reclaim the header band in focus mode: the action row rises to the logo line */
@media (min-width: 1200px) {
    body.bbo-focus main {
        margin-top: -3.7rem;
    }
}

/* Keep the centered output clear of the fixed rail on narrower viewports */
@media (max-width: 1100px) {
    body.bbo-focus .page {
        padding-right: 5.6rem;
    }
}

@media (max-width: 860px) {
    .speaker-grid {
        grid-template-columns: 1fr;
    }
    /* Rail becomes a horizontal strip under the header on small screens */
    body.bbo-focus .page {
        padding-right: 2rem;
    }
    body.bbo-focus .focus-rail {
        position: static;
        flex-direction: row;
        border-radius: var(--radius);
        width: fit-content;
        margin-bottom: 1rem;
        box-shadow: none;
    }
    .rail-div {
        width: 1px;
        height: 20px;
        margin: 0 0.15rem;
    }
}

@media (max-width: 640px) {
    .page { padding: 1.5rem 1rem 3rem; }
    body.bbo-focus .page { padding-right: 1rem; }
    .logo { font-size: 2rem; }
    .bbo-preview { padding: 1.5rem 1.15rem 1.8rem; }
    .doc-folio {
        flex-wrap: wrap;
        row-gap: 0.4rem;
        margin-bottom: 1.4rem;
    }
    .bbo-editor .edit-title {
        font-size: 1.7rem;
    }
    .mode-choice {
        grid-template-columns: 1fr;
    }
}

/* --- Autosave status, delete --- */
.save-status {
    display: inline-flex;
    align-items: center;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-faint);
    white-space: nowrap;
    padding: 0 0.25rem;
}

.save-status.is-saved { color: var(--accent); }
.save-status.is-saving { color: var(--ink-soft); }
.save-status.is-pending { color: var(--ink-faint); }
.save-status.is-error { color: var(--error-text); }

.btn-delete-bbo {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-soft);
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.4rem 0.7rem;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.btn-delete-bbo:hover {
    color: var(--error-text);
    border-color: var(--error-border);
}

.archive-status {
    font-size: 0.7rem;
    color: var(--ink-faint);
}

.archive-status:empty {
    display: none;
}

.archive-status.is-found { color: var(--accent); }
.archive-status.is-checking { color: var(--ink-soft); }
.archive-status.is-error { color: var(--error-text); }
.archive-status.is-missing { color: var(--error-text); }

.bio-missing {
    color: var(--error-text);
}

.bio-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.35rem;
}

.btn-bio-archive {
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--ink-faint);
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
}

.btn-bio-archive:hover {
    color: var(--accent);
}

.bio-archive-status {
    font-size: 0.7rem;
    color: var(--ink-faint);
}

.bio-archive-status:empty {
    display: none;
}

.bio-archive-status.is-found { color: var(--accent); }
.bio-archive-status.is-checking { color: var(--ink-soft); }
.bio-archive-status.is-error { color: var(--error-text); }
