:root {
  --ink: #17202a;
  --muted: #6f7c87;
  --faint: #9da7af;
  --line: #e3e8ec;
  --line-strong: #d2d9df;
  --paper: #ffffff;
  --canvas: #f3f5f6;
  --navy: #16324a;
  --navy-2: #234b67;
  --teal: #178b86;
  --teal-soft: #e7f5f3;
  --blue-soft: #eaf2f8;
  --gold: #b98533;
  --gold-soft: #fff6e5;
  --danger: #b94141;
  --shadow: 0 10px 30px rgba(22, 50, 74, 0.07);
  --radius: 16px;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 0 0, rgba(23, 139, 134, 0.06), transparent 32rem),
    var(--canvas);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.is-hidden { display: none !important; }

.app-shell { width: min(1460px, calc(100% - 40px)); margin: 0 auto; }

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid rgba(210, 217, 223, 0.75);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, var(--navy), var(--navy-2));
  border-radius: 12px;
  font-family: Georgia, serif;
  font-size: 24px;
  box-shadow: 0 7px 18px rgba(22, 50, 74, 0.2);
}

.eyebrow, .section-kicker {
  margin: 0 0 2px;
  color: var(--teal);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; color: var(--navy); font-size: 22px; line-height: 1.25; letter-spacing: -0.02em; }
h2 { margin-bottom: 0; color: var(--navy); font-size: 18px; letter-spacing: -0.01em; }
h3 { margin-bottom: 0; color: var(--navy); font-size: 15px; }

.topbar-meta { display: flex; align-items: center; gap: 14px; }
.cloud-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid #bfe1dc;
  border-radius: 999px;
  color: #13746f;
  background: #f2fbfa;
  font-size: 12px;
  font-weight: 700;
}
.cloud-badge i { width: 7px; height: 7px; border-radius: 50%; background: #1aae8f; box-shadow: 0 0 0 4px rgba(26, 174, 143, 0.12); }
.privacy-note { color: var(--muted); font-size: 12px; }

main { padding: 24px 0 42px; }

.summary-strip {
  display: grid;
  grid-template-columns: 1.25fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.summary-card {
  min-height: 126px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}
.summary-card span { color: var(--muted); font-size: 12px; font-weight: 650; }
.summary-card strong { margin: 6px 0 4px; color: var(--navy); font-family: "DIN Alternate", "Arial Narrow", sans-serif; font-size: clamp(23px, 2vw, 31px); letter-spacing: -0.03em; }
.summary-card small { color: var(--faint); font-size: 11px; }
.summary-primary { position: relative; border-color: transparent; color: #fff; background: linear-gradient(125deg, #16324a 0%, #204d68 68%, #1a766f 120%); }
.summary-primary::after { content: ""; position: absolute; width: 160px; height: 160px; right: -70px; top: -75px; border: 1px solid rgba(255,255,255,.17); border-radius: 50%; box-shadow: 0 0 0 22px rgba(255,255,255,.035), 0 0 0 48px rgba(255,255,255,.025); }
.summary-primary span, .summary-primary small { color: rgba(255, 255, 255, 0.7); }
.summary-primary strong { color: #fff; }

.workspace-grid { display: grid; grid-template-columns: minmax(430px, 0.92fr) minmax(520px, 1.35fr); gap: 18px; align-items: start; }
.workspace-grid > *, .results-column, .panel, .table-scroll { min-width: 0; }
.results-column { display: grid; gap: 18px; }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}
.input-panel { padding: 24px; }
.result-panel, .line-panel, .history-panel { padding: 24px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.panel-heading.compact { margin-bottom: 12px; }

.text-button {
  padding: 3px 0;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}
.text-button:hover { color: var(--navy); border-color: var(--navy); }
.text-button.danger:hover { color: var(--danger); border-color: var(--danger); }

.form-section { margin: 0; padding: 20px 0; border-top: 1px solid var(--line); }
.form-section:first-of-type { padding-top: 2px; border-top: 0; }
.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.section-title > span { min-width: 25px; color: var(--teal); font-family: "DIN Alternate", monospace; font-size: 11px; font-weight: 800; letter-spacing: .08em; }

.field-grid { display: grid; gap: 13px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.wide { grid-column: 1 / -1; }
.field { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.field > span { color: #51606c; font-size: 11px; font-weight: 700; }
.field em { color: var(--faint); font-style: normal; font-weight: 500; }

input, select {
  width: 100%;
  min-height: 41px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: #fff;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input { padding: 9px 11px; font-variant-numeric: tabular-nums; }
select { padding: 9px 30px 9px 11px; }
input:hover, select:hover { border-color: #b6c2ca; }
input:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(23, 139, 134, .11); }
input::placeholder { color: #b3bbc2; }

.compound-field { display: grid; grid-template-columns: minmax(0, 1fr) 92px; }
.compound-field input { border-radius: 8px 0 0 8px; }
.compound-field select { border-left: 0; border-radius: 0 8px 8px 0; color: var(--navy); background: #f7f9fa; font-size: 12px; font-weight: 700; }
.suffix-field { position: relative; }
.suffix-field input { padding-right: 35px; }
.suffix-field b { position: absolute; top: 50%; right: 12px; color: var(--faint); transform: translateY(-50%); font-size: 12px; }

.preset-row { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 13px; }
.preset-row > span { margin-right: 3px; color: var(--faint); font-size: 10px; font-weight: 700; }
.preset-row button {
  padding: 5px 8px;
  border: 1px solid #d8e3e6;
  border-radius: 6px;
  color: #45616c;
  background: #f5f9fa;
  font-size: 10px;
}
.preset-row button:hover { border-color: #9fc9c5; color: var(--teal); background: var(--teal-soft); }

.expense-details summary { display: flex; align-items: center; justify-content: space-between; list-style: none; cursor: pointer; }
.expense-details summary::-webkit-details-marker { display: none; }
.expense-details summary .section-title { margin-bottom: 0; }
.expense-details summary small { color: var(--faint); font-size: 10px; }
.expense-details[open] summary { margin-bottom: 15px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 14px; padding: 4px; border-radius: 9px; background: #edf1f3; }
.segmented button { min-height: 34px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; }
.segmented button.active { color: var(--navy); background: #fff; box-shadow: 0 2px 7px rgba(22, 50, 74, .08); }

.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding-top: 20px; border-top: 1px solid var(--line); }
.form-actions p { flex: 1; margin: 0; color: var(--muted); font-size: 11px; }
.form-actions p.error { color: var(--danger); }
.form-actions p.success { color: var(--teal); }

.primary-button, .secondary-button, .save-button {
  min-height: 39px;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 750;
  transition: transform .14s ease, background .14s ease, border-color .14s ease;
}
.primary-button { min-width: 145px; border: 1px solid var(--navy); color: #fff; background: var(--navy); }
.primary-button:hover { background: #224a67; transform: translateY(-1px); }
.primary-button span { margin-left: 12px; }
.secondary-button { border: 1px solid var(--line-strong); color: var(--navy); background: #fff; }
.secondary-button:hover:not(:disabled) { border-color: var(--navy); }
.secondary-button:disabled { cursor: not-allowed; opacity: .45; }
.save-button { width: 100%; margin-top: 16px; border: 1px solid #bfe1dc; color: #13746f; background: var(--teal-soft); }
.save-button:hover { border-color: var(--teal); }

.empty-state { min-height: 365px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-state strong { margin: 16px 0 4px; color: var(--navy); }
.empty-state span { color: var(--faint); font-size: 12px; }
.empty-chart { width: 92px; height: 62px; display: flex; align-items: flex-end; justify-content: center; gap: 7px; padding-bottom: 8px; border-bottom: 1px solid #cbd4da; }
.empty-chart i { width: 11px; border-radius: 3px 3px 0 0; background: #dfe7eb; }
.empty-chart i:nth-child(1) { height: 20px; }
.empty-chart i:nth-child(2) { height: 35px; }
.empty-chart i:nth-child(3) { height: 27px; }
.empty-chart i:nth-child(4) { height: 48px; background: #c1d9d7; }

.result-callout { position: relative; padding: 19px 20px; overflow: hidden; border-radius: 12px; color: #fff; background: linear-gradient(125deg, var(--navy), #24506b); }
.result-callout > span { display: block; color: rgba(255,255,255,.68); font-size: 11px; }
.result-callout > strong { display: block; margin: 4px 0 11px; font-family: "DIN Alternate", "Arial Narrow", sans-serif; font-size: 34px; letter-spacing: -.03em; }
.result-callout > div { display: flex; align-items: center; gap: 10px; }
.result-callout b { color: #9ce1d4; font-size: 13px; }
.result-callout small { color: rgba(255,255,255,.64); }

.breakdown-list { margin: 14px 0 0; }
.breakdown-list > div { display: flex; justify-content: space-between; align-items: center; gap: 14px; min-height: 39px; border-bottom: 1px solid #edf0f2; }
.breakdown-list dt { color: var(--muted); font-size: 11px; }
.breakdown-list dd { margin: 0; color: #33424d; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.breakdown-list .emphasis { margin: 4px 0; padding: 0 10px; border: 0; border-radius: 7px; background: var(--gold-soft); }
.breakdown-list .emphasis dt, .breakdown-list .emphasis dd { color: #8b6123; }

.panel-description { margin: -2px 0 14px; color: var(--muted); font-size: 11px; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 9px 8px; border-bottom: 1px solid var(--line-strong); color: var(--faint); text-align: left; white-space: nowrap; font-size: 10px; font-weight: 800; letter-spacing: .04em; }
td { padding: 8px; border-bottom: 1px solid #edf0f2; color: #45535e; white-space: nowrap; font-size: 11px; font-variant-numeric: tabular-nums; }
.line-input-table { min-width: 520px; }
.line-result-table { min-width: 760px; margin-top: 16px; }
.line-input-table input { min-height: 34px; padding: 7px 8px; font-size: 11px; }
.line-input-table td:nth-child(1) { width: 32%; }
.line-input-table td:nth-child(2), .line-input-table td:nth-child(3) { width: 26%; }
.remove-line { width: 28px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; color: var(--faint); background: #fff; }
.remove-line:hover { border-color: #e2b9b9; color: var(--danger); background: #fff4f4; }
.line-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 13px; }
.line-actions span { color: var(--muted); font-size: 11px; }
.line-result-table tfoot td { color: var(--navy); border-top: 2px solid var(--navy); border-bottom: 0; font-weight: 800; }

.history-list { display: grid; gap: 8px; }
.history-empty { padding: 20px 0; color: var(--faint); text-align: center; font-size: 11px; }
.history-item { display: grid; grid-template-columns: 76px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fbfcfc; }
.history-item:hover { border-color: #c8d7dc; background: #f7fafb; }
.history-time { color: var(--faint); font-size: 10px; }
.history-main { min-width: 0; }
.history-main strong { display: block; overflow: hidden; color: var(--navy); text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.history-main span { color: var(--muted); font-size: 10px; }
.history-actions { display: flex; gap: 5px; }
.history-actions button { padding: 4px 7px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: #fff; font-size: 10px; }
.history-actions button:hover { color: var(--navy); border-color: var(--navy); }

.formula-dialog { width: min(760px, calc(100% - 28px)); max-height: min(760px, calc(100vh - 40px)); padding: 0; border: 0; border-radius: 16px; box-shadow: 0 25px 70px rgba(20, 38, 52, .24); }
.formula-dialog::backdrop { background: rgba(13, 28, 39, .5); backdrop-filter: blur(3px); }
.dialog-heading { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; gap: 20px; padding: 22px 24px 17px; border-bottom: 1px solid var(--line); background: #fff; }
.dialog-heading button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: #fff; font-size: 22px; line-height: 1; }
.formula-content { padding: 20px 24px 26px; }
.formula-step { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.formula-step:last-child { border-bottom: 0; }
.formula-step > span { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; color: var(--teal); background: var(--teal-soft); font-size: 10px; font-weight: 800; }
.formula-step h3 { margin: 2px 0 5px; font-size: 13px; }
.formula-step p { margin: 2px 0; color: var(--muted); font-family: Consolas, "SFMono-Regular", monospace; font-size: 11px; word-break: break-word; }
.formula-step strong { display: block; margin-top: 5px; color: var(--navy); }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: 340px; padding: 12px 16px; border-radius: 9px; color: #fff; background: var(--navy); box-shadow: 0 12px 30px rgba(22, 50, 74, .24); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .18s ease, transform .18s ease; font-size: 12px; }
.toast.show { opacity: 1; transform: translateY(0); }

footer { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line-strong); color: var(--faint); font-size: 10px; }

@media (max-width: 1120px) {
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 680px) {
  .app-shell { width: min(100% - 22px, 1460px); }
  .topbar { align-items: flex-start; padding: 18px 0; }
  .topbar-meta { align-items: flex-end; flex-direction: column; gap: 7px; }
  .privacy-note { display: none; }
  h1 { font-size: 18px; }
  .brand-mark { width: 39px; height: 39px; font-size: 21px; }
  main { padding-top: 14px; }
  .summary-strip { grid-template-columns: 1fr 1fr; gap: 9px; }
  .summary-card { min-height: 104px; padding: 15px; }
  .summary-card strong { font-size: 21px; }
  .summary-card small { display: none; }
  .input-panel, .result-panel, .line-panel, .history-panel { padding: 18px; }
  .two-columns, .three-columns { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }
  .history-item { grid-template-columns: 62px minmax(0, 1fr); }
  .history-actions { grid-column: 2; }
  footer { align-items: flex-start; flex-direction: column; justify-content: center; gap: 3px; }
}

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