:root {
  --bg: oklch(1 0 0); --surface: oklch(.975 .004 38); --surface-strong: oklch(.94 .006 38);
  --ink: oklch(.20 .018 35); --muted: oklch(.47 .018 35); --line: oklch(.88 .008 38);
  --primary: oklch(.62 .16 38); --primary-hover: oklch(.56 .17 38); --primary-pale: oklch(.95 .035 38);
  --accent: oklch(.47 .12 205); --sidebar: oklch(.16 .012 210); --sidebar-ink: oklch(.94 .006 210);
  --success: oklch(.48 .12 150); --warning: oklch(.64 .14 75); --danger: oklch(.52 .17 25); --focus: oklch(.66 .15 205);
  --z-sticky: 20; --z-backdrop: 40; --z-modal: 50; --z-toast: 70;
}
* { box-sizing: border-box; }
html { height: 100%; }
body { min-height: 100%; margin: 0; color: var(--ink); background: var(--bg); font: 14px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
h1 { font-size: 2rem; letter-spacing: -.025em; }
h2 { margin-bottom: 8px; font-size: 1.35rem; letter-spacing: -.015em; }
h3 { margin-bottom: 8px; font-size: 1rem; }
.muted, .field-help { color: var(--muted); }
.section-label { margin-bottom: 8px; color: var(--primary-hover); font-size: 12px; font-weight: 700; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; font-size: 18px; font-weight: 750; text-decoration: none; letter-spacing: -.02em; }
.brand-mark { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 8px; background: var(--primary); color: white; font-family: ui-serif, "Songti SC", serif; }
.brand-light { color: var(--sidebar-ink); }

.login-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 1.25fr) minmax(380px, .75fr); }
.login-context { min-height: 100vh; display: flex; flex-direction: column; padding: 48px clamp(40px, 4vw, 72px); color: var(--sidebar-ink); background: var(--sidebar); }
.login-copy { max-width: 650px; margin: auto 0 64px; }
.login-copy h1 { max-width: 18ch; margin-bottom: 24px; font-size: clamp(2.4rem, 4.5vw, 4rem); letter-spacing: -.035em; }
.login-copy > p:last-child { max-width: 52ch; color: oklch(.76 .01 210); font-size: 16px; }
.context-line { color: oklch(.78 .119 38.1); font-weight: 700; }
.workflow-steps { display: flex; gap: clamp(24px, 4vw, 64px); padding: 24px 0 0; border-top: 1px solid oklch(.34 .012 210); list-style: none; }
.workflow-steps li { display: grid; gap: 5px; color: oklch(.76 .01 210); }
.workflow-steps span { color: oklch(.78 .119 38.1); font-size: 12px; font-weight: 800; }
.login-panel { display: grid; place-items: center; padding: 48px; }
.login-form { width: min(100%, 390px); display: grid; gap: 14px; }
.login-form > div { margin-bottom: 20px; }

label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 10px 12px; transition: border-color 160ms ease-out, background 160ms ease-out; }
input, select { min-height: 42px; }
textarea { resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: oklch(.72 .015 38); }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: 0; }
.form-error { margin: 0; color: var(--danger); font-size: 13px; }
.field-help { margin: -4px 0 0; font-size: 12px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 8px; padding: 9px 15px; font-weight: 720; transition: background 160ms ease-out, color 160ms ease-out, transform 100ms ease-out; }
.button:active { transform: translateY(1px); }
.button.primary { color: white; background: var(--primary); }
.button.primary:hover { background: var(--primary-hover); }
.button.secondary { border: 1px solid var(--line); background: var(--bg); }
.button.secondary:hover { background: var(--surface); }
.button.danger { color: white; background: var(--danger); }
.button.full { width: 100%; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; font-size: 20px; }
.icon-button:hover { background: var(--surface-strong); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 16px 16px; background: var(--sidebar); color: var(--sidebar-ink); z-index: var(--z-sticky); }
.sidebar > .brand { padding: 0 8px; margin-bottom: 38px; }
.primary-nav { display: grid; gap: 4px; }
.nav-item { width: 100%; min-height: 42px; display: flex; align-items: center; gap: 11px; border: 0; border-radius: 8px; padding: 8px 12px; color: oklch(.76 .01 210); background: transparent; text-align: left; }
.nav-item span { width: 18px; text-align: center; }
.nav-item:hover { color: white; background: oklch(.23 .012 210); }
.nav-item.active { color: white; background: oklch(.29 .035 38); }
.sidebar-note { display: flex; align-items: flex-start; gap: 10px; margin-top: auto; padding: 16px 12px; border-top: 1px solid oklch(.28 .012 210); color: oklch(.82 .01 210); }
.sidebar-note strong, .sidebar-note small { display: block; }
.sidebar-note small { margin-top: 2px; color: oklch(.64 .01 210); }
.live-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: oklch(.68 .14 150); }
.logout { margin-top: 4px; }
.app-main { min-width: 0; }
.topbar { position: sticky; top: 0; height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 32px; border-bottom: 1px solid var(--line); background: color-mix(in oklch, var(--bg) 94%, transparent); backdrop-filter: blur(10px); z-index: var(--z-sticky); }
.breadcrumb { min-width: 0; overflow: hidden; font-weight: 720; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.workspace { min-height: calc(100vh - 72px); padding: 32px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-heading h1 { margin-bottom: 7px; }
.page-heading p { margin-bottom: 0; }

.status-chip { display: inline-flex; align-items: center; gap: 7px; min-height: 28px; border-radius: 999px; padding: 4px 10px; background: var(--surface-strong); color: var(--muted); font-size: 12px; font-weight: 750; white-space: nowrap; }
.status-chip i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-chip.success { color: var(--success); background: oklch(.95 .03 150); }
.status-chip.warning { color: oklch(.48 .12 75); background: oklch(.96 .04 75); }
.status-chip.danger { color: var(--danger); background: oklch(.95 .035 25); }
.status-chip.active { color: var(--primary-hover); background: var(--primary-pale); }
.status-chip.info { color: var(--accent); background: oklch(.95 .03 205); }

.project-layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.project-index { min-height: 560px; border-right: 1px solid var(--line); background: var(--surface); }
.project-index header, .section-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.project-index h2, .section-header h2 { margin: 0; font-size: 15px; }
.project-list { display: grid; }
.project-row { width: 100%; display: grid; gap: 5px; border: 0; border-bottom: 1px solid var(--line); padding: 16px 20px; background: transparent; text-align: left; }
.project-row:hover { background: var(--bg); }
.project-row.active { background: var(--bg); box-shadow: inset 3px 0 var(--primary); }
.project-row small { color: var(--muted); }
.project-detail { min-width: 0; }
.detail-intro { padding: 28px; border-bottom: 1px solid var(--line); }
.detail-intro header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.policy-line { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.policy-token { border-radius: 999px; padding: 4px 9px; background: var(--surface); color: var(--muted); font-size: 12px; }
.chapter-list { width: 100%; border-collapse: collapse; }
.chapter-list th, .chapter-list td { padding: 13px 20px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.chapter-list th { color: var(--muted); background: var(--surface); font-size: 12px; }
.chapter-list tr[data-id] { cursor: pointer; }
.chapter-list tr[data-id]:hover td { background: var(--surface); }
.chapter-title { font-weight: 700; }
.empty-state { max-width: 520px; margin: 0 auto; padding: 96px 28px; text-align: center; }
.empty-state .empty-mark { display: grid; width: 52px; height: 52px; margin: 0 auto 18px; place-items: center; border-radius: 12px; background: var(--primary-pale); color: var(--primary-hover); font-size: 23px; }
.empty-state p { color: var(--muted); }

.chapter-toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.chapter-toolbar h1 { margin-bottom: 9px; }
.toolbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.chapter-workbench { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.translation-sheet { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.translation-head, .paragraph-row { display: grid; grid-template-columns: 54px minmax(0, 1fr) minmax(0, 1fr); }
.translation-head { color: var(--muted); background: var(--surface); font-size: 12px; font-weight: 750; }
.translation-head > div, .paragraph-row > div { padding: 12px 16px; }
.translation-head > div + div, .paragraph-row > div + div { border-left: 1px solid var(--line); }
.paragraph-row { border-top: 1px solid var(--line); }
.paragraph-row:hover { background: color-mix(in oklch, var(--surface) 55%, white); }
.paragraph-number { color: var(--muted); font: 12px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace; }
.source-text, .target-text { white-space: pre-wrap; line-height: 1.75; }
.target-text.empty { color: var(--muted); font-style: italic; }
.paragraph-edit { width: 100%; min-height: 108px; }
.inline-actions { display: flex; gap: 8px; margin-top: 10px; }
.inspector { position: sticky; top: 92px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.inspector-tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--surface); }
.inspector-tab { flex: 1; border: 0; border-bottom: 2px solid transparent; padding: 12px 8px; background: transparent; color: var(--muted); font-weight: 700; }
.inspector-tab.active { border-bottom-color: var(--primary); color: var(--ink); }
.inspector-body { max-height: calc(100vh - 170px); overflow: auto; padding: 16px; }
.issue, .run-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.issue:last-child, .run-row:last-child { border-bottom: 0; }
.issue header, .run-row header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 7px; }
.issue p, .run-row p { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.run-row .button { margin-top: 10px; }
.run-detail header { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.run-detail header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.run-detail dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; margin: 18px 0; font-size: 13px; }
.run-detail dt { color: var(--muted); }
.run-detail dd { margin: 0; min-width: 0; }
.run-detail .hash { overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.run-detail .json-preview { max-height: 340px; max-width: none; margin: 8px 0 16px; padding: 12px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); text-overflow: clip; white-space: pre-wrap; }
.severity { font-size: 11px; font-weight: 800; }
.severity.critical { color: var(--danger); }.severity.major { color: oklch(.48 .12 75); }.severity.minor { color: var(--accent); }

.memory-table, .settings-table { width: 100%; border: 1px solid var(--line); border-radius: 12px; border-spacing: 0; overflow: hidden; }
.memory-table th, .memory-table td, .settings-table th, .settings-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.memory-table th, .settings-table th { background: var(--surface); color: var(--muted); font-size: 12px; }
.memory-table tr:last-child td, .settings-table tr:last-child td { border-bottom: 0; }
.json-preview { max-width: 52ch; overflow: hidden; color: var(--muted); font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.settings-wrap { overflow-x: auto; border-radius: 12px; }
.settings-table { min-width: 930px; }
.settings-table input, .settings-table select { min-width: 120px; }
.settings-table .url-input { min-width: 230px; }
.settings-table .temperature-input { width: 72px; min-width: 72px; }
.settings-table .enabled-cell { text-align: center; }
.settings-table input[type="checkbox"] { min-width: 18px; width: 18px; min-height: 18px; }

.dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); border: 0; border-radius: 12px; padding: 0; color: var(--ink); background: var(--bg); }
.dialog-wide { width: min(760px, calc(100vw - 32px)); }
.dialog::backdrop { background: oklch(.08 0 0 / .58); }
.dialog form { display: grid; gap: 13px; padding: 24px; }
.dialog header, .dialog footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog header { margin-bottom: 7px; }
.dialog header h2 { margin: 0; }
.dialog footer { justify-content: flex-end; margin-top: 10px; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 380px; border-radius: 10px; padding: 13px 16px; color: white; background: var(--sidebar); z-index: var(--z-toast); }
.skeleton-page { display: grid; gap: 14px; }
.skeleton { height: 72px; border-radius: 8px; background: linear-gradient(90deg, var(--surface) 25%, var(--surface-strong) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
.skeleton.wide { height: 130px; }
.mobile-only { display: none; }

@keyframes shimmer { to { background-position: -200% 0; } }
@media (max-width: 1080px) { .chapter-workbench { grid-template-columns: 1fr; } .inspector { position: static; } .inspector-body { max-height: none; } }
@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 248px; transition: transform 180ms ease-out; }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { padding: 0 20px; }
  .workspace { padding: 24px 20px; }
  .project-layout { grid-template-columns: 1fr; }
  .project-index { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .project-list { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .project-row { border-right: 1px solid var(--line); }
}
@media (max-width: 720px) {
  .login-layout { grid-template-columns: 1fr; }
  .login-context { min-height: 42vh; padding: 28px 24px; }
  .login-copy { margin: 72px 0 32px; }
  .login-copy h1 { font-size: 2.45rem; }
  .workflow-steps { display: none; }
  .login-panel { padding: 40px 24px; }
  .topbar { height: 64px; }
  .workspace { min-height: calc(100vh - 64px); padding: 20px 14px; }
  .topbar-actions .status-chip { display: none; }
  .page-heading, .chapter-toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { justify-content: flex-start; }
  .field-pair { grid-template-columns: 1fr; gap: 13px; }
  .translation-head { display: none; }
  .paragraph-row { grid-template-columns: 42px 1fr; }
  .paragraph-row > div + div { border-left: 1px solid var(--line); }
  .paragraph-row .target-text { grid-column: 2; border-top: 1px dashed var(--line); border-left: 1px solid var(--line); }
  .chapter-list th:nth-child(3), .chapter-list td:nth-child(3) { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
