/* CRM V90 simple emergency mobile mode. Desktop and laptop remain unchanged. */
@media (max-width: 767px) {
  :root {
    --crm-mobile-simple-bg: #f5f7fb;
    --crm-mobile-simple-surface: #ffffff;
    --crm-mobile-simple-line: #dbe4ef;
    --crm-mobile-simple-text: #13253d;
    --crm-mobile-simple-muted: #71839a;
    --crm-mobile-simple-accent: #ff5c35;
  }

  body,
  #main,
  #content {
    background: var(--crm-mobile-simple-bg) !important;
  }

  /* Simple top bar: menu, page title, new appointment, account. */
  #topbar {
    height: 56px !important;
    min-height: 56px !important;
    padding: 7px 10px !important;
    display: grid !important;
    grid-template-columns: 42px minmax(0, 1fr) 42px 42px !important;
    grid-template-rows: 42px !important;
    gap: 7px !important;
    align-items: center !important;
    background: #ffffff !important;
    border-bottom: 1px solid var(--crm-mobile-simple-line) !important;
    box-shadow: 0 3px 12px rgba(15, 23, 42, .06) !important;
  }

  #topbar #hamburger-btn {
    grid-column: 1 !important;
    grid-row: 1 !important;
  }

  #topbar .page-title,
  #page-title-text {
    display: block !important;
    grid-column: 2 !important;
    grid-row: 1 !important;
    min-width: 0 !important;
    margin: 0 !important;
    color: var(--crm-mobile-simple-text) !important;
    font-family: 'DM Sans', 'Inter', Arial, sans-serif !important;
    font-size: 16px !important;
    line-height: 1.2 !important;
    font-weight: 900 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  #topbar .search-wrap,
  #topbar .hubspot-search,
  #topbar #crm-refresh-btn,
  #topbar .notif-btn,
  #topbar .hub-notif-btn,
  #topbar .topbar-utility-icons,
  #topbar .hub-assistant-chip,
  #topbar .hub-inline-btn {
    display: none !important;
  }

  #topbar .topbar-actions {
    display: contents !important;
  }

  #topbar .hub-quick-add {
    display: inline-flex !important;
    grid-column: 3 !important;
    grid-row: 1 !important;
  }

  #topbar .hub-account-chip {
    display: inline-flex !important;
    grid-column: 4 !important;
    grid-row: 1 !important;
  }

  #topbar #hamburger-btn,
  #topbar .hub-quick-add,
  #topbar .hub-account-chip {
    width: 42px !important;
    min-width: 42px !important;
    height: 42px !important;
    min-height: 42px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 1px solid var(--crm-mobile-simple-line) !important;
    border-radius: 12px !important;
    background: #ffffff !important;
    color: #34465d !important;
    box-shadow: none !important;
    align-items: center !important;
    justify-content: center !important;
  }

  #topbar .hub-quick-add {
    border-color: #ffd0c3 !important;
    background: #fff5f1 !important;
    color: var(--crm-mobile-simple-accent) !important;
  }

  #topbar #hamburger-btn svg,
  #topbar .hub-quick-add svg {
    width: 20px !important;
    height: 20px !important;
    stroke-width: 1.8 !important;
  }

  #topbar .hub-account-avatar {
    width: 32px !important;
    height: 32px !important;
    margin: 0 !important;
    background: #20344f !important;
    color: #ffffff !important;
  }

  #content {
    padding: 10px 10px calc(70px + env(safe-area-inset-bottom)) !important;
  }

  /* Keep mobile page headers focused on title and one primary action. */
  #content > .page > .section-header,
  #content > .page > .crm-unified-command-header,
  #page-allappointments > .crm-appt-command-header {
    min-height: 0 !important;
    padding: 12px !important;
    margin: 0 0 10px !important;
    border-radius: 15px !important;
    background: #ffffff !important;
    border: 1px solid var(--crm-mobile-simple-line) !important;
    box-shadow: 0 5px 16px rgba(15, 23, 42, .035) !important;
  }

  #content > .page > .section-header .section-title,
  #content > .page > .crm-unified-command-header .section-title,
  #page-allappointments .section-title {
    font-family: 'DM Sans', 'Inter', Arial, sans-serif !important;
    font-size: 20px !important;
    line-height: 1.2 !important;
    letter-spacing: -.02em !important;
  }

  #content > .page > .section-header .section-sub,
  #content > .page > .crm-unified-command-header .section-sub,
  #page-allappointments .section-sub,
  #content > .page > .crm-unified-command-header .crm-unified-command-center,
  #content > .page > .crm-unified-command-header .crm-unified-header-stats,
  #content > .page > .crm-unified-command-header .crm-unified-view-tabs {
    display: none !important;
  }

  /* All Appointments: title plus one action only. */
  #page-allappointments > .crm-appt-command-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    gap: 10px !important;
    align-items: center !important;
  }

  #page-allappointments .crm-appt-command-title {
    min-width: 0 !important;
  }

  #page-allappointments .crm-appt-command-center,
  #page-allappointments .crm-appt-tabs,
  #page-allappointments .crm-appt-header-stats,
  #page-allappointments .crm-appt-action-secondary {
    display: none !important;
  }

  #page-allappointments .crm-appt-command-actions {
    display: block !important;
    width: auto !important;
  }

  #page-allappointments .crm-appt-action-primary {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 !important;
    overflow: hidden !important;
    color: transparent !important;
    font-size: 0 !important;
    border-radius: 12px !important;
    position: relative !important;
  }

  #page-allappointments .crm-appt-action-primary::after {
    content: '+' !important;
    position: absolute !important;
    inset: 0 !important;
    display: grid !important;
    place-items: center !important;
    color: #ffffff !important;
    font-size: 24px !important;
    font-weight: 500 !important;
  }

  /* Compact appointment filter. Advanced fields open only when requested. */
  #page-allappointments .all-appt-toolbar,
  #page-allappointments .crm-appt-filter-panel {
    padding: 10px !important;
    margin: 0 0 10px !important;
    border-radius: 15px !important;
    background: #ffffff !important;
    border: 1px solid var(--crm-mobile-simple-line) !important;
    box-shadow: none !important;
  }

  #page-allappointments .all-appt-filter-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 44px !important;
    gap: 8px !important;
    align-items: end !important;
  }

  #page-allappointments .all-appt-filter-grid > .all-appt-filter-field:first-child {
    grid-column: 1 !important;
    display: block !important;
  }

  #page-allappointments .all-appt-filter-grid > .all-appt-filter-field:first-child .all-appt-filter-label {
    display: none !important;
  }

  #page-allappointments #all-appt-search {
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 13px !important;
    border-radius: 12px !important;
    font-size: 13px !important;
  }

  #page-allappointments .crm-mobile-filter-toggle {
    grid-column: 2 !important;
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    padding: 0 !important;
    border: 1px solid #ffd0c3 !important;
    border-radius: 12px !important;
    background: #fff5f1 !important;
    color: var(--crm-mobile-simple-accent) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0 !important;
  }

  #page-allappointments .crm-mobile-filter-toggle::before {
    content: '☰' !important;
    font-size: 18px !important;
    line-height: 1 !important;
  }

  #page-allappointments .crm-mobile-advanced-filter {
    display: none !important;
    grid-column: 1 / -1 !important;
  }

  #page-allappointments .all-appt-toolbar.mobile-filters-open .crm-mobile-advanced-filter {
    display: flex !important;
  }

  #page-allappointments .all-appt-toolbar.mobile-filters-open .all-appt-sort-control,
  #page-allappointments .all-appt-toolbar.mobile-filters-open .all-appt-clear-btn {
    display: block !important;
  }

  #page-allappointments .all-appt-toolbar.mobile-filters-open .all-appt-sort-control {
    width: 100% !important;
  }

  #page-allappointments .all-appt-toolbar.mobile-filters-open .all-appt-sort-btn,
  #page-allappointments .all-appt-toolbar.mobile-filters-open .all-appt-clear-btn {
    width: 100% !important;
    height: 42px !important;
    min-height: 42px !important;
    border-radius: 11px !important;
  }

  #page-allappointments .all-appt-filter-label {
    margin-bottom: 5px !important;
    font-size: 9px !important;
  }

  #page-allappointments .all-appt-filter-field input,
  #page-allappointments .all-appt-filter-field select {
    height: 42px !important;
    min-height: 42px !important;
    border-radius: 11px !important;
  }

  /* Appointment cards show only emergency information. */
  #page-allappointments #all-appt-mobile-list {
    gap: 9px !important;
  }

  #page-allappointments .all-appt-card-pro {
    padding: 13px !important;
    border-radius: 15px !important;
    box-shadow: none !important;
  }

  #page-allappointments .all-appt-card-head-pro {
    gap: 8px !important;
  }

  #page-allappointments .all-appt-card-identity .avatar {
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
  }

  #page-allappointments .all-appt-card-patient {
    font-size: 14px !important;
  }

  #page-allappointments .all-appt-card-muted {
    font-size: 10px !important;
  }

  #page-allappointments .all-appt-card-status-stack {
    gap: 5px !important;
  }

  #page-allappointments .all-appt-card-status-stack .badge {
    padding: 5px 8px !important;
    font-size: 9px !important;
  }

  #page-allappointments .all-appt-card-section-title,
  #page-allappointments .all-appt-card-grid-pro .all-appt-card-field:nth-child(2),
  #page-allappointments .all-appt-card-footer-pro > div {
    display: none !important;
  }

  #page-allappointments .all-appt-card-grid-pro {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    margin-top: 11px !important;
  }

  #page-allappointments .all-appt-card-field {
    min-height: 0 !important;
    padding: 9px !important;
    border-radius: 10px !important;
  }

  #page-allappointments .all-appt-card-field:first-child {
    grid-column: 1 / -1 !important;
  }

  #page-allappointments .all-appt-card-field span {
    font-size: 8px !important;
  }

  #page-allappointments .all-appt-card-field strong {
    font-size: 11px !important;
  }

  #page-allappointments .all-appt-card-footer-pro {
    margin-top: 10px !important;
    padding-top: 10px !important;
    display: block !important;
  }

  #page-allappointments .all-appt-booking-details-btn {
    width: 100% !important;
    height: 40px !important;
    min-height: 40px !important;
    border-radius: 11px !important;
    font-size: 11px !important;
  }

  /* Compact dashboard cards while retaining useful information. */
  #page-dashboard .grid4 {
    gap: 8px !important;
  }

  #page-dashboard .metric-card {
    min-height: 94px !important;
    padding: 11px !important;
    border-radius: 14px !important;
  }

  #page-dashboard .metric-icon {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    font-size: 14px !important;
  }

  #page-dashboard .metric-val {
    font-size: 21px !important;
  }

  #page-dashboard .metric-label {
    font-size: 10px !important;
  }

  /* Smaller AI launcher. Full agent remains available. */
  .crm-ai-fab {
    right: 12px !important;
    bottom: calc(72px + env(safe-area-inset-bottom)) !important;
    width: 42px !important;
    min-width: 42px !important;
    height: 42px !important;
    padding: 0 !important;
    border-radius: 50% !important;
  }

  .crm-ai-fab b {
    display: none !important;
  }

  .crm-ai-fab span {
    font-size: 18px !important;
  }

  /* Short, non-blocking feedback. */
  .toast {
    left: 14px !important;
    right: 64px !important;
    bottom: calc(74px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    max-width: none !important;
    min-height: 40px !important;
    padding: 9px 12px !important;
    border-radius: 12px !important;
    font-size: 11px !important;
    line-height: 1.35 !important;
    white-space: normal !important;
  }

  /* Essential bottom navigation only. */
  #mobile-bottom-nav {
    height: calc(62px + env(safe-area-inset-bottom)) !important;
    padding: 0 5px env(safe-area-inset-bottom) !important;
    background: #ffffff !important;
    border-top: 1px solid var(--crm-mobile-simple-line) !important;
    box-shadow: 0 -6px 22px rgba(15, 23, 42, .08) !important;
  }

  #mobile-bottom-nav .mbn-inner {
    height: 62px !important;
  }

  #mobile-bottom-nav .mbn-item {
    height: 52px !important;
    color: #71839a !important;
    gap: 3px !important;
  }

  #mobile-bottom-nav .mbn-item.active {
    color: var(--crm-mobile-simple-accent) !important;
    background: #fff5f1 !important;
  }

  #mobile-bottom-nav .mbn-icon {
    width: 23px !important;
    height: 23px !important;
  }

  #mobile-bottom-nav .mbn-icon svg {
    width: 22px !important;
    height: 22px !important;
    stroke: currentColor !important;
  }

  #mobile-bottom-nav .mbn-item > span:last-child {
    font-size: 9px !important;
    font-weight: 800 !important;
  }

  /* Shorter More menu containing only emergency modules. */
  #mobile-more-sheet {
    left: 10px !important;
    right: 10px !important;
    bottom: calc(70px + env(safe-area-inset-bottom)) !important;
    padding: 10px !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
    border-radius: 16px !important;
    background: #ffffff !important;
    border: 1px solid var(--crm-mobile-simple-line) !important;
    box-shadow: 0 18px 50px rgba(15, 23, 42, .18) !important;
  }

  #mobile-more-sheet button {
    min-height: 72px !important;
    padding: 8px 4px !important;
    border-radius: 12px !important;
    background: #f8fafc !important;
    border: 1px solid #e5ebf2 !important;
    color: #34465d !important;
  }

  #mobile-more-sheet .crm-v88-more-icon {
    width: 25px !important;
    height: 25px !important;
    color: var(--crm-mobile-simple-accent) !important;
  }

  #mobile-more-sheet .crm-v88-more-label {
    font-size: 9px !important;
  }

  /* Night mode uses the same simplified structure. */
  body.crm-night-mode #topbar,
  body.crm-night-mode #content > .page > .section-header,
  body.crm-night-mode #content > .page > .crm-unified-command-header,
  body.crm-night-mode #page-allappointments > .crm-appt-command-header,
  body.crm-night-mode #page-allappointments .all-appt-toolbar,
  body.crm-night-mode #mobile-bottom-nav,
  body.crm-night-mode #mobile-more-sheet {
    background: #20262e !important;
    border-color: #3d4652 !important;
  }

  body.crm-night-mode #topbar .page-title,
  body.crm-night-mode #page-title-text,
  body.crm-night-mode #content > .page > .section-header .section-title,
  body.crm-night-mode #content > .page > .crm-unified-command-header .section-title {
    color: #f3f6fa !important;
  }

  body.crm-night-mode #topbar #hamburger-btn,
  body.crm-night-mode #topbar .hub-account-chip {
    background: #29313a !important;
    border-color: #414b58 !important;
    color: #eef2f7 !important;
  }

  body.crm-night-mode #mobile-bottom-nav .mbn-item.active {
    background: #382820 !important;
    color: #ff8a61 !important;
  }
}
