:root {
    --bg: #f5f4f0;
    --surface: #ffffff;
    --ink: #1d2327;
    --muted: #6b7378;
    --line: #e2e0d9;
    --accent: #1f5f5b;
    --accent-ink: #ffffff;
    --accent-soft: #e3efed;
    --warn: #9a5b00;
    --warn-soft: #fbefd9;
    --danger: #a3272f;
    --danger-soft: #f8e1e2;
    --ok: #26703a;
    --ok-soft: #e1f1e4;
    --radius: 8px;
    --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #15181a;
        --surface: #1d2124;
        --ink: #e7e9ea;
        --muted: #9aa3a8;
        --line: #2f3539;
        --accent: #5fb3aa;
        --accent-ink: #0d1f1d;
        --accent-soft: #1d3331;
        --warn: #e7b25c;
        --warn-soft: #3a2e17;
        --danger: #ef8a90;
        --danger-soft: #3b1f22;
        --ok: #7fcf92;
        --ok-soft: #1c3322;
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

h1 {
    font-size: 1.6rem;
    margin: 0;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 1.05rem;
    margin: 0 0 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin: 1.25rem 0 0.5rem;
}

code, .mono {
    font-family: var(--mono);
    font-size: 0.9em;
}

pre {
    margin: 0;
}

.wrap {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
}

main.wrap {
    padding-top: 24px;
    padding-bottom: 64px;
}

/* Top bar */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    height: 56px;
}

.brand {
    font-weight: 700;
    color: var(--ink);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-ink);
}

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
}

.nav-link {
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
}

.nav-link:hover {
    color: var(--ink);
    background: var(--bg);
}

.nav-link.active {
    color: var(--ink);
    background: var(--accent-soft);
    font-weight: 600;
}

.nav-sep {
    margin-left: 16px;
    padding-left: 16px;
    border-left: 1px solid var(--line);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

/* Page header */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.head-actions {
    display: flex;
    gap: 8px;
}

.back {
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--muted);
}

.lead {
    color: var(--muted);
    max-width: 80ch;
    margin: -4px 0 20px;
}

/* Cards & layout */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.card-head h2 {
    margin: 0;
}

.stack {
    display: grid;
    gap: 16px;
    align-content: start;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.split-wide {
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.grid-4 {
    display: grid;
    grid-template-columns: 120px repeat(3, auto);
    gap: 16px;
    align-items: end;
    justify-content: start;
}

@media (max-width: 900px) {
    .split, .split-wide, .grid-2, .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* Forms */
.form {
    display: grid;
    gap: 16px;
}

.form h2 {
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.form h2:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.field {
    display: grid;
    gap: 4px;
}

label {
    font-weight: 600;
    font-size: 0.9rem;
}

input[type=text], input[type=number], input[type=password], input[type=email], textarea, select {
    width: 100%;
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
}

textarea {
    resize: vertical;
    line-height: 1.5;
}

input:focus, textarea:focus, select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: transparent;
}

.check {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
    font-weight: 600;
}

.check input {
    margin: 0;
}

.check .hint {
    flex-basis: 100%;
    padding-left: 22px;
}

.hint {
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 400;
    margin: 0;
}

.actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 4px;
}

.prompt-editor {
    font-size: 0.85rem;
    min-height: 420px;
}

textarea.reply {
    min-height: 320px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 7px 14px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
}

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

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.btn-primary:hover {
    filter: brightness(1.08);
    border-color: var(--accent);
}

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

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

.btn-danger-ghost:hover {
    background: var(--danger-soft);
    border-color: transparent;
}

.btn-small {
    padding: 3px 10px;
    font-size: 0.82rem;
}

.btn[disabled] {
    opacity: 0.6;
    cursor: wait;
}

form.button_to {
    display: inline;
}

/* Flash */
.flash {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
}

.flash ul {
    margin: 4px 0 0;
    padding-left: 20px;
}

.flash-notice {
    background: var(--ok-soft);
    color: var(--ok);
}

.flash-alert {
    background: var(--danger-soft);
    color: var(--danger);
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.table th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
}

.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

.table tr:last-child td {
    border-bottom: 0;
}

.table tr.inactive td {
    opacity: 0.55;
}

.row-title {
    font-weight: 600;
    text-decoration: none;
    color: var(--ink);
}

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

.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filters select {
    width: auto;
    min-width: 160px;
}

/* Badges & meters */
.badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg);
    color: var(--muted);
    border: 1px solid var(--line);
    text-decoration: none;
    white-space: nowrap;
}

.badge-category {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: transparent;
}

.badge-warn, .badge-pending {
    background: var(--warn-soft);
    color: var(--warn);
    border-color: transparent;
}

.badge-processing {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: transparent;
}

.badge-done, .review-approved {
    background: var(--ok-soft);
    color: var(--ok);
    border-color: transparent;
}

.badge-failed, .review-rejected {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: transparent;
}

.review-edited {
    background: var(--warn-soft);
    color: var(--warn);
    border-color: transparent;
}

.meter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.meter-bar {
    width: 60px;
    height: 6px;
    background: var(--line);
    border-radius: 3px;
    overflow: hidden;
    display: inline-block;
}

.meter-bar span {
    display: block;
    height: 100%;
    background: var(--ok);
}

.meter-mid .meter-bar span {
    background: var(--warn);
}

.meter-low .meter-bar span {
    background: var(--danger);
}

.meter-label {
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
}

/* Detail views */
.meta {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 6px 12px;
    margin: 0 0 16px;
}

.meta dt {
    color: var(--muted);
    font-size: 0.85rem;
}

.meta dd {
    margin: 0;
}

.email-body, .prompt, .template-body {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: var(--mono);
    font-size: 0.84rem;
    line-height: 1.55;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
}

.email-body {
    font-family: inherit;
    font-size: 0.95rem;
    max-height: 70vh;
    overflow: auto;
}

.prompt {
    max-height: 420px;
    overflow: auto;
}

.details summary {
    cursor: pointer;
    font-weight: 600;
}

.inline-details {
    font-size: 0.85rem;
}

.inline-details summary {
    cursor: pointer;
    color: var(--muted);
}

.working {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    padding: 8px 0 16px;
}

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

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

.template {
    border-top: 1px solid var(--line);
    padding: 14px 0;
}

.template:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.template header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.template.inactive {
    opacity: 0.55;
}

.examples {
    margin: 0 0 16px;
    padding-left: 20px;
}

.list {
    margin: 0;
    padding-left: 18px;
    display: grid;
    gap: 4px;
}

.vars {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}

.vars td {
    padding: 6px 8px 6px 0;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

/* Prompt pipeline overview */
.pipeline {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

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

.pipeline-step {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    display: grid;
    gap: 10px;
    align-content: start;
}

.step-num {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
}

.prompt-card {
    display: grid;
    gap: 4px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    text-decoration: none;
    color: var(--ink);
}

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

/* Misc */
.empty {
    text-align: center;
    padding: 48px 20px;
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    color: var(--muted);
}

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

.small {
    font-size: 0.82rem;
}

.nowrap {
    white-space: nowrap;
}

.right {
    text-align: right;
}

.prewrap {
    white-space: pre-wrap;
}

.spacer {
    flex: 1;
}

/* Feedback */
.form.compact {
    gap: 8px;
    margin-top: 10px;
}

.feedback-box {
    margin-top: 16px;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.feedback-box summary {
    cursor: pointer;
    font-weight: 600;
}

.steps {
    padding-left: 20px;
    display: grid;
    gap: 10px;
}

.steps li::marker {
    font-weight: 700;
    color: var(--accent);
}

/* Sign-in */
.user-menu {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.user-name {
    font-size: 0.85rem;
    color: var(--muted);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.login {
    display: grid;
    place-items: center;
    padding: 48px 0;
}

.login-card {
    width: 100%;
    max-width: 400px;
    display: grid;
    gap: 16px;
}

.login-card h1 {
    font-size: 1.4rem;
}

.login-card p {
    margin: 0;
}

.login-card form.button_to {
    display: block;
}

.btn-microsoft {
    width: 100%;
    justify-content: center;
    padding: 10px 14px;
    background: var(--surface);
    border-color: var(--muted);
}

.login-card .form .btn {
    width: 100%;
    justify-content: center;
}

.or {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 0.8rem;
}

.or::before, .or::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

.login-fallback summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

/* Settings: two model columns */
.model-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
}

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

.model-grid h2 .step-num {
    width: 24px;
    height: 24px;
    font-size: 0.8rem;
}
