/* byggadmin — rolig, ryddig, psykologisk beroligende.
   Lav-kontrast blå/grå/varmhvit. Source Serif for overskrifter (system fallback),
   Inter for brødtekst. Generøs luft. Ingen chrome junk. */

:root {
    --bg:        #f6f4ef;   /* varm hvit */
    --surface:   #ffffff;
    --ink:       #232730;   /* nesten svart, litt blått */
    --ink-soft:  #5c6472;
    --rule:      #e3e0d7;
    --accent:    #3d5a80;   /* dempet bla */
    --accent-2:  #98c1d9;
    --danger:    #a8464a;
    --ok:        #5b8266;
    --focus:     #3d5a80;
    --radius:    8px;
    --shadow-sm: 0 1px 2px rgba(35, 39, 48, 0.04), 0 1px 3px rgba(35, 39, 48, 0.06);
    --shadow-md: 0 2px 6px rgba(35, 39, 48, 0.06), 0 6px 16px rgba(35, 39, 48, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-feature-settings: "ss01", "cv11";
    line-height: 1.55;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    font-family: "Source Serif Pro", Georgia, "Times New Roman", serif;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin: 0 0 0.6em;
}

h1 { font-size: 2.2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ===== Auth pages (login, register) ===== */

body.auth {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 8vh 1.5rem 3rem;
}

.auth-shell {
    width: 100%;
    max-width: 420px;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 { font-size: 2.6rem; margin-bottom: 0.2em; }
.auth-header .tagline {
    color: var(--ink-soft);
    font-style: italic;
    margin: 0;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem 2rem 1.6rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--rule);
}

.auth-card h2 {
    margin-top: 0;
    text-align: center;
}

.stack { display: flex; flex-direction: column; gap: 1.05rem; }

.stack label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.92rem;
    color: var(--ink-soft);
}

.stack label input {
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.stack label input:focus {
    outline: none;
    border-color: var(--focus);
    box-shadow: 0 0 0 3px rgba(61, 90, 128, 0.15);
}

.stack label small {
    color: var(--ink-soft);
    font-size: 0.78rem;
}

.actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    margin-top: 0.4rem;
}

button.primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.75rem 1.3rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s, transform 0.1s;
}

button.primary:hover { background: #2f4a6e; }
button.primary:active { transform: translateY(1px); }
button.primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: auto;
}
button.primary:disabled:hover { background: var(--accent); }

a.secondary {
    color: var(--ink-soft);
    font-size: 0.95rem;
}

.error {
    background: rgba(168, 70, 74, 0.08);
    border: 1px solid rgba(168, 70, 74, 0.25);
    color: var(--danger);
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius);
    margin-bottom: 1.2rem;
    font-size: 0.92rem;
}

.auth-footer {
    margin-top: 2.2rem;
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.82rem;
    line-height: 1.5;
    padding: 0 1rem;
}

/* ===== Main app shell ===== */

body.app {
    height: 100vh;
    overflow: hidden;
}

.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    height: 100vh;
}

.sidebar {
    background: #2b3140;
    color: #e6e8ec;
    padding: 1.5rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 1.3rem;
}

.sidebar .brand {
    font-family: "Source Serif Pro", Georgia, serif;
    font-size: 1.4rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.sidebar-btn {
    background: transparent;
    color: #e6e8ec;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.65rem 0.85rem;
    text-align: left;
    cursor: pointer;
    font-size: 0.92rem;
    transition: background 0.12s, border-color 0.12s;
}

.sidebar-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); }
.sidebar-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.sidebar .logout {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

button.text {
    background: transparent;
    color: #b7bcc8;
    border: none;
    cursor: pointer;
    padding: 0.3rem 0;
    font-size: 0.88rem;
}
button.text:hover { color: #fff; }

.main {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;   /* grid item: lets inner flex shrink instead of overflow */
    min-height: 0;
    background: var(--bg);
    overflow: hidden;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.8rem;
    background: var(--surface);
    border-bottom: 1px solid var(--rule);
}

.topbar .project-name {
    font-family: "Source Serif Pro", Georgia, serif;
    font-size: 1.15rem;
    color: var(--ink);
}

.topbar .user-name {
    color: var(--ink-soft);
    font-size: 0.9rem;
}

/* ===== Chat column ===== */

.chat-shell {
    flex: 1;
    min-height: 0;                /* critical: lets .chat-log actually scroll */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 1.4rem 1.8rem 0.8rem;
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
}

.chat-log {
    flex: 1;
    min-height: 0;                /* same trick, one level deeper */
    overflow-y: auto;
    overscroll-behavior: contain; /* wheel events don't leak to the body */
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    padding: 0.2rem 0.2rem 1rem 0;
}

.placeholder {
    max-width: 520px;
    text-align: center;
    color: var(--ink-soft);
    margin: auto;
}

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

.msg {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.msg-header {
    font-size: 0.78rem;
    color: var(--ink-soft);
    letter-spacing: 0.02em;
}

.msg-body {
    white-space: pre-wrap;
    line-height: 1.55;
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid var(--rule);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.msg-user .msg-body {
    background: #eef2f7;
    border-color: #d8dfe8;
}

.msg-assistant .msg-body {
    background: #ffffff;
}

/* --- live action-log inside assistant bubble --- */

.action-log {
    margin: 0 0 0.6rem;
    padding: 0.4rem 0.6rem;
    background: rgba(0, 0, 0, 0.025);
    border-left: 2px solid var(--rule);
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.action-log[open] {
    padding-bottom: 0.5rem;
}

.action-log-summary {
    cursor: pointer;
    list-style: none;
    padding: 0.1rem 0;
    user-select: none;
    color: var(--ink-soft);
}

.action-log-summary::-webkit-details-marker { display: none; }

.action-log[open] > .action-log-summary {
    /* Hide the summary while expanded — the action lines themselves
       are the content. Show only when collapsed as a chip. */
    display: none;
}

.action-log.collapsed {
    background: transparent;
    border-left: none;
    padding: 0.2rem 0;
}

.action-log.collapsed > .action-log-summary {
    display: inline-block;
    padding: 0.1rem 0.55rem;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--surface);
    font-size: 0.78rem;
    color: var(--ink-soft);
}

.action-log.collapsed > .action-log-summary::after {
    content: " \25BE"; /* ▾ */
    opacity: 0.6;
}

.action-log-lines {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.action-line {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    line-height: 1.35;
}

.action-icon {
    display: inline-block;
    width: 1.1em;
    text-align: center;
    font-weight: 600;
    flex-shrink: 0;
}

.action-line.pending .action-icon {
    color: var(--accent);
    animation: action-pulse 1.1s ease-in-out infinite;
}

.action-line.done .action-icon {
    color: #2e7d32;
}

.action-line.failed .action-icon {
    color: #c0392b;
}

.action-label {
    white-space: pre-wrap;
    word-break: break-word;
}

@keyframes action-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.chat-input {
    display: flex;
    gap: 0.6rem;
    padding: 0.8rem 0 0.2rem;
    border-top: 1px solid var(--rule);
}

.chat-input textarea {
    flex: 1;
    resize: none;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 0.98rem;
    line-height: 1.45;
}

.chat-input textarea:focus {
    outline: none;
    border-color: var(--focus);
    box-shadow: 0 0 0 3px rgba(61, 90, 128, 0.12);
}

.chat-input button.primary {
    align-self: flex-end;
    padding: 0.7rem 1.2rem;
}

.disclaimer {
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.78rem;
    margin: 0.4rem 0 0.8rem;
}

.topbar .phase {
    color: var(--ink-soft);
    font-family: "Inter", sans-serif;
    font-size: 0.88rem;
    font-weight: normal;
}

/* Sidebar project selector */

.sidebar-projects { margin: 0; }
.sidebar-projects > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-projects > summary::-webkit-details-marker { display: none; }
.sidebar-projects .muted {
    color: #90959f;
    font-size: 0.78rem;
    text-align: right;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-btn.as-summary { width: 100%; border: 1px solid transparent; }

.project-list {
    margin-top: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding-left: 0.4rem;
}
.project-row { margin: 0; }
.project-pick {
    width: 100%;
    text-align: left;
    background: transparent;
    color: #d2d5dd;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.45rem 0.6rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.86rem;
}
.project-pick:hover { background: rgba(255,255,255,0.06); }
.project-pick.active { background: rgba(152, 193, 217, 0.14); border-color: rgba(152, 193, 217, 0.35); }
.project-pick .phase { color: #98a0af; font-size: 0.74rem; }
.project-list .hint { color: #98a0af; font-size: 0.8rem; padding: 0 0.3rem; }

.upload-label { position: relative; display: block; cursor: pointer; }
.upload-label.disabled { opacity: 0.45; cursor: not-allowed; }
.upload-status {
    font-size: 0.76rem;
    padding: 0.25rem 0.5rem;
    color: #98a0af;
    min-height: 1rem;
}
.upload-status.info { color: #98c1d9; }
.upload-status.ok { color: #a5c9a5; }
.upload-status.error { color: #e79298; }

/* ===== Empty state (no project yet) ===== */

.empty-state {
    margin: auto;
    max-width: 480px;
    padding: 2.5rem 1.5rem;
    text-align: center;
    color: var(--ink-soft);
}

.empty-state h2 {
    font-size: 1.6rem;
    margin: 0 0 1rem;
    color: var(--ink);
}

.empty-state p {
    margin: 0 0 0.9rem;
    line-height: 1.55;
}

.empty-state p:last-child {
    margin-bottom: 0;
    color: var(--ink-soft);
    font-size: 0.95rem;
}

/* P1-I: empty-cards — three concrete handlings replace the "Velkommen,
   dra mappa hit" block. Desktop: side-by-side. Mobil/smal: stacked. */
.empty-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin: 2rem auto 0.5rem;
    max-width: 960px;
    padding: 0 1rem;
}
.empty-card {
    display: block;
    text-align: left;
    background: var(--surface, #fff);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    padding: 1.1rem 1rem;
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
    font: inherit;
    transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}
.empty-card:hover,
.empty-card:focus {
    border-color: rgba(108, 64, 151, 0.45);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    outline: none;
}
.empty-card h2 {
    font-size: 1rem;
    margin: 0 0 0.5rem;
    color: var(--ink);
}
.empty-card p {
    margin: 0;
    font-size: 0.86rem;
    line-height: 1.4;
    color: var(--ink-soft);
}
.empty-card.empty-drop {
    border-style: dashed;
}
.empty-card.empty-outlook {
    border-color: rgba(0, 120, 212, 0.35);
}
.empty-card.empty-outlook h2 {
    color: #0078d4;
}
.empty-card.empty-demo {
    border-color: rgba(108, 64, 151, 0.35);
}
.empty-card.empty-demo h2 {
    color: #6c4097;
}
.empty-fallback {
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.9rem;
    margin: 0.6rem 0 1rem;
}

/* P1-K: mobile-only set is hidden by default; CSS swap on narrow. */
.empty-cards-mobile {
    display: none;
}
.empty-mini-link {
    color: var(--accent, #6c4097);
    text-decoration: underline;
    margin-left: 0.3rem;
}
.empty-mini-link:hover { text-decoration: none; }

@media (max-width: 720px) {
    .empty-cards-desktop { display: none; }
    .empty-cards-mobile {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.7rem;
        margin: 1rem auto 0.5rem;
        padding: 0 1rem;
    }
    .empty-cards-mobile .empty-card {
        text-align: left;
        padding: 1.2rem 1rem;
    }
    .empty-cards-mobile .empty-card h2 {
        font-size: 1.05rem;
    }
}

/* ===== Feedback modal ===== */

dialog.feedback-dialog {
    border: none;
    border-radius: var(--radius);
    padding: 1.6rem 1.6rem 1.2rem;
    width: min(540px, 92vw);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    color: var(--ink);
}
dialog.feedback-dialog::backdrop {
    background: rgba(35, 39, 48, 0.45);
    backdrop-filter: blur(2px);
}
dialog.feedback-dialog h2 { margin-top: 0; }
dialog.feedback-dialog .muted { color: var(--ink-soft); font-size: 0.88rem; margin-top: -0.4rem; }
dialog.feedback-dialog select,
dialog.feedback-dialog textarea,
dialog.feedback-dialog input[type="text"] {
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: #fff;
    font: inherit;
    width: 100%;
}
dialog.feedback-dialog textarea { resize: vertical; }
dialog.feedback-dialog .actions { margin-top: 0.6rem; }

.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: #2f4a3e;
    color: #fff;
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    font-size: 0.94rem;
}

/* ===== Drag-and-drop overlay ===== */

.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(35, 39, 48, 0.55);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    animation: drop-fade-in 0.12s ease-out;
    pointer-events: none; /* let the drop event through to window */
}
.drop-overlay.hidden { display: none; }

.drop-card {
    background: var(--surface);
    border: 2px dashed var(--accent);
    border-radius: 12px;
    padding: 2.4rem 3rem;
    max-width: 480px;
    text-align: center;
    box-shadow: var(--shadow-md);
}
.drop-card h2 {
    margin: 0 0 0.6rem;
    color: var(--accent);
}
.drop-card p {
    margin: 0;
    color: var(--ink-soft);
    line-height: 1.5;
    font-size: 0.95rem;
}

@keyframes drop-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* --- Phase 7: Markdown rendering, citations, responsive mobile --- */

.msg-body .citation {
    color: var(--accent);
    font-size: 0.88em;
    white-space: nowrap;
    text-decoration: none;
    border-bottom: 1px dotted var(--accent);
    cursor: pointer;
    padding: 0 .05em;
    border-radius: 2px;
    transition: background-color .12s ease;
}
.msg-body .citation:hover,
.msg-body .citation:focus {
    background: var(--accent-2);
    outline: none;
}

/* Confidence tiers from claim_policy. A citation without any tier
   class defaults to the base .citation style (effectively HIGH). */
.msg-body .citation.citation-high {
    /* baseline — same as .citation */
}
.msg-body .citation.citation-medium {
    color: #8a6a1f;
    border-bottom-style: dashed;
    border-bottom-color: #b88a2b;
}
.msg-body .citation.citation-medium:hover,
.msg-body .citation.citation-medium:focus {
    background: rgba(184, 138, 43, 0.15);
}
.msg-body .citation.citation-medium::after {
    content: "◎";
    font-size: 0.72em;
    margin-left: 0.12em;
    vertical-align: super;
    color: #b88a2b;
}
.msg-body .citation.citation-low {
    color: var(--danger);
    border-bottom-style: dashed;
    border-bottom-color: var(--danger);
    background: rgba(168, 70, 74, 0.06);
}
.msg-body .citation.citation-low:hover,
.msg-body .citation.citation-low:focus {
    background: rgba(168, 70, 74, 0.18);
}
.msg-body .citation.citation-low::after {
    content: "?";
    font-size: 0.78em;
    margin-left: 0.12em;
    vertical-align: super;
    font-weight: 700;
    color: var(--danger);
}

/* P0-A: memory_observation citations — purple dashed underline + ⚠.
   Renders on top of any tier class so users see at a glance that the
   claim came from prior conversation memory, not a document this turn. */
.msg-body .citation.citation-memory {
    color: #6c4097;
    border-bottom-style: dashed;
    border-bottom-color: #6c4097;
}
.msg-body .citation.citation-memory:hover,
.msg-body .citation.citation-memory:focus {
    background: rgba(108, 64, 151, 0.14);
}
.msg-body .citation.citation-memory::after {
    content: "⚠";
    font-size: 0.78em;
    margin-left: 0.18em;
    vertical-align: super;
    color: #6c4097;
}

/* P1-H: demo-prosjekt banner inside the brain panel. Tag + soft
   purple border so the user always knows this is the example, not
   their own data, and a clear button to remove it. */
.brain-demo-banner {
    margin: 0 0 0.8rem 0;
    padding: 0.6rem 0.7rem;
    border: 1px dashed rgba(108, 64, 151, 0.45);
    border-radius: 6px;
    background: rgba(108, 64, 151, 0.06);
}
.brain-demo-tag {
    display: inline-block;
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
    background: #6c4097;
    color: #fff;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-bottom: 0.3rem;
}
.brain-demo-banner p {
    margin: 0.2rem 0 0.4rem 0;
    font-size: 0.85rem;
    line-height: 1.35;
}
.brain-demo-delete {
    background: transparent;
    border: 1px solid #6c4097;
    color: #6c4097;
    padding: 0.25rem 0.55rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8rem;
}
.brain-demo-delete:hover,
.brain-demo-delete:focus {
    background: #6c4097;
    color: #fff;
}

/* P2-AD: floating action button + quick-observation modal. The FAB
   only renders on touch / narrow viewports — desktop users have the
   regular drag-drop and chat box, no need for an extra entry. */
.quick-obs-fab {
    display: none;
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    width: 60px; height: 60px;
    border-radius: 50%;
    background: #6c4097;
    color: #fff;
    font-size: 2rem;
    line-height: 60px;
    text-align: center;
    border: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    z-index: 50;
    cursor: pointer;
    padding: 0;
}
.quick-obs-fab:active { transform: scale(0.95); }
@media (max-width: 720px), (pointer: coarse) {
    .quick-obs-fab { display: block; }
}

dialog.quick-obs-dialog {
    border: none;
    border-radius: 10px;
    padding: 0;
    width: min(420px, 92vw);
    max-height: 90vh;
}
dialog.quick-obs-dialog::backdrop {
    background: rgba(0, 0, 0, 0.4);
}
.quick-obs-form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1rem;
}
.quick-obs-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
}
.quick-obs-header h2 {
    margin: 0;
    font-size: 1.1rem;
    flex: 1;
}
.quick-obs-project {
    font-size: 0.85rem;
    color: var(--ink-soft);
}
.quick-obs-switch {
    background: transparent;
    border: none;
    color: #6c4097;
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0;
}
.quick-obs-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    min-height: 0;
}
.quick-obs-thumb {
    position: relative;
    width: 80px; height: 80px;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.05);
}
.quick-obs-thumb img {
    width: 100%; height: 100%;
    object-fit: cover;
}
.quick-obs-thumb-x {
    position: absolute;
    top: 2px; right: 2px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: none;
    width: 22px; height: 22px;
    border-radius: 50%;
    font-size: 0.9rem;
    cursor: pointer;
    line-height: 22px;
    padding: 0;
}
.quick-obs-actions-row {
    display: flex;
    gap: 0.5rem;
}
.quick-obs-camera-btn {
    cursor: pointer;
}
.quick-obs-form textarea {
    width: 100%;
    min-height: 80px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 0.5rem;
    font: inherit;
    resize: vertical;
}
.quick-obs-status {
    margin: 0;
    font-size: 0.82rem;
    color: var(--ink-soft);
    min-height: 1.1em;
}
.quick-obs-status[data-ok="0"] { color: var(--danger); }
.quick-obs-form .actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}
.icon-btn.listening {
    background: rgba(168, 70, 74, 0.18);
    border-color: var(--danger);
}
.quick-obs-project-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0;
    max-height: 50vh;
    overflow-y: auto;
}
.quick-obs-project-list li button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.7rem;
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    margin-bottom: 0.3rem;
    cursor: pointer;
    font: inherit;
    color: var(--ink);
}
.quick-obs-project-list li button:hover {
    background: rgba(108, 64, 151, 0.08);
}

/* P2-V: morning-brief banner. Sits above chat-log when user returns
   after >=8h and the digestor imported new e-post. */
.morning-brief {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.9rem;
    margin: 0.6rem 0;
    border-left: 3px solid #6c4097;
    background: rgba(108, 64, 151, 0.08);
    border-radius: 4px;
}
.morning-brief-body {
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.4;
}
.morning-brief-cta {
    background: #6c4097;
    color: #fff;
    border: none;
    padding: 0.35rem 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
}
.morning-brief-close {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: var(--ink-soft);
    cursor: pointer;
    line-height: 1;
}

/* P1-N: inbox suggestions card on empty state. */
.inbox-suggestions {
    max-width: 960px;
    margin: 0.5rem auto 1rem;
    padding: 1rem;
    border: 1px dashed rgba(0, 120, 212, 0.4);
    border-radius: 8px;
    background: rgba(0, 120, 212, 0.04);
}
.inbox-suggestions h3 {
    margin: 0 0 0.4rem;
    font-size: 1rem;
    color: #0078d4;
}
.inbox-suggestion-list {
    list-style: none;
    padding: 0;
    margin: 0.6rem 0 0;
}
.inbox-suggestion-list li {
    padding: 0.35rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.inbox-suggestion-list li:last-child {
    border-bottom: none;
}

/* P3-BJ/BK/CC: action-log detail + compact layout on heavy turns. */
.action-line-detail {
    color: var(--ink-soft);
    font-size: 0.85em;
}
.action-line-link {
    color: #6c4097;
    text-decoration: none;
    margin-left: 0.15em;
    font-weight: 500;
}
.action-line-link:hover { text-decoration: underline; }
.action-log-lines.compact .action-line {
    font-size: 0.82em;
    padding-top: 0.05rem;
    padding-bottom: 0.05rem;
    line-height: 1.25;
}

/* P1-Q: varselsklokker i brain-panel — fargekoder etter hvor mye tid
   som er igjen. Grønn = >50%, gul = 20-50%, rød = <20%, svart = preklusjon. */
.brain-clocks li {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.3rem;
    padding: 0.3rem 0.4rem;
    margin-bottom: 0.3rem;
    border-radius: 4px;
    border-left: 3px solid transparent;
    background: rgba(0, 0, 0, 0.02);
}
.brain-clocks li.brain-clock-tier-green { border-left-color: #2f7a3a; }
.brain-clocks li.brain-clock-tier-yellow {
    border-left-color: #b88a2b;
    background: rgba(184, 138, 43, 0.08);
}
.brain-clocks li.brain-clock-tier-red {
    border-left-color: #a8464a;
    background: rgba(168, 70, 74, 0.10);
}
.brain-clocks li.brain-clock-tier-preclusion {
    border-left-color: #000;
    background: rgba(0, 0, 0, 0.10);
    color: #000;
}
.brain-clock-dot {
    display: inline-block;
    width: 8px; height: 8px; border-radius: 50%;
    background: currentColor;
    margin-right: 0.15rem;
}
.brain-clock-tier-green   .brain-clock-dot { background: #2f7a3a; }
.brain-clock-tier-yellow  .brain-clock-dot { background: #b88a2b; }
.brain-clock-tier-red     .brain-clock-dot { background: #a8464a; }
.brain-clock-tier-preclusion .brain-clock-dot { background: #000; }
.brain-clock-deadline {
    width: 100%;
    font-size: 0.82rem;
    color: var(--ink-soft);
}

/* P0-G: short yellow fade applied to a brain section when it was
   re-rendered in response to a brain_invalidated event. Lets the
   user see what just changed without re-reading the whole panel. */
.brain-section.brain-section-flash {
    animation: brain-section-flash 1.8s ease-out;
}
@keyframes brain-section-flash {
    0% {
        background: rgba(255, 232, 130, 0.55);
    }
    60% {
        background: rgba(255, 232, 130, 0.25);
    }
    100% {
        background: transparent;
    }
}

/* P0-F / eval B1 (2026-04-19): validator-system failure banner.
   Prominent header-position with ⚠-symbol so a stressed byggeleder
   can't miss that this reply bypassed our verifier. Visually louder
   than the old info-band. */
.msg-validator-failure {
    margin: 0 0 0.7rem 0;
    padding: 0.6rem 0.8rem;
    border: 1px solid #b88a2b;
    border-left: 4px solid #b88a2b;
    background: rgba(254, 243, 199, 0.9);  /* gold-50-ish */
    font-size: 0.9rem;
    color: #5a3e10;
    line-height: 1.45;
    border-radius: 4px;
}
.msg-validator-failure-title {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: #7a4e12;
}
.msg-validator-failure-body {
    font-size: 0.85rem;
}
.msg.msg-validator-crashed {
    /* subtle companion marker on the bubble itself */
    border-left-color: #b88a2b;
}

/* Bubble-level marker when one or more claims were dropped after
   retries exhausted. The surrounding text is still shown — only
   the unverifiable sentences were stripped. Clicking "Hvorfor?"
   opens the audit modal with per-claim detail. */
.msg.msg-with-drop {
    border-left: 3px solid var(--danger);
    padding-left: 0.6rem;
}
.msg.msg-with-drop::after {
    content: attr(data-dropped-note);
    display: block;
    margin-top: 0.55rem;
    padding-top: 0.4rem;
    border-top: 1px dashed rgba(168, 70, 74, 0.35);
    font-size: 0.82rem;
    color: var(--ink-soft);
    font-style: italic;
    white-space: pre-line;
}

.msg-actions {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    margin-top: 0.4rem;
}
.msg-why {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: 999px;
    color: var(--ink-soft);
    font: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease;
}
.msg-why:hover {
    background: #fafaf4;
    border-color: var(--accent);
    color: var(--accent);
}
.msg-star {
    padding: 0.1rem 0.45rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    color: rgba(35, 39, 48, 0.35);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    transition: color .12s ease, background .12s ease;
}
.msg-star:hover {
    color: #c99a3f;
    background: #fafaf4;
}
.msg-star.on {
    color: #c99a3f;
}
.msg.starred {
    border-left: 3px solid #c99a3f;
    padding-left: 0.55rem;
}

/* ===== WS7: discovery-progress-banner ===== */
.discovery-banner {
    position: sticky;
    top: 0;
    z-index: 21;
    background: #eef4fb;
    border-bottom: 1px solid var(--rule);
    color: var(--ink);
    padding: 0.55rem 0.9rem;
    font-size: 0.9rem;
    font-style: italic;
    box-shadow: var(--shadow-sm);
}

/* ===== Live upload banner (pushed from broker) ===== */

.upload-banner {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #fbfaf6;
    border-bottom: 1px solid var(--rule);
    padding: 0.6rem 0.9rem;
    font-size: 0.88rem;
    max-height: 30vh;
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
}
.upload-banner.hidden { display: none; }
.upload-banner .summary {
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.15rem;
}
.upload-list {
    list-style: none;
    padding: 0;
    margin: 0.3rem 0 0;
}
.upload-list li {
    padding: 0.08rem 0;
    color: var(--ink-soft);
    font-size: 0.82rem;
    line-height: 1.3;
}
.upload-list li.ok::before {
    content: "✓ ";
    color: var(--ok);
    font-weight: 700;
}
.upload-list li.fail::before {
    content: "× ";
    color: var(--danger);
    font-weight: 700;
}
/* P1-J: live-build banner copy. The filename stays neutral; the
   "fant ..."-suffix is highlighted so the user's eye lands on it. */
.upload-list .upload-filename {
    color: var(--ink);
    font-weight: 500;
}
.upload-list .upload-finding {
    color: #6c4097;
    font-weight: 500;
}
.upload-list .upload-error {
    color: var(--danger);
}

/* ===== Project-brain sidebar panel ===== */

.brain-panel {
    padding: 0.4rem 0.15rem 0.1rem 0.15rem;
    font-size: 0.86rem;
    max-height: 70vh;
    overflow-y: auto;
}
.brain-section {
    margin: 0 0 0.8rem;
    padding: 0 0 0.4rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brain-section:last-child { border-bottom: 0; }
.brain-section h4 {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0 0 0.35rem;
    color: rgba(230, 232, 236, 0.55);
    font-weight: 600;
}
.brain-section h5 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0.5rem 0 0.25rem;
    color: rgba(230, 232, 236, 0.45);
    font-weight: 600;
}
.brain-fact {
    margin: 0;
    font-size: 0.86rem;
    color: rgba(230, 232, 236, 0.85);
}
.brain-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.brain-list li {
    position: relative;
    padding: 0.22rem 0;
    line-height: 1.35;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.brain-list li:last-child { border-bottom: 0; }
.brain-date {
    display: inline-block;
    min-width: 4.2em;
    color: rgba(230, 232, 236, 0.55);
    font-size: 0.78rem;
    margin-right: 0.3rem;
}
.brain-num {
    color: rgba(230, 232, 236, 0.6);
    font-size: 0.78rem;
    margin-right: 0.25rem;
}
.brain-muted {
    color: rgba(230, 232, 236, 0.5);
    font-size: 0.8rem;
}
.brain-memory-list li {
    padding-right: 1.6rem;
}
.brain-memory-text {
    font-size: 0.84rem;
    line-height: 1.35;
}
.brain-meta {
    font-size: 0.74rem;
    margin-top: 0.12rem;
}
.brain-delete {
    position: absolute;
    right: 0;
    top: 0.15rem;
    width: 1.4rem;
    height: 1.4rem;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 50%;
    color: rgba(230, 232, 236, 0.35);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: background .12s ease, color .12s ease;
}
.brain-delete:hover {
    background: rgba(168, 70, 74, 0.2);
    color: #f6b5b7;
}
.brain-empty {
    margin: 0;
    font-style: italic;
}

/* ===== Viewer + audit dialogs — reuse feedback-dialog pattern ===== */

dialog.viewer-dialog,
dialog.audit-dialog {
    border: none;
    border-radius: var(--radius);
    padding: 0;
    width: min(900px, 94vw);
    max-height: min(90vh, 820px);
    background: var(--surface);
    box-shadow: var(--shadow-md);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
dialog.viewer-dialog[open],
dialog.audit-dialog[open] {
    display: flex;
}
dialog.viewer-dialog::backdrop,
dialog.audit-dialog::backdrop {
    background: rgba(35, 39, 48, 0.5);
    backdrop-filter: blur(2px);
}

.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.2rem;
    border-bottom: 1px solid var(--rule);
    background: #fbfaf6;
}
.viewer-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.viewer-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}
.viewer-actions a {
    font-size: 0.88rem;
    color: var(--accent);
    text-decoration: none;
}
.viewer-actions a:hover { text-decoration: underline; }
.viewer-frame {
    flex: 1;
    width: 100%;
    border: 0;
    background: #fff;
}

/* ===== Audit modal body ===== */

.audit-body {
    padding: 1rem 1.3rem 1.3rem;
    overflow-y: auto;
    line-height: 1.5;
}
.audit-section {
    margin: 0 0 1rem;
    padding: 0 0 0.7rem;
    border-bottom: 1px solid var(--rule);
}
.audit-section:last-child { border-bottom: 0; }
.audit-section h3 {
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-soft);
    margin: 0 0 0.35rem;
    font-weight: 600;
}
.audit-section p { margin: 0.2rem 0; }
.audit-list {
    margin: 0.35rem 0 0;
    padding-left: 1.2rem;
    font-size: 0.92rem;
}
.audit-list li { margin: 0.15rem 0; }
.audit-list code {
    background: #f5f2ea;
    padding: 0.05em 0.35em;
    border-radius: 3px;
    font-size: 0.9em;
}
.audit-ok { color: var(--ok); font-weight: 600; }
.audit-warn { color: var(--danger); font-weight: 600; }
.audit-muted { color: var(--ink-soft); }
.msg-body strong {
    font-weight: 600;
}
.msg-body ul {
    margin: 0.5em 0;
    padding-left: 1.4em;
}
.msg-body li {
    margin-bottom: 0.2em;
}
.msg-body p {
    margin: 0.4em 0;
}

/* Responsive: mobile-first */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        z-index: 100;
        transition: left 0.25s ease;
        box-shadow: var(--shadow-md);
    }
    .sidebar.open {
        left: 0;
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 99;
    }
    .sidebar-overlay.active {
        display: block;
    }
    .hamburger {
        display: flex !important;
    }
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    .chat-form textarea {
        font-size: 16px; /* prevent iOS zoom on focus */
    }
    .msg-body {
        font-size: 0.95rem;
    }
}

.hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1.3rem;
    color: var(--ink);
}

/* ===== Chat input — camera + mic buttons ===== */
.chat-input {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
}
.chat-input textarea { flex: 1; }
.chat-actions {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}
.icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 1.05rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.icon-btn:hover:not(:disabled) {
    background: #fafaf4;
    border-color: var(--accent);
    color: var(--accent);
}
.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.icon-btn.on {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* iOS safe-area padding so the chat input doesn't sit behind the bottom bar. */
@supports (padding: env(safe-area-inset-top)) {
    .topbar {
        padding-top: calc(0.55rem + env(safe-area-inset-top));
    }
    .chat-input {
        padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
    }
}


/* Anbud / tilbuds-evaluator (spec: SPEC_ANBUDSEVALUATOR.md). */
.brain-tenders li {
    margin-bottom: 0.8rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
}
.brain-tenders li:last-child {
    border-bottom: none;
}
.brain-tender-head {
    margin-bottom: 0.3rem;
}
.brain-sublist {
    list-style: none;
    padding-left: 1rem;
    margin: 0.2rem 0 0.3rem;
    font-size: 0.92em;
}
.brain-sublist li {
    padding: 0.1rem 0;
    border: none;
    margin: 0;
}
.brain-small {
    font-size: 0.88em;
    padding: 0.2rem 0 0.2rem 1rem;
}

/* Seriøsitets-lys — gjenbruker samme fargekoder som warning_clocks. */
.brain-seriosity-gronn,
.brain-seriosity-gul,
.brain-seriosity-rod,
.brain-seriosity-ukjent {
    display: inline-block;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
}
.brain-seriosity-gronn   { background: #2f7a3a; }
.brain-seriosity-gul     { background: #b88a2b; }
.brain-seriosity-rod     { background: #a8464a; }
.brain-seriosity-ukjent  { background: #888; }

/* Aisteins verdict som badge. */
.brain-verdict-anbefales,
.brain-verdict-ok,
.brain-verdict-betenkelig,
.brain-verdict-fraraades {
    display: inline-block;
    padding: 0.05rem 0.35rem;
    border-radius: 3px;
    font-size: 0.78em;
    font-weight: 600;
    margin-left: 0.3rem;
}
.brain-verdict-anbefales   { background: #d3ebd8; color: #18481e; }
.brain-verdict-ok          { background: #e6e8ee; color: #333; }
.brain-verdict-betenkelig  { background: #fae8cf; color: #663807; }
.brain-verdict-fraraades   { background: #f5d1d3; color: #571d20; }

/* Fag-status-bar: én chip per fag i prosjektet. */
.brain-trade-phases {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.6rem;
}
.brain-trade-phase {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 3px;
    font-size: 0.8em;
    background: var(--border);
    color: var(--text);
}
.brain-trade-phase strong {
    font-weight: 600;
    margin-right: 0.15rem;
}
/* Phase-spesifikke farger. */
.brain-trade-ikke_startet        { background: #f0f0f0; color: #666; }
.brain-trade-planlegger_foresporsel { background: #e8e8f2; color: #2d2d80; }
.brain-trade-anbud_forespørsel   { background: #dde6f5; color: #1f3a7a; }
.brain-trade-anbud_evaluering    { background: #fae8cf; color: #663807; }
.brain-trade-valgt_venter_kontrakt { background: #e6dff6; color: #3a2d7a; }
.brain-trade-kontrahert          { background: #d3ebd8; color: #18481e; }
.brain-trade-utførelse           { background: #c2e0cc; color: #093218; font-weight: 600; }
.brain-trade-ferdigstilt         { background: #cfe0d3; color: #2a4e33; }
.brain-trade-avlyst              { background: #f5d1d3; color: #571d20; text-decoration: line-through; }
