:root {
    color-scheme: light;
    --ink: #13231d;
    --muted: #65736d;
    --surface: #ffffff;
    --canvas: #f3f5f1;
    --line: #dce3df;
    --brand: #1f5b45;
    --brand-dark: #174334;
    --accent: #d9f26a;
    --danger: #9c2f2f;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--canvas);
}

a { color: inherit; }

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 68px;
    padding: 0 5vw;
    color: #fff;
    background: var(--brand-dark);
}

.brand {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: .02em;
    text-decoration: none;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    font-size: .9rem;
}

.site-nav form { margin: 0; }

.link-button {
    padding: 0;
    color: inherit;
    font: inherit;
    text-decoration: underline;
    background: none;
    border: 0;
    cursor: pointer;
}

.page-shell {
    width: min(1180px, 90vw);
    margin: 0 auto;
    padding: 64px 0 96px;
}

.hero { max-width: 720px; margin-bottom: 36px; }
.hero h1, .auth-card h1 { margin: 0 0 12px; font-size: clamp(2rem, 5vw, 4rem); line-height: 1; }
.hero p { color: var(--muted); font-size: 1.05rem; line-height: 1.7; }

.eyebrow {
    margin: 0 0 14px;
    color: var(--brand);
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.feature-card, .auth-card {
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 18px 45px rgb(19 35 29 / 7%);
}

.feature-card { display: block; text-decoration: none; transition: transform .16s ease, box-shadow .16s ease; }
.feature-card:hover { transform: translateY(-3px); box-shadow: 0 22px 55px rgb(19 35 29 / 12%); }

.feature-card h2 { margin: 24px 0 10px; font-size: 1.35rem; }
.feature-card p { min-height: 72px; color: var(--muted); line-height: 1.55; }
.card-number { color: var(--brand); font-weight: 800; }

.status-pill {
    display: inline-block;
    padding: 7px 11px;
    color: var(--brand-dark);
    font-size: .78rem;
    font-weight: 700;
    background: var(--accent);
    border-radius: 999px;
}

.auth-card { width: min(460px, 100%); margin: 5vh auto 0; }
.auth-card h1 { font-size: 2.25rem; }
.muted { color: var(--muted); line-height: 1.55; }
.alert { padding: 12px 14px; color: var(--danger); background: #fff0f0; border-radius: 10px; }

.stacked-form { display: grid; gap: 10px; margin-top: 26px; }
.stacked-form label { margin-top: 8px; font-size: .85rem; font-weight: 750; }
.stacked-form input {
    width: 100%;
    padding: 12px 13px;
    font: inherit;
    background: #fff;
    border: 1px solid #b9c5bf;
    border-radius: 10px;
}
.stacked-form input:focus { outline: 3px solid rgb(217 242 106 / 50%); border-color: var(--brand); }

.primary-button {
    margin-top: 14px;
    padding: 13px 18px;
    color: #fff;
    font: inherit;
    font-weight: 750;
    background: var(--brand);
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}
.primary-button:hover { background: var(--brand-dark); }
.search-results { display: grid; gap: 6px; }
.search-results:empty { display: none; }
.search-results button { text-align: left; }
.export-actions { flex-wrap: wrap; margin-top: 16px; }

.message-stack { display: grid; gap: 8px; margin-bottom: 24px; }
.notice { padding: 13px 16px; background: #e8f4ee; border: 1px solid #b8d9c9; border-radius: 12px; }
.notice-error { color: var(--danger); background: #fff0f0; border-color: #f0caca; }
.breadcrumbs { display: flex; gap: 10px; margin-bottom: 32px; color: var(--muted); font-size: .9rem; }
.breadcrumbs a { color: var(--brand); }
.form-layout { display: grid; grid-template-columns: minmax(250px, .8fr) minmax(0, 1.4fr); gap: 48px; align-items: start; }
.form-intro { position: sticky; top: 28px; }
.form-intro h1, .result-header h1 { margin: 0 0 16px; font-size: clamp(2rem, 4vw, 3.3rem); line-height: 1.08; }
.form-intro p { color: var(--muted); line-height: 1.65; }
.generation-form, .editor-card, .context-card, .state-card {
    padding: 30px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
    box-shadow: 0 18px 45px rgb(19 35 29 / 7%);
}
.generation-form { display: grid; gap: 20px; }
.field-group { display: grid; gap: 8px; }
.field-group > label { font-size: .88rem; font-weight: 750; }
.field-group input:not([type="checkbox"]), .field-group textarea, .field-group select, .editor-card textarea {
    width: 100%; padding: 12px 13px; color: var(--ink); font: inherit; background: #fff;
    border: 1px solid #b9c5bf; border-radius: 10px;
}
.field-group select[multiple] { min-height: 150px; }
.field-group textarea:focus, .field-group input:focus, .field-group select:focus, .editor-card textarea:focus {
    outline: 3px solid rgb(217 242 106 / 50%); border-color: var(--brand);
}
.checkbox-field label { display: flex; gap: 10px; align-items: flex-start; line-height: 1.45; }
.checkbox-field input { width: 18px; height: 18px; margin-top: 2px; }
.help-text { color: var(--muted); line-height: 1.45; }
.field-error { color: var(--danger); }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; align-items: center; }
.secondary-button { display: inline-block; padding: 12px 17px; color: var(--brand-dark); font: inherit; font-weight: 750; text-decoration: none; background: #edf1ee; border: 0; border-radius: 10px; cursor: pointer; }
.result-header { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; margin-bottom: 30px; }
.status-pending, .status-processing { background: #fff0aa; }
.status-ready { background: var(--accent); }
.status-failed { color: #fff; background: var(--danger); }
.state-card { display: flex; gap: 20px; justify-content: space-between; align-items: center; }
.state-card h2 { margin: 0 0 8px; }
.state-card p { margin: 0; color: var(--muted); line-height: 1.55; }
.spinner { width: 34px; height: 34px; flex: 0 0 auto; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.editor-layout { display: grid; grid-template-columns: minmax(220px, .55fr) minmax(0, 1.6fr); gap: 22px; align-items: start; }
.context-card h2 { margin-top: 0; }
.context-card dl { display: grid; gap: 6px; margin: 24px 0; }
.context-card dt { margin-top: 12px; color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
.context-card dd { margin: 0; line-height: 1.5; }
.full-width { width: 100%; }
.section-heading { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.section-heading h2 { margin: 0; }
.section-heading .primary-button { margin-top: 0; }
.editor-card textarea { min-height: 520px; margin-top: 22px; line-height: 1.55; resize: vertical; }
.recent-section { margin-top: 60px; }
.document-list { margin-top: 18px; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.document-row { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 18px 22px; text-decoration: none; border-bottom: 1px solid var(--line); }
.document-row:last-child { border-bottom: 0; }
.document-row:hover { background: #f9fbf9; }
.document-row small { display: block; margin-top: 5px; color: var(--muted); }
.filter-panel {
    display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 14px;
    align-items: end; padding: 22px; background: var(--surface); border: 1px solid var(--line);
    border-radius: 18px;
}
.filter-panel select, .filter-panel input {
    width: 100%; padding: 10px 11px; color: var(--ink); font: inherit; background: #fff;
    border: 1px solid #b9c5bf; border-radius: 9px;
}
.filter-actions { display: flex; gap: 8px; align-items: center; }
.filter-actions .primary-button { margin-top: 0; }
.history-section { margin-top: 22px; }
.history-table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 16px; text-align: left; border-bottom: 1px solid var(--line); }
.history-table th { color: var(--muted); font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; }
.history-table tbody tr:last-child td { border-bottom: 0; }
.history-actions { white-space: nowrap; }
.history-actions a { margin-right: 10px; color: var(--brand); }
.pagination { display: flex; justify-content: center; gap: 18px; margin-top: 22px; color: var(--muted); }
.pagination a { color: var(--brand); }
.analytics-filter { grid-template-columns: repeat(2, minmax(160px, 220px)) auto; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 22px 0; }
.metric-card, .analytics-card {
    padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
    box-shadow: 0 18px 45px rgb(19 35 29 / 5%);
}
.metric-card { display: grid; gap: 7px; }
.metric-card span, .metric-card small { color: var(--muted); }
.metric-card strong { font-size: 2rem; }
.analytics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.analytics-card h2 { margin: 0 0 22px; }
.analytics-card h3 { margin: 24px 0 12px; font-size: 1rem; }
.analytics-bars { display: grid; gap: 18px; }
.analytics-bar-row > div:first-child { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 7px; }
.analytics-bar { height: 9px; overflow: hidden; background: #edf1ee; border-radius: 999px; }
.analytics-bar span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.analytics-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0; }
.analytics-summary div { padding: 14px; background: var(--canvas); border-radius: 12px; }
.analytics-summary dt { color: var(--muted); font-size: .8rem; }
.analytics-summary dd { margin: 5px 0 0; font-size: 1.35rem; font-weight: 800; }
.error-type-list { display: grid; gap: 8px; padding: 0; list-style: none; }
.error-type-list li { display: flex; justify-content: space-between; gap: 14px; }

@media (max-width: 800px) {
    .site-header { align-items: flex-start; gap: 16px; padding-block: 18px; }
    .site-nav { align-items: flex-end; flex-direction: column; gap: 8px; }
    .card-grid { grid-template-columns: 1fr; }
    .feature-card p { min-height: auto; }
    .form-layout, .editor-layout { grid-template-columns: 1fr; }
    .form-intro { position: static; }
    .result-header { flex-direction: column; }
    .state-card { align-items: flex-start; flex-direction: column; }
    .filter-panel { grid-template-columns: 1fr; }
    .metric-grid, .analytics-grid { grid-template-columns: 1fr; }
}
