/* =====================================================================
   Hverdagsbibel · Studio
   Calm, dignified devotional palette: warm off-white, deep indigo accent,
   gold hairline. System font stack. No external assets.
   ===================================================================== */

:root {
    --bg:          #f7f4ee;   /* warm off-white */
    --surface:     #fffdf9;
    --surface-2:   #f1ece2;
    --ink:         #2c2a31;   /* near-black, slightly warm */
    --ink-soft:    #6a6570;
    --ink-faint:   #98929c;
    --accent:      #2b2a55;   /* deep indigo */
    --accent-soft: #3c3b6e;
    --accent-ink:  #f6f4ff;
    --gold:        #b8965a;   /* gold hairline */
    --gold-soft:   #d8c39a;
    --line:        #e4ddd0;
    --danger:      #8a2f3a;
    --bubble-agent:#f1ece2;
    --bubble-sys:  #efeae0;
    --radius:      14px;
    --radius-sm:   9px;
    --shadow:      0 1px 2px rgba(36, 32, 25, .05),
                   0 8px 28px rgba(36, 32, 25, .07);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
            Arial, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    line-height: 1.5;
}

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

a { color: var(--accent); }

/* ---------------------------------------------------------------------
   Gate page
   --------------------------------------------------------------------- */
.gate-body {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: 1.5rem;
    background:
        radial-gradient(1200px 600px at 50% -10%, #efe9dd 0%, transparent 60%),
        var(--bg);
}

.gate-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2.4rem 2rem 2.1rem;
    text-align: center;
}

.gate-mark {
    color: var(--accent);
    display: inline-grid;
    place-items: center;
    width: 60px; height: 60px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--gold-soft);
    margin-bottom: 1rem;
}

.gate-title {
    font-size: 1.25rem;
    font-weight: 650;
    letter-spacing: .2px;
    margin: 0 0 .4rem;
}

.gate-sub {
    color: var(--ink-soft);
    font-size: .92rem;
    margin: 0 0 1.4rem;
}

.gate-error {
    background: #f7e9eb;
    color: var(--danger);
    border: 1px solid #e8c6cc;
    border-radius: var(--radius-sm);
    padding: .55rem .75rem;
    font-size: .88rem;
    margin: 0 0 1rem;
}

.gate-form {
    display: grid;
    gap: .55rem;
    text-align: left;
}

.gate-label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--ink-soft);
}

.gate-input {
    font: inherit;
    padding: .7rem .8rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
}

.gate-input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.gate-btn {
    margin-top: .4rem;
    font: inherit;
    font-weight: 650;
    padding: .72rem 1rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-ink);
    cursor: pointer;
    transition: background .15s ease;
}
.gate-btn:hover  { background: var(--accent-soft); }
.gate-btn:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   Studio shell
   --------------------------------------------------------------------- */
.studio-body {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

.studio-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .7rem 1.1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 0 rgba(184, 150, 90, .25); /* gold hairline */
    flex: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    min-width: 0;
}

.brand-mark {
    color: var(--accent);
    display: inline-grid;
    place-items: center;
    width: 34px; height: 34px;
    border-radius: 9px;
    background: var(--surface-2);
    border: 1px solid var(--gold-soft);
    flex: none;
}

.brand-name {
    font-weight: 650;
    font-size: 1.02rem;
    letter-spacing: .2px;
    white-space: nowrap;
}
.brand-dot { color: var(--gold); }

.header-note {
    margin: 0;
    font-size: .78rem;
    color: var(--ink-faint);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .2rem .65rem;
    white-space: nowrap;
}

/* Pane tabs — only shown on narrow screens. */
.pane-tabs {
    display: none;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: .35rem .5rem;
    gap: .3rem;
    flex: none;
}
.pane-tab {
    flex: 1;
    font: inherit;
    font-weight: 600;
    font-size: .9rem;
    color: var(--ink-soft);
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    padding: .5rem;
    cursor: pointer;
}
.pane-tab.is-active {
    background: var(--accent);
    color: var(--accent-ink);
}
.pane-tab:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 1px;
}

/* Two-pane layout */
.studio-main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1px;
    background: var(--line);
}

.pane {
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

/* ---------------------------------------------------------------------
   Chat pane
   --------------------------------------------------------------------- */
.thread-wrap {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.2rem 1.1rem .6rem;
    scroll-behavior: smooth;
}

.thread {
    list-style: none;
    margin: 0 auto;
    padding: 0;
    max-width: 680px;
    display: flex;
    flex-direction: column;
    gap: .7rem;
}

.msg {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}
.msg-body {
    padding: .65rem .85rem;
    border-radius: var(--radius);
    font-size: .96rem;
    white-space: pre-wrap;     /* preserve line breaks; text-only */
    overflow-wrap: anywhere;
    word-break: break-word;
}
.msg-time {
    font-size: .72rem;
    color: var(--ink-faint);
    padding: 0 .3rem;
}

/* client → right, accent bubble */
.msg.role-client {
    align-self: flex-end;
    align-items: flex-end;
}
.msg.role-client .msg-body {
    background: var(--accent);
    color: var(--accent-ink);
    border-bottom-right-radius: 5px;
}

/* agent → left, light bubble */
.msg.role-agent {
    align-self: flex-start;
    align-items: flex-start;
}
.msg.role-agent .msg-body {
    background: var(--bubble-agent);
    color: var(--ink);
    border: 1px solid var(--line);
    border-bottom-left-radius: 5px;
}

/* system → centered, muted */
.msg.role-system {
    align-self: center;
    align-items: center;
    max-width: 90%;
    text-align: center;
}
.msg.role-system .msg-body {
    background: transparent;
    color: var(--ink-soft);
    font-size: .88rem;
    border: 1px dashed var(--gold-soft);
    border-radius: 999px;
    padding: .5rem 1rem;
}

/* New-message fade-in */
.msg {
    animation: msg-in .18s ease both;
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}

/* "Hverdagsbibel arbejder…" indicator */
.working {
    max-width: 680px;
    margin: .2rem auto .4rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--ink-soft);
    font-size: .85rem;
    padding: 0 .3rem;
}
.working[hidden] { display: none; }
.working-dots { display: inline-flex; gap: 3px; }
.working-dots i {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--gold);
    display: inline-block;
    animation: bounce 1.1s infinite ease-in-out both;
}
.working-dots i:nth-child(1) { animation-delay: -.24s; }
.working-dots i:nth-child(2) { animation-delay: -.12s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(.5); opacity: .4; }
    40%           { transform: scale(1);  opacity: 1; }
}

/* Composer */
.composer {
    display: flex;
    align-items: flex-end;
    gap: .55rem;
    padding: .7rem 1.1rem .25rem;
    margin: 0 auto;
    width: 100%;
    max-width: calc(680px + 2.2rem);
    flex: none;
}
.composer-input {
    flex: 1;
    font: inherit;
    font-size: .96rem;
    resize: none;
    max-height: 40vh;
    padding: .65rem .85rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    line-height: 1.45;
}
.composer-input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 0;
    border-color: var(--accent);
}
.composer-send {
    flex: none;
    width: 44px; height: 44px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}
.composer-send:hover { background: var(--accent-soft); }
.composer-send:disabled { opacity: .45; cursor: default; }
.composer-send:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.composer-hint {
    margin: 0 auto;
    width: 100%;
    max-width: calc(680px + 2.2rem);
    padding: 0 1.1rem .7rem;
    font-size: .76rem;
    color: var(--ink-faint);
    flex: none;
}

/* ---------------------------------------------------------------------
   Preview pane
   --------------------------------------------------------------------- */
.preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
    padding: .55rem .8rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex: none;
}
.preview-title {
    font-size: .82rem;
    font-weight: 650;
    color: var(--ink-soft);
    letter-spacing: .3px;
    text-transform: uppercase;
}
.preview-actions { display: flex; gap: .4rem; }
.preview-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font: inherit;
    font-size: .82rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--accent);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: .4rem .65rem;
    cursor: pointer;
    transition: background .15s ease;
}
.preview-btn:hover { background: var(--bubble-agent); }
.preview-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.preview-frame-wrap {
    flex: 1;
    min-height: 0;
    background:
        repeating-conic-gradient(#f0ece4 0% 25%, #f6f3ec 0% 50%) 0 / 22px 22px;
    padding: .7rem;
}
.preview-frame {
    width: 100%;
    height: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    box-shadow: var(--shadow);
}

/* ---------------------------------------------------------------------
   Responsive: stack into tabs on narrow screens
   --------------------------------------------------------------------- */
@media (max-width: 820px) {
    .pane-tabs { display: flex; }
    .studio-main { grid-template-columns: 1fr; }
    .pane { display: none; }
    .pane.is-active { display: flex; }
    .msg { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
    .thread-wrap { scroll-behavior: auto; }
    .msg { animation: none; }
    .working-dots i { animation: none; }
}
