﻿:root {
  --bg: #f3f6f9;
  --paper: #ffffff;
  --ink: #17212b;
  --muted: #687786;
  --line: #dbe4ec;
  --line-strong: #c4d2df;
  --blue: #1769aa;
  --blue-dark: #105284;
  --blue-soft: #e7f1fb;
  --green: #1f7a52;
  --green-soft: #e6f5ed;
  --amber: #a76300;
  --amber-soft: #fff1d2;
  --red: #b83b3b;
  --red-soft: #fff0f0;
  --shadow: 0 12px 34px rgba(27, 48, 68, .10);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: radial-gradient(circle at top left, #eaf3fb 0, transparent 32rem), var(--bg); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { width: min(100%, 1900px); margin: 0 auto; padding: 20px 22px 32px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.brand-block { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(145deg, #1769aa, #0d4774); color: #fff; font-size: 22px; font-weight: 700; box-shadow: 0 8px 20px rgba(23,105,170,.22); }
h1 { margin: 0; font-size: 24px; letter-spacing: .02em; }
.brand-block p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.save-state { display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); color: var(--muted); font-size: 13px; white-space: nowrap; }
.save-dot { width: 8px; height: 8px; border-radius: 50%; background: #92a0ad; }
.save-state[data-state="saved"] .save-dot { background: #31a46e; }
.save-state[data-state="dirty"] .save-dot, .save-state[data-state="saving"] .save-dot { background: #e5a52f; }
.save-state[data-state="error"] .save-dot { background: var(--red); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat-card { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.86); }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-card strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.stat-card strong.stat-time { font-size: 14px; font-weight: 600; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.92); box-shadow: 0 3px 12px rgba(30,60,90,.04); }
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-grow { flex: 1; }
.field-label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.search-label { margin-left: 10px; }
.control { border: 1px solid var(--line-strong); border-radius: 9px; padding: 9px 11px; background: #fff; color: var(--ink); outline: none; }
.control:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23,105,170,.12); }
.control-name { width: 110px; }
.control-search { width: min(260px, 34vw); }
.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-height: 38px; padding: 8px 13px; border-radius: 9px; border: 1px solid transparent; text-decoration: none; cursor: pointer; font-weight: 600; font-size: 13px; transition: transform .12s ease, background .12s ease, border-color .12s ease; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: #edf3f8; color: #24435b; border-color: #d9e5ef; }
.btn-secondary:hover { background: #dfebf5; }
.btn-outline { background: #fff; color: var(--blue-dark); border-color: #b8cfe2; }
.btn-outline:hover { background: var(--blue-soft); }

.conflict-bar { margin-top: 10px; display: flex; gap: 12px; align-items: center; padding: 10px 14px; border: 1px solid #e8c475; border-radius: 10px; background: var(--amber-soft); color: #6f4700; font-size: 13px; }
.conflict-bar[hidden] { display: none; }
.text-btn { border: 0; background: none; color: var(--blue-dark); font-weight: 700; text-decoration: underline; cursor: pointer; }
.danger-text { color: var(--red); }

.sheet-wrap { position: relative; margin-top: 12px; border: 1px solid var(--line-strong); border-radius: 15px; background: var(--paper); box-shadow: var(--shadow); overflow: hidden; }
.sheet-scroll { max-height: calc(100vh - 295px); min-height: 360px; overflow: auto; scrollbar-gutter: stable; }
.sheet { border-collapse: separate; border-spacing: 0; min-width: 3180px; width: max-content; font-size: 12px; }
.sheet th, .sheet td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); vertical-align: top; }
.sheet thead th { position: sticky; top: 0; z-index: 8; min-width: 92px; height: 58px; padding: 8px 7px; background: #eaf2f8; color: #26445b; font-weight: 700; text-align: center; line-height: 1.35; border-bottom-color: #c9d9e6; }
.sheet thead th.required-head::after { content: " *"; color: var(--red); }
.sheet tbody tr:nth-child(even) td { background: #fbfdff; }
.sheet tbody tr:hover td { background: #f5faff; }
.row-handle { position: sticky; left: 0; z-index: 6; width: 58px; min-width: 58px; padding: 8px 6px; background: #edf3f8 !important; text-align: center; color: var(--muted); }
.sheet thead .row-handle { z-index: 10; }
.row-number { display: block; font-weight: 700; color: #35556d; margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.delete-row { border: 0; background: transparent; color: #a04b4b; padding: 3px 5px; cursor: pointer; font-size: 11px; }
.delete-row:hover { text-decoration: underline; }

.sheet td { background: var(--paper); }
.cell-wrap { min-height: 42px; display: flex; flex-direction: column; gap: 4px; }
.cell-control { width: 100%; min-width: 0; border: 1px solid transparent; border-radius: 6px; padding: 7px 7px; background: transparent; color: inherit; outline: none; resize: vertical; line-height: 1.45; }
.cell-control:hover { border-color: #cfdce7; background: #fff; }
.cell-control:focus { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 2px rgba(23,105,170,.12); }
textarea.cell-control { min-height: 46px; }
.sheet td.missing .cell-control { border-color: #e3a3a3; background: #fffafa; }
.sheet td.missing::after { content: "必填"; color: var(--red); font-size: 10px; padding: 0 7px 5px; }
.sheet tr.filtered-out { display: none; }
.sheet tr.search-hit td { box-shadow: inset 0 0 0 2px rgba(229,165,47,.22); }
.purchase-cell { min-width: 280px; }
.generate-one { align-self: flex-start; border: 0; background: var(--blue-soft); color: var(--blue-dark); border-radius: 6px; padding: 4px 7px; cursor: pointer; font-size: 11px; }
.generate-one:hover { background: #d8eafb; }
.empty-state { padding: 60px 20px; text-align: center; color: var(--muted); }

.notes-panel { margin-top: 14px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.9); }
.notes-panel h2 { margin: 0 0 9px; font-size: 15px; }
.notes-panel ul { margin: 0; padding-left: 20px; color: #455665; line-height: 1.65; font-size: 13px; }
.footer-note { margin-top: 14px; text-align: center; color: var(--muted); font-size: 12px; }

.token-dialog { border: 0; border-radius: 16px; padding: 0; width: min(92vw, 420px); box-shadow: 0 30px 80px rgba(15,40,60,.32); }
.token-dialog::backdrop { background: rgba(15, 28, 39, .45); backdrop-filter: blur(3px); }
.token-dialog form { padding: 24px; }
.token-dialog h2 { margin: 0 0 8px; }
.token-dialog p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.token-dialog .field-label { display: block; margin-bottom: 7px; }
.token-dialog .control { width: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.dialog-error { color: var(--red) !important; margin-top: 9px !important; }

@media (max-width: 980px) {
  .app-shell { padding: 14px 10px 24px; }
  .topbar { align-items: flex-start; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-group { width: 100%; }
  .control-search { flex: 1; width: auto; min-width: 150px; }
  .sheet-scroll { max-height: calc(100vh - 390px); }
  h1 { font-size: 20px; }
}

@media (max-width: 560px) {
  .brand-mark { width: 40px; height: 40px; border-radius: 12px; font-size: 18px; }
  .brand-block p { display: none; }
  .save-state { padding: 7px 10px; font-size: 12px; }
  .stat-card { padding: 10px 11px; }
  .stat-card strong { font-size: 17px; }
  .toolbar { padding: 10px; }
  .btn { padding: 8px 10px; }
}
.sheet thead th.auto-head {
  background: #e2f0d9;
  color: #315c3b;
}
.sheet td.derived-cell {
  background: #f7fbfe !important;
}
.cell-control.derived-control {
  min-height: 54px;
  background: #f0f6fa;
  color: #405a6e;
  cursor: default;
  resize: none;
}
.cell-control.derived-control:focus {
  border-color: transparent;
  box-shadow: none;
}
.lookup-notice {
  margin-top: 10px;
  padding: 9px 13px;
  border: 1px solid #b8cfe2;
  border-radius: 9px;
  background: #eef7ff;
  color: #24435b;
  font-size: 13px;
}
.lookup-notice[hidden] { display: none; }
.lookup-notice[data-state="loading"] { border-color: #b8cfe2; background: #eef7ff; }
.lookup-notice[data-state="success"] { border-color: #a8d2bc; background: #e9f7ef; color: #1f6b48; }
.lookup-notice[data-state="error"] { border-color: #e3b0b0; background: #fff2f2; color: #9b3030; }
/* Single-record form layout */
.record-workspace {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 14px;
  margin-top: 12px;
  min-height: 620px;
}
.record-sidebar,
.record-form-panel {
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.record-sidebar { overflow: hidden; display: flex; flex-direction: column; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 15px; border-bottom: 1px solid var(--line); background: #f8fbfd; }
.sidebar-head strong { display: block; font-size: 15px; }
.sidebar-head span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.btn-small { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.sidebar-search { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.sidebar-search .control { width: 100%; }
.record-list { overflow: auto; padding: 7px; max-height: calc(100vh - 335px); }
.record-item { width: 100%; display: grid; grid-template-columns: 34px minmax(0,1fr) auto; gap: 9px; align-items: center; border: 1px solid transparent; border-radius: 10px; padding: 10px 9px; margin: 0 0 5px; background: transparent; text-align: left; color: var(--ink); cursor: pointer; }
.record-item:hover { background: #f3f8fc; border-color: #d7e5f0; }
.record-item.active { background: var(--blue-soft); border-color: #a8c9e4; box-shadow: inset 3px 0 0 var(--blue); }
.record-item-no { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: #edf3f8; color: #35556d; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.record-item-text { min-width: 0; }
.record-item-text strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.record-item-text small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; font-size: 11px; }
.record-item-state { border-radius: 999px; padding: 3px 7px; font-size: 10px; white-space: nowrap; }
.record-item-state[data-state="empty"] { background: #edf1f4; color: #697988; }
.record-item-state[data-state="warning"] { background: var(--amber-soft); color: var(--amber); }
.record-item-state[data-state="done"] { background: var(--green-soft); color: var(--green); }
.record-list-empty { padding: 32px 12px; text-align: center; color: var(--muted); font-size: 12px; }

.record-form-panel { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.form-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 18px 22px 14px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg,#fbfdff,#f5f9fc); }
.record-position { display: block; color: var(--blue-dark); font-size: 12px; font-weight: 700; }
.form-panel-head h2 { margin: 4px 0 0; font-size: 21px; }
.record-badge { padding: 6px 10px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.record-badge[data-state="empty"] { background: #edf1f4; color: #697988; }
.record-badge[data-state="warning"] { background: var(--amber-soft); color: var(--amber); }
.record-badge[data-state="done"] { background: var(--green-soft); color: var(--green); }
.form-body { flex: 1; overflow: auto; padding: 4px 22px 24px; }
.form-section { padding: 18px 0 6px; border-bottom: 1px solid var(--line); }
.form-section:last-child { border-bottom: 0; }
.form-section h3 { margin: 0 0 13px; font-size: 14px; color: #27475f; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.form-field { min-width: 0; padding: 8px; border: 1px solid transparent; border-radius: 10px; }
.form-field-wide { grid-column: 1 / -1; }
.form-field label { display: block; margin-bottom: 6px; color: #4e6170; font-size: 12px; font-weight: 700; }
.required-label::after { content: " *"; color: var(--red); }
.form-control { width: 100%; min-height: 40px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 10px; background: #fff; color: var(--ink); outline: none; resize: vertical; line-height: 1.5; }
textarea.form-control { min-height: 78px; }
.form-control:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23,105,170,.12); }
.form-control.derived-control { min-height: 86px; background: #eef5fa; color: #405a6e; resize: vertical; }
.form-field-derived { background: #f7fbfe; border-color: #dceaf4; }
.form-field.missing { border-color: #e4b4b4; background: #fff8f8; }
.form-field.missing .form-control { border-color: #d98c8c; background: #fffdfd; }
.field-hint { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 18px; border-top: 1px solid var(--line); background: #f8fbfd; }
.footer-nav, .footer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-danger-soft { color: #9b3030; background: #fff1f1; border-color: #ebc1c1; }
.btn-danger-soft:hover { background: #ffe7e7; }

@media (max-width: 1100px) {
  .record-workspace { grid-template-columns: 255px minmax(0,1fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 780px) {
  .record-workspace { display: block; }
  .record-sidebar { margin-bottom: 12px; }
  .record-list { max-height: 210px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field-wide { grid-column: auto; }
  .form-footer { align-items: flex-start; flex-direction: column; }
  .footer-nav, .footer-actions { width: 100%; }
  .footer-actions { justify-content: flex-end; }
}
/* U9-style detail grid below the form */
.entry-workspace { display: grid; gap: 14px; margin-top: 12px; }
.form-head-actions { display: flex; align-items: center; gap: 9px; }
.detail-panel { border: 1px solid var(--line-strong); border-radius: 15px; background: var(--paper); box-shadow: var(--shadow); overflow: hidden; }
.detail-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: #f8fbfd; }
.detail-panel-head > div { display: flex; align-items: baseline; gap: 10px; }
.detail-panel-head h2 { margin: 0; font-size: 16px; }
.detail-panel-head span { color: var(--muted); font-size: 12px; }
.detail-search { width: min(380px, 46vw); }
.detail-scroll { max-height: 420px; overflow: auto; scrollbar-gutter: stable; }
.detail-table { width: max-content; min-width: 3000px; border-collapse: separate; border-spacing: 0; font-size: 11px; }
.detail-table th, .detail-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: middle; max-width: 270px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-table th { position: sticky; top: 0; z-index: 4; background: #eaf2f8; color: #26445b; font-weight: 700; text-align: center; }
.detail-table tbody tr { cursor: pointer; }
.detail-table tbody tr:nth-child(even) td { background: #fbfdff; }
.detail-table tbody tr:hover td { background: #f2f8fd; }
.detail-table tbody tr.active-detail-row td { background: #e8f3fb !important; box-shadow: inset 0 2px 0 #8fc0e4, inset 0 -2px 0 #8fc0e4; }
.detail-table tbody tr:focus { outline: none; }
.detail-table tbody tr:focus td { background: #edf7ff; }
.detail-row-number { width: 52px; min-width: 52px; text-align: center !important; color: var(--muted); font-variant-numeric: tabular-nums; }
.detail-status-cell { width: 78px; min-width: 78px; text-align: center !important; }
.detail-status-badge { display: inline-block; min-width: 48px; padding: 3px 6px; border-radius: 999px; font-size: 10px; text-align: center; }
.detail-status-badge[data-state="empty"] { background: #edf1f4; color: #697988; }
.detail-status-badge[data-state="warning"] { background: var(--amber-soft); color: var(--amber); }
.detail-status-badge[data-state="done"] { background: var(--green-soft); color: var(--green); }
.detail-strong-cell { color: #183b56; font-weight: 700; }
.detail-derived-cell { color: #567286; background: #f5f9fc !important; }
.detail-empty { padding: 40px !important; text-align: center !important; color: var(--muted); }
@media (max-width: 780px) {
  .detail-panel-head { align-items: stretch; flex-direction: column; }
  .detail-search { width: 100%; }
  .form-head-actions { align-items: flex-end; flex-direction: column; }
  .detail-scroll { max-height: 330px; }
}
/* Two-tab layout */
.view-tabs {
  display: inline-flex;
  gap: 4px;
  margin-top: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #eaf1f7;
}
.view-tab {
  min-width: 94px;
  border: 0;
  border-radius: 9px;
  padding: 9px 20px;
  background: transparent;
  color: #52687a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.view-tab:hover { background: rgba(255,255,255,.72); }
.view-tab.active { background: #fff; color: var(--blue-dark); box-shadow: 0 2px 8px rgba(24,60,90,.12); }
.tab-view[hidden] { display: none !important; }
.entry-workspace { margin-top: 10px; }
.list-tip { padding: 9px 14px; border-top: 1px solid var(--line); background: #f8fbfd; color: var(--muted); font-size: 11px; text-align: right; }
.tab-view .detail-scroll { max-height: max(360px, calc(100vh - 340px)); }
.detail-table { min-width: max-content; }
.form-panel-head { border-radius: 15px 15px 0 0; }
@media (max-width: 780px) {
  .view-tabs { display: flex; width: 100%; }
  .view-tab { flex: 1; }
  .tab-view .detail-scroll { max-height: 430px; }
}
