:root {
  color-scheme: light;
  --ink: #241d27;
  --muted: #766d7a;
  --line: #e8e1eb;
  --surface: #ffffff;
  --surface-soft: #faf8fb;
  --background: #f5f2f6;
  --accent: #672878;
  --accent-dark: #4d1d59;
  --accent-soft: #f0e8f4;
  --green: #18794e;
  --green-soft: #e5f5ed;
  --amber: #9a6700;
  --amber-soft: #fff4d6;
  --red: #b42318;
  --red-soft: #fff0ef;
  --shadow: 0 10px 30px rgba(55, 29, 65, 0.06);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--background); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.app-shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 64px; }
.app-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding: 10px 0 24px; }
.brand-block h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.25rem); letter-spacing: -0.055em; }
.eyebrow, .label, .section-kicker { margin: 0; color: var(--muted); font-size: .72rem; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.eyebrow { margin-bottom: 5px; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.buy-select-wrap select { min-width: 180px; max-width: 260px; }
select, input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); padding: 11px 12px; }
select:focus, input:focus, textarea:focus, button:focus-visible { outline: 3px solid rgba(103, 40, 120, .23); outline-offset: 2px; }
.status-badge, .pill { display: inline-flex; align-items: center; min-height: 30px; padding: 5px 10px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: .76rem; font-weight: 850; white-space: nowrap; }
.payment-label { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: .78rem; font-weight: 750; }
.status-badge.is-closed, .pill.is-closed { background: #eceaec; color: #615b63; }
.pill.is-tentative { background: var(--amber-soft); color: var(--amber); }
.pill.is-confirmed { background: var(--green-soft); color: var(--green); }
.icon-button, .button { min-height: 44px; border: 0; border-radius: 11px; cursor: pointer; font-weight: 800; }
.icon-button { width: 44px; background: var(--accent); color: #fff; font-size: 1.35rem; }
.button { padding: 10px 15px; background: var(--accent); color: #fff; }
.button:hover, .button:focus-visible, .icon-button:hover { background: var(--accent-dark); }
.button.secondary { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.button.secondary:hover, .button.secondary:focus-visible { background: var(--surface-soft); }
.button.danger { background: var(--red); }
.button.small { min-height: 38px; padding: 8px 12px; font-size: .88rem; }
.button:disabled, .icon-button:disabled { cursor: wait; opacity: .58; }
.notice { min-height: 0; margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.notice.is-error { color: var(--red); }
.notice.is-success { color: var(--green); }
.primary-nav { display: flex; gap: 5px; padding: 5px; margin-bottom: 22px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.6); }
.nav-tab { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 850; }
.nav-tab.is-active { background: var(--accent); color: #fff; box-shadow: 0 5px 12px rgba(103,40,120,.2); }
.view-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.view-heading h2 { margin: 0; font-size: 1.55rem; letter-spacing: -.03em; }
.view-heading p { margin: 4px 0 0; color: var(--muted); }
.heading-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card, .buyer-card, .product-card, .summary-card { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.buyer-card, .product-card { overflow: hidden; }
.card-body, .product-body { padding: 18px; }
.buyer-top, .product-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.buyer-title, .product-title { min-width: 0; }
.buyer-title h3, .product-title h3 { overflow-wrap: anywhere; margin: 0; font-size: 1.1rem; }
.buyer-meta, .product-meta { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-top: 8px; color: var(--muted); font-size: .83rem; }
.save-status { display: inline-flex; align-items: center; gap: 5px; min-height: 25px; padding: 3px 8px; border-radius: 999px; font-size: .74rem; font-weight: 850; }
.save-status.is-saving { background: var(--accent-soft); color: var(--accent); }
.save-status.is-saved { background: var(--green-soft); color: var(--green); }
.save-status.is-error { background: var(--red-soft); color: var(--red); }
.save-spinner { width: 11px; height: 11px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.retry-button { min-height: 25px; padding: 3px 8px; border: 1px solid currentColor; border-radius: 999px; background: transparent; color: var(--red); cursor: pointer; font-size: .72rem; font-weight: 850; }
.expand-button { min-width: 44px; min-height: 44px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); color: var(--accent); cursor: pointer; font-size: 1.1rem; font-weight: 900; }
.mini-stats, .finance-grid, .summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 16px; }
.mini-stat, .finance-item { padding: 10px; border-radius: 11px; background: var(--surface-soft); }
.mini-stat .label, .finance-item .label { display: block; font-size: .66rem; }
.mini-stat strong, .finance-item strong { display: block; margin-top: 4px; font-size: 1rem; }
.finance-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.finance-item.total { background: var(--accent-soft); }
.buyer-expanded, .product-expanded { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--line); }
.product-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.product-row:last-child { border-bottom: 0; }
.product-row.is-zero { color: var(--muted); }
.product-row-info { min-width: 0; }
.product-row-name { overflow-wrap: anywhere; font-weight: 750; }
.product-row-price { margin-top: 3px; color: var(--muted); font-size: .82rem; }
.stepper { display: inline-flex; align-items: center; flex: 0 0 auto; gap: 6px; }
.stepper button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--accent); cursor: pointer; font-size: 1.4rem; font-weight: 850; }
.stepper button:hover, .stepper button:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.stepper-value { min-width: 30px; text-align: center; font-size: 1.05rem; font-weight: 850; }
.notes-area { margin-top: 15px; }
.notes-area label, .form-field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: .78rem; font-weight: 750; }
.notes-area textarea { min-height: 70px; resize: vertical; }
.meta-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.empty-state, .loading-panel, .error-panel { padding: 38px 22px; border: 1px dashed var(--line); border-radius: 16px; background: var(--surface); text-align: center; color: var(--muted); }
.empty-state h3, .error-panel h2 { margin: 0 0 7px; color: var(--ink); }
.empty-state p, .error-panel p { margin: 0 0 17px; }
.spinner { width: 28px; height: 28px; margin: 0 auto 12px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 0 18px; }
.summary-card { padding: 18px; }
.summary-card strong { display: block; margin-top: 7px; font-size: 1.45rem; }
.summary-card.total { background: var(--accent); color: #fff; }
.summary-card.total .label { color: #eadcf0; }
.section-block { margin-top: 24px; }
.section-block h3 { margin: 0 0 12px; font-size: 1.1rem; }
.buyer-breakdown-list { display: grid; gap: 12px; }
.buyer-breakdown-card { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.buyer-breakdown-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.buyer-breakdown-heading h4 { margin: 0; font-size: 1rem; }
.buyer-breakdown-heading > strong { color: var(--accent); font-size: 1.1rem; }
.buyer-breakdown-finance { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 13px; }
.buyer-breakdown-finance .finance-item { padding: 9px; }
.scenario { padding: 15px; border: 1px solid #c8dff0; border-radius: 13px; background: #eef8ff; }
.payment-summary { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.payment-summary strong { overflow-wrap: anywhere; color: var(--accent); }
.scenario h3 { margin: 0 0 6px; }
.scenario p { margin: 4px 0; color: #31566e; }
.buyer-list, .product-list { display: grid; gap: 14px; }
.inline-list { display: grid; gap: 8px; }
.inline-list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.inline-list-row:last-child { border-bottom: 0; }
.modal-root[hidden] { display: none; }
.modal-root { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 18px; background: rgba(36,29,39,.45); }
.modal { width: min(520px, 100%); max-height: min(720px, calc(100vh - 36px)); overflow: auto; padding: 22px; border-radius: 18px; background: var(--surface); box-shadow: 0 25px 70px rgba(36,29,39,.25); }
.modal h2 { margin: 0; font-size: 1.35rem; }
.modal p { color: var(--muted); line-height: 1.5; }
.form-stack { display: grid; gap: 14px; margin-top: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.multi-select-list { display: grid; gap: 7px; max-height: 280px; overflow: auto; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.multi-select-option { display: flex; align-items: center; gap: 11px; min-height: 48px; padding: 10px 12px; border-radius: 9px; cursor: pointer; background: var(--surface); font-weight: 700; }
.multi-select-option:has(input:checked) { background: var(--accent-soft); color: var(--accent); }
.multi-select-option input { width: 21px; height: 21px; flex: 0 0 auto; }
.selected-list { display: flex; flex-wrap: wrap; gap: 7px; min-height: 34px; align-items: center; }
.selected-chip { padding: 7px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .84rem; font-weight: 800; }
.selected-item { display: grid; grid-template-columns: minmax(0, 1fr) 120px; align-items: center; gap: 9px; width: 100%; padding: 7px 0; border-bottom: 1px solid var(--line); font-weight: 700; }
.selected-item:last-child { border-bottom: 0; }
.inline-add-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.inline-add-row:has(#new-master-price) { grid-template-columns: minmax(0, 1fr) 110px auto; }
.button-spinner { display: inline-block; width: 13px; height: 13px; margin-right: 7px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; vertical-align: -2px; animation: spin .7s linear infinite; }
.checkbox-row { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: .9rem; }
.checkbox-row input { width: 20px; height: 20px; }
.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; }
@media (max-width: 760px) {
  .app-shell { width: min(100% - 22px, 600px); padding-top: 15px; }
  .app-header { align-items: stretch; flex-direction: column; padding-bottom: 17px; }
  .header-actions { justify-content: stretch; }
  .buy-select-wrap { flex: 1 1 180px; }
  .buy-select-wrap select { max-width: none; }
  .card-grid, .summary-grid { grid-template-columns: 1fr; }
  .view-heading { align-items: stretch; flex-direction: column; }
  .heading-actions .button { flex: 1; }
  .finance-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .buyer-breakdown-finance { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 430px) {
  .primary-nav { position: sticky; top: 0; z-index: 3; margin-inline: -5px; border-radius: 0 0 14px 14px; backdrop-filter: blur(10px); }
  .nav-tab { font-size: .84rem; }
  .card-body, .product-body, .summary-card { padding: 15px; }
  .product-row { align-items: flex-start; }
  .stepper button { width: 46px; height: 46px; }
  .stepper-value { min-width: 27px; }
  .modal { padding: 18px; }
  .multi-select-list { max-height: 42vh; }
  .inline-add-row, .inline-add-row:has(#new-master-price) { grid-template-columns: 1fr; }
  .selected-item { grid-template-columns: minmax(0, 1fr) 105px; }
}
