/* RIELITY OS — phone layout (2026-10-13). Loaded by every OS page; mobile-shell.js adds the bars.
   Desktop (> 820px) is unchanged: these rules only apply on narrow screens. */
.m-only { display: none; }
.m-topbar, .m-bottomnav, .m-fab, .m-sheet, .m-sheet-backdrop { display: none; }
.m-offline { position: fixed; left: 50%; transform: translateX(-50%); top: calc(10px + env(safe-area-inset-top)); z-index: 450; background: #18181b; color: #fff;
  font: 600 13px/1.4 Inter, -apple-system, sans-serif; padding: 10px 16px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 24px); display: none; }
.m-offline.show { display: block; }
.m-offline.ok { background: #15803d; }
.m-install { display: none; }

@media (max-width: 820px) {
  .m-only { display: block; }
  aside.sidebar { display: none !important; }
  .main { margin-left: 0 !important; padding: calc(68px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)) !important; max-width: 100vw; overflow-x: hidden; }
  .page-title { font-size: 22px !important; }
  /* iOS zooms into any field under 16px — keep them at 16px on phones */
  input, select, textarea { font-size: 16px !important; }
  button, .btn-save, .btn-util, .btn-primary, .btn-secondary { min-height: 40px; }

  /* top bar */
  .m-topbar { display: flex; position: fixed; top: 0; left: 0; right: 0; z-index: 120; align-items: center; gap: 10px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: rgba(255,255,255,.94); -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border, #e7e7e9); }
  .m-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text, #18181b); font: 800 15px/1 var(--font, Inter, sans-serif); letter-spacing: .4px; flex: 1; min-width: 0; }
  .m-brand img { width: 26px; height: 26px; object-fit: contain; }
  .m-icon-btn { position: relative; width: 44px; height: 44px; border-radius: 12px; border: none; background: none; display: flex; align-items: center; justify-content: center; color: var(--text, #18181b); cursor: pointer; padding: 0; }
  .m-icon-btn svg { width: 22px; height: 22px; }
  .m-icon-btn:active { background: var(--surface2, #f6f6f7); }
  .m-badge { position: absolute; top: 6px; right: 5px; background: #b91c1c; color: #fff; border-radius: 99px; font: 700 10.5px/16px Inter, sans-serif; min-width: 16px; height: 16px; padding: 0 4px; text-align: center; }
  .m-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--surface2, #f6f6f7); display: flex; align-items: center; justify-content: center; font: 700 13px Inter, sans-serif; color: var(--text, #18181b); overflow: hidden; }
  .m-avatar img { width: 100%; height: 100%; object-fit: cover; }

  /* bottom navigation */
  .m-bottomnav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96); -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--border, #e7e7e9); }
  .m-tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 50px; border: none; background: none; text-decoration: none;
    color: var(--text-muted, #71717a); font: 600 11px/1 var(--font, Inter, sans-serif); cursor: pointer; border-radius: 12px; padding: 0; }
  .m-tab svg { width: 23px; height: 23px; }
  .m-tab.active { color: var(--text, #18181b); }
  .m-tab.active svg { stroke-width: 2.4; }
  .m-tab:active { background: var(--surface2, #f6f6f7); }

  /* quick actions */
  .m-fab { display: flex; position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 121; width: 54px; height: 54px; border-radius: 18px; border: none;
    background: var(--text, #18181b); color: #fff; align-items: center; justify-content: center; box-shadow: 0 10px 28px rgba(24,24,27,.28); cursor: pointer; }
  .m-fab svg { width: 26px; height: 26px; }

  /* sheets (More, quick actions, account) */
  .m-sheet-backdrop.open { display: block; position: fixed; inset: 0; z-index: 180; background: rgba(24,24,27,.38); }
  .m-sheet.open { display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 190; max-height: 86dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
    background: var(--surface, #fff); border-radius: 20px 20px 0 0; padding: 8px 14px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -12px 40px rgba(0,0,0,.18); }
  .m-grab { width: 40px; height: 5px; border-radius: 99px; background: var(--border, #e7e7e9); margin: 4px auto 10px; }
  .m-sheet h3 { font: 700 11px/1 var(--font, Inter, sans-serif); text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted, #71717a); margin: 14px 4px 6px; }
  .m-sheet h3:first-of-type { margin-top: 4px; }
  .m-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .m-link { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 74px; padding: 10px 6px; border-radius: 14px; background: var(--surface2, #f6f6f7);
    color: var(--text, #18181b); text-decoration: none; font: 600 12px/1.2 var(--font, Inter, sans-serif); text-align: center; border: none; cursor: pointer; }
  .m-link svg, .m-link .ico { width: 22px; height: 22px; opacity: .85; }
  .m-link.active { background: var(--text, #18181b); color: #fff; }
  .m-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 12px; border-radius: 12px; border: none; background: none; text-decoration: none;
    color: var(--text, #18181b); font: 600 15px/1.3 var(--font, Inter, sans-serif); text-align: left; cursor: pointer; }
  .m-row:active { background: var(--surface2, #f6f6f7); }
  .m-row svg { width: 22px; height: 22px; flex-shrink: 0; }
  .m-row small { display: block; font-weight: 500; font-size: 12.5px; color: var(--text-muted, #71717a); }
  .m-page-tools { padding: 4px 2px; }
  .m-page-tools .sidebar-heading { margin: 12px 4px 6px; }
  .m-page-tools .sidebar-item { min-height: 44px; }

  /* keyboard open: give the form the whole screen */
  body.m-kb .m-bottomnav, body.m-kb .m-fab { display: none; }

  /* existing page pieces */
  .toast { bottom: calc(86px + env(safe-area-inset-bottom)) !important; white-space: normal !important; max-width: calc(100vw - 32px); text-align: center; }
  .modal-overlay { padding: calc(8px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom)) !important; align-items: flex-start; }
  .modal { width: 100% !important; max-width: 100% !important; padding: 20px 16px !important; border-radius: 16px !important; }
  .bell-panel { top: calc(62px + env(safe-area-inset-top)) !important; left: 10px !important; right: 10px !important; width: auto !important; max-width: none !important; max-height: 70dvh !important; }
  .m-install.show { display: flex; gap: 10px; align-items: center; margin: 0 0 14px; padding: 12px 14px; border-radius: 14px; background: var(--surface2, #f6f6f7); font: 500 13px/1.4 var(--font, Inter, sans-serif); color: var(--text, #18181b); }
  .m-install a { font-weight: 700; color: inherit; }
  .m-install svg { width: 22px; height: 22px; flex-shrink: 0; }
  .m-install button { margin-left: auto; border: none; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--text-muted, #71717a); min-height: 0; }

  /* wide tables become cards (mobile-shell.js labels each cell with its column name) */
  table.m-cards, table.m-cards tbody, table.m-cards tr, table.m-cards td { display: block; width: 100%; box-sizing: border-box; }
  table.m-cards thead { display: none; }
  table.m-cards tr { border: 1px solid var(--border, #e7e7e9); border-radius: 12px; margin-bottom: 10px; padding: 6px 12px; background: var(--surface, #fff); }
  table.m-cards td { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0 !important; border: none !important; text-align: right; font-size: 14px; }
  table.m-cards td::before { content: attr(data-label); font-weight: 600; color: var(--text-muted, #71717a); text-align: left; font-size: 12.5px; flex-shrink: 0; max-width: 45%; }
  table.m-cards td[data-label=""]::before { content: none; }
  table.m-cards td:empty { display: none; }
  .table-wrap, .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* tab strips and stage trackers scroll sideways inside themselves (the page itself never does) */
  .tabs-row, .sm-tabs, .tab-bar, .journey-panel { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap !important; scrollbar-width: none; }
  .tabs-row::-webkit-scrollbar, .sm-tabs::-webkit-scrollbar, .tab-bar::-webkit-scrollbar, .journey-panel::-webkit-scrollbar { display: none; }
  .tabs-row > *, .sm-tabs > *, .tab-bar > * { flex-shrink: 0; white-space: nowrap; min-height: 44px; }
}
@media (max-width: 520px) {
  /* side-by-side form fields stack on narrow phones so each field is full width */
  .modal .two-col, .modal .two, .modal .three-col, .modal .field-row, .drawer .two-col, .drawer .two { grid-template-columns: 1fr !important; }
}
