:root {
  color-scheme: light;
  --bg: #eef0f2;
  --surface: #ffffff;
  --surface-soft: #f4f5f6;
  --line: #d8dde1;
  --line-strong: #bec6cc;
  --text: #111820;
  --muted: #66727e;
  --brand: #b42318;
  --brand-dark: #8f1c14;
  --charcoal: #3e4852;
  --charcoal-dark: #2f3740;
  --success: #287a5d;
  --warning: #a15c08;
  --focus-ring: rgba(180, 35, 24, 0.16);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); }
body { color: var(--text); font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", Arial, sans-serif; font-size: 14px; }
button, input { font: inherit; }

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  width: calc(100% - 24px);
  height: calc(100vh - 24px);
  min-height: 660px;
  margin: 12px auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(17, 24, 32, 0.04);
}

.topbar { display: flex; min-height: 86px; align-items: center; justify-content: space-between; gap: 24px; padding: 16px 28px; border-bottom: 1px solid var(--line); }
.brand { display: flex; min-width: 0; align-items: center; gap: 14px; }
.brand-logo { width: 52px; height: 52px; flex: 0 0 52px; border-radius: 8px; }
.brand-copy { display: flex; min-width: 0; align-items: baseline; gap: 10px; }
h1, h2, p { margin: 0; }
h1 { overflow: hidden; font-size: 22px; font-weight: 750; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
h2 { font-size: 16px; font-weight: 750; line-height: 1.35; }
.brand-copy p { color: var(--muted); font-size: 13px; }
.actions { display: flex; flex: 0 0 auto; gap: 10px; }
.button { display: inline-flex; height: 40px; min-width: 96px; align-items: center; justify-content: center; padding: 0 16px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-weight: 700; }
.button:focus-visible, .drop-zone:focus-within { outline: 3px solid var(--focus-ring); outline-offset: 1px; }
.button:disabled { cursor: not-allowed; opacity: 0.5; }
.secondary { border-color: var(--line-strong); color: var(--text); background: var(--surface); }
.secondary:hover:not(:disabled) { border-color: #959fa7; background: var(--surface-soft); }
.primary { border-color: rgba(180, 35, 24, 0.22); color: rgba(180, 35, 24, 0.62); background: rgba(180, 35, 24, 0.08); }
.primary:hover:not(:disabled) { border-color: rgba(180, 35, 24, 0.36); background: rgba(180, 35, 24, 0.13); }
.primary.is-ready { border-color: var(--brand); color: #fff; background: var(--brand); box-shadow: 0 4px 12px rgba(180, 35, 24, 0.18); }
.primary.is-ready:hover:not(:disabled) { border-color: var(--brand-dark); background: var(--brand-dark); }
.success { border-color: var(--brand); color: #fff; background: var(--brand); }
.success:hover:not(:disabled) { border-color: var(--brand-dark); background: var(--brand-dark); }

.status-row { display: grid; min-height: 66px; grid-template-columns: minmax(280px, auto) minmax(240px, 1fr); align-items: center; gap: 28px; padding: 12px 28px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.status-row.is-success { border-bottom-color: #85c9ad; background: #e6f6ef; box-shadow: inset 6px 0 0 var(--success); }
.status-row.is-success .status-label { color: #257158; font-weight: 700; }
.status-row.is-success #statusText { color: #155c43; font-size: 16px; font-weight: 800; }
.status-row.is-working { background: #fff8e9; box-shadow: inset 6px 0 0 #d58a1f; }
.status-copy { display: flex; min-width: 0; align-items: center; gap: 16px; }
.status-label { flex: 0 0 auto; color: var(--muted); font-size: 13px; }
#statusText { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.progress-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 42px; align-items: center; gap: 10px; }
progress { width: 100%; height: 7px; overflow: hidden; border: 0; border-radius: 4px; accent-color: var(--success); background: #dfe3e6; }
progress::-webkit-progress-bar { border-radius: 4px; background: #dfe3e6; }
progress::-webkit-progress-value { border-radius: 4px; background: var(--success); }
#progressText { color: var(--muted); font-size: 12px; text-align: right; }

.workspace { display: grid; min-height: 0; grid-template-columns: minmax(340px, 0.85fr) minmax(360px, 1fr) minmax(520px, 1.55fr); gap: 12px; padding: 12px; background: var(--bg); }
.panel { min-width: 0; min-height: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.panel-head { display: flex; min-height: 56px; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-head > div { display: flex; align-items: center; gap: 10px; }
.section-index { color: var(--brand); font-size: 12px; font-weight: 800; letter-spacing: 0.08em; }
.file-badge, .count-badge, .sheet-badge { overflow: hidden; max-width: 52%; padding: 5px 8px; border-radius: 999px; color: var(--muted); background: var(--surface-soft); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.input-panel { display: grid; grid-template-rows: auto auto auto minmax(0, 1fr); }
.drop-zone { display: grid; min-height: 166px; margin: 16px; place-items: center; align-content: center; gap: 8px; padding: 20px; border: 1px dashed var(--line-strong); border-radius: 8px; cursor: pointer; text-align: center; background: #fafbfb; transition: border-color 120ms ease, background 120ms ease; }
.drop-zone:hover, .drop-zone.is-dragging { border-color: var(--brand); background: #fff7f6; }
.drop-zone input { display: none; }
.drop-zone small { color: var(--muted); line-height: 1.6; }
.upload-icon { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 50%; color: #fff; background: var(--charcoal); font-size: 22px; }
.import-notice { display: flex; align-items: center; gap: 12px; margin: -6px 16px 14px; padding: 15px 16px; border: 2px solid #66b895; border-radius: 10px; color: #155c43; background: #e5f7ef; box-shadow: 0 5px 16px rgba(40, 122, 93, 0.14); }
.import-notice > span { display: grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; border-radius: 50%; color: #fff; background: var(--success); font-size: 18px; font-weight: 900; }
.import-notice div { min-width: 0; }
.import-notice strong { display: block; font-size: 16px; }
.import-notice p { overflow: hidden; margin-top: 4px; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.success-toast { position: fixed; z-index: 1000; top: clamp(90px, 18vh, 150px); left: 50%; display: flex; width: min(560px, calc(100% - 32px)); align-items: center; gap: 14px; padding: 17px 20px; border: 2px solid #4fa982; border-radius: 12px; color: #124f3b; background: #effbf6; box-shadow: 0 16px 38px rgba(24, 93, 69, 0.28); opacity: 0; transform: translate(-50%, -16px) scale(0.98); transition: opacity 180ms ease, transform 180ms ease; }
.success-toast.is-visible { opacity: 1; transform: translate(-50%, 0) scale(1); }
.success-toast-icon { display: grid; width: 42px; height: 42px; flex: 0 0 42px; place-items: center; border-radius: 50%; color: #fff; background: var(--success); font-size: 24px; font-weight: 900; box-shadow: 0 0 0 5px rgba(40, 122, 93, 0.12); }
.success-toast strong { display: block; font-size: 18px; line-height: 1.3; }
.success-toast p { margin-top: 4px; color: #326c58; font-size: 14px; line-height: 1.45; }
.rule-box { align-self: start; margin: 0 16px 16px; padding: 14px; border: 1px solid #e1e5e8; border-radius: 8px; background: var(--surface-soft); }
.rule-box strong { display: block; margin-bottom: 8px; }
.rule-box p { color: var(--muted); font-size: 12px; line-height: 1.65; }
.rule-box code { display: block; margin: 9px 0; padding: 10px; border-radius: 6px; color: #29313a; background: #e9ecef; font-family: inherit; font-weight: 750; line-height: 1.55; }

.coefficient-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.source-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 14px 14px 8px; padding: 12px; border-left: 3px solid var(--brand); background: var(--surface-soft); }
.source-card div { display: grid; gap: 4px; }
.source-card span { color: var(--muted); font-size: 12px; }
.text-link { flex: 0 0 auto; color: var(--brand); font-size: 12px; font-weight: 700; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.coefficient-grid { display: grid; align-content: start; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 4px 14px 8px; padding-right: 3px; overflow: auto; }
.coefficient-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 7px 9px; border: 1px solid #e5e8eb; border-radius: 6px; font-size: 12px; }
.coefficient-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coefficient-item span { color: var(--brand); font-weight: 750; }
.database-note { padding: 10px 14px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.5; }

.results-panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.stats div { display: grid; gap: 4px; padding: 10px; border: 1px solid #e3e6e9; border-radius: 7px; background: #fff; }
.stats span { color: var(--muted); font-size: 11px; }
.stats strong { font-size: 18px; }
.stats .ok strong { color: var(--success); }
.stats .warn strong { color: var(--warning); }
.empty-state { display: grid; place-items: center; align-content: center; gap: 8px; padding: 30px; color: var(--muted); text-align: center; }
.empty-state strong { color: #3f4852; }
.empty-state span { max-width: 520px; font-size: 12px; line-height: 1.7; }
.result-content { display: grid; min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto; }
.warnings { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.warning-chip { padding: 5px 8px; border-radius: 999px; color: var(--warning); background: #fff5e8; font-size: 11px; }
.warning-chip.ok { color: var(--success); background: #eaf7f1; }
.table-wrap { min-height: 0; overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
th { position: sticky; z-index: 1; top: 0; padding: 9px 8px; border-bottom: 1px solid var(--line-strong); color: #36404a; text-align: left; white-space: nowrap; background: #f5f6f7; }
td { max-width: 230px; padding: 8px; border-bottom: 1px solid #eceef0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.number { text-align: right; font-variant-numeric: tabular-nums; }
td.status-ok { color: var(--success); font-weight: 700; }
td.status-warn { color: var(--warning); font-weight: 700; }
.preview-note { padding: 8px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

@media (max-width: 1300px) {
  .workspace { grid-template-columns: minmax(320px, 0.9fr) minmax(340px, 1fr); grid-template-rows: 520px 520px; align-content: start; overflow: auto; }
  .results-panel { min-height: 520px; grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .app-shell { width: 100%; height: auto; min-height: 100vh; margin: 0; border: 0; border-radius: 0; }
  .topbar { align-items: flex-start; flex-direction: column; padding: 14px; }
  .brand-copy { align-items: flex-start; flex-direction: column; gap: 2px; }
  .actions { width: 100%; }
  .button { min-width: 0; flex: 1; padding: 0 8px; }
  .status-row { grid-template-columns: 1fr; gap: 10px; padding: 12px 14px; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: minmax(520px, auto); padding: 8px; overflow: visible; }
  .results-panel { grid-column: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
