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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: #FAFAFA;
  color: #09090B;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

code, pre, .mono, .input-mono {
  font-family: 'JetBrains Mono', monospace;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  letter-spacing: -0.025em;
  font-weight: 700;
  color: #09090B;
}

h1 {
  font-size: clamp(1.75rem, 3.5vw, 2.35rem);
  font-weight: 800;
  line-height: 1.2;
}

h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

h3 {
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

p {
  color: #71717A;
}

/* Nav & Top Header */
.site-header {
  border-bottom: 1px solid #E4E4E7;
  background-color: #FFFFFF;
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #09090B;
}

.brand-badge {
  background: #09090B;
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 4px 7px;
  border-radius: 4px;
  letter-spacing: -0.02em;
}

.brand-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.link-secondary {
  color: #71717A;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.link-secondary:hover {
  color: #09090B;
}

.btn-primary {
  background: #09090B;
  color: #FFFFFF;
  border: 1px solid #09090B;
  padding: 7px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-outline {
  background: #FFFFFF;
  color: #09090B;
  border: 1px solid #E4E4E7;
  padding: 6px 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-outline:hover {
  background: #F4F4F5;
  border-color: #D4D4D8;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* Layout System */
.main-wrapper {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  flex: 1;
  width: 100%;
}

.hero-section {
  margin-bottom: 24px;
  border-bottom: 1px solid #E4E4E7;
  padding-bottom: 20px;
}

.hero-subtitle {
  font-size: 1rem;
  color: #52525B;
  margin-top: 8px;
  max-width: 820px;
  line-height: 1.6;
}

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.badge-pill {
  background: #F4F4F5;
  color: #3F3F46;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 9999px;
  border: 1px solid #E4E4E7;
}

/* Controls Bar */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  background: #FFFFFF;
  border: 1px solid #E4E4E7;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 24px;
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #52525B;
}

.select-control {
  background: #FFFFFF;
  border: 1px solid #E4E4E7;
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #09090B;
  cursor: pointer;
}

.select-control:focus {
  outline: none;
  border-color: #09090B;
}

/* App Grid */
.app-grid {
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 1024px) {
  .app-grid {
    grid-template-columns: 1fr;
  }
}

/* Panels */
.panel-card {
  background: #FFFFFF;
  border: 1px solid #E4E4E7;
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #F4F4F5;
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.panel-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #09090B;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-subtitle {
  font-size: 0.75rem;
  color: #71717A;
  margin-top: 2px;
}

/* Form Styles */
.form-group {
  margin-bottom: 14px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #27272A;
  margin-bottom: 4px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prefix, .input-suffix {
  position: absolute;
  font-size: 0.75rem;
  color: #71717A;
  pointer-events: none;
}

.input-prefix {
  left: 9px;
}

.input-suffix {
  right: 9px;
}

.input-control {
  width: 100%;
  border: 1px solid #E4E4E7;
  background-color: #FFFFFF;
  border-radius: 5px;
  padding: 7px 10px;
  font-size: 0.8125rem;
  color: #09090B;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-control.with-prefix {
  padding-left: 24px;
}

.input-control.with-suffix {
  padding-right: 26px;
}

.input-control:focus {
  outline: none;
  border-color: #09090B;
  box-shadow: 0 0 0 1px #09090B;
}

.field-hint {
  font-size: 0.7rem;
  color: #71717A;
  margin-top: 3px;
}

/* KPI Summary Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.kpi-card {
  background: #FFFFFF;
  border: 1px solid #E4E4E7;
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #52525B;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: #09090B;
  margin: 6px 0 2px;
  letter-spacing: -0.02em;
}

.kpi-subtext {
  font-size: 0.72rem;
  color: #71717A;
}

.kpi-card.kpi-highlight-positive .kpi-value {
  color: #166534;
}

.kpi-card.kpi-highlight-negative .kpi-value {
  color: #DC2626;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.status-valid {
  background: #DCFCE7;
  color: #166534;
}

.status-warning {
  background: #FEF9C3;
  color: #854D0E;
}

.status-invalid {
  background: #FEE2E2;
  color: #991B1B;
}

/* Waterfall Breakdown Chart */
.waterfall-container {
  background: #FFFFFF;
  border: 1px solid #E4E4E7;
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.waterfall-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.waterfall-bar-outer {
  background: #F4F4F5;
  height: 28px;
  border-radius: 6px;
  display: flex;
  overflow: hidden;
  position: relative;
  border: 1px solid #E4E4E7;
  margin-bottom: 12px;
}

.wf-segment {
  height: 100%;
  transition: width 0.3s ease;
  position: relative;
}

.wf-cogs { background: #3B82F6; }
.wf-fulfillment { background: #8B5CF6; }
.wf-gateway { background: #EC4899; }
.wf-returns { background: #F59E0B; }
.wf-cac { background: #F97316; }
.wf-profit { background: #10B981; }
.wf-loss { background: #EF4444; }

.waterfall-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #52525B;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Table Design */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid #E4E4E7;
  border-radius: 6px;
  margin-bottom: 20px;
  background: #FFFFFF;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  text-align: left;
}

.data-table th, .data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #E4E4E7;
}

.data-table th {
  background: #F8FAFC;
  font-weight: 600;
  color: #334155;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

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

.data-table tr.row-highlight {
  background: #F1F5F9;
  font-weight: 700;
}

.data-table tr.row-total-profit {
  background: #ECFDF5;
  font-weight: 700;
  color: #065F46;
}

.data-table tr.row-total-loss {
  background: #FEF2F2;
  font-weight: 700;
  color: #991B1B;
}

.data-table .num-cell {
  text-align: right;
}

/* Formula Callout Card */
.formula-card {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 20px;
  font-size: 0.8125rem;
}

.formula-card h4 {
  font-size: 0.875rem;
  margin-bottom: 8px;
  color: #1E293B;
}

.formula-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.formula-item {
  background: #FFFFFF;
  border: 1px solid #E2E8F0;
  padding: 8px 12px;
  border-radius: 5px;
}

.formula-title {
  font-weight: 600;
  color: #334155;
  font-size: 0.75rem;
  margin-bottom: 2px;
}

.formula-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  color: #0F172A;
}

/* Disclaimers */
.disclaimer-box {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 0.75rem;
  color: #92400E;
  line-height: 1.5;
  margin-bottom: 20px;
}

/* Footer */
.site-footer {
  border-top: 1px solid #E4E4E7;
  background-color: #FFFFFF;
  padding: 40px 20px 24px;
  margin-top: auto;
}

.footer-container {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 32px;
}

@media (max-width: 768px) {
  .footer-container {
    grid-template-columns: 1fr;
    gap: 24px;
  }
}

.footer-col h4 {
  font-size: 0.875rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: #09090B;
}

.footer-col p {
  font-size: 0.8125rem;
  line-height: 1.5;
  color: #71717A;
}

.footer-links {
  list-style: none;
}

.footer-links li {
  margin-bottom: 8px;
}

.footer-links a, .footer-links span {
  font-size: 0.8125rem;
  color: #71717A;
  text-decoration: none;
  transition: color 0.15s ease;
}

.footer-links a:hover {
  color: #09090B;
}

.footer-bottom {
  max-width: 1240px;
  margin: 24px auto 0;
  padding-top: 20px;
  border-top: 1px solid #F4F4F5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #71717A;
  flex-wrap: wrap;
  gap: 12px;
}

/* Modal System */
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-scrim.hidden {
  display: none !important;
}

.modal-window {
  background: #FFFFFF;
  border: 1px solid #E4E4E7;
  border-radius: 8px;
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: #71717A;
  padding: 4px;
  line-height: 1;
}

.modal-close-btn:hover {
  color: #09090B;
}

.segmented-control {
  display: flex;
  background: #F4F4F5;
  padding: 3px;
  border-radius: 6px;
  margin-bottom: 16px;
  gap: 2px;
}

.segment-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #71717A;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.segment-btn.active {
  background: #FFFFFF;
  color: #09090B;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Buy Me a Coffee Floating Action Button */
.support-widget-float {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #09090B;
  color: #FFFFFF;
  border: 1px solid #27272A;
  padding: 8px 14px;
  border-radius: 9999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 50;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.support-widget-float:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* Print Styles */
@media print {
  .site-header, .controls-bar, .tool-monetization-slot, .support-widget-float, .btn-primary, .btn-outline, .site-footer {
    display: none !important;
  }
  body, .main-wrapper {
    background: #FFFFFF !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  .app-grid {
    grid-template-columns: 1fr !important;
  }
  .panel-card, .kpi-card, .table-responsive, .waterfall-container {
    border: 1px solid #000000 !important;
    box-shadow: none !important;
    break-inside: avoid;
  }
}
