:root {
    --bg: #f4f6f2;
    --surface: #ffffff;
    --surface-soft: #f8faf7;
    --ink: #19342e;
    --muted: #6e7d78;
    --line: #dfe7e2;
    --brand: #163f36;
    --brand-2: #225c4e;
    --accent: #d7e96f;
    --accent-ink: #22331b;
    --danger: #b34242;
    --warning: #986b16;
    --info: #315d91;
    --radius: 16px;
    --shadow: 0 12px 34px rgba(25, 52, 46, .08);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: 14px;
    line-height: 1.55;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.admin-shell { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: 262px;
    display: flex;
    flex-direction: column;
    padding: 24px 18px 18px;
    color: #eef6f2;
    background: var(--brand);
    border-right: 1px solid rgba(255, 255, 255, .08);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 2px 8px 28px; }
.brand-mark {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    color: var(--brand);
    background: var(--accent);
    font-weight: 800;
    letter-spacing: -.04em;
}
.brand-copy strong { display: block; font-size: 17px; letter-spacing: -.02em; }
.brand-copy span { color: #a9c1ba; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

.nav-label { margin: 17px 12px 8px; color: #87a59d; font-size: 11px; font-weight: 700; letter-spacing: .12em; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    margin: 3px 0;
    padding: 0 13px;
    border-radius: 11px;
    color: #bad0ca;
    font-weight: 600;
    transition: .16s ease;
}
.nav-link:hover { color: white; background: rgba(255, 255, 255, .07); }
.nav-link.active { color: var(--accent-ink); background: var(--accent); }
.nav-link svg { width: 19px; height: 19px; flex: none; }
.sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-backdrop { display: none; }
.sidebar-close { display: none; }
.admin-user { display: flex; align-items: center; gap: 10px; padding: 8px; }
.avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--brand);
    background: #d9e8e2;
    font-weight: 800;
}
.admin-user strong { display: block; color: white; font-size: 13px; }
.admin-user span { display: block; max-width: 150px; overflow: hidden; color: #94aea7; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.logout-button { width: 100%; margin-top: 5px; color: #bad0ca; background: none; border: 0; text-align: left; }

.main { min-height: 100vh; margin-left: 262px; }
.topbar {
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 34px;
    background: rgba(244, 246, 242, .93);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 21px; letter-spacing: -.03em; }
.topbar-subtitle { margin-top: 2px; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.mobile-menu { display: none; width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.content { max-width: 1500px; margin: 0 auto; padding: 28px 34px 52px; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-heading h2 { margin: 0 0 4px; font-size: 25px; letter-spacing: -.035em; }
.page-heading p { margin: 0; color: var(--muted); }

.btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-weight: 700;
    line-height: 1;
    transition: .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: white; background: var(--brand); }
.btn-accent { color: var(--accent-ink); background: var(--accent); }
.btn-secondary { color: var(--ink); background: white; border-color: var(--line); }
.btn-danger { color: var(--danger); background: #fff4f4; border-color: #f1cccc; }
.btn-sm { min-height: 32px; padding: 6px 10px; border-radius: 8px; font-size: 12px; }
.btn svg { width: 17px; height: 17px; }

.grid { display: grid; gap: 18px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.two-col { grid-template-columns: minmax(0, 1.55fr) minmax(320px, .85fr); }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(25,52,46,.025); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.card-header h3 { margin: 0; font-size: 16px; letter-spacing: -.02em; }
.card-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.card-body { padding: 20px; }
.card-footer { padding: 15px 20px; background: var(--surface-soft); border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }

.stat-card { position: relative; min-height: 132px; padding: 20px; overflow: hidden; }
.stat-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: var(--brand); background: #e5eee9; }
.stat-icon.accent { background: #eff5c8; }
.stat-icon.blue { color: var(--info); background: #e8f0fa; }
.stat-icon.orange { color: var(--warning); background: #f8efd9; }
.stat-icon svg { width: 19px; height: 19px; }
.stat-value { margin-top: 16px; font-size: 28px; font-weight: 800; line-height: 1; letter-spacing: -.04em; }
.stat-label { margin-top: 7px; color: var(--muted); font-size: 12px; }
.stat-note { position: absolute; top: 21px; right: 18px; padding: 4px 8px; border-radius: 99px; color: var(--brand); background: #edf4f0; font-size: 10px; font-weight: 700; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 15px 18px; margin-bottom: 16px; background: white; border: 1px solid var(--line); border-radius: 14px; }
.toolbar .search { min-width: 260px; flex: 1; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { color: #425a54; font-size: 12px; font-weight: 700; }
.field small { color: var(--muted); }
.input, .select, .textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    color: var(--ink);
    background: white;
    border: 1px solid #cfdbd5;
    border-radius: 10px;
    outline: none;
    transition: .15s ease;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(34,92,78,.1); }
.textarea { min-height: 120px; resize: vertical; }
.textarea.code { min-height: 320px; color: #26433c; background: #f8faf8; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.65; }
.field-error { color: var(--danger); font-size: 12px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 12px 16px; color: var(--muted); background: var(--surface-soft); border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 800; letter-spacing: .04em; text-align: left; white-space: nowrap; }
.table td { padding: 14px 16px; border-bottom: 1px solid #edf1ee; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfcfa; }
.cell-title { font-weight: 750; }
.cell-sub { margin-top: 2px; color: var(--muted); font-size: 11px; }
.cell-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 99px; font-size: 11px; font-weight: 750; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge-success { color: #23704f; background: #e7f5ed; }
.badge-warning { color: #8a6116; background: #fbf2dc; }
.badge-danger { color: #a23e3e; background: #fae8e8; }
.badge-neutral { color: #62716c; background: #edf1ef; }
.badge-info { color: #315d91; background: #e9f0f9; }
.badge-purple { color: #6d4d91; background: #f0eafb; }

.flash { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; padding: 13px 15px; border: 1px solid #b9ddca; border-radius: 12px; color: #245e46; background: #ebf8f0; }
.flash.error { color: #8d3939; background: #fff0f0; border-color: #edc2c2; }
.flash-close { background: none; border: 0; color: inherit; font-size: 20px; }

.scenario-cover { width: 56px; height: 44px; object-fit: cover; border-radius: 9px; background: #e6ede9; border: 1px solid var(--line); }
.scenario-cover.placeholder { display: grid; place-items: center; color: #668079; font-weight: 800; }
.scenario-title-cell { display: flex; align-items: center; gap: 12px; min-width: 280px; }

.detail-hero { display: grid; grid-template-columns: 168px 1fr; gap: 24px; padding: 22px; }
.detail-cover { width: 168px; height: 126px; object-fit: cover; border-radius: 14px; background: #e7eee9; }
.detail-cover.placeholder { display: grid; place-items: center; color: #638078; font-size: 28px; font-weight: 800; }
.detail-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.detail-description { max-width: 820px; color: var(--muted); }
.section-stack > * + * { margin-top: 18px; }

.dialogue-panel { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.dialogue-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 16px 18px; background: #f8faf7; border-bottom: 1px solid var(--line); }
.dialogue-head h4 { margin: 0 0 3px; font-size: 15px; }
.dialogue-head p { margin: 0; color: var(--muted); font-size: 12px; }
.turn { display: grid; grid-template-columns: 118px 1fr; gap: 16px; padding: 16px 18px; border-bottom: 1px solid #edf1ee; }
.turn:last-child { border-bottom: 0; }
.speaker { font-weight: 800; }
.speaker-role { color: var(--muted); font-size: 11px; }
.utterance + .utterance { margin-top: 14px; padding-top: 14px; border-top: 1px dashed #dce5e0; }
.utterance-id { color: #81908b; font-family: ui-monospace, monospace; font-size: 10px; }
.utterance-en { margin-top: 4px; font-size: 15px; font-weight: 650; }
.utterance-zh { margin-top: 4px; color: var(--muted); }
.utterance-tools { display: flex; align-items: center; gap: 8px; margin-top: 9px; flex-wrap: wrap; }
.audio-player { height: 32px; max-width: 280px; }
.audio-form { display: none; grid-template-columns: 1fr 120px auto; gap: 8px; margin-top: 10px; padding: 12px; background: #f5f8f6; border-radius: 10px; }
.audio-form.open { display: grid; }

.assigned-voices { display: grid; gap: 10px; }
.assigned-voice { display: grid; grid-template-columns: minmax(130px,.7fr) minmax(200px,1fr) auto; align-items: center; gap: 18px; padding: 12px 14px; background: var(--surface-soft); border-radius: 12px; }
.assigned-voice strong, .assigned-voice span { display: block; }
.assigned-voice span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.voice-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; }
.voice-card { display: flex; flex-direction: column; gap: 14px; padding: 18px; min-width: 0; }
.voice-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.voice-card-head h3 { margin: 0; font-size: 17px; }
.voice-card-head span:not(.voice-monogram) { color: var(--muted); font-size: 11px; }
.voice-monogram { width: 38px; height: 38px; display: grid; place-items: center; color: white; background: var(--brand); border-radius: 12px; font-weight: 850; }
.voice-labels { display: flex; flex-wrap: wrap; gap: 6px; }
.voice-labels span { padding: 4px 7px; color: #52645f; background: #edf1ef; border-radius: 99px; font-size: 10px; font-weight: 700; }
.voice-card p { min-height: 42px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.voice-card audio { width: 100%; height: 34px; }
.voice-card form { display: grid; gap: 8px; margin-top: auto; }
.voice-card code { overflow: hidden; color: #82918c; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.voice-no-preview { min-height: 34px; display: grid; place-items: center; color: var(--muted); background: var(--surface-soft); border-radius: 9px; font-size: 11px; }

.word-list { display: flex; flex-wrap: wrap; gap: 8px; }
.word-chip { display: inline-flex; align-items: center; gap: 8px; padding: 7px 9px 7px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfb; }
.word-chip strong { font-size: 12px; }
.word-chip span { color: var(--muted); font-size: 11px; }
.chip-remove { padding: 0; color: #9b6565; background: none; border: 0; }

.progress-bar { width: 100%; height: 8px; overflow: hidden; background: #e7edea; border-radius: 99px; }
.progress-bar span { display: block; height: 100%; background: var(--brand-2); border-radius: inherit; }
.metric-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.metric-row strong { font-size: 12px; }
.metric-row span { color: var(--muted); font-size: 11px; }

.empty { padding: 44px 20px; color: var(--muted); text-align: center; }
.empty strong { display: block; margin-bottom: 4px; color: var(--ink); font-size: 15px; }

.pagination { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 16px 18px; border-top: 1px solid var(--line); }
.pagination-info { color: var(--muted); font-size: 12px; }
.pagination-links { display: flex; gap: 5px; }
.page-link { min-width: 34px; height: 34px; display: grid; place-items: center; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: white; font-size: 12px; }
.page-link.current { color: white; background: var(--brand); border-color: var(--brand); }
.page-link.disabled { opacity: .42; }

.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 1.05fr) minmax(440px, .95fr); background: white; }
.login-story { position: relative; display: flex; flex-direction: column; justify-content: space-between; padding: 48px; overflow: hidden; color: white; background: var(--brand); }
.login-story::before, .login-story::after { content: ""; position: absolute; border: 1px solid rgba(215,233,111,.18); border-radius: 50%; }
.login-story::before { width: 480px; height: 480px; right: -160px; top: -110px; }
.login-story::after { width: 310px; height: 310px; left: -140px; bottom: -130px; }
.login-brand { position: relative; z-index: 1; }
.login-copy { position: relative; z-index: 1; max-width: 570px; }
.login-kicker { display: inline-flex; padding: 6px 10px; color: var(--accent-ink); background: var(--accent); border-radius: 99px; font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.login-copy h1 { max-width: 540px; margin: 20px 0 16px; font-size: clamp(38px, 5vw, 66px); line-height: 1.04; letter-spacing: -.055em; }
.login-copy p { max-width: 500px; margin: 0; color: #afc9c2; font-size: 16px; }
.login-foot { position: relative; z-index: 1; color: #8eaba3; font-size: 12px; }
.login-form-side { display: grid; place-items: center; padding: 42px; background: #fbfcfa; }
.login-box { width: min(420px, 100%); }
.login-box h2 { margin: 0 0 8px; font-size: 28px; letter-spacing: -.04em; }
.login-box > p { margin: 0 0 30px; color: var(--muted); }
.login-box .field { margin-bottom: 17px; }
.login-submit { width: 100%; min-height: 47px; margin-top: 6px; }
.remember { display: flex; align-items: center; gap: 8px; margin: 6px 0 18px; color: var(--muted); }

.meta-list { display: grid; gap: 12px; }
.meta-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding-bottom: 12px; border-bottom: 1px solid #edf1ee; }
.meta-item:last-child { padding: 0; border: 0; }
.meta-item span { color: var(--muted); font-size: 12px; }
.meta-item strong { text-align: right; }
.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-form .field { min-width: 150px; flex: 1; }

.article-block-editor { display: grid; gap: 16px; }
.article-block-row { padding: 16px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 14px; }
.article-block-head { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.article-block-head .field { min-width: 210px; }

@media (max-width: 1180px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-col { grid-template-columns: 1fr; }
    .voice-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 820px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { position: absolute; top: 23px; right: 17px; z-index: 2; width: 34px; height: 34px; display: grid; place-items: center; color: #b9d0ca; background: rgba(255,255,255,.07); border: 0; border-radius: 10px; font-size: 23px; }
    .sidebar-backdrop { position: fixed; inset: 0; z-index: 30; display: block; padding: 0; background: rgba(14, 34, 29, .42); border: 0; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
    .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
    body.sidebar-open { overflow: hidden; }
    .main { margin-left: 0; }
    .mobile-menu { display: grid; place-items: center; }
    .topbar { padding: 12px 18px; }
    .content { padding: 22px 18px 40px; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .detail-hero { grid-template-columns: 1fr; }
    .detail-cover { width: 100%; height: 210px; }
    .turn { grid-template-columns: 1fr; gap: 8px; }
    .audio-form { grid-template-columns: 1fr; }
    .assigned-voice { grid-template-columns: 1fr; }
    .voice-grid { grid-template-columns: 1fr; }
    .login-page { grid-template-columns: 1fr; }
    .login-story { min-height: 320px; padding: 32px; }
    .login-story .login-foot { display: none; }
    .login-copy h1 { font-size: 40px; }
}

@media (max-width: 560px) {
    .stats-grid { grid-template-columns: 1fr; }
    .page-heading { flex-direction: column; }
    .page-heading .btn { width: 100%; }
    .toolbar > * { width: 100%; }
    .toolbar .search { min-width: 0; }
    .topbar-actions .btn { min-height: 36px; padding: 7px 10px; font-size: 11px; white-space: nowrap; }
    .topbar-actions .btn-secondary { display: none; }
    .topbar-actions .btn span { display: inline; }
    .topbar h1 { font-size: 18px; }
    .topbar-subtitle { max-width: 195px; }
    .login-form-side { padding: 30px 22px 44px; }
}
.generation-layout{grid-template-columns:minmax(0,1.65fr) minmax(290px,.75fr)}
.character-catalog{display:grid;gap:10px;margin-top:8px}.character-filter-bar{position:sticky;top:0;z-index:2;display:grid;grid-template-columns:minmax(160px,1.35fr) repeat(3,minmax(130px,1fr)) auto;gap:8px;padding:10px;border:1px solid var(--line);border-radius:16px;background:rgba(255,255,255,.96);backdrop-filter:blur(12px)}
.character-catalog-summary{display:flex;align-items:center;gap:14px;min-height:28px;color:var(--muted);font-size:12px}.character-catalog-summary strong{margin-left:auto;color:var(--text);font-size:13px}.character-select-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;max-height:680px;overflow:auto;padding:2px 5px 8px 2px}
.character-option{display:flex;gap:11px;padding:14px;border:1px solid var(--line);border-radius:16px;background:var(--surface-soft);cursor:pointer;transition:border-color .18s ease,box-shadow .18s ease,transform .18s ease}.character-option:hover{transform:translateY(-1px);border-color:#b9c8c2}.character-option.selected{border-color:#294f44;box-shadow:0 0 0 2px rgba(41,79,68,.1);background:#f6faf8}.character-option[hidden]{display:none}
.character-option input{margin-top:5px}.character-option-copy{display:grid;gap:5px;min-width:0}.character-option strong{display:flex;align-items:baseline;gap:8px}.character-option strong i{font-size:13px;font-style:normal;font-weight:700;color:var(--muted)}.character-option small{color:var(--muted);line-height:1.45}.character-option em{font-size:12px;font-style:normal;font-weight:700}.character-option em.ready{color:#1e8d67}.character-option em.missing,.error-text{color:#b74b4b}.character-tags{display:flex!important;grid-auto-flow:column;justify-content:start;gap:6px!important}.character-tags b{padding:3px 7px;border-radius:999px;background:#e9efec;color:#536861;font-size:10px;font-weight:700}.character-empty{padding:28px;text-align:center;border:1px dashed var(--line);border-radius:16px;color:var(--muted)}
.compact-list{margin:0;padding-left:20px;color:var(--muted);display:grid;gap:9px;line-height:1.5}
.generation-stats{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:12px}.generation-stats article{padding:18px;border-radius:18px;background:var(--surface);border:1px solid var(--line);display:grid;gap:7px}.generation-stats span{font-size:12px;color:var(--muted)}.generation-stats strong{font-size:18px}
.prompt-copy{white-space:pre-wrap;line-height:1.65}.generation-json{max-height:620px;overflow:auto;margin-top:16px;white-space:pre-wrap}
.cover-generation-grid{display:grid;grid-template-columns:minmax(320px,1.15fr) minmax(300px,.85fr);gap:24px;align-items:start}.generated-cover-wrap{min-width:0}.generated-cover{display:grid;place-items:center;width:100%;aspect-ratio:3/2;border-radius:18px;object-fit:cover;background:var(--surface-soft);border:1px solid var(--line);color:var(--muted);font-weight:700}.ready-text{color:#1e8d67}
@media(max-width:1100px){.character-filter-bar{grid-template-columns:repeat(2,minmax(0,1fr))}.character-filter-bar .btn{width:100%}}@media(max-width:900px){.generation-layout{grid-template-columns:1fr}.generation-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.character-select-grid{grid-template-columns:1fr}.cover-generation-grid{grid-template-columns:1fr}}@media(max-width:560px){.character-filter-bar{grid-template-columns:1fr}.character-catalog-summary{align-items:flex-start;flex-wrap:wrap}.character-catalog-summary strong{margin-left:0;width:100%}}
