:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-pressed: #0066cc;
  --accent-soft: #e8f1fc;
  --hairline: rgba(0, 0, 0, 0.08);
  --hairline-strong: rgba(0, 0, 0, 0.12);
  --warn: #7a5c00;
  --warn-bg: #fff6de;
  --warn-border: #e6d29a;
  --danger: #b42318;
  --danger-bg: #fff2f1;
  --ok: #1d7a46;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.045);
  --radius: 16px;
  --radius-sm: 12px;
  --header-h: 72px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
    "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

html { overflow-x: hidden; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.47;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.011em;
}

button, input, select {
  font: inherit;
  letter-spacing: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(245, 245, 247, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
}

.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem 0.45rem;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.mark {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.brand-copy { min-width: 0; }

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 0 0 auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--hairline);
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-weight: 560;
  font-size: 0.72rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.lang-switch {
  display: inline-flex;
  padding: 3px;
  background: #e8e8ed;
  border-radius: 999px;
}

.lang-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  min-height: 32px;
  padding: 0 0.85rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 560;
  cursor: pointer;
}

.lang-switch button[aria-pressed="true"] {
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
}

.header-meta {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem 0.7rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.meta-line { color: var(--muted); }

.meta-line code, code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(0, 0, 0, 0.04);
  padding: 0.12rem 0.4rem;
  border-radius: 6px;
  color: var(--ink);
  word-break: break-all;
}

.disclaimer-banner {
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn);
}

.disclaimer-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.95rem 1.5rem;
}

.disclaimer-banner strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.disclaimer-banner p {
  margin: 0;
  font-size: 0.9rem;
  max-width: 72ch;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.15rem;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem 1.4rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  font-weight: 630;
  letter-spacing: -0.022em;
}

.hint {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0 0 0.9rem;
}

.quantity-note {
  margin: 1rem 0 0;
  padding: 0.75rem 0.85rem;
  background: #f5f5f7;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.875rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.field > span,
.field legend {
  font-weight: 560;
  font-size: 0.8125rem;
  color: var(--ink);
}

.field input[type="number"],
.field input[type="email"],
.field input[type="text"],
.field select,
.item-label {
  min-height: 44px;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  width: 100%;
  appearance: none;
}

.field select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%236e6e73' d='M1.2 1.4L6 6.2l4.8-4.8'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2rem;
}

.field input:focus,
.field select:focus,
.item-label:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.18);
}

.mode-fieldset { margin-top: 1.15rem; }

.segmented {
  display: flex;
  padding: 3px;
  background: #e8e8ed;
  border-radius: 12px;
  gap: 2px;
}

.segmented.compact { max-width: 220px; }

.segment {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 550;
  cursor: pointer;
  color: var(--ink);
}

.segment input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.segment:has(input:checked) {
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
}

.segment:has(input:focus-visible) {
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.18);
}

.line-item-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.6rem;
  padding: 0.65rem;
  background: #f5f5f7;
  border-radius: 12px;
}

.merge-check {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  white-space: nowrap;
}

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.lines-chip {
  margin: 0;
  font-size: 0.875rem;
}

.lines-chip strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 1rem 0 0.85rem;
}

.result-tile {
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  background: #fbfbfd;
  min-width: 0;
}

.result-tile.total {
  grid-column: 1 / -1;
  background: var(--accent-soft);
  border-color: #c5dbf6;
}

.result-tile .label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 560;
}

.result-tile .value {
  font-size: 1.7rem;
  font-weight: 650;
  margin: 0.2rem 0 0.35rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  word-break: break-word;
}

.result-tile.total .value {
  font-size: 2rem;
  color: #0040a8;
}

.result-tile .explain {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.result-meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.result-meta .meta-line { margin: 0; font-size: 0.78rem; }

.warn {
  background: var(--warn-bg);
  color: var(--warn);
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  font-size: 0.875rem;
  border: 1px solid var(--warn-border);
}

.error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
}

.disclaimer-short {
  margin: 0.9rem 0 0;
  padding: 0.7rem 0.85rem;
  border-left: 3px solid #d4b66a;
  background: #fffaf0;
  color: var(--warn);
  font-size: 0.8125rem;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.split-card {
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 1rem 1.05rem;
  background: #fbfbfd;
  min-width: 0;
}

.split-card.merged {
  background: #f3faf5;
  border-color: #cfe6d6;
}

.split-card .split-kicker {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 560;
  margin-bottom: 0.15rem;
}

.split-card .split-amount {
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.split-card .split-detail {
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.delta {
  margin: 0.9rem 0 0;
  font-weight: 620;
  color: var(--accent);
  font-size: 0.95rem;
}

.pid-section.emphasize {
  border-color: #b7d3f5;
  box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft);
}

.checklist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.static-checklist li {
  position: relative;
  padding: 0.65rem 0.85rem 0.65rem 2.1rem;
  background: #fafafa;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  font-size: 0.9375rem;
  line-height: 1.4;
}

.static-checklist li::before {
  content: "";
  position: absolute;
  left: 0.85rem;
  top: 1.05rem;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 980px;
  min-height: 44px;
  min-width: 44px;
  padding: 0.7rem 1.25rem;
  font-weight: 560;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  box-sizing: border-box;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:active { background: var(--accent-pressed); }

.btn.secondary {
  background: #fff;
  border-color: var(--hairline-strong);
  color: var(--ink);
}

.btn.secondary:hover { background: #f5f5f7; }

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  min-height: 44px;
  padding: 0 0.35rem;
}

.cta-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}

.cta-row .btn.primary {
  width: 100%;
}

@media (min-width: 640px) {
  .cta-row {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .cta-row .btn.primary {
    width: auto;
    min-width: 12rem;
  }
}

.copy-status {
  color: var(--ok);
  font-size: 0.875rem;
}

.tech-details {
  margin: 1.25rem 0 0.75rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: #fafafa;
  font-size: 0.8125rem;
}

.tech-details summary {
  cursor: pointer;
  font-weight: 560;
  color: var(--ink);
  list-style: none;
}

.tech-details summary::-webkit-details-marker { display: none; }

.tech-details[open] summary { margin-bottom: 0.55rem; }

.tech-details .meta-line {
  margin: 0.25rem 0;
}

body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal[hidden] { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: min(88vh, 720px);
  background: var(--card);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  padding: 1rem 1.15rem max(1.25rem, env(safe-area-inset-bottom, 0px));
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
    padding: 1.5rem;
  }
  .modal-dialog {
    border-radius: 16px;
    box-shadow: var(--shadow), 0 24px 64px rgba(0, 0, 0, 0.18);
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.modal-x {
  appearance: none;
  border: none;
  background: #f0f0f2;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-x:hover { background: #e5e5ea; }

.brief-preview {
  margin: 0;
  flex: 1 1 auto;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.55;
  background: #f5f5f7;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  color: var(--ink);
  border: 1px solid var(--hairline);
  min-height: 160px;
}

.modal-actions {
  display: flex;
  flex-direction: column-reverse;
  align-items: stretch;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.modal-actions .btn {
  width: 100%;
}

.modal-actions .copy-status {
  text-align: center;
  order: -1;
}

@media (min-width: 640px) {
  .modal-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-bottom: 0;
  }
  .modal-actions .btn {
    width: auto;
    min-width: 7.5rem;
  }
  .modal-actions .btn.primary {
    order: 2;
  }
  .modal-actions .btn.secondary {
    order: 1;
  }
  .modal-actions .copy-status {
    order: 0;
    margin-right: auto;
    text-align: left;
  }
}

.footer {
  max-width: 1080px;
  margin: 0 auto 2.75rem;
  padding: 0 1.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.footer h2 {
  font-size: 0.95rem;
  color: var(--ink);
  margin: 0 0 0.5rem;
}

.footer ul {
  padding-left: 1.15rem;
  margin: 0;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover { text-decoration: underline; }

.footer-legal {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--hairline);
}

@media (min-width: 960px) {
  .workspace {
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  }

  .col-results {
    position: sticky;
    top: 5.6rem;
  }
}

@media (max-width: 720px) {
  .grid-2,
  .result-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .lang-switch button {
    min-height: 44px;
    padding: 0 1rem;
  }

  .segment {
    min-height: 44px;
  }

  .header-inner {
    align-items: flex-start;
    padding: 0.75rem 1rem 0.35rem;
    flex-wrap: wrap;
  }

  .header-meta,
  .disclaimer-inner,
  .page,
  .footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .card { padding: 1.1rem 1rem 1.15rem; }

  .tagline { white-space: normal; }

  .badge { display: none; }

  .line-item-row {
    grid-template-columns: 1fr;
  }

  .merge-check { white-space: normal; }

  .btn.primary,
  .btn.secondary,
  #add-item {
    width: 100%;
  }


  .result-tile .value { font-size: 1.55rem; }
  .result-tile.total .value { font-size: 1.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}


.toast-layer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  pointer-events: none;
}

.toast-layer[hidden] { display: none !important; }

.toast-layer.is-open { pointer-events: auto; }

.toast-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.toast-layer.is-visible .toast-backdrop { opacity: 1; }

.toast-card {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  width: min(92vw, 340px);
  padding: 1.05rem 1.1rem 1.05rem 1.05rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.16),
    0 2px 8px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  color: var(--ink);
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast-layer.is-visible .toast-card {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-layer.is-leaving .toast-card {
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
}

.toast-layer.is-leaving .toast-backdrop { opacity: 0; }

.toast-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(52, 199, 89, 0.12);
  color: #248a3d;
}

.toast-layer.is-error .toast-icon {
  background: rgba(255, 59, 48, 0.12);
  color: #d70015;
}

.toast-icon-ok,
.toast-icon-err { display: none; }

.toast-layer:not(.is-error) .toast-icon-ok { display: block; }
.toast-layer.is-error .toast-icon-err { display: block; }

.toast-msg {
  margin: 0.35rem 1.6rem 0.15rem 0;
  flex: 1 1 auto;
  font-size: 0.98rem;
  font-weight: 590;
  letter-spacing: -0.015em;
  line-height: 1.35;
}

.toast-x {
  appearance: none;
  border: none;
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toast-x:hover { background: rgba(0, 0, 0, 0.1); }

@media (prefers-reduced-motion: reduce) {
  .toast-backdrop,
  .toast-card {
    transition: none;
  }
}
