/* Responsive styles - All media queries */

/* ============================================
   Hamburger Menu & Mobile Sidebar
   ============================================ */

.hamburger-menu {
  display: none;
  position: fixed;
  top: var(--sp-4);
  left: var(--sp-4);
  z-index: 1001;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-3);
  cursor: pointer;
  transition: all var(--transition-base);
}

.hamburger-menu:hover {
  background: var(--page-bg);
}

.hamburger-menu svg,
.hamburger-menu .material-symbols-outlined {
  width: 24px;
  height: 24px;
  color: var(--text-main);
}

/* Mobile sidebar overlay / backdrop */
.sidebar-overlay,
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 39;
  opacity: 0;
  transition: opacity var(--transition-slow);
}

.sidebar-overlay.active {
  opacity: 1;
}

/* ============================================
   Tablet (768px - 1023px)
   ============================================ */

@media (max-width: 1023px) {
  /* Hide sidebar on tablet by default (new layout) */
  .app-sidebar {
    display: none;
  }

  /* When toggled open */
  .app-sidebar.mobile-open {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: 16rem;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  }

  /* Legacy sidebar */
  .sidebar {
    width: 280px;
  }

  main:not(.app-main) {
    grid-template-columns: 280px 1fr;
  }

  .chart-card {
    padding: var(--sp-5);
  }

  .metric-card {
    padding: var(--sp-3);
  }

  .metric-value {
    font-size: 1.5rem;
  }

  /* Form pages wider on tablet */
  .form-page {
    width: 60%;
  }

  /* Split pane stacks vertically on tablet */
  .split-pane-container {
    flex-direction: column;
  }

  .split-pane-container .form-page {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding-right: 0;
    padding-bottom: var(--sp-6);
    margin-bottom: var(--sp-6);
  }

  .split-pane-container .chart-pane {
    padding-left: 0;
  }

  .taxes-glance-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    padding: var(--sp-4) 0;
  }
}

/* ============================================
   Mobile (< 768px)
   ============================================ */

@media (max-width: 768px) {
  /* Show hamburger */
  .hamburger-menu {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Sidebar as slide-in drawer */
  .sidebar,
  .app-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 16rem;
    height: 100vh;
    z-index: 40;
    transition: left var(--transition-slow);
    overflow-y: auto;
  }

  .sidebar.active,
  .app-sidebar.mobile-open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  }

  .sidebar.active ~ .sidebar-overlay {
    display: block;
  }

  /* Full-width main content */
  main:not(.app-main) {
    grid-template-columns: 1fr;
    padding: var(--sp-4);
    margin-top: 4rem;
  }

  /* Header adjustments */
  header {
    padding: 0 var(--sp-4);
    margin-left: 3.5rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: var(--text-base);
  }

  /* Stat cards: 1 column */
  .summary-stats {
    grid-template-columns: 1fr;
  }

  /* Mode toggle */
  .mode-toggle {
    margin-top: var(--sp-4);
  }

  .mode-btn {
    font-size: var(--text-base);
    padding: var(--sp-2) var(--sp-4);
  }

  /* Chart cards stack */
  .chart-card {
    margin-bottom: var(--sp-6);
  }

  .chart-container {
    height: 250px;
  }

  /* Chart and table height adjustments for mobile */
  .chart-body .chart-container {
    height: 250px;
  }

  .chart-data-table {
    max-height: 250px;
  }

  /* Cash Flow: Stack vertically on mobile (override desktop row layout) */
  .chart-card[data-planner-tab="cashflow"] .chart-body {
    flex-direction: column;
    gap: 0;
  }

  .chart-card[data-planner-tab="cashflow"] .chart-body .chart-container {
    flex: none;
    width: 100%;
    height: 400px;
  }

  .chart-card[data-planner-tab="cashflow"] .chart-data-summary {
    flex: none;
    width: 100%;
    max-height: 250px;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    padding-left: 0;
    padding-top: var(--sp-3);
    margin-top: var(--sp-3);
  }

  /* Chart with table - mobile adjustments */
  .chart-with-table .chart-container {
    height: 250px;
    min-height: 250px;
  }

  .chart-with-table .chart-data-table {
    width: 100%;
    min-width: 0;
    max-height: 250px;
  }

  .chart-with-table .planner-table {
    min-width: 500px;
  }

  /* Form pages full width on mobile */
  .form-page {
    width: 100%;
  }

  /* Split pane stacks vertically on mobile */
  .split-pane-container {
    flex-direction: column;
  }

  .split-pane-container .form-page {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding-right: 0;
    padding-bottom: var(--sp-4);
    margin-bottom: var(--sp-4);
  }

  .split-pane-container .chart-pane {
    padding-left: 0;
  }

  .taxes-glance-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    padding: var(--sp-4) 0;
  }

  /* Compact Run Simulation button on mobile */
  .header-right .simulate-btn {
    padding: var(--sp-2);
    min-width: 44px;
  }

  .header-right .simulate-btn span:not(.material-symbols-outlined) {
    display: none;
  }

  /* Metric cards */
  .chart-metrics {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-3);
  }

  .metric-card {
    padding: var(--sp-3);
  }

  .metric-label {
    font-size: var(--text-2xs);
  }

  .metric-value {
    font-size: 1.125rem;
  }

  /* Tables with scroll */
  .chart-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .chart-table {
    min-width: 600px;
  }

  .chart-table th,
  .chart-table td {
    padding: var(--sp-2);
    font-size: var(--text-sm);
  }

  /* Chat */
  .chat-messages {
    max-height: 400px;
  }

  .chat-message {
    padding: var(--sp-3);
  }

  .chat-drawer {
    width: 100%;
  }

  /* Form inputs */
  .input-group label {
    font-size: var(--text-sm);
  }

  .input-group input,
  .input-group select {
    font-size: var(--text-base);
    padding: var(--sp-2);
  }

  /* Export button always visible on mobile */
  .chart-export-btn {
    opacity: 1;
    padding: 0.625rem;
  }

  /* Loading */
  .loading-spinner-content {
    padding: var(--sp-8);
  }

  .spinner {
    width: 40px;
    height: 40px;
  }

  .progress-bar-content {
    padding: var(--sp-6);
  }

  .chart-skeleton {
    height: 250px;
  }

  /* Layout stacking */
  .chart-metrics,
  .tax-rates-comparison,
  .break-even-comparison,
  .advantage-grid {
    flex-direction: column;
  }

  .comparison-divider {
    flex-direction: row;
    padding: var(--sp-2) 0;
  }

  .metric-card {
    min-width: 100%;
  }

  /* SS, Roth, Survivor responsive */
  .ss-couple-layout { grid-template-columns: 1fr; }
  .strategy-persons { flex-direction: column; }
  .person-divider { transform: rotate(90deg); }
  .ss-metrics-grid, .ss-couple-metrics { grid-template-columns: 1fr; }
  .ss-timing-tabs { flex-wrap: wrap; }
  .survivor-metrics-grid { grid-template-columns: 1fr; }
  .survivor-toggle-section { padding: var(--sp-4); }
  .spending-metrics-grid { grid-template-columns: 1fr; }
  .spending-toggle-section { padding: var(--sp-4); }
  .adjustment-details { gap: var(--sp-1); }
  .strategy-comparison-grid { grid-template-columns: 1fr; }
  .banner-stats { flex-direction: column; gap: var(--sp-2); }
  .roth-metrics-grid { grid-template-columns: 1fr; }
  .strategy-metrics { grid-template-columns: 1fr; }

  /* Modal responsive */
  .modal-content {
    max-height: 95vh;
  }

  .analysis-method {
    padding: var(--sp-4);
  }

  .scenario-badge {
    width: 100%;
    justify-content: center;
  }

  /* Toast */
  .toast-container {
    left: var(--sp-4);
    right: var(--sp-4);
    top: var(--sp-4);
  }

  .toast {
    min-width: 0;
    max-width: 100%;
  }
}

/* ============================================
   Small Mobile (max-width: 480px)
   ============================================ */

@media (max-width: 480px) {
  header {
    margin-left: 3rem;
  }

  header h1 {
    font-size: 1.25rem;
  }

  .sidebar,
  .app-sidebar {
    width: 16rem;
  }

  .chart-metrics {
    grid-template-columns: 1fr;
  }

  .chart-container {
    height: 220px;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .mode-toggle {
    width: 100%;
  }

  .mode-btn {
    flex: 1;
  }

  .chat-input {
    font-size: var(--text-base);
  }
}

/* ============================================
   Desktop (1024px+) - Stat Cards 4-Column
   ============================================ */

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

/* ============================================
   Touch Target Improvements
   ============================================ */

button,
.mode-btn,
.send-button,
.chart-export-btn,
.toast-close,
.hamburger-menu {
  min-height: 44px;
  min-width: 44px;
}

input,
select,
textarea {
  min-height: 44px;
}

.metric-card {
  min-height: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.chart-table tbody tr {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.chart-table tbody tr:active {
  background-color: rgba(0, 181, 119, 0.1);
}

/* ============================================
   Accessibility
   ============================================ */

.skip-to-content {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--primary);
  color: white;
  padding: var(--sp-3) var(--sp-6);
  text-decoration: none;
  font-weight: var(--fw-semibold);
  z-index: 10000;
  border-radius: 0 0 var(--radius-lg) 0;
  transition: top var(--transition-slow);
}

.skip-to-content:focus {
  top: 0;
  outline: 3px solid var(--text-main);
  outline-offset: 2px;
}

/* Focus styles - use green instead of amber */
*:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(0, 181, 119, 0.1);
}

.mode-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.chart-export-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  opacity: 1;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ============================================
   Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .toast,
  .loading-spinner-overlay,
  .progress-bar-overlay,
  .sidebar {
    transition: none;
  }
}

/* ============================================
   High Contrast Mode
   ============================================ */

@media (prefers-contrast: high) {
  .chart-card,
  .stat-card {
    border: 2px solid var(--text-main);
  }

  button,
  .mode-btn {
    border: 2px solid currentColor;
  }

  .chart-export-btn {
    background: var(--text-main);
    color: var(--surface-card);
  }

  input,
  select,
  textarea {
    border: 2px solid var(--text-main);
  }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
  .sidebar,
  .app-sidebar,
  .hamburger-menu,
  .sidebar-overlay,
  .mode-toggle,
  .chat-interface,
  .chat-drawer,
  .chart-export-btn,
  .toast-container,
  .loading-spinner-overlay,
  .progress-bar-overlay,
  .skip-to-content {
    display: none !important;
  }

  main:not(.app-main) {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .chart-card {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .chart-container {
    height: auto;
    min-height: 400px;
  }
}
