/* ========== css/mobile.css ========== */
/* Web app only: phone & tablet layout (under 900px). Computer screens are not affected.
   Sizes grow with the screen: clamp(smallest, % of screen width, largest). */

.mob-menu-btn, .mob-tabbar, .mob-page-title { display: none; }

@media (max-width: 900px) {

  :root {
    /* One size per category; each grows smoothly from 320px to 900px wide */
    --fs-small: clamp(10px,   calc(8.5px  + 0.45vw), 12px);    /* labels, notes   */
    --fs-text:  clamp(11px,   calc(9.5px  + 0.55vw), 14px);    /* normal text     */
    --fs-btn:   clamp(11px,   calc(9.5px  + 0.5vw),  13.5px);  /* buttons, tabs   */
    --fs-head:  clamp(13px,   calc(11px   + 0.7vw),  17px);    /* headings        */
    --fs-title: clamp(16px,   calc(13px   + 1vw),    22px);    /* app title       */

    /* Old names used above, mapped to the categories */
    --fs-xs: var(--fs-small);
    --fs-sm: var(--fs-btn);
    --fs-md: var(--fs-text);
    --fs-lg: var(--fs-head);
    --fs-xl: var(--fs-title);

    --gap: clamp(6px, 2.5vw, 12px);     /* spacing */
  }

  body { font-size: var(--fs-md); }
  h1 { font-size: var(--fs-xl); }
  h2 { font-size: var(--fs-lg); }
  h3 { font-size: var(--fs-md); }

  /* One column; the whole page scrolls */
  .page-container { flex-direction: column; min-height: auto; }
  .left-section   { overflow: visible; }
  .left-page      { overflow: visible; }

  /* ── Top bar ──
     Row 1: logo · title · Sell Mode · Buy Mode · ☰
     Row 2: current page title (☰ moves here on narrow phones) */
  .left-banner {
    position: sticky; top: 0; z-index: 80;
    display: flex; flex-wrap: wrap; align-items: center;
    gap: 6px 8px; padding: 8px 4%;
  }
  .left-banner img           { order: 0; width: clamp(22px, 7vw, 32px); height: auto; }
  .left-banner .banner-title { order: 1; white-space: nowrap; }
  .left-banner .mode-tabs    { order: 2; flex: 0 0 auto; width: auto; margin-left: auto; gap: 4px; }
  .left-banner .mode-tab     { flex: 0 0 auto; min-width: 0; padding: 4px 8px; }
  .mob-menu-btn {
    display: block; order: 3;
    background: rgba(255,255,255,0.15); color: #fff; border: none; border-radius: 8px;
    line-height: 1; padding: 3px 9px; cursor: pointer;
  }
  .mob-page-title {
    display: block; order: 4; flex: 1 1 100%; min-width: 0;
    background: var(--accent); color: #fff; font-weight: 600;
    border-radius: 6px; padding: 6px 10px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  /* ── ☰ Page menu: hidden until tapped, then full screen ── */
  .left-nav { display: none; }
  body.mob-nav-open .left-nav {
    display: flex; flex-direction: column;
    position: fixed; inset: 0; z-index: 70;
    padding: 100px 4% 20px; overflow-y: auto;
  }
  body.mob-nav-open .left-nav-btn {
    width: 100%; text-align: left; font-size: var(--fs-lg);
    padding: 12px 10px; margin: 2px 0;
  }
  .left-nav-sep { display: none !important; }

  /* ── Listing buttons: 3 rows ──
     Row 1: Search · Row 2: Select all, All users, Active | Removed · Row 3: Add Selected, Delete Selected, Sort, Refresh */
  #listings-toolbar {
    flex-wrap: wrap; align-items: center;
    gap: var(--gap) !important; padding: var(--gap) 4% !important;
  }
  #listings-left-group,
  #listings-right-group { display: contents !important; }   /* let their buttons join the rows */

  /* Row 1 */
  #listings-search-wrap  { order: 1; flex: 1 1 100% !important; max-width: none !important; margin: 0 !important; }
  #listings-search-input { font-size: var(--fs-md) !important; padding: 6px 10px !important; height: 34px; }

  /* Row 2 */
  #listings-left-group > label { order: 2; }
  #user-filter-wrap      { order: 3; }
  #user-filter-btn       { width: auto !important; max-width: 42vw; overflow: hidden; text-overflow: ellipsis;
                           padding: 6px 10px !important; }
  #user-filter-menu      { min-width: 0 !important; width: 80vw; max-width: 320px; left: 0 !important; }
  #listings-view-switch  { order: 4; flex: 1 1 auto; min-width: 0; }
  #listings-view-switch > button { flex: 1 1 0; min-width: 0; }

  /* Forced line break between row 2 and row 3 */
  #listings-toolbar::before { content: ""; order: 5; flex-basis: 100%; height: 0; }

  /* Row 3: Add Selected, Delete Selected, Sort share the width; Refresh stays a square */
  #listings-right-group > *  { order: 6; flex: 1 1 0; min-width: 0 !important; width: auto !important; }
  #listings-refresh-btn      { flex: 0 0 40px !important; }

  #listings-toolbar button {
    font-size: var(--fs-sm) !important; padding: 0 2px !important;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #listings-toolbar #listings-refresh-btn { font-size: 18px !important; }

  /* ── Car cards: % of the screen ── */
  .listings-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
    gap: var(--gap); margin: var(--gap) 4%;
  }
  .listing-card  { width: auto; height: auto; overflow: hidden; }
  .listing-image { width: 100%; height: auto; aspect-ratio: 3 / 2; display: block; }
  .card-footer   { height: auto !important; padding: 6px 10px 10px !important; }
  .card-title    { font-size: var(--fs-md); }
  .listing-card .price { font-size: var(--fs-md); }

  /* Remove / Delete buttons and the checkbox on each card: smaller */
  .listing-card .add-vehicle-btn,
  .listing-card .listing-delete-btn {
    font-size: var(--fs-xs) !important; padding: 4px 10px !important;
    width: auto !important; min-width: 0 !important; height: auto !important;
  }
  .listing-card .listing-select-cb { width: 18px; height: 18px; }

  .pagination { font-size: var(--fs-sm); margin-bottom: var(--gap); }

  /* ── Properties / My Vehicles: full screen when opened from the bottom bar ── */
  body:not(.mob-panel-open) .details-panel { display: none !important; }
  body.mob-panel-open .details-panel {
    display: block !important;
    position: fixed; top: 0; left: 0; right: 0; bottom: 56px; z-index: 90;
    width: 100%; min-width: 0; max-width: none; height: auto;
    overflow-y: auto; border: none; padding: 0 4% 14px;
    font-size: var(--fs-md);
  }
  .details-panel .ext-title { margin: 0 -4.5%; font-size: var(--fs-lg); height: 48px; }
  .details-panel .panel-tabs { display: none; }               /* the bottom bar replaces them */
  .details-panel button { font-size: var(--fs-sm); }

  /* ── Bottom bar (Saved Listings page only) ── */
  body.mob-on-listings .mob-tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 56px; z-index: 95;
    background: #fff; border-top: 1px solid var(--border); box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  }
  .mob-tabbar button {
    flex: 1; min-width: 0; border: none; border-top: 3px solid transparent; background: none;
    font-size: var(--fs-sm); font-weight: 600; color: #6b7590; cursor: pointer;
  }
  .mob-tabbar button.active { color: var(--primary); border-top-color: var(--primary); }
  body.mob-on-listings .page-container { padding-bottom: 64px; }

  /* ── Other pages ── */
  .page-content { padding: 4% 4% 24px; }
  .left-page button { font-size: var(--fs-sm); }
  .left-page table  { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; font-size: var(--fs-sm); }

  /* Text boxes: same size as the text around them (zoom-on-tap is off in the page header) */
  input, select, textarea { font-size: var(--fs-sm); }
  .left-page button, .details-panel button { white-space: nowrap; }

  /* ── Properties: label and field on the same row; labels line up in a column ── */
  .details-panel .field-row { flex-wrap: wrap; gap: 6px var(--gap); margin-bottom: 6px; }
  .details-panel .field-row .field-inline {
    flex: 1 1 0 !important; max-width: none !important; min-width: 0 !important;
    flex-direction: row; align-items: center; gap: 4px;
  }
  .details-panel .field-inline label {
    font-size: var(--fs-xs); width: 4.8em; flex-shrink: 0; white-space: nowrap;
  }
  /* Type gets its own row; Year and Price share the next one */
  .details-panel .field-row:has(#vehicleTypeSelect) .field-inline:first-child { flex: 1 1 100% !important; }

  .details-panel .field-inline > input,
  .details-panel .field-inline > select,
  .details-panel .field-static,
  .details-panel .price-input-wrap { flex: 1 1 auto; min-width: 0 !important; width: auto; }
  .details-panel .field-inline > input,
  .details-panel .field-inline > select,
  .details-panel .price-input-wrap input,
  .details-panel .field-static { font-size: var(--fs-sm); padding: 6px 5px; }
  .details-panel .price-input-wrap span { font-size: var(--fs-sm); padding: 6px 0 6px 5px; }
  .details-panel textarea { font-size: var(--fs-sm); }

  /* AI image buttons: share the row, one line each */
  .details-panel .ai-row-1 { gap: 6px !important; }
  .details-panel .ai-row-1 > button,
  .details-panel .ai-row-1 > div { flex: 1 1 auto !important; width: auto !important; min-width: 0; }
  .details-panel .ai-row-1 > div > button { width: 100% !important; }
  .details-panel .ai-row-1 button { font-size: var(--fs-xs) !important; padding: 7px 4px !important; }

  /* Dealership Description / AI Description: two tabs of exactly the same width */
  .details-panel .desc-tab-row { gap: var(--gap); }
  .details-panel .desc-tab-label { flex: 1 1 0; min-width: 0; }
  .details-panel .desc-tab {
    display: block; width: 100%; box-sizing: border-box; text-align: center;
    font-size: var(--fs-sm); padding: 7px 4px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
  }
  #aiTabLabel { width: 100%; }

  /* Translate row + Save button */
  #translateLanguage { font-size: var(--fs-sm) !important; }
  #translateBtn, .details-panel .generate-ai-btn { font-size: var(--fs-sm); padding: 7px 10px; }
  .details-panel .select-post-btn { font-size: var(--fs-md); padding: 10px; }

  /* ── My Vehicles ── */
  /* Remove All · Select Platforms ▾ · Auto Post: each as wide as its text, never overlapping */
  .details-panel .vehicle-toolbar {
    display: grid !important;
    grid-template-columns: auto 1fr auto;     /* the middle button takes any extra space */
    gap: 6px !important;
  }
  .details-panel .vehicle-toolbar > div { position: relative; }
  .details-panel .vehicle-toolbar button {
    font-size: var(--fs-sm) !important;
    padding: 7px 6px !important;
    white-space: nowrap;
  }
  .details-panel .vehicle-toolbar > div > button { width: 100%; }   /* Select Platforms fills its column */
  #autoPostMenu { left: 0; right: auto; }
  .details-panel .vehicle-thumb { width: 30%; height: auto; aspect-ratio: 1 / 1; }
  .details-panel .vehicle-info  { padding: 6px; font-size: var(--fs-sm); }
  .details-panel .vehicle-title { font-size: var(--fs-md); }
  .details-panel .platform-badge { font-size: var(--fs-xs) !important; padding: 4px 8px !important; }
  .details-panel .vehicle-actions button { font-size: var(--fs-sm) !important; padding: 7px 4px !important; }
}

/* ═════════════ Other pages (phones & tablets) ═════════════ */
@media (max-width: 900px) {

  /* Pictures, charts and wide content never wider than the screen */
  .left-page img, .left-page canvas, .left-page svg, .left-page video { max-width: 100%; }
  .left-page canvas, .left-page svg { height: auto; }

  /* ── Activity (stronger rules: the page's own built-in styles load after this file) ── */
  body #page-activity .page-content { padding: 4% 4% 24px !important; }
  #listings-hub-section, #activity-section { margin-top: 20px !important; }

  #page-activity .act-card      { padding: var(--gap); }
  #page-activity .act-card-head { flex-wrap: wrap; gap: var(--gap); }
  #page-activity .act-card-title { white-space: normal; flex-wrap: wrap; }
  #page-activity .hub-sync      { max-width: 100%; }
  #analytics-tools, #activity-tools, #hub-perf-tools { width: 100%; }

  /* Listing Performance: full-width search; platform buttons in one swipeable row */
  #page-activity #hub-perf-tools { justify-content: stretch; }
  #page-activity #hub-perf-tools > * { flex: 1 1 auto; }
  #page-activity .perf-search { width: 100% !important; margin-right: 0 !important; }
  #page-activity .hub-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
                             width: 100%; padding-bottom: 2px; }
  #page-activity .hub-tab  { flex: 0 0 auto; white-space: nowrap; }

  /* Tables: keep their columns readable and scroll sideways inside the card */
  #page-activity .act-scroll { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  #page-activity .act-table  { display: table !important; min-width: 680px; }
  #analytics-section .act-table { min-width: 820px; }

  /* No. column: fixed width so "No. ▲" fits (the table's own widths are % of the table) */
  #page-activity .act-table col:first-child,
  #page-activity .act-table th:first-child,
  #page-activity .act-table td:first-child:not([colspan]) { width: 56px !important; }
  #page-activity .act-table th:first-child { overflow: visible; text-overflow: clip; }

  /* Pagination: stays centered in the visible part of the card while the table scrolls */
  #page-activity .act-table tr.hub-pager > td,
  #page-activity .act-table tr:last-child > td[colspan] { padding-left: 0 !important; padding-right: 0 !important; }
  #page-activity .act-table tr.hub-pager .hub-pager-inner,
  #page-activity .act-table tr:last-child > td[colspan] > div {
    position: sticky; left: 0;
    width: calc(92vw - 2 * var(--gap) - 4px);   /* = the visible width of the card */
    justify-content: center;
  }
  
  /* Date filter calendar (shared by all tables): compact, centered on screen */
  .custom-cal-wrapper {
    position: fixed !important;
    top: 50% !important; left: 50% !important;
    transform: translate(-50%, -50%);
    width: min(240px, 86vw); min-width: 0 !important;
    padding: 8px !important; z-index: 1000 !important;
  }
  .custom-cal-wrapper .cal-header { margin-bottom: 4px; }
  .custom-cal-wrapper .cal-title  { font-size: var(--fs-btn) !important; }
  .custom-cal-wrapper .cal-nav    { font-size: var(--fs-head) !important; padding: 0 6px; }
  .custom-cal-wrapper .cal-grid   { gap: 1px; }
  .custom-cal-wrapper .cal-dow,
  .custom-cal-wrapper .cal-day    { font-size: var(--fs-small) !important; padding: 4px 0; }
  .custom-cal-wrapper .cal-hint   { margin-top: 4px; min-height: 0; }
  .custom-cal-wrapper .cal-footer { margin-top: 6px; }
  .custom-cal-wrapper .cal-set-btn { padding: 5px 14px; }

  /* ── Schedule Auto Post: fixed 4-row grid (6 columns) ──
     Row 1: All Users ▾ (half)          | 0/2 listings selected (half)
     Row 2: Schedule (2/3)              | Daily Posting Limit (1/3)
     Row 3: Remove Logo (half)          | AI Description (half)
     Row 4: Language ENG ESP (half)     | Platforms ▾ (half) */
  .sched-toolbar {
    position: static;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);   /* two equal halves, split in the centre */
    gap: 6px;
    padding: var(--gap) 4%;
    align-items: stretch;
  }
  .sched-toolbar > * { min-width: 0; margin: 0 !important; }

  .sched-toolbar > .sched-dropdown-wrap:has(#schedUserBtn)      { grid-area: 1 / 1; }
  .sched-toolbar > #schedCount                                  { grid-area: 1 / 2; align-self: center;
                                                                  text-align: right; white-space: nowrap;
                                                                  overflow: hidden; text-overflow: ellipsis;
                                                                  font-size: var(--fs-small) !important; }
  .sched-toolbar > .sched-field:has(#schedStart)                { grid-area: 2 / 1; }
  .sched-toolbar > .sched-field:has(#schedLimit)                { grid-area: 2 / 2; }
  .sched-toolbar > #schedRemoveLogoWrap                         { grid-area: 3 / 1; }
  .sched-toolbar > #schedAiDescriptionWrap                      { grid-area: 3 / 2; }
  .sched-toolbar > .sched-field:has(.sched-lang)                { grid-area: 4 / 1; }
  .sched-toolbar > .sched-dropdown-wrap:has(#schedPlatformsBtn) { grid-area: 4 / 2; }

  /* Compact boxes; every label stays on ONE line */
  .sched-field, .sched-toggle {
    display: flex; align-items: center; justify-content: space-between;
    gap: 3px; padding: 4px 5px !important; overflow: hidden;
  }
  .sched-field-label, .sched-toggle-label {
    font-size: var(--fs-small) !important; white-space: nowrap; line-height: 1.2;
  }

  /* Row 2 left: "Schedule" → "Time" and "to" → "–" on phones, so it fits half a row */
  .sched-field:has(#schedStart) > .sched-field-label { font-size: 0 !important; }
  .sched-field:has(#schedStart) > .sched-field-label::after { content: "Time"; font-size: var(--fs-small); }
  .sched-field:has(#schedStart) .sched-to { font-size: 0 !important; }
  .sched-field:has(#schedStart) .sched-to::after { content: "–"; font-size: var(--fs-small); }

  /* Dropdown buttons fill their cell */
  .sched-dropdown-wrap { display: block; }
  .sched-dropdown-btn  { width: 100%; height: 100%; padding: 5px 6px !important; white-space: nowrap;
                         overflow: hidden; text-overflow: ellipsis; }
  .sched-dropdown-menu { max-width: 86vw; }
  .sched-toolbar > .sched-dropdown-wrap:has(#schedPlatformsBtn) .sched-dropdown-menu { left: auto; right: 0; }

  /* Narrow time boxes (no clock icon; tapping still opens the phone's picker) */
  .sched-field input[type="time"] { flex: 0 1 auto; width: auto; min-width: 0; padding: 3px 2px;
                                    font-size: var(--fs-small) !important; }
  .sched-field input[type="time"]::-webkit-datetime-edit,
  .sched-field input[type="time"]::-webkit-datetime-edit-fields-wrapper { font-size: var(--fs-small); padding: 0; }
  .sched-field input[type="time"]::-webkit-calendar-picker-indicator { display: none; }
  .sched-field input[type="number"] { width: 2.8em; padding: 3px 2px; text-align: center; }

  /* Language: ENG and ESP right next to each other */
  .sched-toolbar > .sched-field:has(.sched-lang) { justify-content: flex-start; gap: 2px; }
  .sched-toolbar > .sched-field:has(.sched-lang) .sched-field-label { margin-right: 6px; }
  .sched-lang { padding: 2px 7px !important; margin: 0 !important; }

  /* Table: keep its own column widths, so Description shows one line with "…" */
  .sched-table { display: table !important; }  .sched-table { display: table !important; }

  /* Bottom: small notes, full-width buttons, centered pager */
  .sched-footer       { flex-direction: column; align-items: stretch; gap: 8px; padding: var(--gap) 4%; }
  .sched-forecast,
  .sched-tz-note      { font-size: var(--fs-small) !important; }
  .sched-footer-right { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
  .sched-save-btn,
  .sched-cancel-btn   { width: 100%; padding: 9px !important; }
  .sched-pagination   { justify-content: center; }
  .sched-table-wrap   { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ── Opportunities / Search Profiles / Acquisition Settings ── */
  .page-content.acq-page { padding: 4% 4% 24px; gap: var(--gap); }
  .acq-head, .acq-head-actions { flex-wrap: wrap; gap: var(--gap); }
  .acq-head-actions > * { flex: 1 1 auto; }
  .acq-stats { grid-template-columns: repeat(2, 1fr); }
  .acq-stats > div { padding: 10px 12px; }
  .acq-stats > div:nth-child(3) { border-left: none; }
  .acq-stats > div:nth-child(n+3) { border-top: 1px solid var(--border); }
  .acq-stats strong { font-size: var(--fs-head) !important; }
  .acq-settings-grid, .acq-form-grid { grid-template-columns: 1fr; }
  .acq-grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .acq-span2 { grid-column: auto; }
  .acq-span4 { grid-column: span 2; }
  .acq-drawer      { width: 100%; padding: 0 4% 30px; }
  .acq-drawer-head { margin: 0 -4.5% 14px; }

  /* ── Help & Account ── */
  .help-form { max-width: none; }

  /* ── Popups ── */
  .modal-box,
  .inline-modal-box,
  .del-confirm-box { width: 92% !important; max-width: 400px; padding: 18px 16px 14px !important; }
  .lightbox-overlay img { max-width: 100vw; max-height: 80vh; }

  /* ── Sign In page ── */
  .login-box { width: 92%; max-width: 380px; padding: 20px 16px; }
}

/* ═════════════ General text sizes (phones & tablets) ═════════════
   Everything follows its category, even sizes written inside the page code.
   This block is last on purpose, so it wins over the rules above. */
@media (max-width: 900px) {

  /* 1. Normal text: everything inherits the size of its category */
  body   { font-size: var(--fs-text) !important; }
  body * { font-size: inherit !important; }

  /* 2. Text boxes, dropdowns and their options */
  input, select, option, optgroup, textarea { font-size: var(--fs-text) !important; }

  /* 3. Buttons and button-like controls */
  button, input[type="button"], input[type="submit"],
  .left-nav-btn, .mode-tab, .tab-btn, .desc-tab, .platform-badge,
  .mob-tabbar button { font-size: var(--fs-btn) !important; }

  /* 4. Small text: field labels, notes, counters */
  small, .field-inline label, .help-label, .modal-msg,
  .gallery-counter, #aiStatusRow, #translateStatusRow,
  #listings-count-label, .lang-hover-tip { font-size: var(--fs-small) !important; }

  /* 5. Headings */
  h2, h3, h4, .ext-title, .help-intro h2 { font-size: var(--fs-head) !important; }

  /* 6. App title */
  h1, .left-banner .banner-title { font-size: var(--fs-title) !important; }

  /* Icons that must stay big enough to tap */
  .mob-menu-btn, .gallery-arrow { font-size: var(--fs-title) !important; }

  /* Bold where it helps reading (same size as normal text) */
  .card-title, .vehicle-title, .price { font-weight: 700; }
}


/* Narrow phones: ☰ moves to row 2, next to the page title */
@media (max-width: 379px) {
  .mob-menu-btn   { order: 5; }
  .mob-page-title { flex: 1 1 calc(100% - 52px); }
}

/* "Hello, <name>" on phones: under the title, small text */
@media (max-width: 900px) {
  .left-banner .banner-title-wrap { order: 1; }
  .banner-greeting { order: 2; font-size: var(--fs-small) !important; margin-top: 0; }
}