:root {
  --ink: #24201b;
  --muted: #756d63;
  --paper: #f4f0e7;
  --surface: #fffdf8;
  --line: #ddd4c5;
  --red: #a43a2a;
  --red-dark: #79271d;
  --gold: #a98545;
  --green: #356b4f;
  --amber: #9a651e;
  --shadow: 0 18px 50px rgba(54, 45, 34, .10);
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 75% 10%, rgba(169,133,69,.10), transparent 28rem), var(--paper); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled, textarea:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(164,58,42,.28); outline-offset: 2px; }
[hidden] { display: none !important; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 32px; }
.login-panel { width: min(1040px, 100%); min-height: 620px; display: grid; grid-template-columns: 1.2fr .8fr; grid-template-rows: auto 1fr; gap: 24px 70px; padding: 48px 56px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.login-panel::after { content: ""; position: absolute; width: 280px; height: 280px; right: -120px; top: -100px; border: 1px solid rgba(169,133,69,.34); border-radius: 50%; box-shadow: 0 0 0 36px rgba(169,133,69,.05), 0 0 0 72px rgba(169,133,69,.035); }
.brand-lockup { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; position: relative; z-index: 1; }
.brand-lockup img, .brand-button img { width: 44px; height: 44px; object-fit: contain; }
.brand-lockup span { font: 700 20px/1.2 "STKaiti", "KaiTi", serif; letter-spacing: .16em; }
.brand-lockup small, .brand-button small { display: block; margin-top: 4px; font: 12px/1.2 sans-serif; letter-spacing: .14em; color: var(--muted); }
.login-copy { align-self: center; }
.eyebrow { margin: 0 0 12px; color: var(--red); font-weight: 700; letter-spacing: .18em; text-transform: uppercase; font-size: 13px; }
.login-copy h1 { font: 700 clamp(36px, 5vw, 58px)/1.22 "STSong", "SimSun", serif; letter-spacing: -.035em; margin: 0 0 26px; }
.login-copy > p:last-child { max-width: 35rem; color: var(--muted); font-size: 17px; line-height: 1.9; }
.login-form { align-self: center; padding: 32px; background: #f8f4eb; border-top: 3px solid var(--red); }
label { display: grid; gap: 8px; margin-bottom: 18px; font-size: 14px; font-weight: 700; color: #514a42; }
input, textarea, select { width: 100%; border: 1px solid #cfc5b5; background: #fff; color: var(--ink); padding: 12px 14px; min-height: 46px; border-radius: 2px; }
textarea { resize: vertical; line-height: 1.65; }
.primary, .secondary, .danger, .quiet { min-height: 44px; border: 1px solid transparent; padding: 10px 18px; font-weight: 700; border-radius: 2px; }
.primary { background: var(--red); color: #fff; }
.primary:hover { background: var(--red-dark); }
.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.danger { background: #7d241c; color: #fff; }
.quiet { background: #eee8dc; color: var(--ink); }
.button-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.wide { width: 100%; }
.form-error { min-height: 1.4em; color: #a1281d; font-size: 13px; }

.app-view { min-height: 100vh; }
.topbar { height: 72px; display: grid; grid-template-columns: 260px 1fr auto; align-items: center; gap: 30px; padding: 0 32px; background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 20; }
.brand-button { border: 0; background: none; color: #fff; display: flex; align-items: center; gap: 12px; text-align: left; padding: 0; }
.brand-button span { font: 700 17px/1.1 "STKaiti", "KaiTi", serif; letter-spacing: .1em; }
.brand-button small { color: #bfb6aa; letter-spacing: .12em; }
.topbar nav { display: flex; align-self: stretch; }
.nav-button { border: 0; border-bottom: 3px solid transparent; padding: 0 22px; background: transparent; color: #c9c1b7; font-weight: 700; }
.nav-button.active { color: #fff; border-color: #c39b52; }
.user-menu { display: flex; align-items: center; gap: 16px; color: #d8d0c5; font-size: 14px; }
.text-button { border: 0; background: none; color: #d8d0c5; padding: 8px; text-decoration: underline; text-underline-offset: 3px; }
#main-content { width: min(1320px, calc(100% - 48px)); margin: 0 auto; padding: 38px 0 80px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 28px; }
.page-head h1 { margin: 0; font: 700 clamp(28px, 4vw, 42px)/1.2 "STSong", "SimSun", serif; }
.page-head p { margin: 8px 0 0; color: var(--muted); line-height: 1.6; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.summary-line { display: flex; gap: 24px; flex-wrap: wrap; padding: 15px 18px; border: 1px solid var(--line); background: rgba(255,253,248,.7); margin-bottom: 24px; }
.summary-line strong { font-size: 20px; margin-right: 6px; }
.summary-line span { color: var(--muted); font-size: 13px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 26px; align-items: start; }
.section-title { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin: 0 0 14px; }
.section-title h2 { margin: 0; font: 700 21px/1.3 "STSong", "SimSun", serif; }
.queue { display: grid; gap: 12px; }
.course-groups { display: grid; gap: 28px; }
.course-group { display: grid; gap: 12px; }
.course-group > header { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 8px; border-bottom: 1px solid var(--line); }
.course-group > header h3 { margin: 0; font: 700 17px/1.35 "STSong", "SimSun", serif; }
.course-group > header span { min-width: 28px; padding: 3px 8px; text-align: center; color: var(--muted); background: #ece5d8; font-size: 12px; }
.course-group.rejected > header h3 { color: var(--red); }
.course-row { width: 100%; display: grid; grid-template-columns: minmax(0,1fr) 150px 120px; align-items: center; gap: 20px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--gold); padding: 20px; text-align: left; color: inherit; }
.course-row:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(50,40,30,.07); }
.course-row h3 { margin: 0 0 6px; font-size: 18px; }
.course-row p { margin: 0; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.course-row .stage { font-weight: 800; color: var(--red); }
.course-row .progress { font-size: 13px; color: var(--muted); }
.create-card, .panel { background: var(--surface); border: 1px solid var(--line); padding: 22px; }
.create-card { border-top: 3px solid var(--red); }
.create-card h2, .panel h2 { margin: 0 0 18px; font: 700 21px/1.3 "STSong", "SimSun", serif; }
.empty { padding: 42px 24px; text-align: center; color: var(--muted); border: 1px dashed #cbbfaa; background: rgba(255,253,248,.55); }

.back-link { border: 0; background: none; padding: 0; color: var(--red); font-weight: 700; margin-bottom: 16px; }
.stage-track { display: grid; grid-template-columns: repeat(5, 1fr); margin: 24px 0; background: var(--surface); border: 1px solid var(--line); }
.stage-step { padding: 16px; border-right: 1px solid var(--line); }
.stage-step:last-child { border-right: 0; }
.stage-step small { display: block; color: var(--muted); margin-top: 6px; }
.stage-step.current { background: #f5e9e3; box-shadow: inset 0 -3px var(--red); }
.stage-step.done { color: var(--green); }
.workbench { display: grid; grid-template-columns: 270px minmax(0,1fr) 310px; gap: 20px; align-items: start; }
.artifact-nav-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
.artifact-nav-head h2 { margin: 0; }
.artifact-nav-head span { color: var(--muted); font-size: 12px; }
.artifact-tree { display: grid; gap: 19px; }
.artifact-group { display: grid; gap: 7px; }
.artifact-group > header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0 8px 6px; border-bottom: 1px solid #ebe3d6; }
.artifact-group > header strong { font-size: 13px; letter-spacing: .05em; }
.artifact-group > header small { color: var(--muted); font: 11px/1.3 ui-monospace, Consolas, monospace; }
.artifact-list { display: grid; gap: 7px; }
.artifact-button { min-height: 44px; width: 100%; border: 1px solid transparent; background: transparent; padding: 9px 10px; text-align: left; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.artifact-button:hover, .artifact-button.active { background: #f2ece1; border-color: var(--line); color: var(--ink); }
.artifact-button.missing { opacity: .64; }
.artifact-button em { font-style: normal; flex: 0 0 auto; font-size: 11px; color: var(--green); }
.artifact-button.missing em { color: var(--muted); }
.preview { min-height: 570px; padding: 0; overflow: hidden; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); background: #f8f4eb; }
.preview-head h2 { margin: 0; font-size: 18px; }
.artifact-path { display: block; margin-top: 4px; color: var(--muted); font: 11px/1.3 ui-monospace, Consolas, monospace; }
.preview-tools { display: flex; gap: 8px; }
.preview-body { padding: 24px; overflow: auto; max-height: 72vh; }
.preview-body pre { margin: 0; white-space: pre-wrap; word-break: break-word; font: 15px/1.82 "Noto Serif SC", "STSong", serif; }
.preview-body img, .preview-body video { max-width: 100%; height: auto; display: block; margin: auto; }
.preview-body audio { width: 100%; margin-top: 80px; }
.editor { width: 100%; min-height: 58vh; border: 0; padding: 0; background: transparent; }
.artifact-empty { min-height: 450px; display: grid; place-content: center; justify-items: center; gap: 12px; padding: 36px; text-align: center; background: linear-gradient(180deg, rgba(248,244,235,.45), transparent); }
.artifact-empty h3 { margin: 0; font: 700 25px/1.4 "STSong", "SimSun", serif; }
.artifact-empty p { max-width: 35rem; margin: 0 0 8px; color: var(--muted); line-height: 1.8; }
.empty-kicker { color: var(--red); font-size: 12px; font-weight: 800; letter-spacing: .12em; }
.markdown-layout { width: min(100%, 800px); margin: 0 auto; }
.document-toc { display: flex; align-items: center; gap: 7px 14px; flex-wrap: wrap; margin: 0 0 28px; padding: 14px 16px; border-left: 3px solid var(--gold); background: #f7f2e8; }
.document-toc strong { width: 100%; font-size: 13px; }
.document-toc a { color: var(--red-dark); font-size: 13px; text-decoration: none; border-bottom: 1px solid rgba(121,39,29,.24); }
.markdown-document { font: 17px/1.92 "Noto Serif SC", "Songti SC", "STSong", serif; color: #2c2823; }
.markdown-document h1, .markdown-document h2, .markdown-document h3, .markdown-document h4 { scroll-margin-top: 96px; color: var(--ink); font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif; line-height: 1.42; }
.markdown-document h1 { margin: 0 0 28px; padding-bottom: 16px; border-bottom: 2px solid var(--ink); font-size: clamp(28px, 4vw, 38px); letter-spacing: -.025em; }
.markdown-document h2 { margin: 42px 0 16px; padding-left: 12px; border-left: 4px solid var(--red); font-size: 23px; }
.markdown-document h3 { margin: 30px 0 12px; font-size: 19px; }
.markdown-document p { margin: 0 0 18px; }
.markdown-document strong { color: #171411; }
.markdown-document code { padding: 2px 6px; background: #eee7da; color: #733224; font: .88em/1.5 ui-monospace, Consolas, monospace; }
.markdown-document blockquote { margin: 22px 0; padding: 16px 20px; border-left: 4px solid var(--gold); background: #f7f2e8; color: #4f463d; font-size: 18px; }
.markdown-document ul, .markdown-document ol { margin: 0 0 20px; padding-left: 1.5em; }
.markdown-document li { margin: 6px 0; }
.markdown-document hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.markdown-table-wrap { max-width: 100%; margin: 20px 0 28px; overflow-x: auto; border: 1px solid var(--line); }
.markdown-document table { width: 100%; border-collapse: collapse; font: 15px/1.72 "Noto Sans SC", "Microsoft YaHei", sans-serif; }
.markdown-document th, .markdown-document td { min-width: 110px; padding: 11px 13px; text-align: left; vertical-align: top; border-bottom: 1px solid #e5dccd; }
.markdown-document th { background: #eee7da; color: #51483f; font-size: 13px; }
.markdown-document tr:last-child td { border-bottom: 0; }
.code-block { padding: 16px !important; overflow-x: auto; background: #24201b; color: #f2eadc; }
.side-stack { display: grid; gap: 16px; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 800; padding: 5px 9px; background: #ece7dc; }
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-pill.approved::before, .status-pill.succeeded::before, .status-pill.awaiting-approval::before { background: var(--green); }
.status-pill.running::before, .status-pill.queued::before { background: var(--amber); }
.status-pill.failed::before, .status-pill.rejected::before { background: var(--red); }
.gate-list { display: grid; gap: 10px; margin-bottom: 18px; }
.gate-row { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 9px; border-bottom: 1px dashed var(--line); font-size: 13px; }
.action-stack { display: grid; gap: 9px; }
.rejection-callout { margin: 0 0 18px; padding: 16px; border: 1px solid #d6a69d; border-left: 4px solid var(--red); background: #fbefec; }
.rejection-callout > strong { color: var(--red-dark); }
.rejection-callout p { margin: 8px 0 14px; line-height: 1.65; color: #5e413b; }
.rejection-actions { display: grid; gap: 8px; }
.reject-box { margin-top: 12px; }
.job-log { white-space: pre-wrap; word-break: break-all; max-height: 260px; overflow: auto; padding: 12px; background: #1e1d1a; color: #e8e0d2; font: 12px/1.55 ui-monospace, Consolas, monospace; }

.ops-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.service-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
.service { padding: 14px; background: #f6f1e8; border: 1px solid var(--line); }
.service strong { display: block; }
.service small { color: var(--muted); }
.user-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.user-table th, .user-table td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--line); }
.user-table th { color: var(--muted); font-size: 12px; }
.doctor-output { max-height: 260px; overflow: auto; background: #24201b; color: #e8e0d2; padding: 14px; white-space: pre-wrap; font: 12px/1.6 ui-monospace, Consolas, monospace; }

dialog { border: 1px solid var(--line); padding: 0; width: min(460px, calc(100% - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(28,24,20,.58); }
.dialog-form { padding: 28px; }
.dialog-form h2 { margin: 0 0 10px; font: 700 25px/1.3 "STSong", serif; }
.dialog-form > p:not(.eyebrow):not(.form-error) { color: var(--muted); line-height: 1.65; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: min(420px, calc(100% - 48px)); padding: 13px 18px; background: var(--ink); color: #fff; box-shadow: var(--shadow); transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { transform: none; opacity: 1; }
.toast.error { background: #8a261d; }

@media (max-width: 980px) {
  .login-panel { grid-template-columns: 1fr; min-height: auto; }
  .dashboard-grid, .workbench { grid-template-columns: 1fr; }
  .artifact-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .artifact-group .artifact-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-stack { grid-template-columns: 1fr 1fr; }
  .topbar { grid-template-columns: 220px 1fr auto; padding: 0 20px; }
}

@media (max-width: 680px) {
  .login-view { padding: 0; align-items: stretch; }
  .login-panel { padding: 28px 22px; border: 0; min-height: 100vh; }
  .login-copy h1 { font-size: 38px; }
  .topbar { height: auto; min-height: 68px; grid-template-columns: 1fr auto; padding: 10px 14px; }
  .topbar nav { grid-column: 1 / -1; order: 3; height: 46px; }
  .nav-button { flex: 1; min-height: 44px; }
  .user-menu #user-name { display: none; }
  #main-content { width: min(100% - 28px, 1320px); padding-top: 26px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .head-actions > * { flex: 1; }
  .summary-line { gap: 14px; }
  .course-row { grid-template-columns: 1fr auto; }
  .course-row .progress { display: none; }
  .stage-track { overflow-x: auto; grid-template-columns: repeat(5, 130px); }
  .artifact-list { grid-template-columns: 1fr 1fr; }
  .artifact-group .artifact-list { grid-template-columns: 1fr; }
  .side-stack, .ops-grid { grid-template-columns: 1fr; }
  .preview { min-height: 440px; }
  .preview-body { max-height: none; }
  .preview-head { align-items: flex-start; }
  .preview-tools { flex-direction: column; }
  .service-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
