/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #f0f4f9;
  color: #1a2a3a;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── Login ────────────────────────────────────────────────────────────────── */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f2744 0%, #1a4b8c 100%);
}

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.login-logo {
  font-size: 26px;
  font-weight: 800;
  color: #0f2744;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 13px;
  color: #6b8099;
  margin-bottom: 28px;
}

/* ── Form fields ──────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 11px;
  font-weight: 600;
  color: #4a5f75;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.field input,
.field select {
  height: 26px;
  padding: 0 8px;
  border: 1px solid #c8d9ee;
  border-radius: 5px;
  font-size: 13px;
  color: #1a2a3a;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.field input:focus,
.field select:focus {
  border-color: #174f86;
  box-shadow: 0 0 0 3px rgba(23,79,134,0.1);
}

/* Login form uses taller fields */
.login-card .field input {
  height: 38px;
  padding: 0 12px;
  font-size: 14px;
  margin-bottom: 4px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  height: 40px;
  background: #174f86;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}

.btn-primary:hover:not(:disabled) { background: #0f3d6e; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-analyze {
  height: 26px;
  padding: 0 16px;
  background: #174f86;
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  width: 100%;
}

.btn-analyze:hover:not(:disabled) { background: #0f3d6e; }
.btn-analyze:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-text {
  background: none;
  border: none;
  color: #174f86;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-signout {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: 5px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-signout:hover { background: rgba(255,255,255,0.12); }

.btn-header-action {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.85);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-header-action:hover:not(:disabled) {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.45);
}

.btn-header-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.header-divider {
  width: 1px;
  height: 18px;
  background: rgba(255,255,255,0.2);
  flex-shrink: 0;
}

/* ── Error ────────────────────────────────────────────────────────────────── */
.error-msg {
  background: #fff0f0;
  color: #c0392b;
  border: 1px solid #f5c6cb;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}

.success-msg {
  background: #f0fff4;
  color: #1b7a3e;
  border: 1px solid #b7e4c7;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}

/* ── Auth tabs ────────────────────────────────────────────────────────────── */
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 22px;
  border-bottom: 2px solid #e2eaf3;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 8px 0;
  font-size: 14px;
  font-weight: 600;
  color: #8aa4be;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.auth-tab.active {
  color: #174f86;
  border-bottom-color: #174f86;
}

.auth-tab:hover:not(.active) { color: #2d6ba8; }

/* ── CAPTCHA ──────────────────────────────────────────────────────────────── */
.captcha-wrap {
  margin: 14px 0 8px;
  display: flex;
  justify-content: center;
}

/* ── App header ───────────────────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(90deg, #0f2744 0%, #1a4b8c 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 48px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.app-title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.app-title-sub {
  font-weight: 400;
  font-size: 13px;
  opacity: 0.75;
  margin-left: 6px;
}

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

.user-email {
  font-size: 12px;
  opacity: 0.8;
}

/* ── Plan badge ───────────────────────────────────────────────────────────── */
.plan-badge {
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  padding: 2px 8px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.plan-free     { background: #4a5f75; color: #fff; }
.plan-starter  { background: #2196f3; color: #fff; }
.plan-pro      { background: #7c3aed; color: #fff; }
.plan-advanced { background: #d97706; color: #fff; }

/* ── Upgrade banner ───────────────────────────────────────────────────────── */
.upgrade-banner {
  background: #fff8e1;
  border-bottom: 1px solid #ffc107;
  padding: 8px 24px;
  font-size: 13px;
  color: #7a4f00;
  text-align: center;
}

.upgrade-banner a { color: #174f86; font-weight: 600; }

/* ── Main layout ──────────────────────────────────────────────────────────── */
.calc-wrap {
  max-width: 1100px;
  margin: 20px auto;
  padding: 0 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 20px 22px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08), 0 2px 12px rgba(0,0,0,0.04);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: #0f2744;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Results wrapper ──────────────────────────────────────────────────────── */
.results-wrap {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* ── Collapsible card (details/summary) ───────────────────────────────────── */
details.card {
  display: block;
}

details.card > summary.card-summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 700;
  color: #0f2744;
  margin-bottom: 0;
  padding: 0;
  width: 100%;
}

details.card > summary.card-summary::-webkit-details-marker { display: none; }
details.card > summary.card-summary::marker { display: none; }

details.card > summary.card-summary::after {
  content: "▾";
  font-size: 18px;
  color: #8a9db5;
  flex-shrink: 0;
  display: inline-block;
  transition: transform 0.2s;
  margin-left: auto;
  padding-left: 8px;
}

details.card:not([open]) > summary.card-summary::after {
  transform: rotate(-90deg);
}

details.card[open] > summary.card-summary {
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eef2f8;
}

.inputs-subtitle-inline {
  font-size: 12px;
  font-weight: 400;
  color: #8a9db5;
  margin-left: 8px;
}

/* ── Rule cards highlight grid ────────────────────────────────────────────── */
.rules-grid-hl {
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 14px !important;
  margin-bottom: 0;
}

.rules-grid-hl .rule-card {
  padding: 18px 16px;
}

.rules-grid-hl .rule-value {
  font-size: 30px;
  font-weight: 800;
}

.rules-grid-hl .rule-desc {
  margin-top: 6px;
}

/* ── Inputs Card ──────────────────────────────────────────────────────────── */
.inputs-card { padding: 18px 22px; }

.inputs-title-row {
  margin-bottom: 14px;
}

.inputs-title {
  font-size: 15px;
  font-weight: 700;
  color: #0f2744;
}

.inputs-subtitle {
  font-size: 12px;
  color: #6b8099;
  margin-top: 2px;
}

/* Main input row: price | rent | units | profile | analyze btn */
.inputs-main-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.inputs-main-row .field {
  flex: 1;
  min-width: 90px;
}

.inputs-main-row .field-sm {
  flex: 0 0 60px;
  min-width: 60px;
}

.inputs-main-row .field-profile {
  flex: 1.4;
  min-width: 150px;
}

.inputs-main-row .field-btn {
  flex: 0 0 96px;
}

/* Advanced toggle row */
.advanced-toggle-row {
  margin-top: 10px;
}

/* Advanced params section */
.advanced-params {
  border-top: 1px dashed #d0dded;
  padding-top: 14px;
  margin-top: 10px;
}

.inputs-adv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 8px 10px;
  margin-bottom: 4px;
}

.inputs-adv-grid .field { margin-bottom: 0; }

.adv-section-label {
  font-size: 10px;
  font-weight: 700;
  color: #8a9db5;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 12px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e8eef7;
}

/* ── Metrics grid ─────────────────────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.metric {
  background: #f5f8fd;
  border: 1px solid #e2eaf5;
  border-radius: 7px;
  padding: 12px 14px;
}

.metric-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b8099;
  margin-bottom: 5px;
}

.metric-value {
  font-size: 19px;
  font-weight: 700;
  color: #0f2744;
  line-height: 1.2;
}

.metric-value.pos { color: #1b7a3e; }
.metric-value.neg { color: #c0392b; }

.metric-bench {
  font-size: 11px;
  margin-top: 4px;
  font-weight: 600;
}

.bench-great, .rule-check.bench-great { color: #1b7a3e; }
.bench-good,  .rule-check.bench-good  { color: #2196f3; }
.bench-bad,   .rule-check.bench-bad   { color: #c0392b; }

/* ── Plan lock ────────────────────────────────────────────────────────────── */
.plan-tag {
  font-size: 10px;
  font-weight: 700;
  background: #7c3aed;
  color: #fff;
  border-radius: 4px;
  padding: 1px 6px;
  letter-spacing: 0.3px;
}

.plan-lock {
  background: #f5f5f5;
  border: 1px dashed #c0c0c0;
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  margin-bottom: 14px;
  font-size: 13px;
  color: #6b8099;
}

/* ── Income & Cash Flow Table ─────────────────────────────────────────────── */
.cf-table {
  border: 1px solid #e2eaf5;
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}

.cf-row {
  display: grid;
  grid-template-columns: 1fr 110px 120px;
  gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid #f0f4f9;
  align-items: center;
}

.cf-row:last-child { border-bottom: none; }

.cf-row span:nth-child(2),
.cf-row span:nth-child(3) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cf-header {
  background: #f5f8fd;
  font-size: 10px;
  font-weight: 700;
  color: #6b8099;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.cf-sub {
  color: #6b8099;
}

.cf-sub span:first-child {
  padding-left: 14px;
  font-size: 12px;
}

.cf-subtotal {
  font-weight: 600;
  color: #0f2744;
  background: #f8fbff;
}

.cf-total {
  font-weight: 700;
  font-size: 14px;
  color: #0f2744;
  background: #eef4fc;
}

.cf-total.positive-cf span:not(:first-child) { color: #1b7a3e; }
.cf-total.negative-cf span:not(:first-child) { color: #c0392b; }

/* ── Rules Grid ───────────────────────────────────────────────────────────── */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 4px;
}

.rule-card {
  background: #f5f8fd;
  border: 1px solid #e2eaf5;
  border-radius: 8px;
  padding: 12px 14px;
  transition: border-color 0.15s, background 0.15s;
}

.rule-card.pass {
  border-color: #86efac;
  background: #f0fdf4;
}

.rule-card.fail {
  border-color: #fca5a5;
  background: #fff5f5;
}

.rule-name {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b8099;
  margin-bottom: 4px;
}

.rule-value {
  font-size: 22px;
  font-weight: 700;
  color: #0f2744;
  line-height: 1.1;
}

.rule-check {
  font-size: 12px;
  font-weight: 600;
  margin-top: 3px;
}

.rule-card.pass .rule-check { color: #1b7a3e; }
.rule-card.fail .rule-check { color: #c0392b; }

.rule-desc {
  font-size: 11px;
  color: #8a9db5;
  margin-top: 4px;
}

/* Compact rule card — matches metrics-grid sizing */
.rule-card-sm {
  padding: 12px 14px;
}

.rule-value-sm {
  font-size: 19px !important;
}

/* ── Stress Test Table ────────────────────────────────────────────────────── */
.stress-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

.stress-table th {
  background: #f5f8fd;
  color: #6b8099;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 8px 12px;
  text-align: right;
  border-bottom: 2px solid #e2eaf5;
  white-space: nowrap;
}

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

.stress-table td {
  padding: 7px 12px;
  text-align: right;
  border-bottom: 1px solid #f0f4f9;
  color: #1a2a3a;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.stress-table td:first-child {
  text-align: left;
  font-weight: 600;
  color: #0f2744;
  white-space: nowrap;
}

.stress-table tr:last-child td { border-bottom: none; }

.stress-table tr.stress-base td {
  background: #f0f6ff;
  font-weight: 700;
}

.stress-table td.val-pos { color: #1b7a3e; font-weight: 600; }
.stress-table td.val-neg { color: #c0392b; font-weight: 600; }
.stress-table td.val-warn { color: #d97706; font-weight: 600; }

/* ── Expense rows ─────────────────────────────────────────────────────────── */
.expense-rows {
  display: flex;
  flex-direction: column;
}

.expense-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 4px;
  border-bottom: 1px solid #f0f4f9;
  font-size: 13px;
  color: #3a4f64;
}

.expense-row:last-child { border-bottom: none; }

.total-row {
  font-weight: 700;
  color: #0f2744;
  padding-top: 10px;
  margin-top: 4px;
  border-top: 2px solid #e2eaf5;
  border-bottom: none;
}

/* ── Tax note ─────────────────────────────────────────────────────────────── */
.tax-note {
  font-size: 11px;
  color: #8a9db5;
  margin-top: 14px;
  font-style: italic;
  line-height: 1.5;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .app-header { padding: 0 14px; }
  .user-email { display: none; }
  .btn-header-action { display: none; }
  .header-divider { display: none; }
  .calc-wrap  { padding: 0 12px 60px; margin-top: 12px; gap: 16px; }
  .card       { padding: 16px 14px; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .metric-value { font-size: 16px; }
  .inputs-main-row { flex-wrap: wrap; }
  .inputs-main-row .field { min-width: 120px; }
  .inputs-adv-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
  .rules-grid { grid-template-columns: 1fr 1fr; }
  .cf-row { grid-template-columns: 1fr 90px 100px; font-size: 12px; padding: 6px 10px; }
  .rules-grid-hl { grid-template-columns: 1fr 1fr !important; }
  .rules-grid-hl .rule-value { font-size: 24px; }
}
