/* NESTORA phone layout (Android and iPhone). Loaded last. Applies at 760px and below. */
@media (max-width: 760px) {
  :root { --topbar-h: 58px; }
  html, body { overflow-x: hidden; max-width: 100%; }

  /* Top bar: menu at top-left, title on its own line of the bar, tools in one tidy row */
  .topbar { padding: 0 12px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); gap: 8px; padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .menu-btn { display: inline-grid; }
  .standalone .back-btn { display: inline-grid; }
  .topbar .brand-text, .topbar-nav, .hide-phone { display: none !important; }
  .topbar-title, .hide-desktop-title { display: block; font-size: 1rem; flex: 1; min-width: 0; }
  .topbar-tools { gap: 6px; }
  .icon-btn { width: 40px; height: 40px; border-radius: 13px; }
  .topbar .avatar { width: 36px; height: 36px; }

  /* Off-canvas menu from the left, over a dimmed page */
  .sidebar, .has-sidebar .sidebar {
    display: flex; position: fixed; z-index: 100; top: 0; left: 0; bottom: 0; height: 100%; width: min(86vw, 330px);
    background: var(--panel-solid); box-shadow: var(--shadow-lg); border-radius: 0 24px 24px 0;
    transform: translateX(-105%); transition: transform .28s var(--ease); visibility: hidden;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .sidebar.open { transform: none; visibility: visible; }
  .sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
  .nav-link { padding: 12px 14px; font-size: 1rem; }

  /* Bottom tab bar */
  .tabbar {
    display: flex; position: fixed; z-index: 80; left: 0; right: 0; bottom: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    background: var(--panel-strong); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
    border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    all: unset; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: .7rem; font-weight: 600; color: var(--text-faint); border-radius: 14px; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .tabbar .icon { width: 22px; height: 22px; }
  .tabbar [aria-current="page"] { color: var(--brand-600); }
  .tabbar [aria-current="page"] .icon { stroke-width: 2.2; }
  .tabbar a:focus-visible, .tabbar button:focus-visible { outline: 2px solid var(--brand-300); }
  body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .alerts { top: auto; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); right: 16px; left: 16px; width: auto; }

  /* Content */
  .main { padding: 18px 14px 32px; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .panel { padding: 18px; border-radius: 20px; }
  .page-head { margin-bottom: 18px; }
  .page-head h1 { font-size: 1.45rem; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.35rem; }
  .grid-2, .grid-3, .grid-4, .form-grid, .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; border-radius: 18px; }
  .stat-value { font-size: 1.45rem; }
  .cards { grid-template-columns: 1fr; gap: 14px; }
  .cards.is-list .card { flex-direction: column; }
  .cards.is-list .card-photo { width: 100%; min-height: 0; aspect-ratio: 4 / 3; }
  .charges-row { grid-template-columns: 1fr 1fr; }
  .charges-row .field:first-child { grid-column: span 2; }
  .has-tabbar .form-actions { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .form-actions .btn { flex: 1; }

  /* Home */
  .hero { border-radius: 24px; padding: 26px 20px; }
  .hero-search { grid-template-columns: 1fr; padding: 8px; border-radius: 18px; }
  .hero-search .btn { grid-column: auto; }
  .hero-stats { gap: 20px; }
  .section { margin-top: 36px; }

  /* Details */
  .gallery { grid-template-columns: 1fr; grid-template-rows: 1fr; height: 62vw; min-height: 230px; border-radius: 20px; }
  .gallery button:not(:first-child) { display: none; }
  .price-hero { font-size: 1.6rem; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }

  /* Tables scroll inside their own box; dates, codes and amounts stay on one line */
  .table td, .table th { padding: 10px; }
  .table .t-title { min-width: 180px; }

  /* Auth */
  .auth-main { padding: 14px; padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .auth-card { padding: 22px 18px; border-radius: 24px; margin-top: 16px; }
  .role-picker label { padding: 12px; }

  .footer { padding: 28px 16px 24px; margin-top: 32px; }
  .footer-grid { flex-direction: column; gap: 14px; }
}

@media (max-width: 960px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  /* Stacked tables: each row becomes a card, so controls never hide off-screen */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  .table-stack tr:last-child { border-bottom: 0; }
  .table-stack td { border: 0; padding: 4px 0; }
  .table-stack td:empty { display: none; }
  .table-stack td[data-label] { display: flex; justify-content: space-between; gap: 12px; text-align: left; }
  .table-stack td[data-label]::before { content: attr(data-label); color: var(--text-muted); font-size: .85rem; font-weight: 600; }
  .table-stack .t-title { min-width: 0; }
  .table-stack tbody tr:hover { background: none; }
  .compare-table th[scope="row"] { white-space: normal; min-width: 104px; max-width: 120px; font-size: .8rem; }
  .compare-table td { min-width: 168px; }
  .row-form { flex-wrap: wrap; }
  .row-form select { max-width: none; flex: 1; }
  .org-head { align-items: flex-start; }
}
@media (max-width: 360px) {
  .role-picker { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.25rem; }
  .btn { padding: 0 14px; }
}
