:root {
  color-scheme: light;
  --surface-base: #FFFFFF;
  --surface-tint: #F5F5F5;
  --surface-tint-soft: #EBEBEB;
  --surface-muted: #D4D4D4;
  --surface-line: #D9D9D9;
  --text-primary: #262626;
  --text-strong: #000000;
  --text-secondary: #7F7F7F;
  --text-tertiary: #A6A6A6;
  --accent: #FDD42B;
  --accent-deep: #FADC2E;
  --accent-secondary: #E97132;
  --accent-secondary-deep: #C04F15;
  --focus: #042433;
  --error: #FF0000;
  --green: #1f7a4d;
  --green-soft: #ddf3e7;
  --red: #a33a3a;
  --red-soft: #f7dddd;
  --amber-soft: #FEEFB2;
  --chart-bar: #2c5282;
  --chart-bar-negative: #c04f15;
  --surface-blue-tint: #EFF3FA;
  --surface-header: #f5f5f5;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 6px 24px rgba(0, 0, 0, 0.03);
  /* Responsive spacing rhythm — shrinks at smaller breakpoints */
  --pad-x: 24px;
  --pad-y: 24px;
  --stack-gap: 24px;
  --grid-gap: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface-base);
  color: var(--text-primary);
  font-family:
    "Noto Sans JP", "Yu Gothic", "Yu Gothic UI",
    "Hiragino Sans", "Meiryo", sans-serif;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.7;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--surface-muted);
  background: var(--surface-base);
  color: var(--text-primary);
  min-height: 36px;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 500;
  transition:
    border-color 200ms ease,
    background 200ms ease;
}

button:hover,
.file-button:hover {
  border-color: #b8b8b8;
  background: var(--surface-tint);
}

button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button.primary {
  background: var(--text-strong);
  border-color: var(--text-strong);
  color: var(--surface-base);
  font-weight: 700;
}

button.primary:hover {
  background: #333;
  border-color: #333;
}

button.ghost {
  background: transparent;
}

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

button.danger:hover {
  background: var(--red-soft);
}

button svg,
.file-button svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  flex-shrink: 0;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--surface-line);
  backdrop-filter: blur(16px);
}

.topbar-inner {
  max-width: 1520px;
  margin: 0 auto;
  min-height: 76px;
  padding: 16px var(--pad-x);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 24px;
}

.brand {
  display: grid;
  gap: 4px;
}

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

.brand-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
}

.brand-divider {
  width: 1px;
  height: 20px;
  background: var(--surface-muted);
}

.eyebrow {
  color: var(--focus);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(20px, 4.2vw, 28px);
  font-weight: 700;
  color: var(--text-strong);
  overflow-wrap: anywhere;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 13px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Dashboard */
.dashboard {
  background: var(--surface-base);
  border-bottom: 1px solid var(--surface-line);
}

.dashboard-inner {
  max-width: 1520px;
  margin: 0 auto;
  padding: 20px var(--pad-x);
}

#dashboard-metrics {
  display: grid;
  gap: 8px;
  min-height: 72px;
  align-content: center;
}

.hero-metrics {
  display: flex;
  align-items: baseline;
  gap: 40px;
}

.hero-metric {
  display: grid;
  gap: 2px;
}

.hero-metric span {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.hero-metric strong {
  font-size: clamp(26px, 5.5vw, 36px);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.hero-metric small {
  font-size: 16px;
  font-weight: 500;
}

.hero-metric.positive strong {
  color: var(--green);
}

.hero-metric.negative strong {
  color: var(--red);
}

.sub-metrics {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.sub-metric {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.sub-metric span {
  font-size: 12px;
  color: var(--text-secondary);
}

.sub-metric strong {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sub-metric small {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
}

.sub-metrics .scenario-row {
  margin-left: auto;
}

/* Assumptions row (forecast + capital side by side) */
.assumptions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--stack-gap);
}

.assumptions-row .section {
  min-width: 0;
}

.subsection-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--surface-line);
}

/* Main content (vertical stack) */
.main-content {
  max-width: 1520px;
  width: 100%;
  margin: 0 auto;
  padding: var(--pad-y) var(--pad-x);
  display: grid;
  gap: var(--stack-gap);
}

/* ===== 入力 / 分析・結果 タブ ===== */
.view-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 12px;
  width: fit-content;
}

.view-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 22px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.view-tab:hover { color: var(--text-primary); }

.view-tab.active {
  background: var(--surface-base);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.08));
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: var(--stack-gap);
}

.results-empty {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 4px;
}

.results-empty svg { flex: 0 0 auto; width: 18px; height: 18px; }
.results-empty p { margin: 0; }

.link-btn {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  color: var(--accent, #c8a84b);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

.info-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--stack-gap);
}

.detail-sections {
  display: grid;
  gap: var(--stack-gap);
}

/* Assumptions summary */
.assumptions-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.assumption-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 12px;
  background: var(--surface-tint);
  border-radius: 8px;
  font-size: 13px;
}

.assumption-item span {
  color: var(--text-secondary);
}

.assumption-item strong {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.section {
  background: var(--surface-base);
  border: 1px solid var(--surface-line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-header {
  padding: 16px var(--pad-x);
  border-bottom: 1px solid var(--surface-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.section-title {
  display: grid;
  gap: 4px;
}

.section-title h2 {
  font-size: 16px;
  font-weight: 700;
  width: fit-content;
  padding-bottom: 2px;
  border-bottom: 2px solid var(--text-primary);
}

.section-title span,
.hint {
  color: var(--text-secondary);
  font-size: 12px;
}

.section-body {
  padding: var(--pad-y) var(--pad-x);
}

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

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

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

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--text-secondary);
  font-size: 12px;
  min-height: 16px;
}

input,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--surface-muted);
  border-radius: 8px;
  background: var(--surface-base);
  color: var(--text-primary);
  padding: 8px 12px;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(4, 36, 51, 0.12);
}

input[type="number"],
input[data-kind="money"] {
  text-align: right;
}

.scenario-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--surface-line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-base);
}

th,
td {
  border-bottom: 1px solid var(--surface-line);
  padding: 8px 12px;
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-header);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
}

td:first-child,
th:first-child {
  text-align: left;
}

tr:last-child td {
  border-bottom: 0;
}

.subsection-note {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
}

.plan-note {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.plan-note strong {
  font-weight: 700;
}

/* Plan table */
.plan-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.plan-header-row .subsection-title {
  margin: 0;
}

.plan-table {
  width: 100%;
  border-collapse: collapse;
}

.plan-table th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 8px;
  border-bottom: 1px solid var(--surface-line);
}

.plan-table td {
  padding: 2px 4px;
  border-bottom: 1px solid var(--surface-line);
}

.plan-table input {
  width: 100%;
}

.plan-table td:last-child {
  width: 36px;
  text-align: center;
}

.actual-table th {
  text-align: center;
}

.actual-table td {
  border-left: 1px solid var(--surface-line);
}

.actual-table td:first-child {
  border-left: none;
}

.actual-table td.ratio,
.actual-table th.ratio {
  text-align: center;
  background: rgba(45, 90, 150, 0.06);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.actual-table th.ratio {
  font-size: 11px;
  line-height: 1.25;
  color: var(--text-secondary);
}

.actual-table td.ratio {
  color: var(--text-primary);
  font-weight: 600;
}

.actual-table input {
  min-width: 92px;
}

.actual-table input.year {
  min-width: 70px;
}

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

.metric {
  border: 1px solid var(--surface-line);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface-base);
  min-height: 94px;
  display: grid;
  align-content: space-between;
  gap: 8px;
}

.metric strong {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.metric span {
  color: var(--text-secondary);
  font-size: 12px;
}

.metric.positive {
  border-color: #98d4b5;
  background: var(--green-soft);
}

.metric.negative {
  border-color: #e0a6a6;
  background: var(--red-soft);
}

.checks {
  display: grid;
  gap: 8px;
}

.check {
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.45;
}

.check-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.check-body {
  display: grid;
  gap: 4px;
  flex: 1;
}

.check-message {
  font-weight: 600;
  font-size: 13px;
}

.check-detail {
  font-size: 12px;
  opacity: 0.8;
}

.check-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.check-goto {
  font-size: 11px;
  padding: 2px 10px;
  min-height: 26px;
  border-radius: 4px;
  font-weight: 600;
  border: 1px solid currentColor;
  background: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: background 150ms ease;
}

.check-goto:hover {
  background: rgba(255, 255, 255, 0.9);
}

.check.ok .check-icon {
  background: var(--green);
  color: white;
}

.check.warn .check-icon {
  background: #b88a1a;
  color: white;
}

.check.error .check-icon {
  background: var(--red);
  color: white;
}

.check.ok {
  background: var(--green-soft);
  color: #185739;
}

.check.warn {
  background: var(--amber-soft);
  color: #74470d;
}

.check.error {
  background: var(--red-soft);
  color: #6b1f1f;
}

.chart {
  height: 220px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  align-items: end;
  gap: 8px;
  border-left: 1px solid var(--surface-line);
  border-bottom: 1px solid var(--surface-line);
  padding: 24px 8px 0;
  overflow: visible;
  background:
    linear-gradient(to top, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    var(--surface-base);
  background-size: 100% 33%;
}

.bar {
  min-height: 2px;
  background: var(--chart-bar);
  border-radius: 4px 4px 0 0;
  position: relative;
}

.bar.negative {
  background: var(--chart-bar-negative);
}

.bar span {
  position: absolute;
  left: 50%;
  bottom: -22px;
  transform: translateX(-50%);
  color: var(--text-secondary);
  font-size: 10px;
}

.chart-dense .bar span {
  font-size: 9px;
}

.chart-dense .bar .value-label {
  font-size: 8px;
}

.forecast-table td {
  font-variant-numeric: tabular-nums;
}

.terminal-row td {
  background: var(--surface-blue-tint, #EFF3FA);
  font-weight: 700;
}

.status-line {
  color: var(--text-secondary);
  font-size: 12px;
}

.button-group {
  display: flex;
  gap: 8px;
}

.diagnostics {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.diag-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 12px;
  background: var(--surface-tint);
  border-radius: 8px;
  font-size: 13px;
}

.diag-item span {
  color: var(--text-secondary);
}

.diag-item strong {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.diag-warn {
  color: var(--accent-secondary);
}

/* Compact section */
.section-compact .section-header {
  padding: 12px var(--pad-x);
}

.section-compact .section-body {
  padding: 16px var(--pad-x);
}

.section-compact .form-grid {
  gap: 12px;
}

/* WACC results */
.wacc-results .result-items {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 12px;
  background: var(--green-soft);
  border-radius: 8px;
  font-size: 13px;
}

.result-item span {
  color: var(--text-secondary);
}

.result-item strong {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--green);
}

/* Unsaved indicator */
button[data-action="save"].has-changes {
  border-color: var(--accent-secondary);
  position: relative;
}

button[data-action="save"].has-changes::after {
  content: '';
  position: absolute;
  top: -3px;
  right: -3px;
  width: 8px;
  height: 8px;
  background: var(--accent-secondary);
  border-radius: 50%;
}

.status-line.unsaved {
  color: var(--accent-secondary);
  font-weight: 500;
}

.status-line.saved-flash {
  color: var(--green);
  font-weight: 500;
  animation: flash-fade 1.5s ease-out forwards;
}

@keyframes flash-fade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Active scenario */
.scenario-row button.active {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

/* Scenario mini tabs */
.scenario-mini-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.scenario-mini-tab {
  padding: 6px 16px;
  border: 1px solid var(--surface-line);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.scenario-mini-tab:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.scenario-mini-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-strong);
  font-weight: 700;
}

.scenario-mini-tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Chart value labels */
.bar .value-label {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Table scroll hint */
.table-wrap {
  position: relative;
}

.table-wrap.scrollable::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 24px;
  background: linear-gradient(to left, rgba(255, 255, 255, 0.9), transparent);
  pointer-events: none;
  border-radius: 0 8px 8px 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
  padding: var(--pad-x);
}

.modal {
  background: var(--surface-base);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 720px;
  max-height: min(80vh, 100% - 16px);
  overflow: auto;
}

.modal-header {
  padding: 16px var(--pad-x);
  border-bottom: 1px solid var(--surface-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal-body {
  padding: var(--pad-y) var(--pad-x);
  display: grid;
  gap: 16px;
}

.import-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.import-detected {
  display: grid;
  gap: 4px;
}

.import-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

/* Excel preview modal */
.excel-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

.preview-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preview-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-item strong {
  font-size: 14px;
}

.excel-warnings {
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--amber-soft);
  border-radius: 6px;
}

.excel-warnings p {
  margin: 4px 0;
  font-size: 13px;
  color: var(--text-primary);
}

/* Sticky summary bar */
.sticky-summary {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--surface-line);
  backdrop-filter: blur(16px);
  transform: translateY(-100%);
  transition: transform 250ms ease;
  pointer-events: none;
}

.sticky-summary.visible {
  transform: translateY(0);
  pointer-events: auto;
}

.sticky-summary-inner {
  max-width: 1520px;
  margin: 0 auto;
  padding: 8px var(--pad-x);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 44px;
}

.sticky-metrics {
  display: flex;
  align-items: center;
  gap: 20px;
}

.sticky-val {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.sticky-val strong {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.sticky-val small {
  font-size: 11px;
  font-weight: 400;
}

.sticky-val.positive strong {
  color: var(--green);
}

.sticky-val.negative strong {
  color: var(--red);
}

.sticky-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.sticky-scenario {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--text-strong);
  letter-spacing: 0.05em;
}

.sticky-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sticky-status-text {
  font-size: 11px;
  color: var(--text-secondary);
}

.sticky-status-text.unsaved {
  color: var(--accent-secondary);
  font-weight: 500;
}

.sticky-save {
  min-height: 30px;
  min-width: 30px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--surface-muted);
  background: transparent;
  cursor: pointer;
}

.sticky-save.has-changes {
  border-color: var(--accent-secondary);
}

.sticky-save svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

/* Sensitivity table */
.sensitivity-table td {
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding: 8px 14px;
  font-size: 13px;
}

.sensitivity-table .base-case {
  background: var(--accent);
  font-weight: 700;
  color: var(--text-strong);
}

.sensitivity-table .base-header {
  font-weight: 900;
  color: var(--text-strong);
}

.sensitivity-table .upside {
  color: var(--green);
}

.sensitivity-table .downside {
  color: var(--red);
}

/* ===================== Responsive ===================== */

/* Small laptop — drop the densest 4-up forms to 3-up */
@media (max-width: 1200px) {
  .form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Tablet — stack the two-up rows, forms to 2-up */
@media (max-width: 1024px) {
  :root {
    --stack-gap: 20px;
  }

  .assumptions-row,
  .info-row {
    grid-template-columns: 1fr;
  }

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

/* Data notice */
.data-notice {
  max-width: 1520px;
  margin: 0 auto;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-tint);
  border-bottom: 1px solid var(--surface-line);
}

.data-notice svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
  flex-shrink: 0;
}

/* Input with unit */
.input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.input-wrap input {
  flex: 1;
  min-width: 0;
}

.unit {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Undo/Redo */
.undo-redo-group {
  display: flex;
  gap: 2px;
}

.undo-redo-group button {
  padding: 0 8px;
  min-width: 36px;
}

.undo-redo-group button:disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

/* Onboarding */
.onboarding .modal-body {
  padding: 24px 32px;
}

.onboarding-content {
  display: grid;
  gap: 20px;
}

.onboarding-step strong {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
}

.onboarding-step p,
.onboarding-step li {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

.onboarding-step ul {
  margin: 0;
  padding-left: 20px;
}

.onboarding-step li {
  margin-bottom: 4px;
}

.onboarding-notice {
  padding: 12px 16px;
  background: var(--amber-soft);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.6;
}

/* Narrow tablet / large phone — single-column header, tighter rhythm */
@media (max-width: 768px) {
  :root {
    --pad-x: 16px;
    --pad-y: 18px;
    --stack-gap: 16px;
    --grid-gap: 12px;
  }

  /* On narrow screens the toolbar is tall — don't pin it, let it scroll away */
  .topbar {
    position: static;
    backdrop-filter: none;
    background: var(--surface-base);
  }

  .sticky-summary-inner {
    padding: 6px var(--pad-x);
    gap: 12px;
  }

  .sticky-metrics {
    gap: 12px;
  }

  .sticky-val strong {
    font-size: 14px;
  }

  .sticky-label {
    font-size: 10px;
  }

  .topbar-inner {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .actions {
    justify-content: flex-start;
  }

  .hero-metrics {
    gap: 24px;
  }

  .sub-metrics {
    gap: 14px 20px;
  }

  .sub-metrics .scenario-row {
    margin-left: 0;
  }

  .actions button span,
  .actions .file-button span {
    display: none;
  }

  .actions button,
  .actions .file-button {
    padding: 0 10px;
    min-height: 34px;
  }

  .wacc-results .result-items {
    grid-template-columns: 1fr;
  }
}

/* Phones */
@media (max-width: 560px) {
  body {
    letter-spacing: 0.02em;
  }

  .form-grid,
  .form-grid.two,
  .form-grid.three,
  .diagnostics,
  .assumptions-list,
  .excel-preview-grid,
  .wacc-results .result-items {
    grid-template-columns: 1fr;
  }

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

  .metric {
    min-height: 0;
    padding: 14px;
  }

  .metric strong {
    font-size: 24px;
  }

  .hero-metrics {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .chart {
    height: 180px;
    gap: 4px;
    padding: 20px 4px 0;
  }

  /* Action toolbar: even, tappable rows */
  .actions {
    width: 100%;
    gap: 6px;
  }

  .actions .status-line {
    flex-basis: 100%;
    order: -1;
  }

  .actions > button,
  .actions > .file-button {
    flex: 1 1 calc(50% - 6px);
    min-height: 42px;
    padding: 0 10px;
  }

  .section-title h2 {
    font-size: 15px;
  }

  .modal {
    border-radius: 14px;
  }

  .more-menu {
    right: auto;
    left: 0;
  }

  .dash-scenarios {
    gap: 6px;
  }

  .dash-scenario-card {
    padding: 8px 6px;
  }

  .dash-scenario-price {
    font-size: 16px;
  }

  .dash-scenario-sub {
    gap: 6px;
    font-size: 10px;
  }
}

/* Small phones */
@media (max-width: 430px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .scenario-row {
    width: 100%;
  }

  .scenario-row button {
    flex: 1;
  }

  th,
  td {
    padding: 8px 10px;
  }
}

/* Field highlight animation */
@keyframes field-pulse {
  0% { box-shadow: 0 0 0 3px rgba(4, 36, 51, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(4, 36, 51, 0.15); }
  100% { box-shadow: 0 0 0 3px rgba(4, 36, 51, 0); }
}

.field-highlight {
  animation: field-pulse 1s ease 2;
  border-color: var(--focus) !important;
}

/* More menu dropdown */
.more-menu-wrap {
  position: relative;
}

.more-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--surface-base);
  border: 1px solid var(--surface-line);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  padding: 4px;
  /* 最長ラベル「バックアップから復元」（アイコン+13px×10字+余白 ≒ 184px）が収まる幅 */
  min-width: 200px;
  z-index: 50;
  max-width: calc(100vw - 16px);
}

.more-menu.open {
  display: grid;
  gap: 2px;
}

.more-menu-item {
  display: flex !important;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  min-height: 36px;
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  /* 「バックアップから復元」等のラベルが途中で折り返さないようメニュー幅を内容に合わせる */
  white-space: nowrap;
}

.more-menu-item:hover {
  background: var(--surface-tint);
}

.more-menu-item svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
  flex-shrink: 0;
}

label.more-menu-item {
  position: relative;
  overflow: hidden;
}

label.more-menu-item input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Sensitivity clickable cells */
.sensitivity-clickable {
  cursor: pointer;
  transition: background 150ms ease;
}

.sensitivity-clickable:hover {
  background: var(--surface-tint) !important;
  text-decoration: underline;
}

.sensitivity-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 12px;
}

/* Calculating status */
.status-line.calculating {
  color: var(--text-secondary);
}

.status-line.calculating::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid var(--surface-muted);
  border-top-color: var(--accent-secondary);
  border-radius: 50%;
  margin-right: 4px;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Computed cell visual distinction */
td[data-computed] {
  color: var(--text-secondary);
  font-style: italic;
  font-weight: 400;
}

/* Auto-calculated field indicator */
.result-items .result-item span::after {
  content: " (自動)";
  font-size: 9px;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* ===== 企業価値どんぶり（比例縮尺ボックス） ===== */
.donburi {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
}

.dbr-col {
  flex: 1;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.dbr-col-head {
  text-align: center;
  margin-bottom: 8px;
  line-height: 1.25;
}

.dbr-col-head strong {
  display: block;
  font-size: 14px;
  color: var(--text-primary);
}

.dbr-col-head span {
  font-size: 11px;
  color: var(--text-secondary);
}

.dbr-box {
  height: 300px;
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--surface-line);
}

.dbr-seg {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #fff;
  text-align: center;
  overflow: hidden;
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.45);
  transition: filter 0.15s;
}

.dbr-seg:hover { filter: brightness(1.08); }

.dbr-seg-lbl { font-size: 11px; font-weight: 600; line-height: 1.1; }
.dbr-seg-val { font-size: 11px; opacity: 0.92; line-height: 1.1; }

.dbr-fcf { background: var(--chart-bar); }
.dbr-tv { background: #7b8fb8; }
.dbr-noa { background: #2d8a6e; }
.dbr-debt { background: var(--red); }
.dbr-equity { background: var(--green); }

.dbr-eq {
  align-self: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0 2px;
}

.dbr-total {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  margin: 12px 0 0;
}

.dbr-total strong { color: var(--text-primary); font-size: 15px; }

.dbr-note {
  text-align: center;
  font-size: 11px;
  color: var(--red);
  margin: 6px 0 0;
}

.dbr-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin: 10px 0 0;
}

.dbr-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
}

.dbr-sw {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
}

@media (max-width: 640px) {
  .donburi { gap: 6px; }
  .dbr-box { height: 220px; }
  .dbr-col-head strong { font-size: 12px; }
  .dbr-seg-lbl, .dbr-seg-val { font-size: 9px; }
  .dbr-eq { font-size: 16px; }
  .sc-bar-row {
    grid-template-columns: 44px 1fr auto;
    gap: 4px;
  }
  .sc-row-badge { font-size: 10px; padding: 2px 4px; }
  .sc-row-val { font-size: 12px; min-width: 56px; }
}

/* ===== Scenario Comparison ===== */
.sc-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.sc-bar-row {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 8px;
  align-items: center;
}

.sc-row-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 4px;
  text-align: center;
  white-space: nowrap;
  background: var(--surface-muted);
  color: var(--text-primary);
}

.sc-row-track {
  height: 28px;
  background: var(--surface-header);
  border-radius: 4px;
  position: relative;
  overflow: visible;
}

.sc-row-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
  background: var(--accent);
  opacity: 0.55;
}

.sc-track-mark {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 0;
  border-left: 2px dashed var(--text-secondary);
  z-index: 1;
  pointer-events: none;
}

.sc-row-val {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  min-width: 72px;
  text-align: right;
}

.sc-row-val small {
  font-size: 11px;
  font-weight: 400;
}

.sc-row-val.positive { color: var(--green); }
.sc-row-val.negative { color: var(--red); }

.sc-legend {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 4px 0 16px;
}

.sc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.sc-table th,
.sc-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--surface-line);
}

.sc-table thead th {
  font-weight: 600;
  text-align: center;
  background: var(--surface-header);
}

.sc-table thead th:first-child {
  text-align: left;
}

.sc-table tbody th {
  text-align: left;
  font-weight: 400;
  color: var(--text-secondary);
}

.sc-table tbody td {
  text-align: right;
  font-weight: 600;
}

.sc-th-bear { color: var(--red); }
.sc-th-base { color: var(--chart-bar); }
.sc-th-bull { color: var(--green); }

.sc-sep td {
  border-bottom: 2px solid var(--surface-line);
  padding: 0;
  height: 2px;
}

.sc-table .positive { color: var(--green); }
.sc-table .negative { color: var(--red); }

/* ===== Dashboard Cards ===== */
.dashboard-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dash-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 2px;
}

.dash-header-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.dash-header-value {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.dash-header-value small {
  font-size: 12px;
  font-weight: 400;
}

.dash-scenarios {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.dash-scenario-card {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--surface-line);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.dash-scenario-card:hover {
  border-color: var(--text-secondary);
}

.dash-scenario-card.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.dash-scenario-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: block;
  cursor: text;
  border-bottom: 1px dashed transparent;
}

.dash-scenario-label:hover {
  border-bottom-color: var(--text-secondary);
}

.dash-scenario-card.active .dash-scenario-label {
  color: var(--text-strong);
}

.dash-scenario-rename {
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--accent);
  background: transparent;
  padding: 0;
  margin-bottom: 4px;
  outline: none;
  display: block;
}

.dash-scenario-price {
  display: block;
  font-size: clamp(16px, 2.5vw, 22px);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.dash-scenario-price small {
  font-size: 11px;
  font-weight: 400;
}

.dash-scenario-sub {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.dash-scenario-sub .positive { color: var(--green); font-weight: 600; }
.dash-scenario-sub .negative { color: var(--red); font-weight: 600; }

.upside-notice {
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--amber-soft);
  border-radius: 8px;
  font-size: 12px;
  color: #74470d;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.5;
}

.upside-notice svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ===== DCF Table Collapse ===== */
.forecast-table.collapsed .detail-col {
  display: none;
}

.forecast-table .key-col {
  font-weight: 600;
  background: rgba(45, 90, 150, 0.04);
}

.terminal-row td.key-col {
  background: var(--surface-blue-tint, #EFF3FA);
}

/* ===== Sensitivity Description ===== */
.sensitivity-description {
  margin: 0 0 16px;
  line-height: 1.6;
}

.sensitivity-description strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
  margin-bottom: 4px;
}

.sensitivity-axes {
  display: flex;
  gap: 24px;
  font-size: 12px;
  color: var(--text-secondary);
}


/* ===== Lead capture gate（ツール直アクセス時のリード獲得モーダル） ===== */
.leadgate-overlay {
  z-index: 300;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.modal.leadgate {
  max-width: 560px;
}

.leadgate-eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-secondary-deep);
}

.leadgate-title {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.4;
  color: var(--text-strong);
}

.leadgate-lead {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.leadgate-form {
  display: grid;
  gap: 14px;
}

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

.leadgate-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.leadgate-field label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.leadgate-req {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-secondary-deep);
  background: rgba(233, 113, 50, 0.12);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.leadgate-field input,
.leadgate-field textarea {
  width: 100%;
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface-base);
  border: 1px solid var(--surface-line);
  border-radius: 9px;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.leadgate-field input:focus,
.leadgate-field textarea:focus {
  outline: none;
  border-color: var(--accent-secondary);
  box-shadow: 0 0 0 3px rgba(233, 113, 50, 0.14);
}

.leadgate-field textarea {
  resize: vertical;
}

.leadgate-consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  cursor: pointer;
}

.leadgate-consent input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent-secondary);
}

.leadgate-consent a {
  color: var(--accent-secondary);
  text-decoration: underline;
}

.leadgate-error {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: #c0392b;
}

.leadgate-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 52px;
  padding: 0 32px;
  background: var(--accent-secondary);
  color: var(--surface-base);
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(233, 113, 50, 0.25);
  transition: background 200ms ease, transform 200ms ease, box-shadow 200ms ease;
}

.leadgate-submit:hover:not(:disabled) {
  background: var(--accent-secondary-deep);
  transform: translateY(-1px);
}

.leadgate-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.leadgate-note {
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: var(--text-tertiary);
}

@media (max-width: 560px) {
  .leadgate-field-row {
    grid-template-columns: 1fr;
  }
}
