/* ==========================================================================
   Loan Calculator - Modern Financial UI Theme (Gold/Amber Accent)
   Designed for klcai UX Financial Suite
   ========================================================================== */

:root {
  --primary: #f59e0b;
  --primary-hover: #d97706;
  --primary-light: #fef3c7;
  --primary-dark: #b45309;
  
  --secondary: #3b82f6;
  --secondary-light: #dbeafe;
  
  --accent: #10b981;
  --accent-light: #d1fae5;

  --warning: #f97316;
  --warning-light: #ffedd5;
  
  --danger: #ef4444;
  --danger-light: #fee2e2;

  --bg-main: #0b1320;
  --bg-card: #152238;
  --bg-subtle: #1e3352;
  --bg-input: #0b1320;
  
  --border: #23395d;
  --border-focus: #f59e0b;

  --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, #152238 0%, #0b1320 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-block {
  display: flex;
  flex-direction: column;
}

.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;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  background-color: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

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

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

/* Nav Links between calculators */
.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: #fbbf24;
}

/* Profile Selector Bar */
.profile-manager-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(11, 19, 32, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
}

.profile-manager-bar label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.profile-manager-bar select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  max-width: 210px;
}

.profile-manager-bar select option,
.profile-manager-bar select optgroup {
  background-color: var(--bg-card);
  color: var(--text-main);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  outline: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #0b1320;
}

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

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

.btn-outline:hover {
  background-color: var(--bg-subtle);
  border-color: var(--primary);
  color: #fbbf24;
}

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

.btn-danger-outline:hover {
  background-color: rgba(239, 68, 68, 0.15);
  border-color: var(--danger);
}

.btn-icon {
  padding: 0.45rem;
  width: 32px;
  height: 32px;
}

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

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

/* Panels */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.results-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.15rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid rgba(35, 57, 93, 0.6);
}

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

.card-title-icon {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

/* Loan Type Selector Grid */
.loan-type-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.15rem;
}

.loan-type-btn {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.35rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.loan-type-btn .type-icon {
  font-size: 1.3rem;
}

.loan-type-btn span {
  font-size: 0.75rem;
  font-weight: 600;
}

.loan-type-btn:hover {
  background: var(--bg-subtle);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fff;
}

.loan-type-btn.active {
  background: rgba(245, 158, 11, 0.12);
  border-color: var(--primary);
  color: #fbbf24;
}

/* Mode Selector Grid */
.mode-selector-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.mode-btn {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.5rem;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.mode-btn span {
  font-size: 0.82rem;
  font-weight: 600;
  display: block;
}

.mode-btn small {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

.mode-btn:hover {
  background: var(--bg-subtle);
  border-color: rgba(245, 158, 11, 0.35);
  color: var(--text-main);
}

.mode-btn.active {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--primary);
  color: #fbbf24;
}

.mode-btn.active small {
  color: #fde68a;
}

/* Form Groups & Sliders */
.form-group {
  margin-bottom: 1.15rem;
}

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

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

.form-label-row label {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

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

input[type="range"] {
  width: 100%;
  height: 6px;
  background: #1e3352;
  border-radius: 9999px;
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
  transition: transform 0.1s ease;
}

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

.slider-val-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.3rem 0.5rem;
  outline: none;
  text-align: right;
  transition: border-color 0.15s ease;
}

.slider-val-box:focus {
  border-color: var(--border-focus);
}

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

.input-prefix {
  position: absolute;
  left: 0.6rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  pointer-events: none;
}

.input-suffix {
  position: absolute;
  right: 0.6rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  pointer-events: none;
}

.input-with-prefix input {
  padding-left: 1.35rem;
  width: 100%;
}

.input-with-suffix input {
  padding-right: 1.35rem;
  width: 100%;
}

select, input[type="text"], input[type="number"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  outline: none;
  width: 100%;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

select:focus, input[type="text"]:focus, input[type="number"]:focus {
  border-color: var(--border-focus);
}

.badge-calc-target {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

/* Solved Target Banner */
.solved-banner {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.15) 0%, rgba(217, 119, 6, 0.08) 100%);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.solved-banner-content h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 0.25rem;
}

.solved-banner-content p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.solved-banner-val {
  font-size: 1.85rem;
  font-weight: 800;
  color: #fff;
  font-family: var(--font-mono);
}

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

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

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--border);
}

.kpi-card.accent-primary::before {
  background: var(--primary);
}

.kpi-card.accent-blue::before {
  background: #3b82f6;
}

.kpi-card.accent-cyan::before {
  background: #06b6d4;
}

.kpi-card.accent-purple::before {
  background: #a855f7;
}

.kpi-card.accent-green::before {
  background: #10b981;
}

.kpi-card.accent-amber::before {
  background: #f59e0b;
}

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

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

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

.status-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  width: fit-content;
  margin-top: 0.2rem;
}

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

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

/* Advisory & Acceleration Banner */
.advisory-box {
  background: rgba(30, 51, 82, 0.45);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.advisory-box.highlight {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.4);
}

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

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

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

/* Chart Tabs */
.chart-tabs-bar {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.tab-btn.active {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}

.chart-container-box {
  position: relative;
  width: 100%;
}

.chart-pane {
  display: none;
  height: 380px;
  position: relative;
  width: 100%;
}

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

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

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

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

.toggle-btn:hover {
  color: var(--text-main);
}

.toggle-btn.active {
  background: var(--primary);
  color: #0b1320;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: right;
  white-space: nowrap;
}

thead {
  position: sticky;
  top: 0;
  background: #152238;
  z-index: 10;
  border-bottom: 2px solid var(--border);
}

th {
  padding: 0.75rem 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

th:first-child, td:first-child {
  text-align: left;
  padding-left: 1rem;
}

td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid rgba(35, 57, 93, 0.4);
  font-family: var(--font-mono);
  color: var(--text-main);
}

tbody tr:hover {
  background: rgba(30, 51, 82, 0.4);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1.5rem;
}

.modal-backdrop.active {
  display: flex;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

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

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

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

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

.modal-body {
  padding: 1.5rem;
}

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

/* Footer */
.app-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-top: 3rem;
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
}

.app-footer a {
  color: var(--primary);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   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 nowrap
   amortization table and the fixed-column button grids were forcing the whole
   page wider than the viewport - on a phone badly, and by ~100px even at
   1440px. 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 preset bar is the widest header row; give it the full width and let
     the select absorb the slack instead of pushing the buttons off screen. */
  .profile-manager-bar {
    width: 100%;
  }

  .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;
  }

  /* Sub-grids collapse to what fits a phone */
  .loan-type-selector {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-selector-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .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-calc-target {
    font-size: 0.7rem;
  }

  /* The lump-sum disclosure is a real control, so give it a real target. */
  summary {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

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

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

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

  /* 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
     26px 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: #1e3352;
    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: #1e3352;
    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;
  }

  .chart-tabs-bar {
    gap: 0.35rem;
    margin-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

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

  /* The schedule table keeps scrolling sideways, but the year column is
     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;
  }

  thead th:first-child,
  tbody td:first-child {
    position: sticky;
    left: 0;
    text-align: left;
    background: var(--bg-card);
  }

  thead th:first-child {
    background: #152238;
    z-index: 11;
  }

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

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

  .solved-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .solved-banner-val {
    font-size: 1.8rem;
  }

  /* 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;
  }

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

  .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(21, 34, 56, 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;
  }
}
