/* ==========================================================================
   Retirement Income & Pension Planner - Modern Financial UI
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-dark: #1e40af;
  
  --secondary: #059669;
  --secondary-light: #d1fae5;
  
  --accent: #7c3aed;
  --accent-light: #ede9fe;

  --warning: #d97706;
  --warning-light: #fef3c7;
  
  --danger: #dc2626;
  --danger-light: #fee2e2;

  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-subtle: #334155;
  --bg-input: #0f172a;
  
  --border: #334155;
  --border-focus: #3b82f6;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 60px;
}

/* Header */
.app-header {
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
  margin-bottom: 2rem;
}

.header-container {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.brand-title {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #fff;
}

.brand-badge {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--primary-dark);
  color: #93c5fd;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  border: 1px solid #3b82f6;
}

.brand-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.scenario-select-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.scenario-select-wrapper label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Buttons and Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border);
  color: var(--text-main);
}
.btn-outline:hover {
  background-color: var(--bg-subtle);
}

.nav-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(30, 51, 82, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  transition: all 0.2s ease;
}
.nav-link-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--primary);
  color: #93c5fd;
}

.view-mode-toggle {
  display: inline-flex;
  background-color: var(--bg-subtle);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background-color: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* Layout */
.layout-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .layout-container {
    grid-template-columns: 1fr;
  }
}

/* Control Panel (Sidebar) */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.15rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #f1f5f9;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-title-icon {
  width: 18px;
  height: 18px;
  color: #60a5fa;
}

/* Forms and Inputs */
.form-group {
  margin-bottom: 1rem;
}

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

.form-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

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

.input-prefix {
  position: absolute;
  left: 0.75rem;
  color: var(--text-dim);
  font-size: 0.875rem;
  pointer-events: none;
}

.input-suffix {
  position: absolute;
  right: 0.75rem;
  color: var(--text-dim);
  font-size: 0.875rem;
  pointer-events: none;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-with-prefix input {
  padding-left: 1.85rem;
}

.input-with-suffix input {
  padding-right: 2rem;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

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

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-subtle);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--primary-hover);
  transform: scale(1.15);
}

.slider-val-box {
  width: 90px;
  text-align: right;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-toggle {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-subtle);
  transition: .25s;
  border-radius: 24px;
  border: 1px solid var(--border);
}

.slider-toggle:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .25s;
  border-radius: 50%;
}

input:checked + .slider-toggle {
  background-color: var(--primary);
}

input:checked + .slider-toggle:before {
  transform: translateX(20px);
}

.conditional-fields {
  transition: all 0.3s ease;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.conditional-fields.hidden {
  display: none;
}

.badge-info {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
}

.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 11px;
  cursor: help;
  margin-left: 4px;
}

/* Results Panel */
.results-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary);
}

.kpi-card.accent-success::before {
  background: var(--secondary);
}
.kpi-card.accent-warning::before {
  background: var(--warning);
}
.kpi-card.accent-purple::before {
  background: var(--accent);
}

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

.kpi-value {
  font-size: 1.65rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
  font-family: var(--font-mono);
}

.kpi-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  width: fit-content;
  margin-top: 0.4rem;
}

.status-tag.safe {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-tag.warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.status-tag.danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Charts Section */
.chart-tabs-bar {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
  padding-bottom: 0.5rem;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover {
  color: var(--text-main);
  background: var(--bg-subtle);
}

.tab-btn.active {
  color: #fff;
  background: var(--primary);
}

.chart-container-box {
  position: relative;
  min-height: 380px;
  width: 100%;
}

.chart-pane {
  display: none;
  height: 380px;
}

.chart-pane.active {
  display: block;
}

/* Strategy Advisory Box */
.advisory-box {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.7) 0%, rgba(15, 23, 42, 0.9) 100%);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

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

.advisory-content h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #f8fafc;
  margin-bottom: 0.35rem;
}

.advisory-content p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Data Table Section */
.table-header-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.table-responsive {
  overflow-x: auto;
  max-height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: right;
  font-family: var(--font-mono);
}

th {
  background-color: #0f172a;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
  font-family: var(--font-sans);
}

th:first-child,
td:first-child {
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 1;
  background-color: var(--bg-card);
}

th:first-child {
  z-index: 3;
  background-color: #0f172a;
}

td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
}

tr:nth-child(even) td {
  background-color: rgba(255, 255, 255, 0.015);
}

tr.retirement-milestone td {
  background-color: rgba(37, 99, 235, 0.15) !important;
  font-weight: bold;
  border-top: 1px solid var(--primary);
  border-bottom: 1px solid var(--primary);
}

tr.depleted-row td {
  background-color: rgba(220, 38, 38, 0.12) !important;
  color: #fca5a5;
}

.highlight-val {
  color: #60a5fa;
  font-weight: 600;
}

.pension-val {
  color: #34d399;
}

.withdrawal-val {
  color: #a78bfa;
}

/* Footer */
.app-footer {
  text-align: center;
  margin-top: 3rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.app-footer a {
  color: var(--text-muted);
  text-decoration: underline;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .header-container {
    flex-direction: column;
    align-items: flex-start;
  }
  .app-header {
    padding: 1rem;
  }
  .layout-container {
    padding: 0 0.75rem;
  }
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Profile Management & Modals
   ========================================================================== */
.profile-manager-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.profile-manager-bar select {
  max-width: 260px;
}

.btn-icon {
  padding: 0.5rem 0.65rem;
}

.btn-danger-outline {
  background: transparent;
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
}
.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
}

/* Modal System */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.modal-backdrop.active .modal-dialog {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
  border-radius: 4px;
}
.modal-close-btn:hover {
  color: #fff;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background: rgba(0, 0, 0, 0.15);
}

/* Saved Profiles List */
.saved-profiles-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.profile-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  transition: background 0.15s;
}

.profile-list-item:hover {
  background: rgba(51, 65, 85, 0.8);
}

.profile-item-meta h4 {
  font-size: 0.95rem;
  color: #f8fafc;
  margin-bottom: 0.2rem;
}

.profile-item-meta p {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.profile-item-actions {
  display: flex;
  gap: 0.5rem;
}

.profile-empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: #1e293b;
  border: 1px solid #3b82f6;
  color: #f8fafc;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: slideInToast 0.25s ease forwards;
  max-width: 360px;
}

.toast.toast-success {
  border-color: #10b981;
}

.toast.toast-error {
  border-color: #ef4444;
}

@keyframes slideInToast {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ==========================================================================
   Responsive & Touch Layout
   Phone and small-tablet refinements. Everything below is scoped inside a
   max-width query, so the desktop layout above is unchanged.
   ========================================================================== */

/* Grid and flex children size to their min-content by default, so the wide
   cash-flow table and the value boxes were forcing the whole page wider than
   the viewport. Let them shrink so .table-responsive scrolls instead of the
   page. */
.layout-container > *,
.controls-panel > *,
.results-panel > *,
.card,
.kpi-card,
.form-group,
.slider-row {
  min-width: 0;
}

@media (max-width: 820px) {
  /* Header */
  .app-header {
    padding: 0.9rem 1rem;
    padding-top: calc(0.9rem + env(safe-area-inset-top));
    margin-bottom: 1.25rem;
  }

  .header-container {
    gap: 0.8rem;
  }

  .brand-title {
    font-size: 1.3rem;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .brand-subtitle {
    font-size: 0.82rem;
  }

  .header-actions {
    width: 100%;
    gap: 0.5rem;
  }

  /* The scenario and preset rows are the widest header content; give them
     the full width and let the select absorb the slack. */
  .scenario-select-wrapper,
  .profile-manager-bar {
    width: 100%;
  }

  .scenario-select-wrapper select,
  .profile-manager-bar select {
    flex: 1 1 8rem;
    min-width: 0;
    max-width: none;
  }

  /* Page gutters */
  .layout-container {
    padding-left: calc(0.85rem + env(safe-area-inset-left));
    padding-right: calc(0.85rem + env(safe-area-inset-right));
    gap: 1.15rem;
  }

  .card {
    padding: 1.05rem;
  }

  /* KPI cards two-up rather than one per row */
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem;
  }

  .kpi-card {
    padding: 0.85rem;
  }

  .kpi-label {
    font-size: 0.72rem;
    margin-bottom: 0.35rem;
  }

  .kpi-value {
    font-size: 1.3rem;
  }

  .kpi-subtext {
    font-size: 0.72rem;
  }

  .badge-info {
    font-size: 0.7rem;
  }

  /* Touch targets: 44px is the Apple HIG / WCAG 2.5.5 minimum. */
  .btn,
  .nav-link-btn,
  .toggle-btn,
  .tab-btn,
  select,
  input[type="number"],
  input[type="text"] {
    min-height: 44px;
  }

  .btn-icon {
    min-width: 44px;
  }

  summary {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .tooltip-icon {
    min-width: 24px;
    min-height: 24px;
  }

  .modal-close-btn {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  input[type="checkbox"] {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  /* iOS zooms the whole viewport when a focused field renders under 16px. */
  input,
  select,
  textarea {
    font-size: 16px;
  }

  .slider-val-box {
    font-size: 15px;
    padding: 0.5rem;
  }

  /* A 16px thumb is hard to hit with a fingertip. Widen the input to a
     34px touch strip and draw the thin track inside it. */
  input[type="range"] {
    height: 34px;
    background: transparent;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    background: #334155;
    border-radius: 9999px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
    margin-top: -11px;
  }

  input[type="range"]::-moz-range-track {
    height: 6px;
    background: #334155;
    border-radius: 9999px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--primary);
    border-radius: 50%;
  }

  /* Charts */
  .chart-pane {
    height: 300px;
  }

  /* One swipeable row of tabs reads better than three stacked full-width
     buttons, and keeps the chart itself above the fold. */
  .chart-tabs-bar {
    gap: 0.35rem;
    margin-bottom: 1rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .chart-tabs-bar .tab-btn {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .chart-tabs-bar::-webkit-scrollbar {
    display: none;
  }

  /* The cash-flow table keeps scrolling sideways; its first column is already
     pinned, so the figures never lose their row label mid-swipe. */
  .table-responsive {
    max-height: 65vh;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  table {
    font-size: 0.78rem;
  }

  th {
    padding: 0.6rem 0.65rem;
  }

  td {
    padding: 0.55rem 0.65rem;
  }

  /* Advisories */
  .advisory-box {
    padding: 0.85rem 0.95rem;
    gap: 0.7rem;
  }

  .advisory-icon {
    font-size: 1.4rem;
  }

  /* Modals become a bottom sheet rather than a small floating dialog.
     Visibility is still owned by .modal-backdrop.active. */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-dialog {
    max-width: none;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 1.1rem;
    padding-right: 1.1rem;
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  .profile-list-item {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Keep toasts clear of the pinned summary bar. */
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .app-footer a {
    display: inline-block;
    padding: 0.25rem 0;
  }

  .app-footer {
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
  }
}

/* Narrow phones (iPhone SE and similar) */
@media (max-width: 380px) {
  .kpi-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .brand-title {
    font-size: 1.15rem;
  }

  .chart-pane {
    height: 260px;
  }
}

/* --------------------------------------------------------------------------
   Mobile summary bar (markup is built by js/mobile.js)
   On a phone the KPI cards sit a screen or two below the sliders, so the
   headline figures are pinned to the bottom while the controls are in view.
   -------------------------------------------------------------------------- */
.mobile-summary-bar {
  display: none;
}

@media (max-width: 820px) {
  .mobile-summary-bar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    background: rgba(30, 41, 59, 0.96);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 18px -8px rgba(0, 0, 0, 0.85);
    transform: translateY(115%);
    transition: transform 0.22s ease;
    cursor: pointer;
  }

  .mobile-summary-bar.visible {
    transform: none;
  }

  .mobile-summary-metric {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
  }

  .mobile-summary-metric + .mobile-summary-metric {
    border-left: 1px solid var(--border);
  }

  .mobile-summary-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
  }

  .mobile-summary-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Room for the bar so it never covers the footer at full scroll. */
  body {
    padding-bottom: 92px;
  }
}
