/*
 * Phone and tablet layout (founder, 23 Nov 2026: "make it mobile friendly,
 * the whole site", PWA). Plan and audit: _non_app_files/docs/MOBILE_FRIENDLY_PLAN.md.
 *
 * Loaded last on every page (base.html, base_public.html). Every rule is
 * inside a SCREEN media query up to 1100 px, so desktop and print are
 * unchanged. Selectors start with :root so they win over the page and
 * component <style> blocks that come later in the page; !important only
 * where the markup carries inline styles.
 */

/* ── Tablets and phones (up to 1100 px): touch screens ─────────────────── */
@media screen and (max-width: 1100px) {

  /* The ☰ menu up to 1100 px (decision 5): the desktop bar needs ~1,070 px. */
  :root .navbar-toggle {
    display: flex;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
    align-items: center;
  }
  :root .navbar-menu {
    position: fixed;
    top: 64px;
    left: -100%;
    width: 100%;
    height: calc(100vh - 64px);
    background-color: var(--primary);
    flex-direction: column;
    align-items: flex-start;
    padding: 24px;
    gap: 0;
    transition: left 0.3s ease;
    overflow-y: auto;
    z-index: 1000;
    box-sizing: border-box;
  }
  :root .navbar-menu.active { left: 0; }
  :root .navbar-menu li {
    width: 100%;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  :root .navbar-menu li:last-child { border-bottom: none; }
  :root .navbar a,
  :root .navbar-nav a,
  :root .navbar .nav-dropdown summary {
    font-size: 16px;
    display: block;
    width: 100%;
    padding: 12px 0;
    box-sizing: border-box;
  }
  :root .navbar .nav-dropdown-menu {
    position: static;
    min-width: 0;
    padding: 0 0 0 16px;
    box-shadow: none;
  }
  :root .navbar .nav-dropdown-menu li { border-bottom: none; padding: 0; }
  :root .notification-nav-item { width: 100%; }
  :root .notification-bell-link { display: flex; align-items: center; width: 100%; }

  /* Buttons: long labels wrap inside the button instead of spilling out
     (the Edit Patient bug, 23 Nov), and stay a finger's height. */
  :root .button,
  :root .button-secondary {
    white-space: normal;
    height: auto;
    min-height: 48px;
    line-height: 1.3;
    text-align: center;
  }

  /* Tables never widen the page: responsive.js puts each one in this box. */
  :root .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Inputs at 16 px: iPhone and iPad Safari zoom in on anything smaller
     and do not zoom back. */
  :root input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=hidden]),
  :root select,
  :root textarea {
    font-size: 16px !important;
  }

  /* Tap targets. */
  :root .ai-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 0;
  }
  :root input[type=checkbox],
  :root input[type=radio] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;        /* in a flex label row the text used to squeeze it */
  }
  :root .toggle-switch input[type=checkbox] { width: 0; height: 0; }   /* the report's switch */
  :root .ip-tab { min-height: 44px; }
  :root .ip-ai-btn,
  :root .ip-add-btn,
  :root .ip-category { min-height: 44px; }
  :root input[type=range] { min-height: 44px; flex: 1 1 auto; min-width: 180px; }   /* pain score (VAS) */
  :root .fc .fc-button { min-width: 44px; min-height: 44px; }        /* diary toolbar */
  :root .public-footer a { display: inline-block; padding: 8px 2px; }  /* Terms | Privacy | … */
  :root .notification-action-btn { min-height: 40px; padding: 8px 14px; }  /* Mark as read / Delete */
  :root .setup-table summary { padding: 10px 0; }                    /* clinic set-up "Edit" */

  /* Assessment progress bar: always one row (progressBar.css wraps it
     below 1024 px). */
  :root .progress-steps { flex-wrap: nowrap; }
}

/* ── Phones (up to 576 px) ────────────────────────────────────────────── */
@media screen and (max-width: 576px) {

  /* Page width: base.html and most pages each have a .container, and each
     took 32 px a side; the text column was ~230 px on a 375 px phone. */
  :root .container,
  :root .container-sm,
  :root .container-md {
    padding: 12px;
    margin: 0;
  }
  :root .container .container,
  :root .container .container-sm,
  :root .container .container-md {
    padding: 0;
  }
  :root .container-card { margin: 12px 0; padding: 14px; }
  :root .ip-group { padding: 8px 10px; }
  :root .report-container { margin: 0; padding: 14px; }
  :root .section-content { padding-left: 0; }

  /* Patient Report: the AI switch on one line, its note underneath. */
  :root .toggle-container { flex-wrap: wrap; }
  :root .toggle-label { flex: 1 1 0; }
  :root .toggle-description { flex: 1 1 100%; }

  /* Feedback page tabs wrap instead of running off the screen. */
  :root .feedback-tabs { flex-wrap: wrap; }
  :root .feedback-tab { padding: 12px 14px; }

  /* "+ Add a finding" rows: the input full width, the button under it. */
  :root .ip-add { flex-wrap: wrap; }
  :root .ip-add-input { flex: 1 1 100%; }
  :root .ip-add-btn { flex: 1 1 100%; }

  /* Tabs that do not fit: a strip you swipe, faded at the edge so it is
     clear there are more (decision 2). */
  :root .ip-tabbar {
    flex-wrap: nowrap;
    -webkit-mask-image: linear-gradient(to right, #000 85%, transparent);
            mask-image: linear-gradient(to right, #000 85%, transparent);
    padding-right: 24px;
  }

  /* Progress bar: six circles in one row and only the current step's name,
     centred under the bar (other names split mid-word at this width). */
  :root .progress-bar-container { box-sizing: border-box; }
  :root .progress-steps { gap: 4px; padding-bottom: 22px; }
  :root .progress-step { position: static; }
  :root .step-circle { z-index: 2; }
  :root .progress-step .step-label { display: none; }
  :root .progress-step.current .step-label {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    margin: 0;
    font-size: 13px;
  }

  /* Cookie banner: the same words, about half the height. */
  :root #cookieConsentBanner { padding: 12px !important; }
  :root #cookieConsentBanner > div { gap: 10px !important; }
  :root #cookieConsentBanner > div > div:first-child { min-width: 0 !important; }
  :root #cookieConsentBanner h3 { font-size: 15px !important; margin-bottom: 4px !important; }
  :root #cookieConsentBanner p { font-size: 12.5px !important; line-height: 1.4 !important; }
  :root #cookieConsentBanner > div > div:last-child { width: 100%; }
  :root #cookieConsentBanner .button { flex: 1 1 0; margin: 0; min-height: 44px; }
}

/* The ☰ button added to the landing, free-trial and pilot pages (Step 4) is
   for phones only. */
.mobile-menu-toggle[data-shared-toggle] { display: none; }

/* ── Public pages' own menu (homepage-navbar), up to 768 px: a ☰ button
   instead of nine stacked links filling the first screen (Step 4). Same look
   as the pricing page's menu, which already had one. ─────────────────── */
@media screen and (max-width: 768px) {
  :root .homepage-navbar {
    position: relative;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
  }
  :root .homepage-navbar .logo { font-size: 18px; min-width: 0; }
  :root .homepage-navbar .logo img { height: 32px; }
  :root .homepage-navbar .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
  }
  :root .homepage-navbar .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1a5f5a;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
    text-align: left;
    padding: 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 1000;
  }
  :root .homepage-navbar .nav-links.active { display: flex; }
  :root .homepage-navbar .nav-links > a,
  :root .homepage-navbar .nav-links > .dropdown {
    padding: 14px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 16px;
  }
  :root .homepage-navbar .nav-links a.cta-btn { margin: 8px 16px 16px; text-align: center; }
}

/* ── Phones and small tablets (up to 900 px): tables as cards ─────────── */
@media screen and (max-width: 900px) {
  /* Tables marked cards-on-small: one card per row, each cell labelled by
     its column (data-label). Patient List and Follow-Ups (decision 1); up to
     900 px because the Patient List table needs ~840 px. */
  :root table.cards-on-small,
  :root table.cards-on-small tbody,
  :root table.cards-on-small tr,
  :root table.cards-on-small td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }
  :root table.cards-on-small { background: none; box-shadow: none; border-radius: 0; overflow: visible; }
  :root table.cards-on-small thead { display: none; }
  :root table.cards-on-small tr {
    background: #fff;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    padding: 8px 14px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  }
  :root table.cards-on-small td {
    border: none;
    padding: 6px 0;
    display: grid;
    grid-template-columns: 38% 1fr;
    gap: 8px;
    overflow-wrap: anywhere;
  }
  :root table.cards-on-small td::before {
    content: attr(data-label);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #64748b);
  }
  :root table.cards-on-small td > * { justify-self: start; text-align: left; }
  :root table.cards-on-small td.card-cell-wide { display: block; }
  :root table.cards-on-small td.card-cell-wide::before { content: none; }
  :root table.cards-on-small td:empty,
  :root table.cards-on-small td.card-cell-empty { display: none; }
  /* The patient's name leads the card. */
  :root table.cards-on-small tr { display: flex; flex-direction: column; }
  :root table.cards-on-small td.card-cell-title {
    order: -1;
    display: block;
    font-size: 17px;
    font-weight: 700;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border, #e2e8f0);
    margin-bottom: 4px;
  }
  :root table.cards-on-small td.card-cell-title::before { content: none; }
}

/* Small tablets: two cards side by side. */
@media screen and (min-width: 577px) and (max-width: 900px) {
  :root table.cards-on-small tbody { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  :root table.cards-on-small tr { margin-bottom: 0; }
}

/* ── Printing: never clip a table in its scroll box ───────────────────── */
@media print {
  .table-scroll { overflow: visible !important; }
}
