:root {
    --bg: #f3efe6;
    --panel: #fffdf8;
    --ink: #1c1914;
    --muted: #6b6458;
    --line: #ddd4c4;
    --accent: #1f5c57;
    --accent-2: #c45c26;
    --sidebar: #1a2422;
    --danger: #9b2c2c;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

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

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

.sidebar {
    background: var(--sidebar);
    color: #e8efe9;
    padding: 1.4rem 1.1rem;
}

.brand {
    font-weight: 650;
    letter-spacing: 0.02em;
    margin-bottom: 1.6rem;
}

.brand span {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: #9bb0aa;
    margin-top: 0.2rem;
}

.nav a {
    display: block;
    color: #d5e0dc;
    text-decoration: none;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    margin-bottom: 0.2rem;
}

.nav a.active,
.nav a:hover {
    background: #2b3c38;
    color: #fff;
}

.main {
    padding: 1.6rem 2rem 3rem;
    max-width: 980px;
}

h1 {
    font-size: 1.35rem;
    font-weight: 650;
    margin: 0 0 1.1rem;
}

.flash {
    padding: 0.7rem 0.9rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.flash-ok { background: #e5f3ea; }
.flash-err { background: #f8e4e0; color: var(--danger); }
.flash-warn { background: #f7ead3; }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 1.1rem 1.2rem;
    margin-bottom: 1rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.row-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    text-align: left;
    padding: 0.55rem 0.4rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }

.btn {
    display: inline-block;
    border: 0;
    border-radius: 7px;
    padding: 0.45rem 0.85rem;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    font: inherit;
}

.btn:hover { filter: brightness(1.08); }

.btn-ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--line);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid #e4c6c6;
}

.btn-sm { padding: 0.28rem 0.6rem; font-size: 0.85rem; }

.cell-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.impersonation {
    margin: 0 0 1rem;
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    background: #2f2418;
    color: #f3dcc8;
    font-size: 0.82rem;
    line-height: 1.35;
}

.impersonation strong { color: #fff; }

.impersonation form { margin-top: 0.45rem; }

.sidebar .impersonation .btn-ghost {
    color: #f3dcc8;
    border-color: #6a5340;
}

.form-grid {
    display: grid;
    gap: 0.85rem;
}

.form-grid.two {
    grid-template-columns: 1fr 1fr;
}

label {
    display: block;
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.form-field label,
.form-field legend {
    font-size: 0.95rem;
    color: var(--ink);
    font-weight: 650;
}

.form-field legend {
    padding: 0 0.35rem;
}

fieldset.form-field {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.75rem 1rem 1rem;
}

.field-hint {
    margin: 0.4rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.4;
}

.choice {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin: 0.55rem 0 0.1rem;
    font-size: 0.95rem;
    font-weight: 550;
    color: var(--ink);
}

.choice input {
    width: auto;
    margin-top: 0.2rem;
}

.textarea-short { min-height: 72px; }
.textarea-prompt { min-height: 200px; }
.textarea-urls { min-height: 110px; }

.form-section-title {
    font-size: 1.05rem;
    font-weight: 650;
    margin: 0.4rem 0 0;
    padding-top: 0.85rem;
    border-top: 1px solid var(--line);
}

input, textarea, select {
    width: 100%;
    font: inherit;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
}

textarea { min-height: 140px; resize: vertical; }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.4rem; }

.pill {
    display: inline-block;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    background: #eee8dc;
    font-size: 0.8rem;
}

.pill-ready { background: #d7eadc; color: #1f5c57; }
.pill-err { background: #f3d6d2; color: #9b2c2c; }

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.1rem;
    border-bottom: 1px solid var(--line);
    margin: 0 0 1rem;
    overflow: hidden;
}

.form-grid > .tabs { margin-bottom: 0; }

.tab {
    appearance: none;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 0.55rem 0.9rem 0.6rem;
    color: var(--muted);
    text-decoration: none;
    font: inherit;
    font-weight: 650;
    cursor: pointer;
    white-space: nowrap;
}

.tab:hover { color: var(--ink); }

.tab.is-active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-meta {
    font-weight: 500;
    color: var(--muted);
    font-size: 0.8rem;
}

.tab.is-active .tab-meta { color: var(--accent); }

.tab-panel {
    display: grid;
    gap: 0.85rem;
}

.tab-panel[hidden],
[data-show][hidden] {
    display: none !important;
}

.tab-intro {
    margin: 0;
    padding: 0.75rem 0.9rem;
    background: #f7f1e6;
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.45;
}

.tab-intro strong { color: var(--ink); font-weight: 650; }

.tab-next {
    margin: 0.9rem 0 0;
    font-size: 0.9rem;
}

.kv-grid {
    display: grid;
    grid-template-columns: minmax(9rem, 12rem) 1fr;
    gap: 0.45rem 1rem;
    margin: 0;
}

.kv-grid dt {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.kv-grid dd {
    margin: 0;
    font-size: 0.95rem;
}

.prompt-preview {
    margin: 0.9rem 0 0;
}

.prompt-preview summary {
    cursor: pointer;
    font-weight: 650;
    color: var(--ink);
}

.prompt-preview pre {
    white-space: pre-wrap;
    font: inherit;
    margin: 0.6rem 0 0;
    padding: 0.7rem 0.8rem;
    background: #f7f1e6;
    border-radius: 7px;
}

.subhead {
    margin: 0 0 0.55rem;
    font-size: 1.02rem;
    font-weight: 650;
}

.form-sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--panel);
    border-top: 1px solid var(--line);
    margin: 0.85rem -1.2rem -1.1rem;
    padding: 0.85rem 1.2rem;
}

.quote {
    background: #f7f1e6;
    border-left: 3px solid var(--accent);
    padding: 0.55rem 0.75rem;
    margin: 0.45rem 0;
    font-size: 0.92rem;
}

.chat-answer {
    white-space: pre-wrap;
    margin: 0 0 0.8rem;
}

.url-box {
    word-break: break-all;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.82rem;
    background: #f7f1e6;
    border-radius: 7px;
    padding: 0.55rem 0.7rem;
    margin: 0.2rem 0 0.6rem;
}

.empty { text-align: center; color: var(--muted); padding: 1.6rem 0; }

.page-busy {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    background: rgba(28, 25, 20, 0.38);
}

.page-busy[hidden] { display: none; }

.page-busy-card {
    display: grid;
    justify-items: center;
    gap: 0.75rem;
    min-width: 12rem;
    padding: 1.15rem 1.4rem 1.05rem;
    background: var(--panel);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(28, 25, 20, 0.18);
}

.page-busy-card p {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 650;
}

.page-busy-spinner {
    width: 1.7rem;
    height: 1.7rem;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: page-busy-spin 0.7s linear infinite;
}

body.is-busy { overflow: hidden; }

.toast-stack {
    position: fixed;
    top: 1.1rem;
    right: 1.1rem;
    z-index: 90;
    display: grid;
    gap: 0.5rem;
    width: min(22rem, calc(100vw - 2rem));
    pointer-events: none;
}

.toast {
    padding: 0.8rem 0.95rem;
    border-radius: 10px;
    background: #1f5c57;
    color: #fff;
    box-shadow: 0 10px 28px rgba(28, 25, 20, 0.18);
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.22s ease, transform 0.22s ease;
    font-size: 0.95rem;
    line-height: 1.35;
}

.toast.is-in {
    opacity: 1;
    transform: translateY(0);
}

.toast-ok { background: #1f5c57; }

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

@media (max-width: 800px) {
    .layout { grid-template-columns: 1fr; }
    .form-grid.two { grid-template-columns: 1fr; }
    .kv-grid { grid-template-columns: 1fr; }
    .row-top { flex-wrap: wrap; }
}
