/* ── Variables ─────────────────────────────────────── */
:root {
  --primary:      #1565C0;
  --primary-dark: #0D47A1;
  --primary-light:#E3F2FD;
  --green:        #2E7D32;
  --red:          #C62828;
  --orange:       #E65100;
  --text:         #1a1a1a;
  --muted:        #6B7280;
  --border:       #E5E7EB;
  --bg:           #F3F4F6;
  --card:         #FFFFFF;
  --radius:       10px;
  --sidebar-w:    280px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
    'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
}

/* ── Header ─────────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #0D47A1, #1976D2);
  color: #fff;
}
.header-inner { padding: 16px 20px 12px; }
.header-inner h1 {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.4px;
}
.header-sub {
  font-size: 12px;
  opacity: 0.78;
  margin-top: 3px;
}

/* ── Ad slots ───────────────────────────────────────── */
.ad-slot {
  background: #fafafa;
  border: 1px dashed #d1d5db;
  border-radius: var(--radius);
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 14px 0;
}
.ad-header {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 0;
  min-height: 60px;
  margin: 0;
}
.ad-label {
  font-size: 10px;
  color: #9CA3AF;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ── Layout ─────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: calc(100vh - 100px);
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-toggle {
  display: none;
  width: 100%;
  padding: 13px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.sidebar-body { padding: 16px; }

.input-group {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.input-group:last-child { border-bottom: none; }
.input-group h2 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--primary);
  margin-bottom: 10px;
}

.field { margin-bottom: 9px; }
.field label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}
.field input[type="number"] {
  width: 100%;
  padding: 7px 9px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21,101,192,0.1);
}
.field input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  margin-top: 4px;
}
.range-val {
  margin-left: auto;
  font-weight: 700;
  color: var(--primary);
  font-size: 13px;
}
.field-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  margin-bottom: 4px;
}
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  background: var(--muted);
  color: #fff;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  cursor: help;
  flex-shrink: 0;
}

/* ── Main ───────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 16px 20px;
  min-width: 0;
}

.alert {
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  border-radius: var(--radius);
  padding: 10px 14px;
  color: #92400E;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── Cards ──────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
}
.card-desc {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.6;
}

/* ── KPI Grid ───────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.kpi-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.kpi-card.highlight {
  background: var(--primary-light);
  border-color: #90CAF9;
}
.kpi-label {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 4px;
  white-space: nowrap;
}
.kpi-value {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}
.kpi-card.highlight .kpi-value { color: var(--primary-dark); }

/* ── Loan summary ───────────────────────────────────── */
.loan-summary {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.summary-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.summary-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

/* ── Crossover badge ────────────────────────────────── */
.crossover-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  padding: 10px 16px;
  margin-bottom: 14px;
}
.cb-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  opacity: 0.8;
}
.cb-value {
  font-size: 22px;
  font-weight: 800;
}

/* ── Chart ──────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 340px;
  margin-bottom: 10px;
}
.chart-note {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}

/* ── Table ──────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}
.data-table th {
  background: var(--primary);
  color: #fff;
  padding: 8px 12px;
  text-align: right;
  font-weight: 600;
  line-height: 1.4;
}
.data-table th:first-child { text-align: center; }
.data-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}
.data-table td:first-child { text-align: center; font-weight: 700; }
.data-table tbody tr:hover  { background: var(--bg); }
.data-table td.pos { color: var(--green); font-weight: 700; }
.data-table td.neg { color: var(--red); }
/* 損益分岐行をハイライト */
.data-table tbody tr.crossover-row td { background: #E8F5E9; }
.data-table tbody tr.crossover-row td:first-child::after {
  content: ' ✓';
  color: var(--green);
}

/* ── Year selector ──────────────────────────────────── */
.year-selector {
  margin-bottom: 20px;
}
.year-selector input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  height: 6px;
  margin-bottom: 8px;
}
.year-label {
  text-align: center;
  font-size: 15px;
  color: var(--muted);
}
.year-label strong {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  margin: 0 2px;
}

/* ── Year detail ────────────────────────────────────── */
.year-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.detail-block {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px 16px;
}
.detail-block-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 12px;
}
.detail-rows { display: flex; flex-direction: column; gap: 6px; }
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-row span { color: var(--muted); }
.detail-row strong { font-weight: 700; }
.detail-row.total {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 2px solid var(--border);
  border-bottom: none;
}
.detail-row.total span { color: var(--text); font-weight: 600; }
.detail-row.total strong { font-size: 16px; }
strong.pos { color: var(--green); }
strong.neg { color: var(--red); }

.detail-note {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ── Cost versus ────────────────────────────────────── */
.cost-versus {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 12px;
}
.cv-col {
  flex: 1;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: center;
}
.cv-buy  { background: var(--primary-light); border: 1.5px solid #90CAF9; }
.cv-rent { background: #FFF3E0; border: 1.5px solid #FFCC80; }
.cv-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
}
.cv-head {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}
.cv-buy  .cv-head { color: var(--primary); }
.cv-rent .cv-head { color: var(--orange); }
.cv-value {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
}
.cv-buy  .cv-value { color: var(--primary-dark); }
.cv-rent .cv-value { color: var(--orange); }
.cv-sub { font-size: 10px; color: var(--muted); }

/* ── Verdict ────────────────────────────────────────── */
.verdict {
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.verdict.buy-wins  { background: var(--primary-light); color: var(--primary-dark); }
.verdict.rent-wins { background: #FFF3E0; color: var(--orange); }
.verdict.even      { background: #F3F4F6; color: var(--muted); }

/* ── Footer ─────────────────────────────────────────── */
.site-footer {
  background: #263238;
  color: #90A4AE;
  text-align: center;
  padding: 14px;
  font-size: 11px;
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 780px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; min-width: unset;
    height: auto; position: static; overflow: visible;
  }
  .sidebar-toggle { display: block; }
  .sidebar-body { display: none; border-top: 1px solid var(--border); }
  .sidebar-body.open { display: block; }
  .main { padding: 12px; }
  .chart-wrap { height: 260px; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .loan-summary { gap: 16px; }
  .chart-wrap { height: 220px; }
  .year-detail { grid-template-columns: 1fr; }
  .cost-versus { flex-direction: column; gap: 8px; }
  .cv-sep { width: 100%; height: 24px; }
}
