:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --text: #17211d;
  --muted: #6d7873;
  --line: #dfe5e2;
  --line-strong: #c9d3ce;
  --green: #167c5a;
  --green-dark: #0d6346;
  --green-soft: #e8f5ef;
  --amber: #a85d00;
  --amber-soft: #fff3dc;
  --red: #b33c35;
  --red-soft: #fceceb;
  --blue: #27678f;
  --blue-soft: #eaf2f8;
  --shadow: 0 12px 34px rgba(24, 39, 32, .08);
  --radius: 8px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
svg { width: 18px; height: 18px; stroke-width: 1.8; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  grid-template-rows: 68px minmax(0, 1fr);
  grid-template-areas: "top top" "side main";
}

.topbar {
  grid-area: top;
  position: sticky;
  top: 0;
  z-index: 30;
  height: 68px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
}

.brand-block, .top-actions, .page-heading, .section-title, .page-footer, .modal-header, .modal-actions {
  display: flex;
  align-items: center;
}

.brand-block { gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--green);
  border-radius: 6px;
  font-weight: 800;
}
.brand-block strong { display: block; font-size: 15px; }
.brand-block span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { gap: 10px; }
.model-state { display: flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 12px; }
.model-state span { width: 7px; height: 7px; border-radius: 50%; background: #c58a24; }
.model-state.online span { background: var(--green); }

.sidebar {
  grid-area: side;
  position: sticky;
  top: 68px;
  height: calc(100vh - 68px);
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  background: #202b27;
  color: #e7ece9;
}
.sidebar nav { display: grid; gap: 6px; }
.step {
  position: relative;
  width: 100%;
  min-height: 52px;
  padding: 0 12px;
  display: grid;
  grid-template-columns: 22px 22px 1fr;
  gap: 9px;
  align-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #aeb8b3;
  text-align: left;
}
.step span { display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid #58645f; border-radius: 50%; font-size: 11px; }
.step b { font-size: 14px; font-weight: 600; }
.step.active { background: #31423b; color: #fff; }
.step.active span { border-color: #6fc5a4; background: var(--green); }
.step.done span { color: transparent; background: var(--green); border-color: var(--green); }
.step.done span::after { content: "✓"; color: white; position: absolute; }
.sidebar-foot { margin-top: auto; padding: 13px 12px; border-top: 1px solid #3a4742; }
.sidebar-foot span, .sidebar-foot small { display: block; }
.sidebar-foot span { font-size: 12px; }
.sidebar-foot small { margin-top: 3px; color: #93a09a; font-size: 11px; }

.workspace { grid-area: main; min-width: 0; padding: 28px clamp(20px, 3.5vw, 52px) 40px; }
.page { display: none; max-width: 1560px; margin: 0 auto; }
.page.active { display: block; animation: pageIn .18s ease-out; }
@keyframes pageIn { from { opacity: .5; transform: translateY(5px); } }
.page-heading { justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-heading h1 { margin: 2px 0 6px; font-size: 28px; line-height: 1.15; }
.page-heading p:not(.eyebrow) { margin: 0; color: var(--muted); font-size: 14px; }
.eyebrow { margin: 0; color: var(--green); font-size: 11px; font-weight: 800; }

.primary-button, .secondary-button, .text-button, .icon-button {
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 6px;
  font-weight: 650;
  white-space: nowrap;
}
.primary-button { padding: 0 16px; color: white; background: var(--green); box-shadow: 0 5px 14px rgba(22,124,90,.16); }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { padding: 0 14px; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); }
.secondary-button:hover { border-color: #98aaa1; }
.text-button { min-height: 32px; padding: 0 7px; color: var(--muted); background: transparent; }
.icon-button { width: 40px; padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--line); }
.compact { min-height: 36px; padding-left: 12px; padding-right: 12px; font-size: 13px; }
.full { width: 100%; }

.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.upload-zone {
  min-height: 196px;
  padding: 25px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px dashed #aab8b1;
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.upload-zone:hover, .upload-zone.dragging { border-color: var(--green); background: #fbfdfc; }
.upload-zone input { display: none; }
.upload-zone strong { margin-top: 12px; font-size: 15px; }
.upload-zone small { margin-top: 5px; color: var(--muted); font-size: 12px; }
.upload-zone em { margin-top: 14px; color: var(--green); font-size: 12px; font-style: normal; font-weight: 700; }
.upload-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 6px; }
.upload-icon svg { width: 23px; height: 23px; }
.upload-icon.excel { color: var(--green); background: var(--green-soft); }
.upload-icon.image { color: var(--blue); background: var(--blue-soft); }

.section-block, .data-panel, .settlement-list, .total-panel { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.section-block { padding: 18px; }
.section-title { justify-content: space-between; gap: 16px; }
.section-title h2 { margin: 0; font-size: 16px; }
.section-title p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.evidence-strip { min-height: 118px; margin-top: 15px; display: flex; gap: 10px; overflow-x: auto; padding-bottom: 3px; }
.evidence-card { position: relative; flex: 0 0 150px; height: 110px; overflow: hidden; border-radius: 6px; background: #edf1ef; border: 1px solid var(--line); }
.evidence-card img { width: 100%; height: 100%; object-fit: cover; }
.evidence-card span { position: absolute; left: 6px; right: 6px; bottom: 6px; padding: 4px 6px; overflow: hidden; border-radius: 4px; background: rgba(20,29,25,.82); color: white; font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.empty-inline { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; color: #9aa59f; font-size: 13px; }
.notes-row { margin-top: 18px; display: grid; grid-template-columns: 1.4fr .6fr; gap: 16px; }
.notes-row label, .form-grid label, .total-panel label { display: block; }
.notes-row label > span, .form-grid label > span, .total-panel label > span { display: block; margin-bottom: 7px; color: #4f5b55; font-size: 12px; font-weight: 700; }
textarea, input, select { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; background: white; color: var(--text); outline: none; }
textarea { min-height: 92px; padding: 11px 12px; resize: vertical; }
input, select { height: 40px; padding: 0 11px; }
textarea:focus, input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,124,90,.08); }
.workbook-summary { min-height: 116px; padding: 16px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid #cbdde7; border-radius: var(--radius); background: #f1f7fa; color: #42677c; font-size: 13px; line-height: 1.6; }
.page-footer { justify-content: space-between; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.footer-actions { display: flex; align-items: center; gap: 10px; }
.footer-hint { color: var(--muted); font-size: 11px; }

.metric-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.analysis-progress { margin-bottom: 14px; padding: 15px 17px; border: 1px solid #bcd8ca; border-radius: var(--radius); background: #f5fbf8; }
.analysis-progress[hidden] { display: none; }
.progress-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.progress-head strong, .progress-head span { display: block; }
.progress-head strong { font-size: 13px; }
.progress-head span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.progress-actions { display: flex; align-items: center; gap: 10px; }
.progress-actions b { color: var(--green-dark); font-size: 18px; font-variant-numeric: tabular-nums; }
.progress-track { height: 7px; margin-top: 12px; overflow: hidden; border-radius: 999px; background: #dce9e3; }
.progress-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green); transition: width .3s ease; }
.progress-stages { margin-top: 8px; display: grid; grid-template-columns: repeat(4, 1fr); color: #8a9690; font-size: 10px; }
.progress-stages span:nth-child(2), .progress-stages span:nth-child(3) { text-align: center; }
.progress-stages span:last-child { text-align: right; }
.progress-stages span.active { color: var(--green-dark); font-weight: 750; }
.metric-row > div { padding: 15px 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric-row span, .metric-row strong { display: block; }
.metric-row span { color: var(--muted); font-size: 12px; }
.metric-row strong { margin-top: 7px; font-size: 24px; }
.metric-row strong.green { color: var(--green); }
.metric-row strong.amber { color: var(--amber); }
.table-toolbar { min-height: 58px; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.segmented { display: inline-flex; padding: 3px; border-radius: 6px; background: #edf1ef; }
.segmented button { min-height: 30px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 12px; }
.segmented button.active { color: var(--text); background: white; box-shadow: 0 1px 4px rgba(20,30,25,.1); }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { height: 43px; padding: 0 12px; background: #f8faf9; color: #66716c; font-size: 11px; text-align: left; white-space: nowrap; }
td { min-height: 56px; padding: 10px 12px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
td input, td select { height: 34px; min-width: 84px; font-size: 12px; }
td .delete-row { width: 30px; height: 30px; border: 0; background: transparent; color: #8c9791; border-radius: 4px; }
td .delete-row:hover { color: var(--red); background: var(--red-soft); }
.recognition-table { min-width: 1080px; }
.recognition-table th:nth-child(1) { width: 9%; }
.recognition-table th:nth-child(2) { width: 14%; }
.recognition-table th:nth-child(3) { width: 25%; }
.recognition-table th:nth-child(4) { width: 9%; }
.recognition-table th:nth-child(5) { width: 12%; }
.recognition-table th:nth-child(6) { width: 12%; }
.recognition-table th:nth-child(7) { width: 9%; }
.recognition-table th:nth-child(8) { width: 8%; }
.recognition-table th:nth-child(9) { width: 42px; }
.price-cell input { text-align: right; }
.price-cell small { display: block; margin-top: 4px; color: var(--green-dark); font-size: 10px; font-weight: 750; text-align: right; }
.confidence { display: flex; align-items: center; gap: 7px; }
.confidence span { width: 52px; height: 5px; overflow: hidden; border-radius: 99px; background: #e6ebe8; }
.confidence i { display: block; height: 100%; background: var(--green); }
.confidence b { font-size: 11px; }
.status-pill, .difference-pill, .ready-badge { display: inline-flex; align-items: center; justify-content: center; gap: 5px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-pill { min-height: 26px; padding: 0 9px; }
.status-pill.matched { color: var(--green-dark); background: var(--green-soft); }
.status-pill.review { color: var(--amber); background: var(--amber-soft); }
.search-box { width: min(320px, 40vw); position: relative; }
.search-box svg { position: absolute; left: 11px; top: 11px; color: #84908a; }
.search-box input { padding-left: 37px; }
.compare-table table { min-width: 1080px; }
.compare-table th:nth-child(1) { width: 27%; }
.compare-table th:nth-child(2) { width: 9%; }
.compare-table th:nth-child(3) { width: 10%; }
.compare-table th:nth-child(4) { width: 11%; }
.compare-table th:nth-child(5) { width: 8%; }
.compare-table th:nth-child(6) { width: 10%; }
.compare-table th:nth-child(7) { width: 12%; }
.compare-table th:nth-child(8) { width: 13%; }
.compare-table td input, .compare-table td select { height: 34px; }
.compare-table .quantity-edit { width: 92px; }
.status-pill.missing { color: var(--amber); background: var(--amber-soft); }
.status-pill.new { color: var(--blue); background: var(--blue-soft); }
.product-cell strong, .product-cell span { display: block; }
.product-cell span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.product-cell .status-pill { display: inline-flex; margin: 0 0 0 6px; vertical-align: middle; }
.difference-pill { min-width: 44px; min-height: 24px; padding: 0 7px; }
.difference-pill.plus { color: var(--green); background: var(--green-soft); }
.difference-pill.minus { color: var(--red); background: var(--red-soft); }
.difference-pill.same { color: #68736e; background: #edf1ef; }
.money { font-variant-numeric: tabular-nums; font-weight: 700; }

.settlement-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.settlement-list { margin-top: 0; padding: 18px; }
.settlement-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; min-height: 64px; border-bottom: 1px solid var(--line); }
.settlement-row:last-child { border-bottom: 0; }
.settlement-row strong, .settlement-row span { display: block; }
.settlement-row span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.settlement-row em { font-style: normal; font-weight: 750; }
.total-panel { position: sticky; top: 88px; margin-top: 0; padding: 20px; box-shadow: var(--shadow); }
.total-panel > div, .total-panel > label { min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.total-panel > div span, .total-panel > label > span { color: var(--muted); font-size: 12px; }
.total-panel > label > span { margin: 0; }
.percent-input { display: flex; align-items: center; width: 86px; }
.percent-input input { height: 34px; border-radius: 5px 0 0 5px; text-align: right; }
.percent-input b { height: 34px; padding: 0 8px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 5px 5px 0; color: var(--muted); font-size: 11px; }
.total-panel .grand-total { margin: 8px -20px 18px; padding: 18px 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #f7faf8; }
.grand-total strong { color: var(--green-dark); font-size: 24px; }
.total-panel > small { margin-top: 12px; display: flex; align-items: center; justify-content: center; gap: 5px; color: var(--muted); font-size: 10px; }
.ready-badge { min-height: 32px; padding: 0 11px; color: var(--green-dark); background: var(--green-soft); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(17, 27, 23, .48); }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(720px, 100%); max-height: calc(100vh - 36px); overflow-y: auto; padding: 22px; border-radius: var(--radius); background: white; box-shadow: 0 30px 80px rgba(12,22,17,.28); }
.modal-header { justify-content: space-between; margin-bottom: 20px; }
.modal-header h2 { margin: 3px 0 0; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid textarea { min-height: 210px; font-size: 12px; line-height: 1.55; }
.secret-input { display: grid; grid-template-columns: 1fr 40px; }
.secret-input input { border-radius: 6px 0 0 6px; }
.secret-input button { border: 1px solid var(--line-strong); border-left: 0; border-radius: 0 6px 6px 0; background: #f8faf9; color: var(--muted); }
.security-note { margin-top: 15px; padding: 11px 12px; display: flex; align-items: center; gap: 8px; border-radius: 6px; color: #4d6d5f; background: var(--green-soft); font-size: 11px; }
.modal-actions { justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 380px; padding: 12px 14px; display: flex; align-items: center; gap: 9px; border-radius: 6px; color: white; background: #24312c; box-shadow: var(--shadow); font-size: 12px; animation: toastIn .18s ease-out; }
.toast.error { background: #8f302b; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 76px minmax(0,1fr); }
  .sidebar { padding-left: 9px; padding-right: 9px; }
  .step { grid-template-columns: 1fr; justify-items: center; padding: 8px 4px; gap: 4px; }
  .step span { display: none; }
  .step b { font-size: 10px; }
  .sidebar-foot { display: none; }
  .workspace { padding: 24px 20px 36px; }
  .notes-row, .settlement-layout { grid-template-columns: 1fr; }
  .total-panel { position: static; }
}

@media (min-width: 1800px) {
  .workspace { padding: 34px 64px 48px; }
  .page { max-width: min(2100px, calc(100vw - 360px)); }
  .page-heading { margin-bottom: 26px; }
  .upload-grid { gap: 20px; }
  .upload-zone { min-height: 220px; }
  .section-block, .data-panel, .settlement-list, .total-panel { margin-top: 20px; }
  .metric-row { gap: 16px; }
}

@media (max-width: 640px) {
  body { padding-bottom: 72px; }
  .app-shell { display: block; }
  .topbar { height: 62px; padding: 0 13px; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .brand-block strong { font-size: 13px; }
  .brand-block span { max-width: 150px; }
  .model-state { display: none; }
  .top-actions .primary-button { display: none; }
  .sidebar { position: fixed; inset: auto 0 0 0; z-index: 50; height: 66px; padding: 5px 8px max(5px, env(safe-area-inset-bottom)); border-top: 1px solid #31423b; }
  .sidebar nav { height: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
  .step { min-height: 50px; grid-template-columns: 1fr; gap: 2px; border-radius: 4px; }
  .step svg { width: 19px; height: 19px; }
  .workspace { padding: 20px 13px 26px; }
  .page-heading { align-items: flex-start; margin-bottom: 17px; }
  .page-heading h1 { font-size: 23px; }
  .page-heading > button, .search-box { flex: 0 0 auto; }
  .page-heading p:not(.eyebrow) { max-width: 95%; font-size: 12px; }
  .page-heading .secondary-button { width: 38px; padding: 0; font-size: 0; }
  .upload-grid { grid-template-columns: 1fr; gap: 10px; }
  .upload-zone { min-height: 150px; padding: 18px; }
  .notes-row { gap: 10px; }
  .metric-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .analysis-progress { padding: 13px; }
  .progress-head { align-items: flex-start; }
  .progress-actions { gap: 4px; }
  .progress-actions .text-button { font-size: 11px; }
  .metric-row > div { padding: 12px; }
  .metric-row strong { font-size: 20px; }
  .table-toolbar { padding: 9px; }
  .segmented button { padding: 0 9px; }
  table { min-width: 820px; }
  .compare-table table { min-width: 760px; }
  .data-panel { margin-left: -13px; margin-right: -13px; border-left: 0; border-right: 0; border-radius: 0; }
  .search-box { width: 38px; }
  .search-box input { padding: 0; color: transparent; background: transparent; border: 0; }
  .settlement-list { padding: 15px; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { width: 100%; max-height: 92vh; border-radius: 8px 8px 0 0; padding: 18px 15px calc(18px + env(safe-area-inset-bottom)); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .modal-actions { position: sticky; bottom: 0; padding-top: 12px; background: white; }
  .toast-region { left: 12px; right: 12px; bottom: 80px; }
  .toast { min-width: 0; max-width: none; }
  .page-footer { align-items: stretch; gap: 10px; }
  .footer-hint { display: none; }
  .footer-actions { width: 100%; display: grid; grid-template-columns: .8fr 1.2fr; }
  .footer-actions button { width: 100%; padding-left: 9px; padding-right: 9px; }
}

@media (max-width: 700px) {
  .recognition-table { min-width: 0; display: block; padding: 10px; }
  .recognition-table thead { display: none; }
  .recognition-table tbody { display: grid; gap: 10px; }
  .recognition-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: white; }
  .recognition-table td { min-height: 0; padding: 0; border: 0; display: block; }
  .recognition-table td::before { content: attr(data-label); display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; }
  .recognition-table td:nth-child(2), .recognition-table td:nth-child(3), .recognition-table td:nth-child(6) { grid-column: 1 / -1; }
  .recognition-table td:nth-child(7), .recognition-table td:nth-child(8) { align-self: end; }
  .recognition-table td:last-child { position: absolute; right: 18px; margin-top: -5px; }
  .recognition-table tr { position: relative; }
  .recognition-table td:last-child::before { display: none; }
  .recognition-table input, .recognition-table select { width: 100%; }
  .price-cell { display: grid !important; grid-template-columns: 1fr auto; align-items: end; gap: 10px; }
  .price-cell::before { grid-column: 1 / -1; }
  .price-cell small { margin: 0 34px 9px 0; font-size: 12px; }
}

/* Evidence preview and saved settlement archive */
.evidence-card { appearance: none; padding: 0; text-align: left; cursor: zoom-in; color: inherit; font: inherit; transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease; }
.evidence-card:hover, .evidence-card:focus-visible { border-color: var(--green); box-shadow: 0 0 0 3px rgba(25, 126, 91, .12); transform: translateY(-2px); outline: none; }
.preview-backdrop { background: rgba(8, 15, 12, .82); }
.image-preview-modal { position: relative; display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; align-items: center; gap: 14px; width: min(1180px, 96vw); height: min(860px, 92vh); }
.image-preview-modal figure { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; height: 100%; margin: 0; }
.image-preview-modal img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.image-preview-modal figcaption { padding-top: 12px; color: white; text-align: center; font-size: 13px; }
.image-preview-modal .icon-button { border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.12); color: white; }
.preview-close { position: absolute; z-index: 2; top: 0; right: 0; }
.preview-nav { width: 44px; height: 44px; }
.settlements-modal { width: min(820px, 100%); }
.settlements-hint { margin: -10px 0 16px; color: var(--muted); font-size: 12px; }
.settlements-list { display: grid; gap: 8px; }
.saved-settlement { display: flex; align-items: center; gap: 16px; min-height: 78px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fbfcfb; }
.saved-settlement-main { min-width: 0; flex: 1; }
.saved-settlement strong, .saved-settlement span, .saved-settlement small { display: block; }
.saved-settlement span { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.saved-settlement small { margin-top: 6px; color: var(--muted); font-size: 11px; }
.saved-settlement a { flex: 0 0 auto; text-decoration: none; }

@media (max-width: 640px) {
  .history-button span { display: none; }
  .history-button { width: 38px; padding: 0; }
  .image-preview-modal { grid-template-columns: 38px minmax(0, 1fr) 38px; gap: 5px; width: 100%; height: 88vh; }
  .preview-close { top: 8px; right: 8px; }
  .preview-nav { width: 36px; height: 36px; }
  .saved-settlement { align-items: flex-start; }
  .saved-settlement a { width: 38px; padding: 0; font-size: 0; }
}
.archive-step { margin-top: 8px; border-top: 1px solid #3a4742; }
@media (max-width: 640px) {
  .sidebar nav { grid-template-columns: repeat(6, 1fr); }
  .archive-step { margin-top: 0; border-top: 0; }
}

.settlements-panel { margin-top: 0; padding: 12px; }
.settlements-page .settlements-list { gap: 0; }
.settlements-page .saved-settlement { min-height: 92px; border-width: 0 0 1px; border-radius: 0; background: white; }
.settlements-page .saved-settlement:last-child { border-bottom: 0; }
.saved-name-field { display: block; }
.saved-name-field span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; }
.saved-name-field input { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: white; font: inherit; font-size: 13px; }
.saved-name-field input:focus { border-color: var(--green); outline: 2px solid rgba(25,126,91,.12); }
.saved-settlement-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.danger-button { height: 36px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid #c53d34; border-radius: 5px; background: #c53d34; color: white; font-weight: 700; }
.delete-action { color: #a33a32; }

@media (max-width: 700px) {
  .settlements-panel { margin-left: -13px; margin-right: -13px; padding: 6px 13px; border-left: 0; border-right: 0; border-radius: 0; }
  .settlements-page .saved-settlement { display: block; padding: 14px 0; }
  .saved-settlement-actions { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr 1fr; }
  .saved-settlement-actions > * { width: 100%; }
}
/* Login and project archive */
.login-body { min-height: 100vh; margin: 0; display: grid; place-items: center; padding: 24px; background: #202b27; color: var(--ink); }
.login-shell { width: min(920px, 100%); display: grid; grid-template-columns: minmax(260px, .8fr) minmax(340px, 1fr); border: 1px solid #44504b; border-radius: 8px; overflow: hidden; background: white; box-shadow: 0 28px 80px rgba(0,0,0,.24); }
.login-brand { display: flex; align-items: flex-start; gap: 14px; padding: 36px 30px; background: #26342f; color: white; }
.login-brand strong, .login-brand span { display: block; }
.login-brand strong { margin-top: 5px; font-size: 18px; }
.login-brand span { margin-top: 8px; color: #b8c5bf; font-size: 12px; line-height: 1.7; }
.login-panel { display: grid; gap: 18px; padding: 36px; }
.login-panel h1 { margin: 4px 0 6px; font-size: 28px; }
.login-panel p { margin: 0; color: var(--muted); }
.login-panel label > span { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 700; }
.login-panel input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid var(--line); border-radius: 5px; font: inherit; }
.login-panel input:focus { border-color: var(--green); outline: 2px solid rgba(25,126,91,.12); }
.login-panel small { color: var(--muted); text-align: center; }
.login-error { padding: 10px 12px; border: 1px solid #e1a39d; border-radius: 5px; background: #fff1ef; color: #a33a32 !important; font-size: 12px; }
.project-record { align-items: flex-start; }
.project-images { display: flex; gap: 8px; margin-top: 12px; overflow-x: auto; padding-bottom: 3px; }
.project-image { position: relative; flex: 0 0 104px; width: 104px; height: 78px; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 5px; background: #eef2f0; cursor: zoom-in; }
.project-image img { width: 100%; height: 100%; object-fit: cover; }
.project-image span { position: absolute; left: 4px; right: 4px; bottom: 4px; padding: 3px 4px; overflow: hidden; border-radius: 3px; background: rgba(20,29,25,.78); color: white; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.no-project-images { display: block; padding: 14px 0; color: var(--muted); font-size: 11px; }
.delete-verification { display: grid; grid-template-columns: auto minmax(120px, 180px) auto auto; gap: 8px; align-items: end; margin-top: 14px; padding: 12px; border: 1px solid #e1a39d; border-radius: 6px; background: #fff7f6; }
.delete-verification > div span, .delete-verification > div small { display: block; }
.delete-verification > div span { color: #8d3730; font-size: 10px; font-weight: 700; }
.delete-verification > div strong { display: block; margin-top: 2px; color: #a62f27; font-size: 22px; letter-spacing: 2px; }
.delete-verification > div small { color: var(--muted); font-size: 9px; }
.delete-verification input { height: 36px; padding: 0 10px; border: 1px solid #d7a09a; border-radius: 5px; font: inherit; }

@media (max-width: 700px) {
  .login-body { padding: 12px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { padding: 20px; }
  .login-panel { padding: 24px 20px; }
  .delete-verification { grid-template-columns: 1fr 1fr; align-items: end; }
  .delete-verification > div, .delete-verification input { grid-column: 1 / -1; }
}
.settlements-page .settlements-list { min-width: 0; grid-template-columns: minmax(0, 1fr); }
.settlements-page .project-record { width: 100%; min-width: 0; box-sizing: border-box; }
.settlements-page .saved-settlement-main { min-width: 0; overflow: hidden; }

/* System management */
.system-step { margin-top: 0; }
.system-layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; align-items: start; }
.system-password-panel, .audit-panel { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: white; }
.system-password-panel { display: grid; gap: 14px; }
.system-password-panel .section-title { margin-bottom: 4px; }
.system-password-panel label > span { display: block; margin-bottom: 6px; font-size: 11px; font-weight: 700; }
.system-password-panel input { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; font: inherit; }
.system-password-panel input:focus { border-color: var(--green); outline: 2px solid rgba(25,126,91,.12); }
.system-password-panel small { color: var(--muted); font-size: 10px; line-height: 1.6; }
.audit-panel { min-width: 0; }
.audit-table-wrap { margin-top: 12px; max-height: calc(100vh - 210px); overflow: auto; border: 1px solid var(--line); }
.audit-table { min-width: 760px; }
.audit-table th { position: sticky; top: 0; z-index: 1; background: #f5f7f6; }
.audit-table td { font-size: 11px; }
.audit-table code { font-family: ui-monospace, Consolas, monospace; }
.audit-result { display: inline-flex; min-width: 42px; justify-content: center; padding: 3px 7px; border-radius: 999px; font-size: 10px; font-weight: 750; }
.audit-result.success { background: #e5f4ed; color: #126b4c; }
.audit-result.failed { background: #fff0ee; color: #a33a32; }

@media (max-width: 1000px) {
  .system-layout { grid-template-columns: 1fr; }
  .audit-table-wrap { max-height: none; }
}

@media (max-width: 640px) {
  .system-password-panel, .audit-panel { margin-left: -13px; margin-right: -13px; padding: 15px 13px; border-left: 0; border-right: 0; border-radius: 0; }
}