/* ============================================================
   PHASE 2: RESPONSIVE & MOBILE LAYOUT
   Layered on top of existing responsive rules in app.css.
   Addresses remaining gaps found during audit.
   ============================================================ */

/* ===== SIDEBAR OVERLAY BACKDROP ===== */
.sidebar-overlay {
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}
.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ===== FLUID TYPOGRAPHY (clamp-based) ===== */
@supports (font-size: clamp(1rem, 2vw, 2rem)) {
  .welcome-text h1 {
    font-size: clamp(1.125rem, 3vw, 1.75rem);
  }
  .section-title-row h1 {
    font-size: clamp(1.125rem, 3vw, 1.5rem);
  }
  .card-header h2 {
    font-size: clamp(0.9375rem, 2.5vw, 1.125rem);
  }
}

/* ============================================================
   1024px — SMALL LAPTOP / TABLET LANDSCAPE
   ============================================================ */
@media (max-width: 1024px) {
  .section-inner {
    max-width: 100%;
    padding: var(--space-5);
  }
  
  /* Chat messages: slightly less padding */
  .chat-messages {
    padding: var(--space-4);
  }
}

/* ============================================================
   768px — TABLET / LARGE PHONE LANDSCAPE
   ============================================================ */
@media (max-width: 768px) {

  /* --- Sidebar: smoother animation + dark overlay --- */
  .sidebar {
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    will-change: transform;
  }
  .sidebar.open {
    box-shadow: 4px 0 32px rgba(0,0,0,0.25);
  }

  /* --- Top bar: tighter at tablet, hide less important items --- */
  .top-bar {
    min-height: 52px;
  }
  .search-trigger {
    border: none;
    background: none;
  }

  /* --- Welcome banner: centered, no ring overflow --- */
  .welcome-banner {
    text-align: center;
    overflow: hidden;
  }
  .welcome-right {
    display: flex;
    justify-content: center;
    margin-top: var(--space-2);
  }
  
  /* --- Milestone labels: truncate gracefully --- */
  .milestone-badges {
    flex-wrap: wrap;
    overflow: visible;
  }
  .badge-earned,
  .badge-locked {
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
  }
  .badge-earned > .badge-label,
  .badge-locked > .badge-label {
    font-size: 0.6875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 56px;
    text-align: center;
  }

  /* --- CRS benchmark bar: smaller text, no overlap with FAB --- */
  .kpi-benchmark,
  .crs-benchmark {
    font-size: 0.6875rem;
  }
  .crs-bench-labels {
    font-size: 0.625rem;
  }

  /* --- Chat section: full height with pinned input --- */
  #section-chat {
    height: 100%;
    overflow: hidden;
  }
  #section-chat .chat-container {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
  }
  .chat-header-bar {
    padding: var(--space-2) var(--space-3);
  }
  .chat-mode-pills {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .chat-mode-pills::-webkit-scrollbar { display: none; }
  .chat-indicators {
    font-size: var(--text-xs);
  }
  .mode-pill {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
  }
  
  /* Chat topic tabs: horizontal scroll */
  .chat-topics, .chat-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .chat-topics::-webkit-scrollbar,
  .chat-tabs::-webkit-scrollbar {
    display: none;
  }

  /* Chat messages container: fill available space */
  .chat-messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding-bottom: var(--space-3);
  }

  /* Chat input: pinned to bottom */
  .chat-input-area {
    flex-shrink: 0;
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
  }

  /* Chat input field: prevent iOS zoom */
  .chat-input-area input,
  .chat-input-area textarea,
  .chat-input-container input,
  .chat-input-container textarea {
    font-size: 16px !important;
  }

  /* Chat suggested questions: horizontal scroll */
  .chat-suggestions, .suggested-questions {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: var(--space-2);
    padding-bottom: var(--space-2);
    flex-wrap: nowrap;
  }
  .chat-suggestions::-webkit-scrollbar,
  .suggested-questions::-webkit-scrollbar {
    display: none;
  }
  .chat-suggestions > *, .suggested-questions > * {
    flex-shrink: 0;
  }

  /* --- Roadmap: contained and compact for mobile --- */
  #section-progress {
    overflow-x: clip;
  }
  .roadmap-card {
    overflow: hidden;
    padding: var(--space-3) !important;
  }
  .roadmap-progress-summary {
    gap: var(--space-2);
  }
  .roadmap-progress-ring {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
  }
  .roadmap-progress-label {
    font-size: var(--text-sm);
  }
  .roadmap-progress-est {
    font-size: var(--text-xs);
  }
  .journey-timeline {
    padding-top: 4px;
    overflow: hidden;
  }
  .journey-phase {
    margin-left: 0;
    padding-left: 36px;
    overflow: hidden;
  }
  .journey-phase::before {
    left: 13px;
  }
  .phase-indicator {
    left: -36px;
  }
  .phase-dot {
    width: 28px;
    height: 28px;
    font-size: 0.65rem;
  }
  .phase-header {
    gap: 8px;
    padding: 4px 0;
  }
  .phase-title {
    font-size: var(--text-base);
  }
  .phase-status {
    font-size: 0.65rem;
    padding: 2px 8px;
    white-space: nowrap;
  }
  .phase-body {
    padding: 2px 0 8px 0;
  }
  .phase-steps {
    gap: 0;
  }
  .step-item {
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-2);
    gap: 8px;
  }
  .step-check {
    width: 24px;
    height: 24px;
    min-width: 24px;
  }
  .step-name {
    font-size: var(--text-sm);
  }
  .step-content {
    min-width: 0;
    overflow: hidden;
  }
  .step-content .step-time-est {
    font-size: var(--text-xs);
  }
  .smart-tool-chip {
    font-size: 0.7rem;
    padding: 2px 8px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .phase-timeline {
    font-size: var(--text-xs);
    padding: 4px 0;
  }
  
  /* Roadmap simulate button: full width */
  .roadmap-actions {
    flex-direction: column;
    gap: var(--space-2);
  }
  .roadmap-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* --- Documents section: table → card layout --- */
  .doc-table {
    display: block;
  }
  .doc-table thead {
    display: none;
  }
  .doc-table tbody {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }
  .doc-table tr {
    display: flex;
    flex-wrap: wrap;
    padding: var(--space-3);
    background: var(--color-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    gap: var(--space-2);
    align-items: center;
  }
  .doc-table td {
    padding: 0;
    border: none;
  }
  .doc-table td:first-child {
    flex: 1;
    font-weight: 600;
    min-width: 60%;
  }
  
  /* Document rows: card style on mobile */
  .doc-row {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .doc-row .doc-name {
    flex: 1 0 100%;
  }

  /* --- Policy hub: cards stack --- */
  .policy-grid {
    grid-template-columns: 1fr;
  }
  .policy-node {
    padding: var(--space-4);
  }

  /* --- Settlement section --- */
  .col-comparison {
    flex-direction: column;
    gap: var(--space-4);
  }
  .col-vs {
    display: none;
  }
  .housing-grid {
    grid-template-columns: 1fr;
  }

  /* --- Scores section: single column, stacked layout --- */
  .score-panel-grid {
    grid-template-columns: 1fr;
  }
  .score-panel {
    flex-direction: column;
    text-align: center;
    padding: var(--space-4);
    overflow: hidden;
  }
  .score-details {
    width: 100%;
    min-width: 0;
  }
  .score-details h3,
  .score-details p {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  .score-circle.large {
    width: 100px;
    height: 100px;
  }
  .breakdown-row {
    font-size: var(--text-xs);
  }

  /* --- Notification panel --- */
  .notif-item {
    flex-wrap: wrap;
  }

  /* --- Family section: stack sponsor cards --- */
  .family-grid, .sponsor-grid {
    grid-template-columns: 1fr;
  }

  /* --- Application section --- */
  .app-checklist-grid, .application-grid {
    grid-template-columns: 1fr;
  }

  /* --- Professional help: stack consultant cards --- */
  .consultant-grid {
    grid-template-columns: 1fr;
  }

  /* --- PR Maintenance / Citizenship --- */
  .pr-grid, .citizenship-grid {
    grid-template-columns: 1fr;
  }

  /* --- Admin panel --- */
  .admin-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .admin-kpis, .engagement-stats, .cost-stats {
    grid-template-columns: 1fr;
  }

  /* --- Universal Search modal: full width on mobile --- */
  .universal-search-overlay .search-modal,
  .search-modal {
    width: calc(100vw - 32px);
    max-width: 100%;
    max-height: 80vh;
  }

  /* --- Simulation modal: full screen on mobile --- */
  .sim-overlay {
    padding: var(--space-3);
  }
  .sim-modal {
    max-height: 90vh;
    width: calc(100vw - 24px);
  }
  .sim-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   480px — SMALL PHONES
   ============================================================ */
@media (max-width: 480px) {
  
  /* --- Section inner: tighter padding --- */
  .section-inner {
    padding: var(--space-3) !important;
  }
  
  /* --- KPI grid: single column on very small screens --- */
  .kpi-grid {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }
  
  /* --- KPI card: horizontal layout on single column --- */
  .kpi-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    text-align: left;
  }
  .kpi-card .kpi-icon {
    flex-shrink: 0;
  }
  .kpi-card .kpi-value {
    font-size: var(--text-lg);
  }
  .kpi-card .kpi-content {
    flex: 1;
    min-width: 0;
  }
  
  /* --- CRS benchmark bar: stack below in single-col layout --- */
  .kpi-benchmark,
  .crs-benchmark {
    width: 100%;
    margin-top: var(--space-2);
  }
  
  /* --- Welcome banner: compact --- */
  .welcome-banner {
    padding: var(--space-4);
    border-radius: var(--radius-md);
  }
  .stat-ring {
    width: 90px;
    height: 90px;
  }
  .stat-value {
    font-size: var(--text-base);
  }
  .milestone-badges {
    gap: var(--space-2);
  }
  .badge-earned > .badge-label,
  .badge-locked > .badge-label {
    max-width: 48px;
    font-size: 0.625rem;
  }

  /* --- Cards: tighter --- */
  .card {
    padding: var(--space-3);
    border-radius: var(--radius-md);
  }

  /* --- Buttons: still 44px min height --- */
  .btn {
    padding: var(--space-2) var(--space-3);
    min-height: 44px;
    font-size: var(--text-sm);
  }

  /* --- Chat input area: small phones --- */
  .chat-input-area, .chat-input-container {
    margin-bottom: 0;
    padding: var(--space-2);
  }

  /* --- Chat bubbles: full width --- */
  .chat-bubble, .message-bubble {
    max-width: 90%;
  }

  /* --- Onboarding modal: nearly full screen --- */
  .onboarding-modal {
    max-width: calc(100vw - 16px);
    padding: var(--space-4) var(--space-3);
    border-radius: 12px;
  }

  /* --- Top bar: minimal --- */
  .top-bar {
    padding: var(--space-2);
    gap: var(--space-1);
    min-height: 48px;
  }
  .top-bar-title {
    font-size: var(--text-sm);
  }
  .icon-btn {
    width: 40px;
    height: 40px;
  }
  .icon-btn i {
    width: 18px;
    height: 18px;
  }

  /* --- Bottom nav: account for small screens --- */
  .mbn-item {
    font-size: 0.6875rem;
    gap: 1px;
  }
  .mbn-item i, .mbn-item svg {
    width: 20px;
    height: 20px;
  }

  /* --- Milestone grid: single column on tiny screens --- */
  .milestone-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ============================================================
   360px — EXTRA SMALL PHONES (Galaxy S series, older phones)
   ============================================================ */
@media (max-width: 360px) {
  .section-inner {
    padding: var(--space-2) !important;
  }
  
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  
  .welcome-text h1 {
    font-size: 1rem;
  }
  
  .milestone-badges {
    gap: var(--space-1);
  }
  .badge-earned > .badge-label,
  .badge-locked > .badge-label {
    display: none;
  }
  
  .stat-ring {
    width: 80px;
    height: 80px;
  }
  
  .top-bar-title {
    font-size: var(--text-xs);
  }
  
  .sidebar {
    width: 100vw;
    left: -100vw;
  }
  .sidebar.open {
    left: 0;
  }
}

/* ============================================================
   LANDSCAPE PHONE — prevent layout breaking
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
  .app-shell {
    height: auto;
    min-height: 100dvh;
  }
  .content-scroll {
    overflow-y: auto;
    max-height: none;
  }
  /* Hide bottom nav in landscape — sidebar is accessible */
  .mobile-bottom-nav {
    display: none !important;
  }
  .content-scroll {
    padding-bottom: var(--space-4);
  }
  .fab-container {
    bottom: 16px;
  }
  .chat-input-area, .chat-input-container {
    margin-bottom: 0;
  }
}

/* ============================================================
   TOUCH TARGETS — ensure minimum 44px on all interactive elements
   ============================================================ */
@media (pointer: coarse) {
  /* All clickable elements get minimum touch target */
  .nav-item,
  .btn,
  .btn-sm,
  .icon-btn,
  .toolkit-card,
  .pathway-pill,
  .smart-tool-chip,
  .step-item,
  .mbn-item,
  .chat-tab,
  .chat-topic-btn,
  .notif-item,
  .action-item,
  .fav-btn,
  .theme-toggle {
    min-height: 44px;
  }
  
  /* Increase touch target on small interactive elements */
  .fav-btn {
    width: 36px;
    height: 36px;
    opacity: 1; /* Always visible on touch */
  }
  
  /* Scrollbar: wider for touch */
  ::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }
}

/* ============================================================
   SAFE AREA INSETS (notch phones)
   ============================================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-bottom-nav {
    padding-bottom: calc(var(--space-1) + env(safe-area-inset-bottom, 0px));
  }
  .chat-input-area, .chat-input-container {
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  }
  @media (max-width: 768px) {
    .content-scroll {
      padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }
    .fab-container {
      bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    }
  }
}

/* ============================================================
   DARK MODE OVERLAY ADJUSTMENTS
   ============================================================ */
[data-theme="dark"] .sidebar-overlay.active {
  background: rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .sidebar {
  box-shadow: none;
}

@media (max-width: 768px) {
  [data-theme="dark"] .sidebar.open {
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.5);
  }
}

/* ============================================================
   MOBILE SELECT DROPDOWNS (hidden on desktop, shown on mobile)
   ============================================================ */
.mobile-pathway-select,
.mobile-tab-select {
  display: none;
}

@media (max-width: 768px) {
  /* --- Show mobile selects, hide desktop pills/tabs --- */
  select.mobile-pathway-select,
  select.mobile-tab-select {
    display: block;
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-size: 16px; /* prevent iOS zoom */
    font-family: var(--font-body);
    font-weight: 500;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-color: var(--color-surface) !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235e6e82' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 16px 16px !important;
    padding-right: 40px;
    cursor: pointer;
    margin-bottom: var(--space-3);
  }
  [data-theme="dark"] select.mobile-pathway-select,
  [data-theme="dark"] select.mobile-tab-select {
    background-color: var(--color-surface) !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ba4bc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 16px 16px !important;
  }
  .mobile-pathway-select:focus,
  .mobile-tab-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(44, 74, 124, 0.12);
  }

  .pathway-pills-row {
    display: none !important;
  }
  #section-resources .resource-tabs,
  #offers-tabs {
    display: none !important;
  }

  /* --- Welcome banner: improved mobile layout --- */
  .welcome-banner {
    flex-direction: column;
    text-align: center;
    padding: var(--space-5) var(--space-4);
    gap: var(--space-4);
  }
  .welcome-text h1 {
    font-size: clamp(1.25rem, 4vw, 1.5rem) !important;
    line-height: 1.3;
  }
  .welcome-text p {
    font-size: var(--text-sm);
    margin-top: var(--space-2);
    line-height: 1.5;
  }
  .welcome-stat {
    display: flex;
    justify-content: center;
  }
  .stat-ring {
    width: 100px;
    height: 100px;
  }
  .milestone-badges {
    justify-content: center;
    margin-top: var(--space-3);
  }

  /* --- Flashcard fix: auto height instead of fixed --- */
  .flashcard {
    height: auto;
    min-height: 140px;
  }
  .flashcard-inner {
    min-height: 140px;
  }
  .flashcard-front,
  .flashcard-back {
    position: relative;
    min-height: 140px;
  }
  .flashcard.flipped .flashcard-front {
    display: none;
  }
  .flashcard.flipped .flashcard-back {
    position: relative;
    transform: none;
    backface-visibility: visible;
  }
  .flashcard:not(.flipped) .flashcard-back {
    display: none;
  }
  .flashcard-grid {
    grid-template-columns: 1fr;
  }
  .flashcard-term {
    font-size: var(--text-base);
    word-break: break-word;
  }
  .flashcard-def {
    font-size: var(--text-xs);
    word-break: break-word;
  }

  /* --- Travel rules grid: single column on mobile --- */
  .travel-rules-grid {
    grid-template-columns: 1fr !important;
  }

  /* --- Pathway filter hero: tighter on mobile --- */
  .pathway-hero-header {
    flex-direction: column;
    gap: var(--space-2);
  }
  .pathway-hero-left {
    flex-direction: column;
    text-align: center;
    align-items: center;
  }
  .pathway-hero-subtitle {
    font-size: var(--text-xs);
  }

  /* --- Resources header: stack on mobile --- */
  .resources-header {
    flex-direction: column;
    gap: var(--space-3);
    align-items: stretch !important;
  }
  .resources-header .search-bar {
    margin-left: 0 !important;
    width: 100%;
  }

  /* --- Offer cards: full width --- */
  .offers-grid {
    grid-template-columns: 1fr !important;
  }

  /* --- AI status pill: hide on mobile to save space --- */
  .ai-status-pill {
    display: none;
  }

  /* --- Section title row: wrap gracefully --- */
  .section-title-row {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* --- Action items: stack content better --- */
  .action-item {
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-3);
  }
  .action-content {
    flex: 1 0 100%;
    min-width: 0;
  }
  .action-impact {
    font-size: var(--text-xs);
  }
  .action-item .btn {
    width: 100%;
    justify-content: center;
  }

  /* --- Residency tracker: stack on mobile --- */
  .res-tracker-visual {
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
  }

  /* --- PR card timeline: tighter --- */
  .prcard-cost-box {
    margin-top: var(--space-3);
  }

  /* --- Offers recommended grid --- */
  .offers-rec-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================
   480px — Tighter mobile-specific fixes
   ============================================================ */
@media (max-width: 480px) {
  .welcome-text h1 {
    font-size: 1.15rem !important;
  }
  .stat-ring {
    width: 85px;
    height: 85px;
  }

  /* Action items: compact layout */
  .action-time-est {
    display: none;
  }

  /* Offer card: tighter padding */
  .offer-card {
    padding: var(--space-3) !important;
  }
}

/* ============================================================
   PRINT: Hide mobile-only elements
   ============================================================ */
@media print {
  .mobile-bottom-nav,
  .fab-container,
  .hamburger,
  .sidebar-overlay {
    display: none !important;
  }
}

/* ============================================================
   CHYRON — mobile: not sticky, scrolls away naturally
   ============================================================ */
@media (max-width: 768px) {
  .sw-watching-bar {
    position: relative;
    top: auto;
    z-index: auto;
    height: 26px;
    font-size: 0.62rem;
  }
  .sw-chyron-live {
    padding: 0 0.5rem;
    font-size: 0.55rem;
  }
}

/* ============================================================
   IMMERSIVE CHAT MODE — Mobile Only
   Apple iMessage-inspired: strip ALL chrome, maximize conversation.
   Triggered by body.chat-immersive class.
   ============================================================ */
@media (max-width: 768px) {

  /* === HIDE EVERYTHING THAT ISN'T CONVERSATION === */
  body.chat-immersive #back-to-site-bar,
  body.chat-immersive #demo-banner,
  body.chat-immersive .journey-progress-bar,
  body.chat-immersive .mobile-bottom-nav,
  body.chat-immersive .fab-container,
  body.chat-immersive .toast-container,
  body.chat-immersive .sw-watching-bar {
    display: none !important;
  }
  body.chat-immersive {
    padding-top: 0 !important;
  }

  /* === TOP BAR: Match dashboard height === */
  body.chat-immersive .top-bar {
    position: fixed !important;
    top: 0 !important;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 0 var(--space-3);
    height: 48px;
    min-height: 48px;
    max-height: 48px;
    border-bottom: 1px solid var(--color-border);
  }
  body.chat-immersive .top-bar .hamburger,
  body.chat-immersive .top-bar #hamburger,
  body.chat-immersive .top-bar .top-bar-actions > *:not(.lang-switcher) {
    display: none !important;
  }
  /* Repurpose title as chat label — match dashboard size */
  body.chat-immersive .top-bar .top-bar-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
    font-family: var(--font-sans, 'General Sans', -apple-system, sans-serif);
  }
  body.chat-immersive .top-bar .lang-switcher {
    transform: none;
  }

  /* === LAYOUT: Fill from top-bar to bottom === */
  body.chat-immersive .app-shell {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }
  body.chat-immersive .main-content {
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    top: 48px !important;
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
  }
  body.chat-immersive .content-scroll {
    padding: 0 !important;
    height: 100% !important;
    overflow: hidden !important;
  }
  body.chat-immersive #section-chat {
    height: 100% !important;
    overflow: hidden;
  }
  body.chat-immersive #section-chat .chat-container {
    height: 100% !important;
    max-height: 100% !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* === CHAT HEADER: HIDE mode pills & indicators === 
     Like iMessage — no settings clutter in conversation view.
     Users can exit chat to access mode switching. */
  body.chat-immersive .chat-header-bar {
    display: none !important;
  }

  /* === MESSAGES: start at top, anchor to bottom once conversation begins === */
  body.chat-immersive .chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 12px 0;
    justify-content: flex-start;
    padding-top: var(--space-6);
  }
  body.chat-immersive .chat-messages.has-conversation {
    justify-content: flex-end;
    padding-top: 0;
  }

  /* === WELCOME — mobile/tablet adjustments === */
  body.chat-immersive .chat-welcome {
    padding: var(--space-6) var(--space-4) var(--space-3);
    max-width: 100%;
  }
  body.chat-immersive .chat-welcome-avatar {
    margin-bottom: var(--space-3);
  }
  body.chat-immersive .chat-welcome-avatar-ring {
    width: 52px;
    height: 52px;
  }
  body.chat-immersive .chat-welcome-avatar-ring i {
    width: 22px;
    height: 22px;
  }
  body.chat-immersive .chat-welcome-greeting {
    font-size: 1.375rem;
  }
  body.chat-immersive .chat-welcome-subtitle {
    font-size: 0.875rem;
  }
  body.chat-immersive .chat-welcome-content {
    margin-bottom: var(--space-4);
  }
  body.chat-immersive .chat-suggestions-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  body.chat-immersive .suggestion-card {
    font-size: 0.8125rem;
    padding: 12px 14px;
    border-radius: var(--radius-lg);
  }
  body.chat-immersive .suggestion-card:active {
    background: oklch(from var(--color-primary) l c h / 0.06);
    border-color: oklch(from var(--color-primary) l c h / 0.3);
  }
  /* Tighten message bubbles */
  body.chat-immersive .chat-bubble {
    max-width: 85%;
    font-size: 0.88rem;
    line-height: 1.4;
  }

  /* === SUGGESTIONS: Horizontal scroll, tight against input === */
  body.chat-immersive .chat-suggestions,
  body.chat-immersive .suggested-questions {
    display: flex !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding: 8px 0 6px;
    flex-wrap: nowrap;
    flex-shrink: 0;
    border-top: none;
    background: transparent;
    max-height: none !important;
    height: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
    margin-top: 8px;
  }
  body.chat-immersive .chat-suggestions::-webkit-scrollbar,
  body.chat-immersive .suggested-questions::-webkit-scrollbar {
    display: none;
  }
  body.chat-immersive .chat-suggestions > *,
  body.chat-immersive .suggested-questions > * {
    flex-shrink: 0;
    font-size: 0.75rem;
    padding: 6px 14px;
    white-space: nowrap;
    border-radius: var(--radius-full);
  }

  /* === INPUT AREA: iMessage-level === */
  body.chat-immersive .chat-input-area {
    padding: 0 !important;
    margin: 0 !important;
    flex-shrink: 0;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
  }
  body.chat-immersive .chat-composer {
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  body.chat-immersive .chat-composer:focus-within {
    border: none;
    box-shadow: none;
  }
  /* Hide tools bar on mobile */
  body.chat-immersive .chat-tools-bar {
    display: none !important;
  }
  body.chat-immersive .chat-input-wrapper {
    padding: 8px 12px 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
  }
  body.chat-immersive .chat-input {
    font-size: 0.9375rem;
    min-height: 38px;
    background: var(--color-surface-2) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: 20px !important;
    padding: 8px 14px !important;
  }
  body.chat-immersive .chat-input:focus {
    border-color: oklch(from var(--color-primary) l c h / 0.35) !important;
    box-shadow: none !important;
  }
  body.chat-immersive .chat-send {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
  }

  /* Composer footer — disclaimer below input */
  body.chat-immersive .chat-composer-footer {
    padding: 2px 12px max(6px, env(safe-area-inset-bottom));
    justify-content: center;
  }
  body.chat-immersive .chat-disclaimer {
    display: block !important;
    text-align: center;
    width: 100%;
    font-size: 0.5625rem;
    opacity: 0.4;
    white-space: normal;
  }
  body.chat-immersive .chat-footer-text {
    display: none !important;
  }

  /* === BACK BUTTON — arrow only, no text === */
  .chat-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0;
    background: none;
    border: none;
    color: var(--color-primary);
    cursor: pointer;
    padding: 4px;
    margin-right: 4px;
  }
  .chat-back-btn [data-chat-back-label] {
    display: none !important;
  }
  .chat-back-btn svg {
    width: 20px;
    height: 20px;
  }
}

/* ===== KPI Bottom Sheet (mobile tap-to-info, replaces hover tooltips) ===== */
#kpi-bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  pointer-events: none;
}
#kpi-bottom-sheet.visible { pointer-events: auto; }

.kpi-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0);
  transition: background 0.25s ease;
}
#kpi-bottom-sheet.visible .kpi-sheet-backdrop {
  background: rgba(0,0,0,0.35);
}
#kpi-bottom-sheet.dismissing .kpi-sheet-backdrop {
  background: rgba(0,0,0,0);
}

.kpi-sheet-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-surface, #1a2332);
  border-top: 1px solid var(--color-border, rgba(255,255,255,0.08));
  border-radius: 16px 16px 0 0;
  padding: 10px 20px 28px;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  -webkit-user-select: none;
  user-select: none;
}
#kpi-bottom-sheet.visible .kpi-sheet-panel {
  transform: translateY(0);
}
#kpi-bottom-sheet.dismissing .kpi-sheet-panel {
  transform: translateY(100%);
}

.kpi-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-text-faint, #606a82);
  opacity: 0.5;
  margin: 0 auto 14px;
}

.kpi-sheet-title {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 650;
  color: var(--color-text, #e2e8f0);
  letter-spacing: -0.01em;
}

.kpi-sheet-body {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-text-muted, #94a3b8);
}

/* Light mode */
[data-theme="light"] .kpi-sheet-panel {
  background: #fff;
  border-top-color: rgba(0,0,0,0.08);
}
[data-theme="light"] .kpi-sheet-title { color: #1a202c; }
[data-theme="light"] .kpi-sheet-body { color: #4a5568; }
[data-theme="light"] .kpi-sheet-handle { background: #cbd5e0; }

/* Hide hover tooltip on touch devices */
@media (hover: none) and (pointer: coarse) {
  .help-tooltip { display: none !important; }
}
