:root {
  --bg: #f8f9fa;
  --card: #ffffff;
  --text: #1a1a1a;
  --text-light: #4a4a4a;
  --muted: #6c757d;
  --line: #dee2e6;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 24px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --pad: 24px;
  --gap: 16px;
  --transition: all 0.2s ease;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* Sticky Summary Bar */
.sticky-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: white;
  border-bottom: 3px solid var(--accent);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.sticky-bar.visible {
  transform: translateY(0);
}

.sticky-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 20px;
  flex-wrap: wrap;
}

.sticky-label {
  font-weight: 600;
  color: var(--text-light);
  font-size: 0.9rem;
}

.sticky-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

.sticky-status {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 12px;
  background: rgba(0,0,0,0.05);
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.header {
  padding: 32px 0 24px 0;
  text-align: center;
}

h1 {
  margin: 0 0 12px 0;
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 1.1rem;
  max-width: 700px;
  margin: 0 auto;
}

/* Grid Layout - Two Column on Desktop */
.grid {
  display: grid;
  gap: 24px;
  margin-top: 32px;
}

@media (min-width: 1024px) {
  .grid {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card h2 {
  margin: 0 0 20px 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  padding-bottom: 12px;
  border-bottom: 2px solid var(--line);
}

/* Groups */
.group {
  border-top: 1px solid var(--line);
  padding-top: 28px;
  margin-top: 28px;
}

.group:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.group h3 {
  margin: 0 0 20px 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

/* Labels and Inputs */
label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  align-self: start;
}

label.with-toggle {
  align-self: start;
}

input, select {
  font: inherit;
  font-weight: 400;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #fff;
  transition: var(--transition);
  font-size: 1rem;
}

input:hover, select:hover {
  border-color: #adb5bd;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input[type="text"], input[type="number"] {
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

/* Tooltip */
.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  color: white;
  font-size: 12px;
  font-weight: 600;
  cursor: help;
  margin-left: 6px;
  position: relative;
  user-select: none;
  transition: var(--transition);
}

.tooltip-icon:hover {
  background: var(--accent);
  transform: scale(1.1);
}

.tooltip-text {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 400;
  white-space: nowrap;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
}

.tooltip-text::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--text);
}

.tooltip-icon:hover .tooltip-text,
.tooltip-icon.active .tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* Responsive tooltip positioning */
@media (max-width: 640px) {
  .tooltip-text {
    white-space: normal;
    max-width: 200px;
    text-align: center;
  }
}

/* Inline Fields */
.inline {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  align-items: start;
}

@media (min-width: 640px) {
  .inline {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .inline {
    grid-template-columns: repeat(3, 1fr);
  }
}

.inline label {
  margin-bottom: 0;
  min-height: 0;
}

/* Checkbox */
.check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.check input {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Buttons */
.buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-start;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

button {
  cursor: pointer;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-weight: 600;
  font-size: 1rem;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

button:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

/* Example Button */
.example-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  width: 100%;
  margin-bottom: 20px;
  font-size: 0.95rem;
  position: relative;
  overflow: hidden;
}

.example-btn::before {
  content: '✨';
  margin-right: 8px;
}

.example-btn:hover {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

/* Reset Button */
#resetBtn {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
}

#resetBtn:hover {
  background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
}

/* KPIs - Results Display */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  transition: var(--transition);
}

.kpi:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.kpi-number {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 8px;
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

.kpi-label {
  font-size: 0.875rem;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.3;
}

/* Hero KPI (Cash Flow) */
.kpi-hero {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-width: 3px;
  padding: 24px;
}

.kpi-hero .kpi-number {
  font-size: 2.5rem;
  margin-bottom: 4px;
}

.kpi-status {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

@media (min-width: 640px) {
  .kpi-hero .kpi-number {
    font-size: 3rem;
  }
}

/* Details List */
.details {
  list-style: none;
  padding: 0;
  margin: 24px 0 0 0;
  border-top: 1px solid var(--line);
}

.details li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  transition: var(--transition);
}

.details li:hover {
  background: rgba(37, 99, 235, 0.02);
  padding-left: 8px;
  padding-right: 8px;
  margin-left: -8px;
  margin-right: -8px;
  border-radius: var(--radius-sm);
}

.details span {
  color: var(--text-light);
  font-weight: 500;
}

.details strong {
  color: var(--text);
  font-weight: 700;
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

/* Stress Test Indicator */
.stress-indicator {
  margin: 24px 0;
  padding: 16px 20px;
  border-radius: var(--radius);
  background: #f8f9fa;
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  transition: var(--transition);
}

.stress-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.stress-message {
  font-size: 0.95rem;
}

.stress-indicator.pass {
  background: rgba(16, 185, 129, 0.1);
  border-color: var(--success);
  color: var(--success);
}

.stress-indicator.warning {
  background: rgba(245, 158, 11, 0.1);
  border-color: var(--warning);
  color: var(--warning);
}

.stress-indicator.fail {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--danger);
  color: var(--danger);
}

/* Sensitivity Table */
.sens {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.sens th, .sens td {
  border: 1px solid var(--line);
  padding: 12px;
  text-align: center;
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

.sens th {
  background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);
  font-weight: 700;
  color: var(--text);
  font-size: 0.9rem;
}

.sens td {
  font-weight: 600;
}

.sens .bad {
  background: #fee;
  color: var(--danger);
}

.sens .ok {
  background: #fffbeb;
  color: var(--warning);
}

.sens .good {
  background: #ecfdf5;
  color: var(--success);
}

/* Footer */
.footer {
  color: var(--muted);
  text-align: center;
  margin: 32px 0 24px;
  font-size: 0.9rem;
}

/* Helper Text */
.muted {
  color: var(--muted);
  margin-top: -8px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.help-text {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0 0 16px 0;
  line-height: 1.5;
  font-weight: 400;
  background: rgba(37, 99, 235, 0.03);
  padding: 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.field-help {
  color: var(--muted);
  font-size: 0.8125rem;
  display: block;
  margin-top: 6px;
  line-height: 1.4;
  font-weight: 400;
  min-height: 18px;
}

.ltv-display {
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 600;
  margin-left: 8px;
}

/* Toggle and Special Fields */
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-height: 24px;
  margin-bottom: 0;
}

.fee-type-toggle {
  padding: 6px 10px;
  font-size: 0.875rem;
  min-width: 70px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  border: 1.5px solid var(--line);
}

/* Calculated Helper Text */
.calc-helper {
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 600;
  margin-top: 6px;
  display: block;
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

/* Micro-interactions */
.updating {
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

/* Mobile Optimizations */
@media (max-width: 640px) {
  .wrap {
    padding: 16px;
  }

  h1 {
    font-size: 1.75rem;
  }

  .sub {
    font-size: 1rem;
  }

  .card {
    padding: 20px;
  }

  .kpi-number {
    font-size: 1.5rem;
  }

  .buttons {
    flex-direction: column;
  }

  button {
    width: 100%;
  }
}

/* Print Styles */
@media print {
  .buttons {
    display: none;
  }
  
  body {
    background: white;
  }
  
  .card {
    box-shadow: none;
    page-break-inside: avoid;
  }
}
