@import url('https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

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

:root {
  --bg-base:        #0d1117;
  --bg-surface:     #161b22;
  --bg-raised:      #1c2128;
  --bg-hover:       #21262d;
  --border:         #30363d;
  --border-focus:   #388bfd;
  --border-subtle:  #21262d;
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7781;
  --blue:           #388bfd;
  --blue-dim:       #1f6feb;
  --green:          #3fb950;
  --green-bg:       rgba(63,185,80,0.08);
  --green-border:   rgba(63,185,80,0.22);
  --red:            #f85149;
  --red-bg:         rgba(248,81,73,0.08);
  --red-border:     rgba(248,81,73,0.22);
  --amber:          #d29922;
  --amber-bg:       rgba(210,153,34,0.08);
  --radius:         6px;
  --radius-lg:      10px;
}

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  font-size: 14px;
}

/* HEADER */
.header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  height: 52px;
  display: flex;
  align-items: center;
}
.header-content {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.logo {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.logo .mdi { font-size: 1.2rem; color: var(--blue); }
.header-controls { display: flex; align-items: center; gap: 0.625rem; }

.select-ctrl {
  background: var(--bg-raised);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.3rem 1.75rem 0.3rem 0.625rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  cursor: pointer;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236e7781' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  transition: border-color 0.15s;
}
.select-ctrl:hover, .select-ctrl:focus { border-color: var(--border-focus); outline: none; }

/* CONTAINER */
.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }

/* HERO */
.hero { margin-bottom: 1.75rem; }
.hero h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
  line-height: 1.3;
  margin-bottom: 0.375rem;
}
.subtitle { font-size: 0.9375rem; color: var(--text-secondary); max-width: 640px; line-height: 1.6; }

/* VALIDATION BANNER */
.val-banner {
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red);
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  margin-bottom: 1rem;
  display: none;
  align-items: center;
  gap: 0.5rem;
}
.val-banner.visible { display: flex; }

/* CARDS */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.375rem 1.5rem;
}
.card-hdr {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 1.125rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.card-hdr .mdi { font-size: 0.9375rem; }

/* CALCULATOR GRID */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
@media (min-width: 960px) {
  .calc-grid { grid-template-columns: 1fr 1fr; }
}

/* FORMS */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 540px) { .form-row { grid-template-columns: 1fr; } }

.form-group { margin-bottom: 1rem; }
.form-group:last-of-type { margin-bottom: 0; }

.field-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.tip-wrap {
  position: relative;
  display: inline-flex;
  cursor: default;
}
.tip-wrap .mdi { font-size: 0.875rem; color: var(--text-muted); line-height: 1; }
.tip-wrap:hover .tip-bubble,
.tip-wrap:focus-within .tip-bubble,
.tip-wrap.active .tip-bubble { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.tip-bubble {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%) translateY(5px);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  width: 200px;
  white-space: normal;
  line-height: 1.45;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
  z-index: 30;
}

.input-wrap { position: relative; }
input[type="number"] {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.5rem 2.25rem 0.5rem 0.7rem;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  appearance: textfield;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; appearance: none; }
input[type="number"]:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(56,139,253,0.12);
}
input[type="number"].err { border-color: var(--red); }
input[type="number"]:disabled { opacity: 0.4; cursor: not-allowed; }

.input-unit {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.8125rem;
  pointer-events: none;
}
.field-err {
  font-size: 0.6875rem;
  color: var(--red);
  margin-top: 0.2rem;
  display: none;
}
.field-err.show { display: block; }

/* RADIO */
.radio-group { display: flex; gap: 0.5rem; margin-top: 0.3rem; }
.radio-opt {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.75rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  user-select: none;
}
.radio-opt:has(input:checked) {
  border-color: var(--border-focus);
  background: rgba(56,139,253,0.07);
  color: var(--text-primary);
}
.radio-opt input[type="radio"] {
  accent-color: var(--blue);
  cursor: pointer;
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
.pmode-group { display: none; margin-top: 1rem; }

/* BUTTONS */
.btn-row { display: flex; gap: 0.75rem; margin-top: 1.25rem; }
.btn {
  flex: 1;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
}
.btn .mdi { font-size: 1rem; }
.btn-primary { background: var(--blue-dim); border-color: var(--blue-dim); color: #fff; }
.btn-primary:hover { background: var(--blue); border-color: var(--blue); }
.btn-ghost { background: var(--bg-raised); border-color: var(--border); color: var(--text-secondary); }
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text-primary); }

/* RESULTS */
.results-section { display: none; }
.results-section.visible { display: block; animation: fadeUp 0.2s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sec-divider { height: 1px; background: var(--border); margin: 1.75rem 0; }
.sec-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.875rem;
}

/* RESULT CARDS */
.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
@media (min-width: 600px) {
  .results-grid { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
}
.result-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.125rem 1.25rem 1.125rem 1.5rem;
  position: relative;
  overflow: hidden;
}
.result-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px;
  height: 100%;
}
.result-card.profitable::before   { background: var(--green); }
.result-card.not-profitable::before { background: var(--red); }

.rc-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.rc-title {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.rc-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.175rem 0.55rem;
  border-radius: 20px;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.rc-badge .mdi { font-size: 0.75rem; }
.rc-badge.profitable { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.rc-badge.not-profitable { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }

.rc-pv {
  font-size: 1.875rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin-bottom: 0.2rem;
}
.rc-pv-label { font-size: 0.6875rem; color: var(--text-muted); margin-bottom: 0.875rem; }

.rc-details {
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.detail-row { display: flex; justify-content: space-between; align-items: center; }
.detail-lbl { font-size: 0.8125rem; color: var(--text-muted); }
.detail-val { font-size: 0.8125rem; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.detail-val.pos { color: var(--green); }
.detail-val.neg { color: var(--red); }

/* METRICS ROW */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
@media (min-width: 600px) { .metrics-row { grid-template-columns: repeat(4, 1fr); } }
.metric-cell {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
}
.metric-lbl {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.3rem;
}
.metric-val {
  font-size: 1.0625rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.metric-sub { font-size: 0.625rem; color: var(--text-muted); margin-top: 0.1rem; }

/* BREAKEVEN CARD */
.bev-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.125rem 1.5rem;
  margin-bottom: 1rem;
}
.bev-section-title {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 1.125rem;
}
.bev-thresholds {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 0;
}
.bev-threshold { text-align: center; padding: 0 1rem; }
.bev-thresh-val {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.025em;
  line-height: 1.1;
  margin-bottom: 0.3rem;
  transition: color 0.2s;
}
.bev-thresh-label {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.35rem;
}
.bev-thresh-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 0.5rem;
}
.bev-thresh-status {
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
  min-height: 1rem;
}
.bev-divider-v {
  width: 1px;
  background: var(--border);
  min-height: 100px;
  align-self: stretch;
}

/* CHART CARDS */
.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.125rem 1.5rem;
  margin-bottom: 1rem;
}
.chart-hdr {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}
.chart-wrap { position: relative; height: 250px; }

/* AMORTIZATION */
.amort-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: border-color 0.15s, color 0.15s;
  user-select: none;
}
.amort-toggle:hover { border-color: var(--text-muted); color: var(--text-primary); }
.amort-toggle.open {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: var(--border-subtle);
}
.amort-toggle-l { display: flex; align-items: center; gap: 0.45rem; }
.amort-toggle .mdi { font-size: 1rem; }

.amort-body {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: none;
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
  overflow: hidden;
  display: none;
  margin-bottom: 1rem;
}
.amort-body.open { display: block; }
.amort-scroll { overflow-x: auto; }

.amort-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}
.amort-tbl th {
  text-align: right;
  padding: 0.5rem 0.875rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-raised);
}
.amort-tbl th:first-child { text-align: center; }
.amort-tbl td {
  text-align: right;
  padding: 0.4rem 0.875rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.amort-tbl td:first-child { text-align: center; color: var(--text-muted); font-size: 0.6875rem; }
.amort-tbl tr:last-child td { border-bottom: none; }
.amort-tbl tr:hover td { background: var(--bg-raised); }

/* INFO */
.info-section { margin-top: 2rem; }
.info-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.375rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.7;
}
.info-card h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 1rem 0 0.3rem;
}
.info-card h3:first-child { margin-top: 0; }
.info-card p { margin-bottom: 0.4rem; }
.info-card ul { padding-left: 1.25rem; margin-top: 0.3rem; }
.info-card li { margin-bottom: 0.3rem; }

footer {
  text-align: center;
  padding: 1.75rem 1rem;
  color: var(--text-muted);
  font-size: 0.6875rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

@media (max-width: 540px) {
  .container { padding: 1.25rem 1rem; }
  .hero h1 { font-size: 1.25rem; }
  .rc-pv { font-size: 1.5rem; }
  .btn-row { flex-direction: column; }
  .radio-group { flex-direction: column; }
}
