:root {
  --brand: #e61e26;
  --brand-dark: #b91c1c;
  --brand-light: #fef2f2;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --border: #e5e7eb;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(180deg, #ffffff 0%, #f9fafb 100%);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* Header Styles */
.header {
  background: white;
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  margin-bottom: 2rem;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.logo-image {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-top: 0.5rem;
  line-height: 1.5;
}

.action-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Button Styles */
.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.875rem;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
}

.btn-primary {
  background: var(--brand);
  color: white;
  box-shadow: 0 2px 8px rgba(230, 30, 38, 0.2);
}

.btn-primary:hover {
  background: var(--brand-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(230, 30, 38, 0.3);
}

.btn-secondary {
  background: white;
  color: var(--text-primary);
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  border-color: var(--brand);
  color: var(--brand);
}

/* Main Layout Grid */
.main-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
  margin-bottom: 2rem;
}

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

/* Card Styles */
.card {
  background: white;
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--bg-secondary);
}

.card-icon {
  width: 40px;
  height: 40px;
  background: var(--brand-light);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Input Styles */
.input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.input {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 0.9375rem;
  font-weight: 500;
  transition: all 0.2s;
  background: white;
}

.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(230, 30, 38, 0.1);
}

.input:hover {
  border-color: #d1d5db;
}

.input-help {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

/* Select Styles */
select.input {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%236B7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
  appearance: none;
}

/* Metric Cards */
.metrics-grid {
  display: grid;
  gap: 1rem;
}

.metric-card {
  padding: 1.25rem;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: white;
  transition: all 0.2s;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.metric-value {
  font-size: 1.875rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.metric-card.primary {
  background: linear-gradient(135deg, var(--brand-light) 0%, white 100%);
  border-color: var(--brand);
}

.metric-card.primary .metric-label {
  color: var(--brand);
}

.metric-card.success {
  background: linear-gradient(135deg, var(--success-light) 0%, white 100%);
  border-color: var(--success);
}

.metric-card.success .metric-value {
  color: var(--success);
}

.metric-card.danger {
  background: linear-gradient(135deg, var(--danger-light) 0%, white 100%);
  border-color: var(--danger);
}

.metric-card.danger .metric-value {
  color: var(--danger);
}

/* Assumptions Box */
.assumptions-box {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--brand-light);
  border: 2px solid var(--brand);
  border-radius: 16px;
}

.assumptions-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pill-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.pill {
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid var(--brand);
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
}

/* COI Toggle */
.coi-box {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--warning-light);
  border: 2px solid var(--warning);
  border-radius: 12px;
}

.toggle-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toggle-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.toggle-results {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(245, 158, 11, 0.3);
  display: flex;
  gap: 2rem;
  font-size: 0.875rem;
  color: var(--text-primary);
}

/* Chart Container */
.chart-card {
  background: white;
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
  margin-bottom: 2rem;
}

.chart-container {
  position: relative;
  height: 300px;
  margin-top: 1.5rem;
}

/* Advice Card */
.advice-card {
  background: white;
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 2px solid var(--border);
  margin-bottom: 2rem;
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.advice-card.success {
  background: var(--success-light);
  border-color: var(--success);
}

.advice-card.danger {
  background: var(--danger-light);
  border-color: var(--danger);
}

.advice-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.advice-content {
  flex: 1;
}

.advice-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.advice-body {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Footer */
.footer {
  text-align: center;
  padding: 3rem 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.footer-logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.footer-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--brand);
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }
  
  .title {
    font-size: 1.5rem;
  }
  
  .header {
    padding: 1.5rem;
  }
  
  .card {
    padding: 1.5rem;
  }
  
  .input-grid {
    grid-template-columns: 1fr;
  }
  
  .action-buttons {
    flex-direction: column;
  }
  
  .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Loading States */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.loading {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Print Styles - Optimized for 2 pages maximum */
@media print {
  /* Page setup */
  @page {
    size: letter;
    margin: 0.5in;
  }
  
  /* Reset backgrounds and colors for print */
  body {
    background: white;
    font-size: 10pt;
    line-height: 1.4;
    color: black;
  }
  
  * {
    overflow: visible !important;
  }
  
  /* Container adjustments */
  .container {
    max-width: 100%;
    padding: 0;
    width: 100%;
  }
  
  /* Header optimization - logo only for print */
  .header {
    background: white !important;
    padding: 0 !important;
    margin-bottom: 0.375rem !important;
    page-break-after: avoid;
    border: none !important;
    clear: both;
    height: 24px !important;
    display: block !important;
  }
  
  /* Show only the logo image */
  .header * {
    display: none !important;
  }
  
  .header .logo-image {
    display: block !important;
    width: 24px !important;
    height: 24px !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
  }
  
  /* Alternative approach - reconstruct header */
  .header::before {
    content: "" !important;
    display: block !important;
    width: 24px !important;
    height: 24px !important;
    background: url('assets/images/The-20-Logo.png') no-repeat center !important;
    background-size: contain !important;
  }
  
  /* Hide interactive elements */
  .btn,
  .action-buttons,
  button,
  .footer {
    display: none !important;
  }
  
  /* Card styling for print */
  .card {
    box-shadow: none !important;
    border: 1px solid #999 !important;
    padding: 0.375rem !important;
    margin-bottom: 0.375rem !important;
    page-break-inside: avoid;
    break-inside: avoid;
    clear: both;
    position: relative !important;
  }
  
  /* Section titles */
  .section-title {
    font-size: 11pt !important;
    font-weight: 600 !important;
    margin-bottom: 0.375rem !important;
    page-break-after: avoid;
    clear: both;
  }
  
  /* Input grid optimization */
  .input-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.375rem !important;
    page-break-inside: avoid;
    clear: both;
  }
  
  .input-group {
    margin-bottom: 0.375rem !important;
    page-break-inside: avoid;
  }
  
  .input-label {
    font-size: 7.5pt !important;
    margin-bottom: 2px !important;
    font-weight: 500 !important;
  }
  
  .input-field {
    border: 1px solid #666 !important;
    background: white !important;
    padding: 0.125rem 0.25rem !important;
    font-size: 8.5pt !important;
    height: 22px !important;
    line-height: 1.2 !important;
  }
  
  /* Metrics section - keep together */
  .metrics-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 0.375rem !important;
    page-break-inside: avoid;
    margin-bottom: 0.5rem !important;
    clear: both;
  }
  
  .metric {
    padding: 0.375rem !important;
    border: 1px solid #999 !important;
    page-break-inside: avoid;
    min-height: auto !important;
  }
  
  .metric-card {
    padding: 0.375rem !important;
    border: 1px solid #999 !important;
    min-height: auto !important;
  }
  
  .metric-label, .metric-title {
    font-size: 7.5pt !important;
    margin-bottom: 2px !important;
    font-weight: 500 !important;
  }
  
  .metric-value {
    font-size: 10pt !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
  }
  
  /* Main grid for print */
  .main-grid {
    display: block !important;
    width: 100% !important;
  }
  
  /* Input section - keep on page 1 */
  #input-section {
    page-break-inside: avoid;
    margin-bottom: 0.5rem !important;
    position: relative !important;
    clear: both;
  }
  
  /* ROI Summary - keep on page 1 */
  #roi-summary {
    page-break-inside: avoid;
    margin-bottom: 0.5rem !important;
    position: relative !important;
    clear: both;
  }
  
  /* Chart section - compact for page 1 */
  #chart-card, .chart-card {
    page-break-inside: avoid !important;
    margin-bottom: 0.375rem !important;
    padding: 0.375rem !important;
    border: 1px solid #999 !important;
    position: relative !important;
    clear: both !important;
    display: block !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
  }
  
  .chart-container {
    position: relative !important;
    width: 100% !important;
    height: 160px !important;
    margin-top: 0.25rem !important;
    clear: both !important;
  }
  
  #gainChart {
    position: relative !important;
    max-height: 150px !important;
    width: 100% !important;
    height: 150px !important;
    display: block !important;
  }
  
  canvas {
    position: relative !important;
    page-break-inside: avoid !important;
  }
  
  /* Card header for chart */
  .card-header {
    display: flex !important;
    align-items: center !important;
    gap: 0.375rem !important;
    margin-bottom: 0.25rem !important;
  }
  
  .card-icon {
    display: none !important;
  }
  
  .card-title {
    font-size: 11pt !important;
    font-weight: 600 !important;
    margin: 0 !important;
  }
  
  /* Advice section if visible */
  #advice {
    page-break-inside: avoid;
    margin-top: 0.5rem !important;
    clear: both !important;
    position: relative !important;
  }
  
  table {
    font-size: 8pt !important;
    width: 100% !important;
  }
  
  th, td {
    padding: 0.25rem 0.375rem !important;
    border: 1px solid #ddd !important;
  }
  
  th {
    background: #f5f5f5 !important;
    font-weight: 600 !important;
  }
  
  /* Advice card when visible */
  .advice-card {
    padding: 0.375rem !important;
    border: 1px solid #999 !important;
    page-break-inside: avoid;
    margin-bottom: 0.5rem !important;
    background: #f9f9f9 !important;
    clear: both !important;
    position: relative !important;
    display: flex !important;
    align-items: flex-start !important;
  }
  
  .advice-icon {
    display: inline-block !important;
    margin-right: 0.375rem !important;
    flex-shrink: 0 !important;
    background: transparent !important;
  }
  
  .advice-content {
    display: inline-block !important;
    flex: 1 !important;
  }
  
  .advice-title {
    font-size: 9pt !important;
    font-weight: 600 !important;
    margin-bottom: 0.125rem !important;
  }
  
  .advice-body {
    font-size: 8pt !important;
    line-height: 1.3 !important;
    margin-bottom: 0 !important;
  }
  
  /* Banner and pills */
  #banner {
    font-size: 8pt !important;
    margin-bottom: 0.25rem !important;
  }
  
  .pill {
    font-size: 7pt !important;
    padding: 0.125rem 0.25rem !important;
  }
  
  /* COI Toggle and Panel - ensure visible on page 1 */
  .toggle-container {
    display: none !important; /* Hide the checkbox toggle in print */
  }
  
  #coiPanel, .toggle-results {
    display: block !important; /* Force display if COI is checked */
    padding: 0.375rem !important;
    margin-bottom: 0.375rem !important;
    margin-top: 0.25rem !important;
    border: 1px solid #666 !important;
    background: #fffbf0 !important;
    page-break-inside: avoid;
    font-size: 8pt !important;
  }
  
  #coiPanel div {
    margin-bottom: 0.125rem !important;
    line-height: 1.2 !important;
  }
  
  #coiPanel strong {
    font-weight: 700 !important;
    color: #d97706 !important;
  }
  
  /* Only show COI panel if it has content */
  #coiPanel:empty {
    display: none !important;
  }
  
  /* Text size adjustments */
  h1 { font-size: 16pt !important; }
  h2 { font-size: 11pt !important; }
  h3 { font-size: 10pt !important; }
  p { font-size: 8.5pt !important; }
  
  /* Controlled margins - fix overlap */
  * {
    margin-top: 0 !important;
  }
  
  .card {
    margin-bottom: 0.5rem !important;
  }
  
  .metric-card {
    margin-bottom: 0 !important;
  }
  
  .input-group {
    margin-bottom: 0.375rem !important;
  }
  
  div[style*="flex"], div[style*="grid"] {
    margin-bottom: 0.375rem !important;
  }
  
  /* Ensure last card doesn't add extra space */
  .card:last-child {
    margin-bottom: 0 !important;
  }
  
  /* Fix any absolute or fixed positioning */
  * {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    z-index: auto !important;
  }
  
  /* Ensure visibility */
  * {
    opacity: 1 !important;
    visibility: visible !important;
  }
}