:root {
  --ink: #17384c;
  --ink-soft: #456271;
  --paper: #f5f7f5;
  --sheet: #ffffff;
  --line: #c8d1d2;
  --line-dark: #8fa1a5;
  --safety: #ffd43b;
  --safety-deep: #c99d00;
  --signal: #be3f35;
  --success: #17765e;
  --mist: #e7edef;
  --shadow: 0 14px 38px rgba(32, 61, 73, .09);
  --radius: 8px;
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(23, 56, 76, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 56, 76, .025) 1px, transparent 1px);
  background-size: 28px 28px;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px clamp(18px, 4vw, 56px);
  color: white;
  background: rgba(23, 56, 76, .97);
  border-bottom: 4px solid var(--safety);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  color: white;
  text-decoration: none;
}
.brand strong { display: block; font-size: 18px; letter-spacing: .02em; }
.brand small { display: block; margin-top: 1px; color: #cbd8dc; font-size: 11px; }
.brand-mark { position: relative; width: 34px; height: 34px; display: grid; gap: 3px; padding: 6px; border: 2px solid white; }
.brand-mark i { display: block; height: 3px; background: var(--safety); transform-origin: left; }
.brand-mark i:nth-child(2) { width: 72%; }
.brand-mark i:nth-child(3) { width: 44%; }

.page-shell { width: min(1180px, calc(100% - 36px)); margin: 0 auto; padding: 42px 0 80px; }
.page-heading, .project-banner, .generator-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(30px, 5vw, 48px); line-height: 1.12; letter-spacing: -.04em; }
h2 { margin-bottom: 9px; font-size: clamp(24px, 3vw, 32px); line-height: 1.2; letter-spacing: -.025em; }
h3 { margin-bottom: 4px; font-size: 19px; line-height: 1.35; }
p { color: var(--ink-soft); line-height: 1.7; }
.document-code { margin-bottom: 9px; color: var(--ink); font-size: 13px; font-weight: 700; }

.primary-button, .secondary-button, .quiet-button, .icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .12s ease, background-color .12s ease, opacity .12s ease;
}
.primary-button { padding: 0 22px; color: #142b37; background: var(--safety); box-shadow: 0 4px 0 var(--safety-deep); }
.primary-button:hover { background: #ffdf67; }
.primary-button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--safety-deep); }
.primary-button:disabled { cursor: not-allowed; opacity: .42; box-shadow: none; transform: none; }
.secondary-button { padding: 0 22px; color: white; background: var(--ink); box-shadow: 0 4px 0 #0c2737; }
.quiet-button { padding: 0 16px; color: inherit; background: transparent; border: 1px solid currentColor; }
.topbar .quiet-button { color: #dce6e8; border-color: #78909a; }
.icon-button { width: 44px; padding: 0; color: var(--ink); background: transparent; font-size: 28px; }
.wide { width: 100%; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(255, 212, 59, .8); outline-offset: 2px; }

.project-list { margin-top: 38px; border-top: 2px solid var(--ink); }
.project-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 96px;
  padding: 18px 10px;
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.project-row:hover { background: rgba(255, 255, 255, .78); }
.project-index { color: var(--line-dark); font-weight: 700; font-variant-numeric: tabular-nums; }
.project-main strong, .project-main small { display: block; }
.project-main strong { margin-bottom: 6px; font-size: 19px; }
.project-main small { overflow: hidden; color: var(--ink-soft); text-overflow: ellipsis; white-space: nowrap; }
.project-status { padding: 5px 9px; color: #7a5e00; background: #fff3be; border-left: 4px solid var(--safety); font-size: 12px; font-weight: 700; }
.project-status.ready { color: #0f5c49; background: #dff3eb; border-color: var(--success); }

.empty-state { position: relative; overflow: hidden; margin-top: 42px; padding: 64px clamp(24px, 7vw, 72px); background: white; border: 1px solid var(--line); box-shadow: var(--shadow); }
.empty-state > * { position: relative; max-width: 560px; }
.empty-grid { position: absolute; inset: 0 0 0 64%; opacity: .25; background: repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 22px), repeating-linear-gradient(var(--ink) 0 1px, transparent 1px 22px); }

.breadcrumb { display: flex; gap: 9px; align-items: center; margin-bottom: 24px; color: var(--ink-soft); font-size: 13px; }
.breadcrumb a { text-decoration-thickness: 1px; text-underline-offset: 3px; }
.project-banner { padding-bottom: 27px; border-bottom: 2px solid var(--ink); }
.project-banner h1 { font-size: clamp(28px, 4vw, 42px); }
.project-banner p:last-child { margin-bottom: 0; }

.source-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin-top: 24px;
  padding: 18px 20px;
  background: #e7eef0;
  border-left: 6px solid var(--ink);
}
.source-strip span, .source-strip strong, .source-strip small { display: block; }
.source-strip span { color: var(--ink-soft); font-size: 12px; }
.source-strip strong { margin: 4px 0; word-break: break-all; }
.source-strip small { color: var(--ink-soft); }
.file-button { display: inline-flex; align-items: center; white-space: nowrap; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.upload-sheet { display: grid; grid-template-columns: 1.1fr .9fr; gap: 46px; margin-top: 36px; padding: 42px; background: white; border: 1px solid var(--line); box-shadow: var(--shadow); }
.sheet-corner { display: inline-block; margin-bottom: 22px; padding: 6px 10px; background: var(--safety); font-size: 12px; font-weight: 700; }
.upload-form { display: flex; flex-direction: column; gap: 18px; }
.file-drop { min-height: 170px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; border: 2px dashed var(--line-dark); background: var(--paper); cursor: pointer; }
.file-drop:hover { border-color: var(--ink); }
.file-drop input { position: absolute; opacity: 0; pointer-events: none; }
.file-drop-title { font-weight: 700; }
.file-drop-name { margin-top: 8px; color: var(--ink-soft); font-size: 13px; }

.generator { margin-top: 34px; }
.generator-heading { align-items: center; margin-bottom: 24px; }
.generator-heading p:last-child { margin-bottom: 0; }
.date-ticket { position: relative; min-width: 180px; padding: 11px 14px 12px; background: var(--safety); font-size: 12px; font-weight: 700; }
.date-ticket::after { content: ""; position: absolute; right: 0; bottom: 0; border-style: solid; border-width: 0 0 18px 18px; border-color: transparent transparent var(--paper) transparent; }
.date-ticket input { width: 100%; margin-top: 6px; padding: 0; color: var(--ink); background: transparent; border: 0; font-size: 17px; font-weight: 700; }

.unit-stack { display: grid; gap: 22px; }
.unit-sheet { background: white; border: 1px solid var(--line); box-shadow: var(--shadow); }
.unit-sheet > header { display: flex; align-items: center; gap: 15px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.unit-sheet > header p { margin: 0; font-size: 12px; }
.unit-number { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; color: white; background: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.message-input { display: block; width: calc(100% - 40px); margin: 20px; padding: 17px; resize: vertical; color: #243f4f; background: #fbfcfa; border: 1px solid var(--line); border-radius: 3px; line-height: 1.75; }
.message-input::placeholder { color: #819498; }

.parse-result { margin: 0 20px 20px; padding-top: 18px; border-top: 2px solid var(--ink); }
.review-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.review-heading h4 { margin: 0; font-size: 17px; }
.review-heading span { color: var(--ink-soft); font-size: 12px; }
.people-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.people-table th, .people-table td { padding: 10px 8px; text-align: center; border-bottom: 1px solid var(--line); }
.people-table th:first-child, .people-table td:first-child { text-align: left; }
.people-table th { color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.people-table input[type="number"] { width: 64px; min-height: 40px; padding: 6px; text-align: center; border: 1px solid var(--line); border-radius: 3px; }
.people-table tfoot th, .people-table tfoot td { color: var(--ink); background: #eef2f2; font-weight: 800; }
.cell-error { color: var(--signal); background: #fae5e2; font-weight: 800; }
.change-editor { display: grid; grid-template-columns: 120px 88px 1fr 1fr; gap: 10px; align-items: center; margin-top: 12px; }
.change-editor strong { font-size: 13px; }
.change-editor input { min-width: 0; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 3px; }
.change-editor input[type="number"] { text-align: center; }
.change-editor input:focus { border-color: var(--ink); }
.change-heading { margin: 22px 0 8px; color: var(--ink); font-size: 14px; }
.notice-list { margin: 18px 0 0; padding: 13px 16px 13px 36px; color: #755b00; background: #fff7d5; border-left: 4px solid var(--safety); font-size: 13px; line-height: 1.65; }
.balance-ok { display: inline-block; margin-top: 16px; padding: 6px 9px; color: #0c654f; background: #e0f4ec; font-size: 12px; font-weight: 700; }
.balance-error { color: var(--signal); background: #fae5e2; }

.generator-actions { position: sticky; bottom: 0; z-index: 20; display: flex; justify-content: flex-end; gap: 12px; margin-top: 22px; padding: 15px; background: rgba(245, 247, 245, .94); border-top: 1px solid var(--line); backdrop-filter: blur(10px); }
.generation-result { margin-top: 18px; padding: 19px; color: #0d5f4b; background: #e2f4ed; border-left: 5px solid var(--success); }
.generation-result a { font-weight: 800; text-underline-offset: 4px; }

.history-section { margin-top: 52px; }
.history-section > header { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 12px; border-bottom: 2px solid var(--ink); }
.history-section > header h2 { margin: 0; }
.history-list a { display: grid; grid-template-columns: 110px 1fr auto; gap: 16px; align-items: center; padding: 16px 8px; text-decoration: none; border-bottom: 1px solid var(--line); }
.history-list a:hover { background: white; }
.history-list span, .history-list small { color: var(--ink-soft); font-size: 12px; }
.history-list strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.plan-dialog { width: min(560px, calc(100% - 28px)); padding: 0; color: var(--ink); background: white; border: 0; box-shadow: 0 24px 80px rgba(19, 45, 60, .24); }
.plan-dialog::backdrop { background: rgba(17, 39, 51, .58); backdrop-filter: blur(3px); }
.plan-dialog form { padding: 26px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; border-bottom: 2px solid var(--ink); }
.dialog-heading h2 { margin-bottom: 14px; }
.plan-dialog label, .login-form label { display: grid; gap: 7px; margin-bottom: 17px; color: var(--ink); font-size: 13px; font-weight: 700; }
.plan-dialog input, .login-form input { min-height: 46px; padding: 10px 12px; color: var(--ink); background: #fbfcfa; border: 1px solid var(--line); border-radius: 3px; }
.two-column-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-help { margin: -4px 0 19px; font-size: 12px; }
.form-error { padding: 9px 11px; color: #8d2921; background: #fae5e2; border-left: 4px solid var(--signal); font-size: 13px; }

.login-body { background-color: #17384c; background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px); }
.login-body .page-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px 0; }
.login-sheet { position: relative; width: min(980px, 100%); display: grid; grid-template-columns: 1.15fr .85fr; overflow: hidden; background: var(--sheet); box-shadow: 0 30px 100px rgba(0, 0, 0, .28); }
.login-rule { position: absolute; top: 0; left: 0; right: 0; height: 10px; background: repeating-linear-gradient(90deg, var(--safety) 0 30px, var(--ink) 30px 42px); }
.login-copy { min-height: 500px; display: flex; flex-direction: column; justify-content: center; padding: clamp(38px, 7vw, 78px); background-image: linear-gradient(rgba(23,56,76,.045) 1px, transparent 1px), linear-gradient(90deg, rgba(23,56,76,.045) 1px, transparent 1px); background-size: 26px 26px; }
.login-copy h1 { max-width: 650px; font-size: clamp(34px, 5vw, 58px); }
.login-copy p:last-child { max-width: 560px; }
.login-form { display: flex; flex-direction: column; justify-content: center; padding: clamp(34px, 6vw, 62px); background: #edf2f2; border-left: 1px solid var(--line); }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 90; max-width: min(420px, calc(100% - 40px)); padding: 14px 16px; color: white; background: var(--ink); border-left: 5px solid var(--safety); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #7e2f2a; border-color: #ff9e8f; }

@media (max-width: 760px) {
  .topbar { min-height: 64px; padding: 9px 16px; }
  .brand small { display: none; }
  .page-shell { width: min(100% - 24px, 680px); padding-top: 26px; }
  .page-heading, .project-banner, .generator-heading { align-items: stretch; flex-direction: column; }
  .page-heading .primary-button, .project-banner .quiet-button { width: 100%; }
  .project-row { grid-template-columns: 38px minmax(0, 1fr); min-height: 88px; }
  .project-status { grid-column: 2; justify-self: start; }
  .upload-sheet { grid-template-columns: 1fr; gap: 16px; padding: 25px 20px; }
  .source-strip { align-items: stretch; flex-direction: column; }
  .replace-form, .file-button { width: 100%; justify-content: center; }
  .date-ticket { width: 100%; }
  .message-input { width: calc(100% - 28px); margin: 14px; min-height: 240px; }
  .parse-result { margin: 0 14px 14px; overflow-x: auto; }
  .people-table { min-width: 520px; }
  .change-editor { grid-template-columns: 1fr 72px; }
  .change-editor input:nth-of-type(2), .change-editor input:nth-of-type(3) { grid-column: 1 / -1; }
  .generator-actions { margin-left: -12px; margin-right: -12px; padding: 13px 12px calc(13px + env(safe-area-inset-bottom)); }
  .generator-actions > * { flex: 1; padding-left: 10px; padding-right: 10px; }
  .history-list a { grid-template-columns: 1fr auto; }
  .history-list span { grid-column: 1 / -1; }
  .two-column-fields { grid-template-columns: 1fr; gap: 0; }
  .login-sheet { grid-template-columns: 1fr; }
  .login-copy { min-height: auto; padding: 56px 26px 32px; }
  .login-copy h1 { font-size: 34px; }
  .login-form { padding: 30px 26px 34px; border-left: 0; border-top: 1px solid var(--line); }
}

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