/* Valoren on a phone or tablet (Milestone 3). Loaded after each page's own styles. Two tiers:
     up to 1024px (every iPad in portrait, and phones): the 220px admin sidebar becomes a drawer opened from a
       menu button (valoren-mobile.js adds it), wide grids drop to two columns.
     any touch screen, at any width (an iPad in landscape keeps the desktop layout): touch targets 44px, form text 16px.
     under 768px (phones): grids and forms go to one column, the homeowner links become a drop-down,
       the sign-in page stacks, the seasonal checklist header compacts.
   With a mouse at desktop width nothing changes except the notifications card. */

.vm-menu-btn, .vm-overlay { display: none; }

/* Notifications card (valoren-push.js), any screen size */
.vm-push { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; background: #fff;
  border: 1px solid #E8E2D6; border-left: 3px solid #B8965A; border-radius: 8px; padding: 14px 16px; margin: 0 0 20px; }
.vm-push-text { margin: 0; font-size: 14px; line-height: 1.5; color: #4A4743; flex: 1 1 220px; }
.vm-push-btn { min-height: 44px; padding: 0 18px; border-radius: 6px; border: 1px solid #B8965A; background: #B8965A; color: #0A0A0A;
  font-size: 13px; font-weight: 600; letter-spacing: 0.03em; cursor: pointer; }
.vm-push-on .vm-push-btn { background: transparent; color: #8A6D3B; }
.vm-push-btn:disabled { opacity: 0.6; cursor: default; }

/* Property cards (admin dashboard): the status and three account buttons wrap when the card is too narrow for one row,
   instead of the card cutting the last button off. Any width; on a wide card nothing moves. */
.pc-footer { flex-wrap: wrap; gap: 8px; }

/* ===================== Tablets and phones: up to 1024px (iPad Pro portrait included) ===================== */
@media (max-width: 1024px) {
  html, body { max-width: 100%; overflow-x: hidden; }

  /* ---- Admin: sidebar drawer. Closed, it is off screen AND out of the tab order and the screen-reader tree ---- */
  .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform 0.22s ease, visibility 0s linear 0.22s;
    width: 260px !important; z-index: 1001 !important; box-shadow: none; }
  body.vm-nav-open .sidebar { transform: none; visibility: visible; transition: transform 0.22s ease; box-shadow: 0 0 40px rgba(0,0,0,0.35); }
  .sidebar { padding-bottom: max(20px, env(safe-area-inset-bottom)) !important; } /* Sign Out clear of the iPhone home indicator (#46) */
  .vm-overlay { position: fixed; inset: 0; background: rgba(10,10,10,0.45); z-index: 1000; }
  body.vm-nav-open .vm-overlay { display: block; }
  body.vm-nav-open { overflow: hidden; }
  .main { margin-left: 0 !important; min-width: 0; width: 100%; }

  .vm-menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin-right: 6px;
    flex: 0 0 auto; border: 1px solid rgba(0,0,0,0.12); border-radius: 6px; background: transparent; color: inherit; cursor: pointer; }
  .vm-menu-btn svg { width: 20px; height: 20px; }
  .nav .vm-menu-btn { display: none; }   /* homeowner pages keep their links on a tablet; the drop-down is phones only */

  .topbar { padding: 10px 18px !important; height: auto !important; min-height: 60px; flex-wrap: wrap; gap: 8px; }
  .topbar-left, .topbar-right { flex-wrap: wrap; min-width: 0; }
  .page-body, .page, .content { padding: 20px !important; max-width: 100% !important; }

  /* Grids: four and five across become two, three across become two */
  .stats-row, .quick-grid, .grid4, .amenity-grid, .properties-grid, .grid3, .sensor-grid, .tier-grid, .ic-grid
    { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .stats-row > *, .quick-grid > *, .grid4 > *, .amenity-grid > *, .properties-grid > *, .info-grid > *, .grid3 > *, .grid2 > *,
  .sensor-grid > *, .tier-grid > *, .modal-grid > *, .fg-row > *, .cl-grid > *, .card-grid > *, .ic-grid > *, .sig-grid > * { min-width: 0; }
  img, svg, video, canvas, table { max-width: 100%; }
  .modal { max-width: calc(100vw - 24px) !important; }

  /* Tab rows and the builder's step strip wrap instead of running off the edge */
  [class*="tab-bar"], [class*="tabs"], .tab-nav, .steps { flex-wrap: wrap; }
  .tab-nav { top: 0 !important; }
  .step { min-width: 0 !important; }

  /* Wide tables scroll inside their own box, never the page */
  .vm-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }



  /* Seasonal checklist and inspection headers may wrap onto two lines */
  .header { height: auto !important; min-height: 58px; flex-wrap: wrap; gap: 8px; }
  .header-left, .header-right { flex-wrap: wrap; min-width: 0; }
  .header-right { margin-left: auto; }

  .toast { max-width: calc(100vw - 24px); }
}

/* ===================== Any touch screen, any width ===================== */
@media (max-width: 1024px), (pointer: coarse) {
  input, select, textarea { font-size: 16px !important; } /* below 16px, iOS zooms the whole page on focus */
  input:not([type="checkbox"]):not([type="radio"]), select { min-height: 44px; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
  /* Every button and button-styled link is at least 44px tall; icon-only buttons are 44px square */
  button, .btn, a.btn, .ibtn, .hbtn, .add-item-trigger, .add-item-btn, .back-btn, .draft-btn, .submit-btn, .tab-btn, .sb-link { min-height: 44px; }
  .cat-del-btn, .item-del, .edit-btn, .sb-signout, .btn-signout { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .properties-grid a, .card-link, .contact-btn, .form-forgot, .form-back, .nav-link, .cl-btn, .cb-btn, .cc-link,
  .page-body a[href^="inspection-ipad.html"], .page-body a[href^="checklist-builder.html"] { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }
  .cl-btn { display: flex; }
  .pc-del, .prop-del, .properties-grid button { min-width: 44px; }
  /* Calendar (#47): month arrows 44px; a task's tick box keeps its small square look inside a 44px tap area */
  .cal-nav-btn { width: 44px !important; min-width: 44px !important; height: 44px !important; flex-shrink: 0 !important; }
  .task-check { width: 44px !important; height: 44px !important; margin: -12px -12px -12px -14px !important; box-sizing: border-box;
    border: 13px solid transparent !important; background-clip: padding-box; box-shadow: inset 0 0 0 1.5px var(--cream3, #E8E2D6); border-radius: 15px !important; }
  .task-check.done { box-shadow: none; }
  .task-del { width: 44px !important; height: 44px !important; min-width: 44px; display: inline-flex !important; align-items: center; justify-content: center;
    margin: -12px -12px -12px 0 !important; flex-shrink: 0; font-size: 16px !important; opacity: 0.6; }
}

/* ===================== Phones: under 768px ===================== */
@media (max-width: 767px) {
  .topbar { padding: 10px 14px !important; }
  .topbar .page-sub { display: none; }
  .page-body, .page, .content { padding: 16px !important; }

  /* Three across and side-by-side forms become one column */
  .properties-grid, .info-grid, .grid3, .grid2, .sensor-grid, .tier-grid, .modal-grid, .fg-row, .cl-grid,
  .card-grid, .ic-grid, .sig-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .modal { width: 100% !important; }
  body { overflow-wrap: break-word; }                 /* a long email address breaks instead of running off the card */
  .btn, button { white-space: normal; }               /* long labels ("Save Property & Activate Portal") wrap */
  .setting-field, .setting-field select, .setting-field input { max-width: 100%; width: 100%; }
  .contact-btns { flex-wrap: wrap; flex-shrink: 1; }

  .tab-nav { padding: 0 8px !important; }
  .tab-nav .tab-btn { flex: 1 1 auto; padding: 12px 10px !important; }
  .step { flex: 1 1 30%; padding: 10px 8px !important; }
  .step .step-label { display: none; }

  .header { padding: 8px 14px !important; }
  .header-right .btn { display: none !important; } /* the same three actions sit in the bar at the bottom of the screen */

  /* Sign-in pages: the brand panel stacks above the form and keeps only the logo */
  body:has(> .left):has(> .right) { flex-direction: column; }
  body > .left { flex: none !important; width: 100% !important; min-height: 0 !important; padding: 20px !important; }
  body > .left .left-center, body > .left .left-bottom, body > .left .left-mountain { display: none !important; }
  body > .right { flex: 1 1 auto !important; width: 100% !important; padding: 28px 20px !important; }

  /* Maintenance Calendar, Bills & Invoicing, Business Health (#47): side panels go below the main column;
     the calendar keeps its month grid, compact, with each entry as a colored bar (tapping a day still adds a task) */
  .page-layout, .billing-layout { grid-template-columns: minmax(0, 1fr) !important; }
  .page-layout > *, .billing-layout > * { min-width: 0; }
  .cal-cell { min-height: 60px !important; padding: 4px 3px !important; }
  .cal-date { width: 22px !important; height: 22px !important; font-size: 11px !important; margin-bottom: 2px !important; }
  .cal-event { font-size: 0 !important; height: 5px; padding: 0 !important; margin: 2px 0 !important; border-radius: 3px !important; pointer-events: none; }
  .cal-day-label { font-size: 9px !important; letter-spacing: 0.04em !important; }
  .addon-row { grid-template-columns: 1fr 1fr !important; }
  [style*="grid-template-columns:1fr 1fr 1fr"], [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr;"], [style*="grid-template-columns: 1fr 1fr;"],
  [style*="grid-template-columns:1fr 1fr\""] { grid-template-columns: minmax(0, 1fr) !important; }
  .rev-bar-label { width: 110px !important; }

  /* ---- Homeowner: top links become a drop-down ---- */
  .nav { padding: 0 14px !important; position: sticky; }
  .nav .vm-menu-btn { display: inline-flex; border-color: rgba(255,255,255,0.2); color: #fff; margin: 0 0 0 auto; }
  .nav-links { display: none !important; }
  body.vm-nav-open .nav-links { display: flex !important; flex-direction: column; align-items: stretch; position: absolute; top: 60px; left: 0; right: 0;
    background: var(--ink, #0A0A0A); padding: 8px 14px 14px; z-index: 1001; box-shadow: 0 12px 30px rgba(0,0,0,0.3); }
  body.vm-nav-open .nav-link { padding: 12px 14px !important; font-size: 15px !important; min-height: 44px; display: flex; align-items: center; }
  .nav-user { display: none; }
  .toast { left: 12px; right: 12px; bottom: 12px; }
}
