:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ===== HEADER ===== */
.header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: white;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(37,99,235,0.35);
  position: sticky;
  top: 0;
  z-index: 200;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.18);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  backdrop-filter: blur(4px);
}

.header-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header-text p {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 1px;
}

/* Mode Toggle */
.mode-toggle {
  display: flex;
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  padding: 4px;
  gap: 2px;
}

.mode-btn {
  padding: 6px 18px;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  color: rgba(255,255,255,0.65);
  background: transparent;
  letter-spacing: 0.02em;
}

.mode-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

/* ===== MAIN LAYOUT ===== */
.main {
  display: grid;
  grid-template-columns: 1fr 390px;
  gap: 20px;
  padding: 20px;
  max-width: 1380px;
  margin: 0 auto;
  align-items: start;
}

.input-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.result-col {
  position: sticky;
  top: 80px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== SELLING PRICE SECTION ===== */
.price-section {
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  border-radius: var(--radius);
  padding: 20px 22px;
  color: white;
  box-shadow: var(--shadow-md);
}

.price-section-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.price-input-block {
  flex: 1;
}

.price-input-block label {
  font-size: 12px;
  opacity: 0.8;
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
}

.price-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.price-currency {
  font-size: 26px;
  font-weight: 300;
  opacity: 0.75;
  line-height: 1;
}

.price-input {
  flex: 1;
  border: none;
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 28px;
  font-weight: 700;
  color: white;
  outline: none;
  width: 0;
  transition: background 0.2s;
  min-width: 0;
}

.price-input:focus {
  background: rgba(255,255,255,0.22);
}

.price-input::placeholder {
  color: rgba(255,255,255,0.35);
  font-weight: 400;
}

/* Platform grid */
.platform-block {
  flex-shrink: 0;
}

.platform-block label {
  font-size: 12px;
  opacity: 0.8;
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
}

.platform-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  width: 220px;
}

.platform-btn-item {
  padding: 6px 4px;
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  color: rgba(255,255,255,0.75);
  line-height: 1.3;
}

.platform-btn-item:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.4);
}

.platform-btn-item.active {
  background: white;
  color: var(--primary);
  border-color: white;
  font-weight: 700;
}

.platform-btn-item .p-emoji {
  font-size: 14px;
  display: block;
  margin-bottom: 1px;
}

/* ===== ACCORDION PANELS ===== */
.accordion {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.acc-header {
  padding: 13px 16px;
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  border-bottom: 1px solid transparent;
}

.acc-header:hover {
  background: #f8fafc;
}

.acc-header.open {
  border-bottom-color: var(--border);
}

.acc-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  margin-right: 11px;
}

.acc-info {
  flex: 1;
  min-width: 0;
}

.acc-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.acc-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.acc-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-left: 10px;
}

.acc-total {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  min-width: 64px;
  text-align: right;
}

.acc-total.zero {
  color: var(--text-light);
}

.acc-arrow {
  color: var(--text-light);
  font-size: 11px;
  transition: transform 0.25s ease;
}

.acc-header.open .acc-arrow {
  transform: rotate(180deg);
}

.acc-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.acc-body.open {
  max-height: 2000px;
}

.acc-content {
  padding: 16px;
}

/* ===== FORM FIELDS ===== */
.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.field-tip {
  font-size: 10px;
  color: var(--text-light);
  margin-top: 3px;
  line-height: 1.4;
}

.input-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.15s;
  background: white;
  height: 36px;
}

.input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.08);
}

.input-pre,
.input-suf {
  padding: 0 9px;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 12px;
  height: 100%;
  display: flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.input-suf {
  border-right: none;
  border-left: 1px solid var(--border);
}

.input-wrap input,
.input-wrap select {
  flex: 1;
  border: none;
  outline: none;
  padding: 0 9px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  height: 100%;
  min-width: 0;
}

.input-wrap select {
  cursor: pointer;
}

/* Subsections inside accordion */
.subsection {
  margin-bottom: 14px;
}

.subsection:last-child {
  margin-bottom: 0;
}

.subsection-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
  display: flex;
  align-items: center;
  gap: 5px;
}

.sep {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

/* Amortization helper box */
.amort-box {
  background: #f0fdf4;
  border: 1.5px solid #bbf7d0;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 8px;
}

.amort-box-title {
  font-size: 11px;
  font-weight: 600;
  color: #166534;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.amort-result {
  margin-top: 8px;
  background: white;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  color: #166534;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Calculated display field */
.calc-display {
  background: var(--primary-light);
  border: 1.5px dashed #93c5fd;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Warning box */
.warn-box {
  background: #fff7ed;
  border-left: 3px solid #f97316;
  border-radius: 0 6px 6px 0;
  padding: 8px 11px;
  font-size: 11px;
  color: #7c2d12;
  line-height: 1.5;
  margin-top: 8px;
}

/* ===== RESULTS PANEL ===== */

/* Hero */
.result-hero {
  border-radius: var(--radius);
  padding: 20px 22px;
  color: white;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.result-hero::before {
  content: '';
  position: absolute;
  top: -30px;
  right: -30px;
  width: 120px;
  height: 120px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
}

.result-hero::after {
  content: '';
  position: absolute;
  bottom: -20px;
  left: -20px;
  width: 80px;
  height: 80px;
  background: rgba(255,255,255,0.06);
  border-radius: 50%;
}

.result-hero.green  { background: linear-gradient(135deg, #065f46, #10b981); }
.result-hero.yellow { background: linear-gradient(135deg, #78350f, #f59e0b); }
.result-hero.red    { background: linear-gradient(135deg, #7f1d1d, #ef4444); }
.result-hero.gray   { background: linear-gradient(135deg, #334155, #64748b); }

.result-hero-label {
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 6px;
  font-weight: 500;
}

.result-margin-val {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  position: relative;
  z-index: 1;
}

.result-hero-sub {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.2);
}

.rhs-item .rhs-val {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  position: relative;
  z-index: 1;
}

.rhs-item .rhs-lbl {
  font-size: 10px;
  opacity: 0.75;
  margin-top: 3px;
}

/* Result cards */
.result-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.result-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 13px 16px 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Chart */
.chart-container {
  padding: 12px 16px;
  position: relative;
}

.chart-canvas-wrap {
  position: relative;
  height: 160px;
  margin-bottom: 4px;
}

/* Breakdown list */
.breakdown-list {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 280px;
  overflow-y: auto;
}

.breakdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.12s;
}

.breakdown-item:hover {
  background: #f8fafc;
}

.bd-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bd-name {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bd-pct {
  font-size: 10px;
  color: var(--text-muted);
  width: 34px;
  text-align: right;
  flex-shrink: 0;
}

.bd-amt {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  width: 58px;
  text-align: right;
  flex-shrink: 0;
}

.bd-profit {
  border-top: 1px solid var(--border);
  margin-top: 2px;
  padding-top: 6px;
}

/* Info grid */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 12px 0;
}

.info-card {
  background: #f8fafc;
  border-radius: 10px;
  padding: 12px;
}

.info-card .ic-val {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.info-card .ic-lbl {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Reverse calculator */
.reverse-calc {
  padding: 12px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.reverse-calc-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.reverse-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.reverse-input-row .input-wrap {
  flex: 1;
  border-color: #fde68a;
}

.reverse-input-row .input-wrap:focus-within {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245,158,11,0.1);
}

.reverse-result-box {
  margin-top: 8px;
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  border-radius: 8px;
  padding: 9px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rr-label {
  font-size: 11px;
  color: #92400e;
}

.rr-val {
  font-size: 16px;
  font-weight: 700;
  color: #92400e;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-muted);
}

.empty-state .es-icon {
  font-size: 36px;
  margin-bottom: 10px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 13px;
  opacity: 0.7;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray   { background: #f1f5f9; color: #475569; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .main {
    grid-template-columns: 1fr 340px;
    gap: 14px;
    padding: 14px;
  }
  .platform-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }
  .result-col {
    position: static;
    order: -1;
  }
  .platform-grid {
    width: 100%;
    grid-template-columns: repeat(4, 1fr);
  }
  .price-section-top {
    flex-direction: column;
    gap: 14px;
  }
  .platform-block { width: 100%; }
  .result-hero-sub { grid-template-columns: 1fr 1fr 1fr; }
}

@media (max-width: 480px) {
  .header { padding: 0 14px; }
  .header-text p { display: none; }
  .mode-btn { padding: 5px 12px; font-size: 12px; }
  .platform-grid { grid-template-columns: repeat(4, 1fr); }
  .fields-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: 1; }
}

/* ===== MODE VISIBILITY ===== */
.adv-only { display: none; }
body.is-advanced .adv-only { display: block; }
body.is-advanced .basic-only { display: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
