:root {
  --bg: #f6f3ea;
  --panel: #fffefa;
  --text: #18212a;
  --muted: #667085;
  --line: #ded7c7;
  --green: #2f7d57;
  --blue: #256f9c;
  --amber: #b56a1a;
  --red: #b13f3f;
  --shadow: 0 14px 34px rgba(25, 31, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans TC", sans-serif;
  line-height: 1.55;
}

a {
  color: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 14px max(16px, calc((100vw - 1060px) / 2));
  background: rgba(246, 243, 234, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: max-content;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  color: var(--green);
}

.top-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
}

.top-nav a,
.nav-form button,
.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}

.nav-form {
  margin: 0;
}

.nav-form button {
  white-space: nowrap;
}

.button.primary {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.button.danger {
  border-color: #e9b7b7;
  color: var(--red);
}

.button.delete {
  border-color: var(--red);
  background: #fff1f1;
  color: var(--red);
}

.button.dashed {
  border-style: dashed;
  border-color: #e7aa2d;
  color: #8a4f00;
  background: transparent;
}

.button.wide {
  width: 100%;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.page {
  width: min(1060px, 100%);
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.page-title,
.panel-head {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.page-title h1,
.panel h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.notice,
.panel,
.empty-panel {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.notice {
  padding: 12px 14px;
  color: #59411b;
  background: #fff6df;
}

.notice.info {
  margin-top: 0;
  color: #31556b;
  background: #eef7f8;
}

.notice.warning {
  margin-top: 0;
  border-color: #f4c56a;
  color: #7a3d00;
  background: #fff8e5;
  box-shadow: none;
}

.notice.error {
  color: #7a2020;
  background: #fff1f1;
}

.panel,
.empty-panel {
  padding: 18px;
}

.stack {
  display: grid;
  gap: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.metric {
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric span {
  display: block;
  color: var(--muted);
}

.metric small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  font-size: 2rem;
  color: var(--green);
}

.metric.money {
  display: grid;
  gap: 4px;
}

.metric.money strong {
  color: #b26712;
  font-size: 1.2rem;
}

.metric.warn strong,
.position-card.watch .position-heading strong {
  color: var(--amber);
}

.metric.focus strong,
.position-card.near-ko .position-heading strong {
  color: var(--blue);
}

.metric.danger strong,
.position-card.danger .position-heading strong {
  color: var(--red);
}

.metric.muted strong {
  color: var(--muted);
}

.position-list,
.detail-grid,
.two-column {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.detail-grid,
.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-shell {
  display: grid;
  gap: 18px;
}

.detail-hero {
  display: grid;
  gap: 12px;
  border-radius: 8px;
  padding: 22px;
  background: #111827;
  color: white;
}

.detail-hero h1,
.detail-hero p {
  margin: 0;
}

.detail-hero p {
  color: #b8c1cc;
}

.hero-facts {
  display: grid;
  grid-template-columns: minmax(96px, 0.6fr) minmax(180px, 1fr) minmax(220px, 1fr);
  gap: 10px;
  margin: 2px 0 0;
}

.hero-facts div {
  display: grid;
  gap: 4px;
  border: 1px solid #263449;
  border-radius: 8px;
  padding: 10px 12px;
  background: #182234;
}

.hero-facts dt {
  color: #93a4b8;
  font-size: 0.78rem;
}

.hero-facts dd {
  margin: 0;
  color: #ffffff;
  font-weight: 800;
}

.detail-hero-top,
.section-title-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.button.ghost {
  border-color: #2b3545;
  background: #182234;
  color: white;
}

.chip.dark {
  border-color: #263449;
  background: #1d2a3d;
  color: #d8e2ee;
}

.detail-section {
  display: grid;
  gap: 14px;
  border-bottom: 1px dashed var(--line);
  padding: 0 0 18px;
}

.detail-section h2 {
  margin: 0;
  color: #a15d12;
  font-size: 1.05rem;
}

.underlying-status-list,
.barrier-grid,
.memory-ko-table,
.status-history-table,
.coupon-table,
.allocation-list {
  display: grid;
  gap: 10px;
}

.underlying-status-row,
.coupon-row,
.detail-allocation div {
  display: grid;
  grid-template-columns: minmax(76px, 0.8fr) repeat(3, minmax(100px, 1fr)) minmax(96px, auto);
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.underlying-status-row strong {
  color: var(--blue);
}

.return-value {
  font-weight: 800;
}

.return-value.positive {
  color: var(--red);
}

.return-value.negative {
  color: var(--green);
}

.return-value.neutral {
  color: var(--muted);
}

.underlying-status-row small {
  color: var(--muted);
  justify-self: end;
}

.barrier-card {
  display: grid;
  gap: 18px;
  border-radius: 8px;
  padding: 16px;
  background: #e5e3dc;
}

.barrier-card-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.barrier-card-head strong {
  color: var(--blue);
}

.barrier-card-head span {
  color: #4b5563;
  font-weight: 700;
}

.barrier-card-head b {
  font-weight: 800;
}

.barrier-card-head em {
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef6ff;
  color: #245b9f;
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}

.barrier-scale-meta {
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
}

.barrier-line {
  position: relative;
  height: 78px;
  margin-top: 4px;
}

.barrier-line::before {
  content: "";
  position: absolute;
  top: 18px;
  right: 0;
  left: 0;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #bf8a77 0%, #efe8d1 42%, #a9d4cf 70%, #b08a42 100%);
}

.barrier-marker {
  position: absolute;
  top: 8px;
  width: 2px;
  height: 20px;
  background: #667085;
  transform: translateX(-50%);
}

.barrier-marker.ko {
  background: #34466a;
}

.barrier-current {
  position: absolute;
  top: 12px;
  display: grid;
  place-items: center;
  width: 0;
  transform: translateX(-50%);
}

.barrier-current::before {
  content: "";
  width: 13px;
  height: 13px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: #2b6cb0;
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.18);
}

.barrier-threshold {
  position: absolute;
  top: 42px;
  display: grid;
  gap: 2px;
  min-width: 88px;
  transform: translateX(-50%);
  text-align: center;
  line-height: 1.15;
}

.barrier-threshold.ki {
  transform: translateX(-50%);
  text-align: center;
}

.barrier-threshold.ko {
  transform: translateX(-50%);
  text-align: center;
}

.barrier-threshold strong {
  color: #8a4f00;
  font-size: 0.78rem;
  font-weight: 900;
}

.barrier-threshold b {
  color: #a15d12;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.barrier-threshold small,
.section-title-row span,
.coupon-row small,
.coupon-allocation-lines,
.coupon-summary span {
  color: var(--muted);
  font-size: 0.84rem;
}

.contract-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 36px;
  margin: 0;
}

.coupon-summary {
  display: grid;
  gap: 10px;
}

.coupon-allocation-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.coupon-allocation-summary div {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
}

.coupon-allocation-summary strong {
  color: var(--ink);
}

.coupon-allocation-summary span,
.coupon-allocation-lines {
  color: var(--muted);
  font-size: 0.84rem;
}

.coupon-summary div,
.detail-allocation div {
  display: flex;
  justify-content: space-between;
}

.coupon-summary strong,
.coupon-row span:nth-child(3),
.detail-allocation span {
  color: #b26712;
  font-weight: 800;
}

.coupon-row {
  grid-template-columns: 48px 1fr 1fr 1fr;
}

.memory-ko-panel {
  display: grid;
  gap: 10px;
  border-top: 1px dashed var(--line);
  padding-top: 14px;
}

.memory-ko-panel h3 {
  margin: 0;
  color: #a15d12;
  font-size: 0.98rem;
}

.memory-ko-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) repeat(3, minmax(100px, 1fr));
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.memory-ko-row strong,
.memory-ko-row span:last-child {
  color: var(--blue);
  font-weight: 800;
}

.memory-ko-row.header {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.memory-ko-row.header span:last-child {
  color: var(--muted);
}

.status-history-row {
  display: grid;
  grid-template-columns: minmax(96px, 0.7fr) minmax(92px, 0.7fr) minmax(110px, 0.8fr) minmax(220px, 1.6fr) minmax(140px, 1fr);
  gap: 12px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.status-history-row strong,
.status-history-row span:nth-child(2) {
  color: var(--blue);
  font-weight: 800;
}

.status-history-row.header {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.status-history-row.header span:nth-child(2) {
  color: var(--muted);
}

.coupon-row.header {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.coupon-row small {
  display: block;
  margin-top: 2px;
}

.coupon-allocation-lines b {
  color: var(--ink);
  font-weight: 800;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 10px;
}

.position-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 8px;
  background: var(--panel);
}

.position-card.watch {
  border-left-color: var(--amber);
}

.position-card.near-ko {
  border-left-color: var(--blue);
}

.position-card.danger {
  border-left-color: var(--red);
}

.position-top,
.position-main {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
}

.position-heading {
  display: flex;
  gap: 10px;
  align-items: center;
}

.position-code {
  border-radius: 6px;
  padding: 2px 8px;
  background: #fff3d6;
  color: #9a5d12;
  font-size: 0.82rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.position-summary,
.position-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.position-summary span + span::before {
  content: "·";
  margin-right: 14px;
  color: #9a8d7c;
}

.position-price-levels {
  display: grid;
  gap: 6px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}

.position-price-row {
  display: grid;
  grid-template-columns: minmax(64px, 0.7fr) repeat(4, minmax(110px, 1fr));
  gap: 10px;
  align-items: center;
  color: #344054;
  font-size: 0.86rem;
}

.position-price-row strong {
  color: var(--blue);
}

.position-price-row span {
  font-variant-numeric: tabular-nums;
}

.position-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
}

.chip {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 10px;
  background: #fbfaf5;
  color: #4b5563;
  font-weight: 700;
}

.position-main span,
.hint,
.empty {
  color: var(--muted);
}

.position-facts,
.detail-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.detail-list {
  grid-template-columns: 1fr;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: #f7f4eb;
  color: #4d5a6f;
  font-size: 0.82rem;
  font-weight: 800;
}

.status-badge.success {
  border-color: #b8dbc3;
  background: #effaf2;
  color: var(--green);
}

.status-badge.warning {
  border-color: #f2d28e;
  background: #fff7df;
  color: #9a5b00;
}

.status-badge.danger {
  border-color: #efb9b9;
  background: #fff0f0;
  color: var(--red);
}

.status-badge.info {
  border-color: #bdd7ee;
  background: #eef7ff;
  color: var(--blue);
}

.job-run-table {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.job-run-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(80px, 0.45fr) minmax(120px, 0.8fr) minmax(220px, 1.5fr) minmax(120px, 0.8fr);
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  font-size: 0.88rem;
}

.job-run-row.header {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

dt {
  color: var(--muted);
  font-size: 0.82rem;
}

dd {
  margin: 2px 0 0;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: white;
  color: var(--text);
  font: inherit;
}

input:disabled,
select:disabled {
  background: #f1eee6;
  color: #8a8173;
  cursor: not-allowed;
}

.field-note {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.section-label {
  color: #344054;
  font-weight: 800;
}

.calculated-field {
  display: grid;
  gap: 6px;
  align-content: start;
}

.calculated-total {
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid #c9ddcf;
  border-radius: 8px;
  padding: 9px 12px;
  background: #f4fbf6;
  color: var(--green);
  font-weight: 800;
}

.calculated-total.empty {
  color: var(--muted);
  font-weight: 700;
}

.form-grid,
.allocation-row,
.underlying-row,
.filter-bar,
.inline-form,
.actions {
  display: grid;
  gap: 10px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide-field {
  grid-column: 1 / -1;
}

.underlying-row {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.allocation-block,
.allocation-rows,
.coupon-editor,
.coupon-edit-table,
#couponScheduleRows {
  display: grid;
  gap: 10px;
}

.coupon-editor {
  margin-top: 12px;
  border-top: 1px dashed var(--line);
  padding-top: 14px;
}

.coupon-edit-row {
  display: grid;
  grid-template-columns: 80px repeat(2, minmax(150px, 1fr));
  gap: 10px;
  align-items: center;
}

.coupon-edit-row.header {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.coupon-edit-row input[readonly] {
  background: #f5f1e7;
  color: var(--muted);
  font-weight: 800;
}

.allocation-row {
  grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) minmax(150px, 0.65fr) auto;
  align-items: end;
}

.filter-bar,
.inline-form,
.actions {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}

.filter-bar {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 0.7fr) auto;
}

.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.status-tab {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 14px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.status-tab.active {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.dashboard-sort-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.dashboard-sort-tab {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 800;
}

.dashboard-sort-tab.active {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.actions {
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  grid-template-columns: none;
  justify-content: end;
}

.table-like {
  display: grid;
  gap: 10px;
}

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.facts-row {
  grid-template-columns: 1fr repeat(4, minmax(120px, 1fr));
}

.auth-shell {
  display: grid;
  min-height: min(640px, calc(100vh - 180px));
  place-items: center;
}

.auth-card {
  width: min(420px, 100%);
}

.auth-card h1 {
  margin: 0;
}

.calendar-filter-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  margin-top: 18px;
}

.calendar-range-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.calendar-range-tab {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
}

.calendar-range-tab.active {
  border-color: var(--amber);
  background: var(--amber);
  color: white;
}

.calendar-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.calendar-summary span {
  font-weight: 700;
}

.calendar-month-list {
  display: grid;
  gap: 22px;
  margin-top: 28px;
}

.calendar-month {
  display: grid;
  gap: 10px;
}

.calendar-month h2 {
  margin: 0;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 8px;
  color: #a15d12;
  font-size: 1.05rem;
}

.calendar-event-list {
  display: grid;
  gap: 8px;
}

.calendar-event-row {
  display: grid;
  grid-template-columns: 48px 72px 1fr minmax(120px, auto);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
  color: inherit;
  text-decoration: none;
}

.calendar-event-row:hover {
  border-color: #c9b996;
}

.calendar-date {
  display: grid;
  justify-items: center;
  line-height: 1.2;
}

.calendar-date strong {
  color: var(--amber);
  font-size: 1.25rem;
}

.calendar-date span,
.calendar-event-main span,
.calendar-event-side span {
  color: var(--muted);
  font-size: 0.82rem;
}

.calendar-event-main .event-customer {
  color: var(--blue);
  font-weight: 800;
}

.event-type {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.event-type.coupon {
  background: #e2f5f7;
  color: #276b7a;
}

.event-type.ko-start {
  background: #f2e8ff;
  color: #6542a4;
}

.event-type.valuation {
  background: #fff3d6;
  color: #9a5d12;
}

.event-type.maturity {
  background: #ffe4e4;
  color: var(--red);
}

.calendar-event-main {
  display: grid;
  gap: 2px;
}

.calendar-event-main .event-condition {
  color: #5f6f89;
  font-weight: 800;
}

.calendar-status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 8px;
  margin-top: 3px;
}

.calendar-status-chips span {
  border: 1px solid #d7cbb1;
  border-radius: 6px;
  padding: 3px 6px;
  background: #fbfaf5;
  color: #42526b;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.calendar-event-side {
  display: grid;
  gap: 2px;
  justify-items: end;
  text-align: right;
}

.calendar-event-side strong {
  color: #b26712;
}

.customer-selector-panel {
  box-shadow: none;
}

.customer-selector-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.customer-detail-panel {
  display: grid;
  gap: 18px;
}

.customer-detail-head,
.customer-contract-main,
.customer-money-grid {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

.customer-detail-head h2 {
  margin: 0;
}

.customer-summary-badges,
.distribution-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.customer-money-grid {
  align-items: stretch;
}

.customer-money-grid div {
  flex: 1;
  display: grid;
  gap: 4px;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfaf5;
}

.customer-money-grid span,
.customer-contract-main span,
.distribution-legend small {
  color: var(--muted);
}

.customer-money-grid strong {
  color: #b26712;
  font-size: 1.08rem;
}

.customer-contract-section {
  display: grid;
  gap: 10px;
  border-top: 1px dashed var(--line);
  padding-top: 16px;
}

.customer-contract-section h3 {
  margin: 0;
  color: #a15d12;
  font-size: 1rem;
}

.customer-contract-list {
  display: grid;
  gap: 10px;
}

.customer-contract-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
}

.customer-contract-card.compact {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.customer-contract-main > div {
  display: flex;
  gap: 8px;
  align-items: center;
}

.customer-contract-main > span {
  color: #b26712;
  font-weight: 800;
}

.customer-contract-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 0;
}

.customer-distribution {
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
  gap: 24px;
  align-items: center;
}

.donut-chart {
  width: min(280px, 100%);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  position: relative;
  justify-self: center;
}

.donut-chart::after {
  content: "";
  position: absolute;
  inset: 30%;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
}

.distribution-legend {
  display: grid;
  gap: 10px;
}

.distribution-legend div {
  display: grid;
  grid-template-columns: 16px minmax(80px, 1fr) minmax(64px, auto) minmax(92px, auto);
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(24, 33, 42, 0.24);
  border-radius: 3px;
}

.compact-list {
  margin: 0;
  padding-left: 20px;
}

.hidden {
  display: none !important;
}

.app-footer {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 18px 16px 28px;
  color: var(--muted);
  font-size: 0.85rem;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  html,
  body {
    width: auto;
    min-height: auto;
    background: var(--bg);
  }

  body {
    font-size: 10.5px;
  }

  .app-header,
  .app-footer,
  .position-actions,
  .detail-actions,
  .notice,
  .print-button {
    display: none !important;
  }

  .page {
    width: 100%;
    max-width: 190mm;
    margin: 0;
    padding: 0;
  }

  .detail-shell {
    display: block;
    gap: 9px;
  }

  .detail-hero,
  .barrier-card,
  .memory-ko-panel,
  .coupon-table,
  .allocation-list {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .detail-hero {
    gap: 7px;
    margin-bottom: 9px;
    padding: 12px 14px;
  }

  .detail-hero h1 {
    font-size: 1.35rem;
    line-height: 1.2;
  }

  .detail-hero p,
  .hero-facts {
    font-size: 0.86rem;
  }

  .hero-facts {
    grid-template-columns: 0.7fr 1.15fr 1.25fr;
    gap: 7px;
  }

  .hero-facts div {
    padding: 7px 9px;
  }

  .detail-section {
    display: block;
    gap: 9px;
    margin-bottom: 9px;
    padding-bottom: 9px;
  }

  .detail-section h2 {
    font-size: 0.95rem;
    margin-bottom: 8px;
  }

  .underlying-status-list,
  .barrier-grid,
  .memory-ko-table,
  .status-history-table,
  .coupon-table,
  .allocation-list {
    display: block;
  }

  .underlying-status-row {
    grid-template-columns: minmax(52px, 0.6fr) repeat(3, minmax(76px, 1fr)) minmax(66px, auto);
    padding: 5px 0;
    font-size: 0.8rem;
  }

  .barrier-grid {
    gap: 8px;
    overflow: visible;
  }

  .barrier-card {
    gap: 10px;
    min-width: 0;
    margin-bottom: 12px;
    padding: 10px 12px;
  }

  .barrier-card-head {
    display: grid;
    grid-template-columns: minmax(48px, 0.45fr) minmax(0, 1fr) auto;
    gap: 8px;
    font-size: 0.8rem;
  }

  .barrier-card-head span {
    text-align: center;
  }

  .barrier-card-head em {
    justify-self: end;
    white-space: nowrap;
  }

  .barrier-scale-meta {
    font-size: 0.72rem;
  }

  .barrier-line {
    height: 98px;
    min-width: 0;
    width: 100%;
  }

  .barrier-threshold b {
    font-size: 0.78rem;
  }

  .barrier-threshold strong,
  .barrier-threshold small {
    font-size: 0.66rem;
  }

  .barrier-threshold {
    min-width: 68px;
  }

  .memory-ko-panel,
  .contract-grid,
  .coupon-summary,
  .coupon-allocation-summary,
  .coupon-table,
  .allocation-list {
    font-size: 0.84rem;
  }

  .memory-ko-panel {
    margin-top: 12px;
  }
}

@media screen and (max-width: 760px) {
  .app-header,
  .page-title,
  .panel-head,
  .customer-detail-head,
  .customer-contract-main,
  .detail-hero-top,
  .section-title-row,
  .barrier-card-head,
  .position-top,
  .position-main,
  .app-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .position-actions {
    flex-wrap: wrap;
    white-space: normal;
  }

  .position-summary {
    display: grid;
    gap: 6px;
  }

  .position-summary span + span::before {
    content: "";
    margin-right: 0;
  }

  .detail-shell {
    gap: 14px;
  }

  .detail-hero {
    padding: 16px;
  }

  .detail-hero h1 {
    font-size: 1.55rem;
    line-height: 1.25;
  }

  .detail-section {
    gap: 12px;
  }

  .underlying-status-row small {
    justify-self: start;
  }

  .barrier-card {
    gap: 14px;
    min-width: 430px;
    padding: 14px;
  }

  .barrier-card-head {
    gap: 8px;
  }

  .barrier-card-head > span {
    display: grid;
    gap: 2px;
    font-size: 0.95rem;
  }

  .barrier-card-head em {
    justify-self: stretch;
    text-align: center;
  }

  .barrier-scale-meta {
    font-size: 0.82rem;
  }

  .barrier-line {
    width: 100%;
    min-width: 390px;
    height: 92px;
    padding-top: 0;
  }

  .barrier-grid {
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .barrier-threshold.ki {
    position: absolute;
    transform: translateX(-50%);
    text-align: center;
  }

  .barrier-threshold.strike {
    position: absolute;
    transform: translateX(-50%);
    text-align: center;
  }

  .barrier-threshold.ko {
    position: absolute;
    transform: translateX(-50%);
    text-align: center;
  }

  .barrier-threshold {
    min-width: 78px;
  }

  .barrier-threshold strong,
  .barrier-threshold b,
  .barrier-threshold small {
    display: block;
    white-space: nowrap;
  }

  .barrier-threshold b {
    font-size: 0.78rem;
  }

  .barrier-threshold strong,
  .barrier-threshold small {
    font-size: 0.7rem;
  }

  .barrier-threshold small {
    display: block;
    margin-top: 2px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid,
  .two-column,
  .contract-grid,
  .customer-selector-form,
  .customer-money-grid,
  .customer-contract-card.compact,
  .customer-contract-facts,
  .customer-distribution,
  .calendar-filter-bar,
  .calendar-range-tabs,
  .calendar-event-row,
  .hero-facts,
  .underlying-status-row,
  .memory-ko-row,
  .status-history-row,
  .job-run-row,
  .coupon-row,
  .detail-actions,
  .position-facts,
  .position-price-row,
  .form-grid,
  .allocation-row,
  .coupon-edit-row,
  .underlying-row,
  .filter-bar,
  .inline-form,
  .row,
  .facts-row {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: stretch;
  }
}
