:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.08);
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

header {
  margin-bottom: 2rem;
}

header h1 {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header p {
  margin: 0;
  color: var(--muted);
}

main {
  display: grid;
  gap: 1.5rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 1.25rem;
  font-size: 1.25rem;
}

.panel h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.subsection {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.subsection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.subsection-header h3 {
  margin: 0;
}

.hint {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

label:not(.scenario-pill) {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

input {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:hover {
  border-color: #94a3b8;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.readonly-value {
  display: flex;
  align-items: center;
  min-height: 2.65rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.subsection-compact {
  padding-top: 1rem;
  margin-top: 1rem;
}

.subsection-compact h3 {
  margin-bottom: 0.5rem;
}

.scenario-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  width: 100%;
  overflow: visible;
}

label.scenario-pill {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

label.scenario-pill::before,
label.scenario-pill::after {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s ease, transform 0.15s ease;
  z-index: 5;
}

label.scenario-pill::after {
  content: attr(data-tooltip);
  bottom: calc(100% + 10px);
  min-width: 11rem;
  max-width: 14rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  white-space: normal;
}

label.scenario-pill::before {
  content: "";
  bottom: calc(100% + 4px);
  border: 6px solid transparent;
  border-top-color: var(--border-strong);
}

label.scenario-pill:hover::before,
label.scenario-pill:hover::after,
label.scenario-pill:focus-within::before,
label.scenario-pill:focus-within::after {
  opacity: 1;
  visibility: visible;
}

label.scenario-pill:hover::after,
label.scenario-pill:focus-within::after {
  transform: translateX(-50%) translateY(-2px);
}

label.scenario-pill:hover {
  border-color: #94a3b8;
  background: var(--surface-2);
}

label.scenario-pill:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

label.scenario-pill input[type="radio"] {
  margin: 0;
  padding: 0;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  accent-color: var(--accent);
  border: none;
  background: transparent;
}

.formula-hint {
  margin: 1rem 0 0;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: "Cambria Math", "Times New Roman", serif;
  font-size: 0.9375rem;
  color: var(--muted);
}

.formula-hint-compact {
  margin-top: 0.65rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  text-align: center;
}

.depreciation-summary {
  margin-top: 0;
  margin-bottom: 0;
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.section-header-row h3 {
  margin: 0;
}

.schedule-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chart-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 1rem;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 180px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: var(--text);
}

.chart-tooltip.hidden {
  display: none;
}

.chart-tooltip-title {
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.chart-tooltip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

#value-chart {
  display: block;
  width: 100%;
  height: 320px;
}

.schedule-modal {
  width: min(960px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.12);
}

.schedule-modal::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.modal-header h3 {
  margin: 0;
}

.modal-table-wrap {
  max-height: calc(100vh - 8rem);
  overflow: auto;
  border: none;
  border-radius: 0;
}

.btn-primary,
.btn-secondary,
.btn-remove {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-primary {
  margin-top: 1.5rem;
  width: 100%;
  padding: 0.85rem 1.25rem;
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  padding: 0.5rem 0.85rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
  background: var(--surface-2);
  border-color: #94a3b8;
}

.btn-remove {
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.btn-remove:hover {
  background: #fef2f2;
  border-color: #fca5a5;
}

.extra-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.75rem;
}

.hidden {
  display: none;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.results-groups {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.results-group {
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.results-group-title {
  margin: 0 0 0.85rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.results-group .summary-cards {
  margin-bottom: 0;
}

.schedule-section .results-group-title {
  margin-top: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.card.highlight {
  border-color: rgba(2, 132, 199, 0.25);
  background: var(--accent-soft);
}

.card .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.card .value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.card .value.positive {
  color: var(--success);
}

.schedule-section h3 {
  margin-bottom: 1rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th,
td {
  padding: 0.65rem 0.85rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  position: sticky;
  top: 0;
}

tbody tr:hover {
  background: rgba(2, 132, 199, 0.04);
}

tbody tr:last-child td {
  border-bottom: none;
}

@media (max-width: 640px) {
  .extra-row {
    grid-template-columns: 1fr;
  }

  header h1 {
    font-size: 1.5rem;
  }
}
