:root {
  color-scheme: light;
  --ink: #1f2b25;
  --muted: #6b7770;
  --line: #dce3de;
  --paper: #f5f7f4;
  --surface: #ffffff;
  --green: #18734f;
  --green-dark: #125a3e;
  --green-soft: #e5f2eb;
  --red: #bd4b3e;
  --red-soft: #fae9e6;
  --amber: #9b6815;
  --amber-soft: #fbf2df;
  --shadow: 0 16px 42px rgba(22, 43, 31, .14);
  font-family: 'DM Sans', 'Noto Sans SC', system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
.app-shell { width: min(100% - 32px, 960px); margin: 0 auto; padding: 28px 0 max(40px, env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 38px; height: 38px; padding: 8px; display: flex; align-items: end; gap: 3px; border-radius: 8px; background: var(--green); }
.brand-mark span { display: block; width: 5px; border-radius: 2px 2px 1px 1px; background: white; }
.brand-mark span:nth-child(1) { height: 10px; opacity: .72; }
.brand-mark span:nth-child(2) { height: 16px; opacity: .86; }
.brand-mark span:nth-child(3) { height: 22px; }
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0; text-transform: uppercase; }
h1, h2, p { margin: 0; }
h1 { margin-top: 2px; font-size: 20px; line-height: 1.2; }
.button { min-height: 42px; padding: 0 15px; border: 1px solid transparent; border-radius: 6px; font-size: 14px; font-weight: 650; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--green); color: white; }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.button-secondary:hover, .button-quiet:hover { background: #ebefec; }
.button-quiet { min-height: 38px; border-color: var(--line); background: transparent; color: var(--ink); }
.notice { display: flex; align-items: baseline; gap: 10px; padding: 13px 15px; border: 1px solid #ead9b3; border-radius: 6px; background: #fff9ed; color: #59451e; font-size: 13px; line-height: 1.5; }
.notice strong { flex: 0 0 auto; font-size: 13px; }
.controls { display: flex; gap: 10px; margin: 20px 0 16px; }
.add-form { display: flex; flex: 1; gap: 8px; min-width: 0; }
.add-form input { width: min(100%, 320px); min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; outline: none; background: var(--surface); color: var(--ink); }
.add-form input:focus, .field-input:focus, .review-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(24, 115, 79, .12); }
.summary-row { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 14px; padding: 13px 15px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summary-row > div { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.summary-label { color: var(--muted); font-size: 12px; }
.summary-row strong { font-size: 14px; font-weight: 700; }
.summary-updated { justify-content: end; }
#dataStatus { max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feedback { margin: 14px 0; padding: 10px 12px; border-radius: 6px; background: var(--green-soft); color: var(--green-dark); font-size: 13px; line-height: 1.45; }
.feedback.error { background: var(--red-soft); color: #873b31; }
.fund-list { display: grid; gap: 10px; margin-top: 12px; }
.fund-card { padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.fund-head { display: flex; justify-content: space-between; gap: 14px; }
.fund-ident { min-width: 0; }
.fund-name { overflow: hidden; font-size: 15px; font-weight: 700; line-height: 1.4; text-overflow: ellipsis; }
.fund-code { margin-top: 4px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.status-pill { align-self: start; flex: 0 0 auto; padding: 5px 8px; border-radius: 4px; background: var(--amber-soft); color: var(--amber); font-size: 11px; font-weight: 700; }
.status-pill.today { background: var(--green-soft); color: var(--green-dark); }
.status-pill.missing { background: #eef0ee; color: #5d6861; }
.fund-metrics { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 10px; margin: 17px 0 13px; padding: 12px 0; border-top: 1px solid #edf0ed; border-bottom: 1px solid #edf0ed; }
.metric-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.metric-value { display: block; overflow: hidden; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.metric-value.small { font-size: 13px; font-weight: 600; }
.positive { color: var(--red); }
.negative { color: var(--green); }
.fund-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.quote-time { min-width: 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.fund-actions { display: flex; gap: 7px; flex: 0 0 auto; }
.small-button { min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; background: white; color: var(--ink); font-size: 12px; font-weight: 650; }
.small-button.primary { border-color: var(--green); background: var(--green); color: white; }
.small-button.remove { padding: 0 8px; color: var(--muted); }
.empty-state { padding: 46px 16px; text-align: center; }
.empty-symbol { width: 42px; height: 42px; margin: 0 auto 13px; display: grid; place-items: center; border-radius: 50%; background: #e9efea; color: var(--green); font-size: 25px; }
.empty-state h2 { font-size: 16px; }
.empty-state p { max-width: 440px; margin: 8px auto 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.data-note { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.55; }
.note-title { margin-bottom: 5px; color: var(--ink); font-size: 12px; font-weight: 700; }
.data-note p + p { margin-top: 5px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.dialog { width: min(480px, calc(100vw - 24px)); max-height: min(90dvh, 820px); padding: 20px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); overflow: auto; }
.dialog::backdrop { background: rgba(17, 31, 23, .42); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 17px; }
.dialog-head h2 { margin-top: 3px; font-size: 18px; line-height: 1.3; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 6px; background: #eef1ee; }
.segment { min-height: 38px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; }
.segment.active { background: white; color: var(--green-dark); box-shadow: 0 1px 3px rgba(20, 40, 28, .1); }
.estimate-strip { margin: 14px 0 16px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fafcf9; font-size: 13px; line-height: 1.5; }
.field-label { display: block; margin: 14px 0 6px; color: var(--ink); font-size: 12px; font-weight: 700; }
.field-input { width: 100%; min-height: 44px; padding: 0 11px; border: 1px solid var(--line); border-radius: 5px; outline: none; background: white; font-size: 16px; }
.scenario-hint { margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.calc-result { min-height: 76px; margin-top: 14px; padding: 12px; border-radius: 6px; background: #f1f5f1; }
.result-empty { color: var(--muted); font-size: 13px; line-height: 1.5; }
.result-main { font-size: 13px; line-height: 1.7; }
.result-main strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.result-range { margin-top: 7px; padding-top: 7px; border-top: 1px solid #dce6de; color: #43564a; font-size: 12px; line-height: 1.6; }
.calc-disclaimer { margin-top: 12px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.import-intro { margin-bottom: 13px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.upload-area { display: grid; gap: 4px; place-items: center; min-height: 98px; padding: 15px; border: 1px dashed #aebbb2; border-radius: 6px; background: #fafcf9; text-align: center; cursor: pointer; }
.upload-area strong { color: var(--green-dark); font-size: 13px; }
.upload-area span { color: var(--muted); font-size: 11px; }
.upload-area input { max-width: 100%; margin-top: 4px; font-size: 11px; }
.screenshot-preview { display: block; max-width: 100%; max-height: 220px; margin: 12px auto 0; border: 1px solid var(--line); border-radius: 5px; object-fit: contain; }
.ocr-progress { margin-top: 10px; color: var(--green-dark); font-size: 12px; }
.import-rows { display: grid; gap: 9px; margin-top: 12px; }
.import-row { padding: 11px; border: 1px solid var(--line); border-radius: 6px; }
.import-row-title { margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.code-match-status { min-height: 18px; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.review-input { width: 100%; min-width: 0; min-height: 38px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; outline: none; font-size: 12px; }
.review-input.name { grid-column: 1 / -1; }
.import-empty { padding: 16px 8px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }
.lot-form { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.lot-add { width: 100%; margin-top: 10px; }
.lot-section-title { margin-top: 16px; font-size: 13px; font-weight: 700; }
.lot-list { display: grid; gap: 8px; margin-top: 8px; }
.lot-row { display: flex; align-items: end; justify-content: space-between; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; }
.lot-row > div:first-child { flex: 1; min-width: 0; }
.lot-row strong { font-size: 12px; }
.lot-row .field-label { margin: 7px 0 0; }
.lot-row .review-input { margin-top: 4px; }
.lot-actions { display: flex; gap: 5px; }
.transaction-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.transaction-title h3 { font-size: 14px; }
.transaction-row { padding: 10px; border: 1px solid var(--line); border-radius: 6px; overflow-wrap: anywhere; }
.transaction-row .transaction-title { margin: 0 0 7px; font-size: 12px; }
.transaction-status { margin-top: 6px; font-size: 12px; color: var(--green-dark); }
.transaction-status.warning { color: #9a6300; }
.check-label { display: flex; align-items: start; gap: 7px; margin-top: 12px; font-size: 12px; line-height: 1.6; }
.ocr-raw { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11px; max-height: 200px; overflow-y: auto; }
#legacyLots { margin-top: 16px; font-size: 12px; }
.review-grid label { min-width: 0; font-size: 12px; }
.review-grid label .review-input { width: 100%; margin-top: 5px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 15px; padding-top: 13px; border-top: 1px solid var(--line); }

@media (max-width: 620px) {
  .app-shell { width: min(100% - 24px, 520px); padding-top: 17px; }
  .topbar { margin-bottom: 15px; }
  .notice { display: grid; gap: 3px; padding: 11px 12px; font-size: 12px; }
  .controls { flex-wrap: wrap; gap: 8px; margin: 14px 0 12px; }
  .add-form { width: 100%; flex-basis: 100%; }
  .add-form input { flex: 1; width: 1px; }
  .controls > .button { width: 100%; }
  .summary-row { grid-template-columns: 1fr 1fr; gap: 8px; padding: 11px 9px; }
  .summary-updated { grid-column: 1 / -1; justify-content: start; }
  .fund-card { padding: 13px; }
  .fund-metrics { grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin: 13px 0 11px; }
  .metric-value { font-size: 15px; }
  .metric-value.small { font-size: 11px; }
  .fund-foot { align-items: flex-end; }
  .fund-actions { gap: 5px; }
  .small-button { min-height: 33px; padding: 0 8px; font-size: 11px; }
  .dialog { position: fixed; inset: auto 0 0; width: 100%; max-width: none; max-height: 92dvh; margin: 0; padding: 18px 16px max(18px, env(safe-area-inset-bottom)); border-radius: 12px 12px 0 0; }
  .dialog::backdrop { background: rgba(17, 31, 23, .48); }
}

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