:root {
  --bg-page: #f4f7fb;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;

  --navy-950: #091b2d;
  --navy-900: #0f2942;
  --navy-800: #163a5f;
  --navy-700: #1e4b7a;
  --navy-100: #e8f0f8;
  --navy-50: #f2f6fb;

  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #eff6ff;
  --accent-border: #bfdbfe;

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  --border-light: #e2e8f0;
  --border-strong: #cbd5e1;

  --safe-700: #047857;
  --safe-600: #059669;
  --safe-500: #10b981;
  --safe-100: #d1fae5;
  --safe-50: #ecfdf5;
  --safe-border: #a7f3d0;

  --amber-700: #b45309;
  --amber-600: #d97706;
  --amber-500: #f59e0b;
  --amber-50: #fffbeb;
  --amber-border: #fde68a;

  --danger-700: #b91c1c;
  --danger-600: #dc2626;
  --danger-500: #ef4444;
  --danger-50: #fef2f2;
  --danger-border: #fecaca;

  /* Cost component bar colors */
  --bar-commission: #3b82f6;
  --bar-interest: #0f2942;
  --bar-management: #f59e0b;
  --bar-transfer: #10b981;
  --bar-extra: #e11d48;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 41, 66, 0.05);
  --shadow-card: 0 4px 18px rgba(15, 41, 66, 0.06), 0 1px 3px rgba(15, 41, 66, 0.04);
  --shadow-float: 0 -6px 24px rgba(15, 41, 66, 0.14);

  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, sans-serif;
  --font-num: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --transition-fast: 150ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --transition-med: 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-page);
  min-height: 100vh;
  padding-bottom: 88px;
  -webkit-font-smoothing: antialiased;
}

.tabular-nums,
.num-input {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

button,
input,
select {
  font-family: inherit;
}

[hidden] {
  display: none !important;
}

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 100%);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.header-wrap {
  max-width: 1140px;
  margin: 0 auto;
  padding: 12px 16px 18px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.back-link:hover {
  color: #ffffff;
}

.header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.header-brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #38bdf8;
}

.site-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.site-subtitle {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.45;
}

.btn-ghost {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.4);
}

/* ==========================================================================
   Main Layout & Cards
   ========================================================================== */
.main-container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 18px 14px 36px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.calculator-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}

.input-column,
.result-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  box-shadow: var(--shadow-card);
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
}

.section-desc {
  margin: 3px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--safe-700);
  background: var(--safe-50);
  border: 1px solid var(--safe-border);
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.live-indicator::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--safe-500);
}

/* ==========================================================================
   Form Controls
   ========================================================================== */
.calc-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-group-compact {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

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

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.form-label {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.form-label-sm {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.label-optional {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-muted);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.field-sub-readout {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--navy-700);
  background: var(--navy-50);
  border: 1px solid var(--navy-100);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.form-hint {
  margin: 0;
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.inline-hint {
  margin: 2px 0 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--amber-700);
  background: var(--amber-50);
  border: 1px solid var(--amber-border);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.form-divider {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 2px 0;
}

/* Segmented Buttons */
.segment-grid {
  display: grid;
  gap: 7px;
}

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

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

.segment-btn {
  appearance: none;
  border: 1.5px solid var(--border-light);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: all var(--transition-fast);
}

.segment-btn:hover {
  border-color: var(--border-strong);
  background: #ffffff;
}

.segment-btn.is-active {
  border-color: var(--navy-900);
  background: var(--navy-900);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(15, 41, 66, 0.16);
}

.segment-btn-buy.is-active {
  border-color: #0f4c81;
  background: #0f4c81;
}

.segment-btn-sell.is-active {
  border-color: #9f1239;
  background: #9f1239;
}

.segment-main {
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.3;
}

.segment-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.segment-btn.is-active .segment-sub {
  color: rgba(255, 255, 255, 0.8);
}

/* Inputs */
.input-unit-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input,
.form-select {
  width: 100%;
  min-height: 42px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-primary);
  background: #ffffff;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-unit-wrap .form-input {
  padding-right: 46px;
}

#managementMonths {
  padding-right: 60px;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.form-input:disabled {
  background: var(--bg-muted);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.input-unit {
  position: absolute;
  right: 11px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

.date-input {
  font-size: 0.86rem;
  padding: 7px 9px;
}

/* Quick Chips */
.quick-chips,
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-group-tight {
  gap: 5px;
  margin-top: 2px;
}

.chip-btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip-btn:hover {
  border-color: var(--navy-700);
  color: var(--navy-900);
  background: var(--navy-50);
}

.chip-btn.is-active {
  border-color: var(--navy-900);
  background: var(--navy-900);
  color: #ffffff;
}

.chip-btn-xs {
  padding: 3px 8px;
  font-size: 0.72rem;
}

.unit-size-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.unit-size-input-wrap {
  width: 118px;
  flex-shrink: 0;
}

/* Inline Notice */
.inline-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  line-height: 1.5;
  margin-top: 4px;
}

.inline-notice-amber {
  background: var(--amber-50);
  border: 1px solid var(--amber-border);
  color: #78350f;
}

.notice-icon {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--amber-600);
}

/* Days Slider */
.days-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.days-input-wrap {
  width: 104px;
  flex-shrink: 0;
}

.days-input-wrap .form-input {
  padding-right: 32px;
}

.slider-wrap {
  margin-top: 4px;
}

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--border-light);
  outline: none;
  cursor: pointer;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--navy-900);
  border: 3px solid #ffffff;
  box-shadow: 0 1px 5px rgba(15, 41, 66, 0.35);
  cursor: pointer;
}

.range-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--navy-900);
  border: 3px solid #ffffff;
  box-shadow: 0 1px 5px rgba(15, 41, 66, 0.35);
  cursor: pointer;
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-subtle);
  margin-top: 4px;
}

.mini-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.form-group.is-disabled-group {
  opacity: 0.58;
}

.extra-cost-box {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: var(--radius-md);
  padding: 11px 12px;
}

.extra-cost-box .input-unit {
  font-size: 0.72rem;
}

.extra-cost-box .input-unit-wrap .form-input {
  padding-right: 76px;
}

/* Sub-accordion */
.sub-accordion {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  margin-top: 4px;
}

.sub-accordion-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--navy-800);
  cursor: pointer;
  user-select: none;
}

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

.accordion-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

details[open] > summary .accordion-chevron {
  transform: rotate(225deg);
}

.sub-accordion-body {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 0.76rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-row input {
  margin-top: 3px;
}

.date-calc-feedback {
  margin: 0;
  font-size: 0.76rem;
  color: var(--navy-800);
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

/* Broker Custom Config Panel */
.custom-panel-desc {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.broker-config-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.broker-config-row {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.broker-config-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.broker-config-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
}

.broker-config-controls {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 8px;
  align-items: center;
}

.broker-config-controls .form-select {
  min-height: 36px;
  font-size: 0.78rem;
  padding: 5px 8px;
}

.broker-config-controls .form-input {
  min-height: 36px;
  font-size: 0.8rem;
  padding: 5px 26px 5px 8px;
}

.broker-config-controls .input-unit {
  right: 8px;
  font-size: 0.72rem;
}

/* ==========================================================================
   Result Hero Card
   ========================================================================== */
.result-hero-card {
  border-top: 4px solid var(--safe-600);
}

.result-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.result-label-title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.condition-pill {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--navy-800);
  background: var(--navy-100);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.hero-warning {
  background: var(--amber-50);
  border: 1px solid var(--amber-border);
  color: #78350f;
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 0.76rem;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.5;
}

.hero-winner-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.winner-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--safe-600);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
}

.winner-name {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-primary);
}

.winner-plan {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.hero-cost-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-light);
}

.hero-cost-value {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--navy-900);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.hero-cost-unit {
  font-size: 1rem;
  font-weight: 700;
  margin-left: 3px;
  color: var(--text-secondary);
}

.hero-cost-rate {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--safe-700);
  background: var(--safe-50);
  border: 1px solid var(--safe-border);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

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

.kpi-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.3;
}

.kpi-value-safe {
  color: var(--safe-700);
}

.kpi-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.hero-unavailable {
  padding: 20px 12px;
  text-align: center;
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
}

.hero-unavailable-title {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.hero-unavailable-desc {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Stacked Bar Chart Card
   ========================================================================== */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.dot-commission { background: var(--bar-commission); }
.dot-interest { background: var(--bar-interest); }
.dot-management { background: var(--bar-management); }
.dot-transfer { background: var(--bar-transfer); }
.dot-extra { background: var(--bar-extra); }

.broker-bars {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.bar-row {
  appearance: none;
  width: 100%;
  text-align: left;
  background: var(--bg-subtle);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 9px 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
}

.bar-row:hover {
  border-color: var(--border-strong);
  background: #ffffff;
}

.bar-row.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.1);
}

.bar-row.is-unavailable {
  opacity: 0.62;
  cursor: default;
}

.bar-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.bar-broker-info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.rank-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.rank-pill-1 {
  background: var(--safe-600);
  color: #ffffff;
}

.bar-broker-name {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-primary);
}

.bar-broker-rate {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.bar-amount-group {
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.bar-total {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--text-primary);
}

.bar-diff {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--danger-600);
}

.bar-diff-zero {
  color: var(--safe-700);
}

.stacked-track {
  width: 100%;
  height: 11px;
  background: var(--border-light);
  border-radius: var(--radius-pill);
  overflow: hidden;
  display: flex;
}

.bar-seg {
  height: 100%;
  transition: width 260ms ease;
}

.seg-commission { background: var(--bar-commission); }
.seg-interest { background: var(--bar-interest); }
.seg-management { background: var(--bar-management); }
.seg-transfer { background: var(--bar-transfer); }
.seg-extra { background: var(--bar-extra); }

.bar-na-note {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Detail Breakdown Card
   ========================================================================== */
.rate-pill {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--navy-900);
  background: var(--navy-100);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 11px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
}

.breakdown-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.breakdown-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-primary);
}

.breakdown-formula {
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.breakdown-amount {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-primary);
  white-space: nowrap;
}

.detail-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px 2px;
  margin-top: 10px;
  border-top: 2px solid var(--navy-900);
}

.detail-total-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.detail-total-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--navy-900);
}

.asset-diff-callout {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--safe-50);
  border: 1px solid var(--safe-border);
  color: #065f46;
  font-size: 0.77rem;
  line-height: 1.5;
}

.detail-actions {
  margin-top: 14px;
}

.btn-primary {
  appearance: none;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--navy-900);
  color: #ffffff;
  padding: 11px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.btn-primary:hover {
  background: var(--navy-800);
}

.btn-primary:active {
  transform: scale(0.99);
}

/* ==========================================================================
   Tables (Comparison, Matrix, Spec)
   ========================================================================== */
.tier-badge {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x pan-y;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
}

.comparison-table,
.matrix-table,
.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  min-width: 660px;
}

.comparison-table th,
.matrix-table th,
.spec-table th {
  background: var(--bg-muted);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.75rem;
  text-align: left;
  padding: 10px 11px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.comparison-table td,
.matrix-table td,
.spec-table td {
  padding: 11px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.comparison-table tbody tr:last-child td,
.matrix-table tbody tr:last-child td,
.spec-table tbody tr:last-child td {
  border-bottom: none;
}

.num-col {
  text-align: right !important;
  white-space: nowrap;
}

.winner-col {
  text-align: center !important;
  white-space: nowrap;
}

.comparison-table tbody tr {
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.comparison-table tbody tr:hover {
  background: var(--navy-50);
}

.comparison-table tbody tr.is-cheapest {
  background: var(--safe-50);
}

.comparison-table tbody tr.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.comparison-table tbody tr.is-unavailable {
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: default;
}

.broker-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.broker-cell-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.broker-cell-name {
  font-weight: 700;
  color: var(--text-primary);
}

.broker-cell-plan {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.total-cell-main {
  font-weight: 800;
  font-size: 0.94rem;
  color: var(--text-primary);
}

.total-cell-diff {
  display: block;
  font-size: 0.71rem;
  font-weight: 700;
  color: var(--danger-600);
}

.total-cell-diff.is-best {
  color: var(--safe-700);
}

.na-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-muted);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.na-text {
  color: var(--text-muted);
  font-weight: 600;
}

.table-footnote {
  margin: 10px 0 0;
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Days Matrix */
.crossover-insight {
  margin-bottom: 12px;
  padding: 10px 13px;
  border-radius: var(--radius-md);
  background: var(--navy-50);
  border: 1px solid var(--navy-100);
  color: var(--navy-900);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.5;
}

.matrix-table tbody tr {
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.matrix-table tbody tr:hover {
  background: var(--navy-50);
}

.matrix-table tbody tr.is-current-days {
  background: var(--accent-soft);
}

.matrix-cell-best {
  font-weight: 800;
  color: var(--safe-700);
  background: rgba(16, 185, 129, 0.09);
}

.matrix-winner-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--safe-100);
  color: var(--safe-700);
}

/* Spec Table */
.spec-table-wrap {
  margin-bottom: 16px;
}

.spec-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.merged-cell {
  background: var(--bg-subtle);
  border-left: 1px solid var(--border-light);
  line-height: 1.55;
}

/* ==========================================================================
   History Section
   ========================================================================== */
.count-badge {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-muted);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin-left: 4px;
}

.btn-danger-ghost {
  appearance: none;
  border: 1px solid var(--danger-border);
  background: var(--danger-50);
  color: var(--danger-700);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-danger-ghost:hover {
  background: #fee2e2;
}

.history-empty {
  text-align: center;
  padding: 20px 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  cursor: pointer;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.history-item:hover {
  border-color: var(--navy-700);
  background: #ffffff;
}

.history-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-primary);
}

.history-meta {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.history-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.history-cost {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--safe-700);
  text-align: right;
}

.history-delete-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-subtle);
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.history-delete-btn:hover {
  background: var(--danger-50);
  color: var(--danger-600);
}

/* ==========================================================================
   Guide Accordions
   ========================================================================== */
.accordion-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.accordion-item {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.accordion-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
}

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

.accordion-body {
  padding: 0 14px 14px;
  font-size: 0.83rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

.accordion-body ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.accordion-body li + li {
  margin-top: 6px;
}

.formula-box {
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-left: 3.5px solid var(--navy-900);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  overflow-x: auto;
  overflow-y: hidden;
}

.formula-box code {
  font-family: var(--font-num);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--navy-900);
}

/* ==========================================================================
   Footer, Mobile Sticky Bar & Toast
   ========================================================================== */
.site-footer {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 14px 24px;
}

.footer-inner {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.6;
  border-top: 1px solid var(--border-light);
  padding-top: 14px;
}

.footer-inner p {
  margin: 0;
}

.mobile-sticky-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: rgba(15, 41, 66, 0.96);
  backdrop-filter: blur(8px);
  color: #ffffff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow-float);
}

.sticky-metrics {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.sticky-item {
  display: flex;
  flex-direction: column;
}

.sticky-label {
  font-size: 0.66rem;
  color: rgba(255, 255, 255, 0.72);
}

.sticky-broker,
.sticky-cost {
  font-size: 0.92rem;
  font-weight: 800;
  white-space: nowrap;
}

.sticky-cost {
  color: #6ee7b7;
}

.sticky-divider {
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, 0.2);
}

.sticky-jump-btn {
  text-decoration: none;
  background: #ffffff;
  color: var(--navy-900);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--navy-950);
  color: #ffffff;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(15, 41, 66, 0.28);
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Responsive Desktop Layout
   ========================================================================== */
@media (min-width: 860px) {
  body {
    padding-bottom: 24px;
  }

  .header-wrap {
    padding: 16px 24px 22px;
  }

  .site-title {
    font-size: 1.32rem;
  }

  .main-container {
    padding: 24px 24px 44px;
    gap: 22px;
  }

  .calculator-layout {
    grid-template-columns: minmax(0, 1.04fr) minmax(0, 0.96fr);
    gap: 22px;
  }

  .card {
    padding: 22px 22px;
  }

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

  .mobile-sticky-bar {
    display: none;
  }

  .toast {
    bottom: 24px;
  }
}
