:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e7e9ee;
    --muted: #9aa2b1;
    --primary: #7c5cff;
    --primary-2: #9d84ff;
    --accent: #34d399;
    --error: #ff6b6b;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, sans-serif;
    background: radial-gradient(1200px 600px at 70% -10%, #1b1e29 0%, var(--bg) 55%);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

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

.center {
    text-align: center;
}

.view {
    min-height: 100vh;
}

.centered {
    display: grid;
    place-items: center;
    padding: 24px;
}

/* ---- Cards & auth ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.auth-card {
    width: min(380px, 100%);
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    animation: rise 0.5s var(--ease) both;
}

.auth-card label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.brand {
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0;
}

.brand.small {
    font-size: 20px;
}

.brand .dot {
    color: var(--primary);
}

input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 11px 13px;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    transition:
        border-color 0.2s var(--ease),
        box-shadow 0.2s var(--ease);
}

input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.18);
}

.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition:
        transform 0.12s var(--ease),
        background 0.2s var(--ease),
        opacity 0.2s;
}

.btn:active {
    transform: translateY(1px) scale(0.99);
}

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

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

.btn.ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
}

.btn.ghost:hover {
    color: var(--text);
    border-color: var(--muted);
}

.btn.small {
    padding: 7px 11px;
    font-size: 13px;
}

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

.error {
    color: var(--error);
    font-size: 13px;
    min-height: 16px;
    margin: 0;
}

/* ---- Topbar ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 17, 21, 0.7);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.tab {
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 7px 16px;
    border-radius: 9px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition:
        color 0.2s,
        background 0.25s var(--ease);
}

.tab.active {
    background: var(--surface-2);
    color: var(--text);
}

.who {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ---- Content ---- */
.content {
    max-width: 900px;
    margin: 0 auto;
    padding: 28px 22px 60px;
}

.tab-panel {
    animation: fade 0.35s var(--ease) both;
}

.section-title {
    font-size: 18px;
    margin: 0 0 16px;
}

.ask-bar {
    display: flex;
    gap: 10px;
}

.ask-bar input {
    flex: 1;
}

.status {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    margin: 18px 0;
    animation: fade 0.3s var(--ease) both;
}

#ask-hint {
    margin-top: 22px;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ---- Variants (A/B) ---- */
.variants {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 22px;
}

@media (max-width: 720px) {
    .variants {
        grid-template-columns: 1fr;
    }
}

.variant {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    animation: rise 0.45s var(--ease) both;
    transition:
        border-color 0.25s var(--ease),
        transform 0.25s var(--ease),
        box-shadow 0.25s var(--ease);
}

.variant:nth-child(2) {
    animation-delay: 0.08s;
}

.variant:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.variant.chosen {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.25);
}

.variant.dimmed {
    opacity: 0.5;
}

.variant .label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--muted);
    text-transform: uppercase;
}

.variant .answer {
    font-size: 14.5px;
    line-height: 1.6;
    white-space: pre-wrap;
}

.variant .reveal {
    font-size: 12px;
    color: var(--accent);
    min-height: 14px;
}

.variant .btn {
    margin-top: auto;
}

/* ---- History ---- */
.history {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.h-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    animation: fade 0.3s var(--ease) both;
}

.h-q {
    font-weight: 600;
    margin-bottom: 10px;
}

.h-meta {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 12px;
}

.h-answers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 720px) {
    .h-answers {
        grid-template-columns: 1fr;
    }
}

.h-a {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    font-size: 13px;
    line-height: 1.55;
}

.h-a.win {
    border-color: var(--accent);
}

.h-a .tag {
    font-size: 11px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}

.h-a.win .tag {
    color: var(--accent);
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 40px;
}

.saved {
    color: var(--accent);
    font-size: 14px;
    margin-top: 22px;
    animation: fade 0.3s var(--ease) both;
}

/* ---- Admin dashboard ---- */
.content.wide {
    max-width: 1180px;
}

.admin-tag {
    font-size: 12px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-weight: 600;
}

.small-text {
    font-size: 12px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 18px;
    animation: fade 0.35s var(--ease) both;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

@media (max-width: 860px) {
    .two-col {
        grid-template-columns: 1fr;
    }
}

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.kpi-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.kpi-value {
    font-size: 26px;
    font-weight: 700;
    margin: 6px 0 2px;
    letter-spacing: -0.02em;
}

.kpi-sub {
    font-size: 12px;
    color: var(--muted);
    min-height: 15px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
    padding: 0 12px 8px 0;
    white-space: nowrap;
}

td {
    padding: 10px 12px 10px 0;
    border-top: 1px solid var(--border);
    vertical-align: top;
}

.rate {
    min-width: 190px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bar {
    position: relative;
    height: 8px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.bar-fill {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--primary);
    border-radius: 999px;
}

.bar-ci {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.22);
}

.verdict {
    border-left: 3px solid var(--muted);
    padding-left: 14px;
}

.verdict.sig {
    border-color: var(--accent);
}

.verdict.nosig {
    border-color: var(--muted);
}

.verdict-head {
    font-size: 20px;
    font-weight: 700;
}

.verdict-sub {
    color: var(--muted);
    font-size: 13px;
    margin: 4px 0;
}

.verdict-p {
    font-size: 13px;
    margin-bottom: 6px;
}

.verdict.sig .verdict-p {
    color: var(--accent);
}

.chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 140px;
    padding-top: 8px;
}

.chart-col {
    flex: 1;
    min-width: 14px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 6px;
}

.chart-bar {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px 6px 0 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: 3px;
}

.chart-bar-decided {
    background: var(--primary);
    border-radius: 5px 5px 0 0;
}

.chart-x {
    font-size: 10px;
    color: var(--muted);
    text-align: center;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.filters input {
    flex: 1;
    min-width: 200px;
}

select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
}

details.h-item {
    margin-bottom: 10px;
}

details.h-item summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

details.h-item summary::before {
    content: '▸';
    color: var(--muted);
    position: absolute;
    margin-left: -14px;
}

details.h-item[open] summary::before {
    content: '▾';
}

details.h-item .h-q,
details.h-item .h-meta {
    margin: 0;
}

details.h-item .h-answers {
    margin-top: 12px;
}

.pending {
    color: var(--muted);
}

.ok {
    color: var(--accent);
}

.bad {
    color: var(--error);
}

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 14px;
}

a.btn {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

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

@keyframes fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
/* ---- App shell with side navigation ---- */
.app-shell {
    display: grid;
    grid-template-columns: 232px 1fr;
    height: 100vh;
    overflow: hidden;
}

.sidenav {
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 20px 16px;
    border-right: 1px solid var(--border);
    background: rgba(23, 26, 33, 0.6);
    position: sticky;
    top: 0;
    height: 100vh;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    border: none;
    background: transparent;
    color: var(--muted);
    text-align: left;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition:
        background 0.2s var(--ease),
        color 0.2s;
}

.nav-item:hover {
    color: var(--text);
    background: var(--surface-2);
}

.nav-item.active {
    background: var(--surface-2);
    color: var(--text);
    box-shadow: inset 2px 0 0 var(--primary);
}

.nav-ico {
    font-size: 15px;
}

.tag-poc {
    margin-left: auto;
    font-size: 9px;
    letter-spacing: 0.08em;
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
}

.sidenav-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 12px;
}

.nav-link:hover {
    color: var(--text);
}

.main {
    min-width: 0;
    height: 100vh;
    overflow-y: auto;
}

.section {
    min-height: 100%;
}

/* These sections manage their own scrolling, so the shell must not add a second one. */
#section-chat,
#section-cycle {
    height: 100%;
    overflow: hidden;
}

.btn.full {
    width: 100%;
}

/* ---- Chat ---- */
.chat-layout {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr) auto;
    /* An implicit grid row is auto-sized, so it grows past height:100% and the panes
       scroll the page instead of themselves. minmax(0, 1fr) pins it to the container. */
    grid-template-rows: minmax(0, 1fr);
    height: 100%;
    min-height: 0;
}

.conv-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 12px;
    padding: 16px 14px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.conv-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conv-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    text-align: left;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    padding: 9px 11px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.18s var(--ease);
}

.conv-item:hover {
    background: var(--surface-2);
}

.conv-item.active {
    background: var(--surface-2);
    border-color: var(--border);
}

.conv-name {
    font-size: 13.5px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-sub {
    font-size: 11px;
    color: var(--muted);
}

.chat-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Without min-height:0 a flex child refuses to shrink below its content, so
       .messages grows the whole layout instead of scrolling inside it. */
    min-height: 0;
}

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
}

.chat-title {
    font-size: 16px;
    margin: 0;
}

/* Between ~1000px and ~1180px the three chat columns leave the middle pane too narrow for
   the title and every action on one line; without these the actions ran past the pane
   (100px over at 1024px). The title may shrink and the actions wrap instead. */
.chat-title-wrap {
    min-width: 0;
    overflow-wrap: anywhere;
}

.chat-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.msg {
    display: flex;
    flex-direction: column;
    max-width: 760px;
}

.msg.user {
    align-self: flex-end;
    align-items: flex-end;
}

.msg .bubble {
    padding: 12px 15px;
    border-radius: 14px;
    font-size: 14.5px;
    line-height: 1.6;
    white-space: pre-wrap;
}

.msg.user .bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg.bot .bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg.bot .bubble.error {
    border-color: var(--error);
    color: var(--error);
}

.typing {
    display: flex;
    gap: 5px;
    align-items: center;
}

.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: blink 1.2s infinite;
}

.typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0%,
    60%,
    100% {
        opacity: 0.25;
    }

    30% {
        opacity: 1;
    }
}

.msg-details {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--muted);
}

.msg-details summary {
    cursor: pointer;
    padding: 3px 0;
}

.detail-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    margin-top: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.dk {
    display: inline-block;
    min-width: 82px;
    color: var(--muted);
    opacity: 0.8;
}

.dsources ul {
    margin: 4px 0 0;
    padding-left: 18px;
}

.chat-bar {
    display: flex;
    gap: 10px;
    padding: 14px 22px 20px;
    border-top: 1px solid var(--border);
}

.chat-bar textarea {
    flex: 1;
    resize: none;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 11px 13px;
    border-radius: 10px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    max-height: 160px;
}

.chat-bar textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.18);
}

.chat-empty {
    margin: auto;
    max-width: 460px;
    text-align: center;
}

.chat-empty h3 {
    margin: 0 0 8px;
}

.memory-panel {
    width: 280px;
    border-left: 1px solid var(--border);
    padding: 18px 16px;
    overflow-y: auto;
}

.mem-title {
    margin: 0 0 6px;
    font-size: 15px;
}

.mem-sub {
    margin: 18px 0 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
}

.mem-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 6px;
    font-size: 12.5px;
    line-height: 1.45;
}

.mem-del {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
}

.mem-del:hover {
    color: var(--error);
}

.mem-summary {
    line-height: 1.55;
}

@media (max-width: 1000px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidenav {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: 16px;
    }

    .sidenav .nav {
        flex-direction: row;
    }

    .sidenav-foot {
        margin-top: 0;
        margin-left: auto;
        flex-direction: row;
        align-items: center;
    }

    .app-shell,
    .main {
        height: auto;
        overflow: visible;
    }

    #section-chat,
    #section-cycle {
        height: auto;
        overflow: visible;
    }

    .chat-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .conv-pane {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 220px;
    }

    .memory-panel {
        width: auto;
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

/* Light markdown inside assistant bubbles. */
.bubble.md {
    white-space: normal;
}

.bubble.md p {
    margin: 0 0 10px;
}

.bubble.md p:last-child {
    margin-bottom: 0;
}

.bubble.md ul {
    margin: 0 0 10px;
    padding-left: 20px;
}

.bubble.md li {
    margin-bottom: 4px;
}

.bubble.md strong {
    font-weight: 650;
}

/* ---- Red-flag triage ---- */
.redflag,
.redflag-bubble {
    border: 1px solid var(--error);
    border-radius: var(--radius);
    background: rgba(255, 107, 107, 0.07);
}

.redflag {
    padding: 18px;
    grid-column: 1 / -1;
}

.redflag .answer {
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 14.5px;
}

.redflag-head {
    color: var(--error);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.02em;
    margin-bottom: 10px;
}

.redflag-foot {
    margin-top: 12px;
    font-size: 11.5px;
    color: var(--muted);
}

/* ---- Nav groups ---- */
.nav-group {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    opacity: 0.65;
    padding: 12px 12px 4px;
}

.nav-group:first-child {
    padding-top: 0;
}

/* ---- Cycle page ---- */
.cycle-layout {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    height: 100%;
    min-height: 0;
}

.cycle-setup {
    padding: 20px 18px;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    min-height: 0;
}

.cycle-chat {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    margin: 14px 0;
}

.field input,
.field select {
    width: 100%;
}

.check {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13px;
    color: var(--text);
    margin: 10px 0;
    cursor: pointer;
}

.check input {
    width: auto;
    accent-color: var(--primary);
}

.cyc-warnings {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0 0;
    min-height: 0;
}

.warn {
    font-size: 12px;
    line-height: 1.5;
    color: #ffb86b;
    background: rgba(255, 184, 107, 0.09);
    border: 1px solid rgba(255, 184, 107, 0.3);
    border-radius: 8px;
    padding: 8px 10px;
}

/* Scoped to the cycle day selector: a bare .locked also matched the safety-core
   panel on the Answer design page and dimmed it to 45% with pointer events off. */
#cyc-day-block.locked {
    opacity: 0.45;
    pointer-events: none;
}

#cyc-day-block.locked #cyc-lock-note {
    pointer-events: auto;
}

.phase-pill-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 10px 0;
}

.phase-pill {
    display: flex;
    flex-direction: column;
    gap: 2px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.phase-pill span {
    font-size: 10.5px;
    font-weight: 500;
    color: var(--muted);
}

.phase-pill.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.22);
}

.phase-pill.impossible {
    opacity: 0.4;
    cursor: not-allowed;
}

.timeline {
    margin: 14px 0 8px;
}

.track {
    position: relative;
    height: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.seg {
    position: absolute;
    top: 0;
    bottom: 0;
}

.seg.menstrual {
    background: #ff6b8a;
}

.seg.follicular {
    background: #5fb3f6;
}

.seg.ovulatory {
    background: #34d399;
}

.seg.luteal {
    background: #a78bfa;
}

.today {
    position: absolute;
    top: -3px;
    bottom: -3px;
    width: 2px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}

.track-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10.5px;
    color: var(--muted);
    margin-top: 4px;
}

.conv-pick {
    max-width: 180px;
    padding: 7px 10px;
    font-size: 13px;
}

/* ---- Guardrails ---- */
.gr-add {
    padding: 0;
}

.gr-add-summary {
    cursor: pointer;
    padding: 14px 18px;
    font-weight: 600;
    font-size: 14px;
}

.gr-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 18px 18px;
}

.gr-form textarea {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    outline: none;
}

.gr-row {
    display: flex;
    gap: 8px;
}

.gr-row select {
    flex: 1;
}

.gr-author {
    font-size: 14px;
    margin: 0 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.gr-item {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.gr-item:last-child {
    border-bottom: none;
}

.gr-title {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.45;
}

.gr-detail {
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.55;
    margin-top: 4px;
}

.gr-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-top: 8px;
}

.chip {
    font-size: 10.5px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
}

.chip.safety {
    color: #ff9db1;
    border-color: rgba(255, 157, 177, 0.4);
}

.chip.clinical {
    color: #7ee0bb;
    border-color: rgba(126, 224, 187, 0.4);
}

.chip.privacy,
.chip.legal {
    color: #ffc98b;
    border-color: rgba(255, 201, 139, 0.4);
}

.chip.prio-high {
    color: var(--error);
    border-color: rgba(255, 107, 107, 0.4);
}

.gr-evidence {
    font-size: 11px;
    color: var(--accent);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.gr-evidence.suggested {
    color: var(--muted);
}

.gr-evidence.none {
    color: var(--muted);
    opacity: 0.7;
    font-family: inherit;
    font-style: italic;
}

.gr-status {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.gr-status-text {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.ok {
    background: var(--accent);
}

.status-dot.partial {
    background: #ffb86b;
}

.status-dot.review {
    background: var(--primary);
}

.status-dot.proposed {
    background: var(--muted);
}

.status-dot.rejected,
.status-dot.muted-status {
    background: var(--border);
}

/* ---- Data page ---- */
.finding {
    border-left: 2px solid var(--border);
    padding-left: 14px;
    margin-bottom: 18px;
}

.finding h4 {
    margin: 0 0 6px;
    font-size: 13.5px;
}

.finding p {
    margin: 0;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--muted);
}

.panel p {
    line-height: 1.65;
}

ul.plain {
    margin: 0;
    padding-left: 18px;
    line-height: 1.75;
    font-size: 14px;
}

.src-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin: 14px 0 18px;
}

.src-grid > div {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}

table.cfg td {
    padding: 7px 14px 7px 0;
    font-size: 13px;
}

table.cfg td:first-child {
    color: var(--muted);
    width: 190px;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92em;
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 5px;
}

@media (max-width: 1000px) {
    .cycle-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .cycle-setup {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}

/* ---- Icons ---- */
.icon-sprite {
    display: none;
}

.ico {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -3px;
}

.ico.tiny {
    width: 13px;
    height: 13px;
    stroke-width: 2.2;
    vertical-align: -2px;
}

.nav-item .ico {
    opacity: 0.85;
}

.nav-item.active .ico {
    opacity: 1;
    color: var(--primary-2);
}

.redflag-head .ico {
    vertical-align: -3px;
    margin-right: 2px;
}

.warn .ico {
    margin-right: 3px;
}

/* ---- Answer design ---- */
ol.contract {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: step;
}

ol.contract li {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    line-height: 1.6;
}

ol.contract li:last-child {
    border-bottom: none;
}

.step-n {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--primary-2);
    font-size: 11px;
    font-weight: 700;
    display: grid;
    place-items: center;
}

.contrast-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.contrast-head {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    padding-bottom: 2px;
}

.contrast-head.ok {
    color: var(--accent);
}

.contrast-head.bad {
    color: var(--error);
}

.contrast-cell {
    font-size: 12.5px;
    line-height: 1.55;
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.contrast-cell.ok {
    border-left: 2px solid var(--accent);
}

.contrast-cell.bad {
    border-left: 2px solid var(--error);
}

.enforce-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.enforce {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
}

.enforce h4 {
    margin: 0 0 6px;
    font-size: 13px;
}

.enforce p {
    margin: 0 0 8px;
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.55;
}

.example {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
    background: var(--surface-2);
}

.example-rule {
    font-weight: 600;
    font-size: 13.5px;
    margin-bottom: 4px;
}

.example-q {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 12px;
}

.example-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

@media (max-width: 860px) {
    .example-pair,
    .contrast-grid,
    .fallback-grid {
        grid-template-columns: 1fr;
    }
}

.example-side {
    border-radius: 9px;
    padding: 11px 13px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.example-side.bad {
    border-left: 2px solid var(--error);
}

.example-side.ok {
    border-left: 2px solid var(--accent);
}

.example-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--muted);
}

.example-side.bad .example-label {
    color: var(--error);
}

.example-side.ok .example-label {
    color: var(--accent);
}

.example-text {
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
}

.example-why {
    margin-top: 11px;
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--muted);
}

.fallback-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.fallback-grid blockquote {
    margin: 6px 0 0;
    padding: 11px 13px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 2px solid var(--muted);
    border-radius: 8px;
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
}

pre.prompt {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    font-size: 11.5px;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre-wrap;
    margin: 10px 0 0;
}

/* ---- Prompt layers ---- */
.layer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 12px;
}

@media (max-width: 1000px) {
    .layer-grid {
        grid-template-columns: 1fr;
    }
}

.layer {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 13px;
    background: var(--surface-2);
}

.layer.locked {
    border-color: rgba(255, 184, 107, 0.35);
}

.layer-head {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
}

.locked-chip {
    color: #ffb86b;
    border-color: rgba(255, 184, 107, 0.4);
}

.live-chip {
    color: var(--accent);
    border-color: rgba(52, 211, 153, 0.4);
}

pre.prompt.short {
    max-height: 230px;
    overflow-y: auto;
    font-size: 10.8px;
}

/* ---- Prompt playground ---- */
/* Prefixed pg- throughout: a bare .side or .metrics would collide with the cycle and
   admin screens the way a bare .locked once dimmed the safety-core panel. */
.pg-grid {
    display: grid;
    grid-template-columns: minmax(320px, 420px) 1fr;
    gap: 18px;
    align-items: start;
    margin-top: 14px;
}

@media (max-width: 1100px) {
    .pg-grid {
        grid-template-columns: 1fr;
    }
}

.pg-controls .field {
    margin-bottom: 10px;
}

.pg-controls textarea {
    width: 100%;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
}

.pg-style-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 13px;
    font-weight: 600;
    margin: 14px 0 6px;
}

textarea.pg-style {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.8px;
    line-height: 1.6;
}

.pg-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 10px 0;
}

.pg-results {
    min-width: 0;
}

.pg-retrieval {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 13px;
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.pg-retrieval code {
    font-size: 11px;
    color: var(--muted);
}

.pg-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

@media (max-width: 1400px) {
    .pg-pair {
        grid-template-columns: 1fr;
    }
}

.pg-side {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    background: var(--surface);
    min-width: 0;
}

.pg-side.candidate {
    border-color: rgba(124, 92, 255, 0.4);
}

.pg-side-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.pg-side-label {
    font-weight: 600;
    font-size: 13px;
}

.pg-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

.pg-metrics .kpi-value {
    font-size: 19px;
    margin: 2px 0 0;
}

.pg-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.pg-violations {
    margin-bottom: 8px;
}

.pg-answer {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    max-height: 460px;
    overflow-y: auto;
}

.chip.bad {
    color: var(--error);
    border-color: rgba(255, 107, 107, 0.4);
}

/* Links inside page content. Without this they fall back to the browser's default blue,
   which measured 1.85:1 against the panel background — well under the 4.5:1 minimum. */
.content a:not(.btn) {
    color: var(--primary-2);
    text-underline-offset: 2px;
}

.content a:not(.btn):hover {
    color: var(--text);
}

/* ---- Page guides ---- */
/* The info button sits in each page's own header, so it never competes with the
   controls already on the right of the chat headers or the composer's Send button. */
:root {
    --guide-w: 380px;
}

.page-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.page-title-row .section-title {
    margin: 0;
}

.info-btn {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition:
        color 0.15s var(--ease),
        background 0.15s var(--ease),
        border-color 0.15s var(--ease);
}

.info-btn .ico {
    width: 18px;
    height: 18px;
    vertical-align: 0;
}

.info-btn:hover,
.info-btn[aria-expanded='true'] {
    color: var(--text);
    background: var(--surface-2);
    border-color: var(--border);
}

.info-btn:focus-visible,
.guide-x:focus-visible {
    outline: 2px solid var(--primary-2);
    outline-offset: 2px;
}

/* Unread: the guide has not been acknowledged yet. */
.info-btn.unread::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary-2);
    box-shadow: 0 0 0 2px var(--bg);
}

.guide-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    width: var(--guide-w);
    max-width: 100vw;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -18px 0 40px rgba(0, 0, 0, 0.35);
    animation: guide-in 0.22s var(--ease);
}

.guide-drawer[hidden] {
    display: none;
}

@keyframes guide-in {
    from {
        transform: translateX(24px);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .guide-drawer {
        animation: none;
    }
}

.guide-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    color: var(--primary-2);
}

.guide-title {
    flex: 1;
    margin: 0;
    font-size: 16px;
    color: var(--text);
}

.guide-title:focus {
    outline: none;
}

.guide-x {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.guide-x:hover {
    color: var(--text);
    background: var(--surface-2);
    border-color: var(--border);
}

.guide-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 20px 8px;
    font-size: 14px;
    line-height: 1.6;
}

.guide-purpose {
    margin: 0 0 18px;
    font-size: 15px;
}

.guide-sub {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.guide-list {
    margin: 0 0 20px;
    padding-left: 20px;
}

.guide-list li {
    margin-bottom: 8px;
}

.guide-list li::marker {
    color: var(--muted);
}

.guide-list code {
    font-size: 12px;
    word-break: break-word;
}

.guide-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
}

.guide-foot-note {
    margin: 0;
    color: var(--muted);
}

.guide-foot .btn {
    margin-left: auto;
}

@media (max-width: 720px) {
    :root {
        --guide-w: 100vw;
    }

    .guide-drawer {
        border-left: none;
    }
}
