/* ==========================================================================
   Layout — app shell (sidebar + top bar), phone bottom nav, auth screens.
   ========================================================================== */
.app{ min-height: 100vh; min-height: 100dvh; }

/* ---------- Shell ---------- */
.shell{ display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh;
  background: linear-gradient(to right, var(--sidebar-bg) var(--sidebar-w), transparent var(--sidebar-w)); }
.main{ min-width: 0; display: flex; flex-direction: column; }
.content{ width: 100%; max-width: 1320px; margin: 0 auto; padding: var(--sp-6) var(--sp-8) var(--sp-10); flex: 1; }

/* ---------- Sidebar ---------- */
.sidebar{
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--sp-5);
  padding: var(--sp-5) var(--sp-4);
  background: var(--sidebar-bg); color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-border);
}
.side-brand{ display: flex; align-items: center; gap: var(--sp-3); padding: 2px var(--sp-2) var(--sp-4); border-bottom: 1px solid var(--sidebar-border); }
.side-brand img{ width: 44px; height: 44px; border-radius: var(--r-md); background: #fff; padding: 3px; object-fit: contain; flex-shrink: 0; }
.side-brand-text{ display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.side-brand-text strong{ font: 800 15px/1.15 var(--font-display); color: var(--sidebar-text-strong); letter-spacing: .01em; }
.side-brand-text span{ font-size: 12px; font-weight: 600; color: var(--sidebar-text); }

.side-section-label{ padding: 0 var(--sp-3); margin-bottom: -10px; font: 700 11px/1 var(--font-sans); letter-spacing: .1em; text-transform: uppercase; color: var(--sidebar-text); opacity: .7; }
.sidebar .tabs{ display: flex; flex-direction: column; gap: 2px; }
.sidebar .tab{
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 44px; padding: 10px 12px;
  border: 0; border-radius: var(--r-md); background: transparent; color: var(--sidebar-text);
  font: 600 15px/1.2 var(--font-sans); text-align: left; cursor: pointer;
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.sidebar .tab .ic{ width: 20px; height: 20px; opacity: .9; }
.sidebar .tab:hover{ background: var(--sidebar-hover); color: var(--sidebar-text-strong); }
.sidebar .tab.active{ background: var(--sidebar-active); color: var(--sidebar-text-strong); box-shadow: inset 3px 0 0 #fff; }
html[data-theme="dark"] .sidebar .tab.active{ box-shadow: inset 3px 0 0 var(--primary); }
.sidebar .tab:focus-visible{ box-shadow: 0 0 0 2px rgba(255,255,255,.6); }

.side-user{ margin-top: auto; padding: var(--sp-4) var(--sp-2) 0; border-top: 1px solid var(--sidebar-border); display: flex; flex-direction: column; gap: var(--sp-2); }
.side-user-row{ display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); min-width: 0; }
.side-user .avatar{ background: rgba(255,255,255,.14); color: #fff; }
.side-user-name{ font-weight: 700; color: var(--sidebar-text-strong); font-size: 14px; line-height: 1.25; word-break: break-word; }
.side-user-meta{ display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--sidebar-text); margin-top: 2px; }
.side-btn{
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 40px; padding: 8px 12px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--sidebar-text);
  font: 600 14px/1.2 var(--font-sans); text-align: left; cursor: pointer;
}
.side-btn .ic{ width: 18px; height: 18px; }
.side-btn:hover{ background: var(--sidebar-hover); color: var(--sidebar-text-strong); }

/* ---------- Top bar ---------- */
.topbar{
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-8);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left{ display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.facility-logo{ width: 44px; height: 44px; border-radius: var(--r-md); object-fit: cover; border: 1px solid var(--border); background: #fff; flex-shrink: 0; }
.topbar-titles{ min-width: 0; }
.topbar-eyebrow{ font-size: 13px; font-weight: 700; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar h1{ font-size: var(--fs-xl); font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right{ display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }
.topbar-date{ font-size: var(--fs-sm); color: var(--text-2); font-weight: 600; margin-right: var(--sp-2); white-space: nowrap; }
.topbar .phone-only{ display: none; }

.banner-area{ margin-bottom: var(--sp-1); }
.footer-note{ text-align: center; color: var(--text-3); font-size: 13px; font-weight: 600; margin-top: var(--sp-8); }

/* ---------- Page header inside content ---------- */
.page-head{ display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head p{ margin: 4px 0 0; color: var(--text-2); font-size: var(--fs-sm); }
.page-actions{ display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* Grids */
.two-col{ display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.two-col > .panel{ margin-bottom: 0; }
.two-col + .panel, .two-col + .two-col{ margin-top: var(--sp-5); }
.grid-2{ display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5); }

/* ---------- Bottom nav (phones) ---------- */
.bottom-nav{ display: none; }

/* ---------- Corner actions (auth screens) ---------- */
.corner-actions{ position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 14px; z-index: 60; display: flex; gap: var(--sp-2); }

/* ---------- Auth / standalone screens ---------- */
.auth-wrap{
  min-height: 100vh; min-height: 100dvh;
  display: grid; grid-template-columns: minmax(380px, 0.9fr) minmax(0, 1.1fr);
}
.auth-aside{
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; gap: var(--sp-8);
  padding: var(--sp-10) clamp(32px, 4vw, 56px);
  background: radial-gradient(1200px 500px at -10% -10%, #1D4FA3 0%, transparent 60%), linear-gradient(160deg, #0B2A6B 0%, #081D4A 100%);
  color: #DCE7FA;
}
.auth-aside::after{
  content: ""; position: absolute; right: -120px; bottom: -120px; width: 380px; height: 380px; border-radius: 50%;
  border: 60px solid rgba(255,255,255,.04); pointer-events: none;
}
.auth-aside-brand{ display: flex; align-items: center; gap: var(--sp-3); }
.auth-aside-brand img{ width: 56px; height: 56px; border-radius: var(--r-md); background: #fff; padding: 4px; }
.auth-aside-brand strong{ display: block; font: 800 18px/1.15 var(--font-display); color: #fff; letter-spacing: .01em; }
.auth-aside-brand span{ font-size: 13px; color: #B5C8EA; font-weight: 600; }
.auth-aside h2{ color: #fff; font-size: clamp(26px, 2.6vw, 36px); line-height: 1.2; font-weight: 800; max-width: 460px; }
.auth-aside h2 em{ font-style: normal; color: #8FBCFF; }
.auth-features{ list-style: none; padding: 0; margin: var(--sp-6) 0 0; display: flex; flex-direction: column; gap: var(--sp-4); max-width: 440px; }
.auth-features li{ display: flex; gap: var(--sp-3); align-items: flex-start; font-size: 15px; line-height: 1.5; }
.auth-features .feat-ic{ display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--r-md); background: rgba(255,255,255,.1); color: #fff; flex-shrink: 0; }
.auth-features .feat-ic .ic{ width: 18px; height: 18px; }
.auth-features strong{ display: block; color: #fff; }
.auth-aside-foot{ font-size: 13px; color: #9FB4DA; font-weight: 600; position: relative; z-index: 1; }

.auth-main{ display: flex; align-items: center; justify-content: center; padding: 84px var(--sp-6) var(--sp-10); }
.auth-card{
  width: 100%; max-width: 440px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: var(--sp-8); box-shadow: var(--shadow-md);
}
.auth-card.wide{ max-width: 540px; }
.auth-card .mobile-brand{ display: none; }
.auth-card .eyebrow{ display: block; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); margin-bottom: 6px; }
.auth-card h1{ font-size: var(--fs-2xl); font-weight: 800; margin-bottom: 6px; }
.auth-card .lead{ color: var(--text-2); font-size: var(--fs-sm); margin-bottom: var(--sp-6); line-height: 1.6; }
.auth-card .btn[type="submit"]{ width: 100%; margin-top: var(--sp-2); }
.auth-divider{ display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-5) 0; color: var(--text-3); font-size: 13px; font-weight: 600; }
.auth-divider::before, .auth-divider::after{ content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-switch{ text-align: center; margin-top: var(--sp-4); font-size: var(--fs-sm); color: var(--text-2); }
.auth-switch a{ cursor: pointer; }
.auth-foot{ text-align: center; margin-top: var(--sp-5); font-size: 13px; color: var(--text-3); }
.register-cta{
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  margin-top: var(--sp-5); padding: var(--sp-4); border-radius: var(--r-md);
  background: var(--primary-soft); border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
}
.register-cta strong{ display: block; color: var(--primary-ink); }
.register-cta span{ font-size: var(--fs-sm); color: var(--text-2); }
.register-cta .btn{ flex-shrink: 0; }
.auth-links{ margin-top: var(--sp-6); padding-top: var(--sp-5); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--sp-2); }

/* Segmented role picker (radio group) */
.segmented{ display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-3); border-radius: var(--r-md); }
.segmented input{ position: absolute; opacity: 0; pointer-events: none; }
.segmented label{
  display: flex; align-items: center; justify-content: center; min-height: 40px; margin: 0; padding: 6px 10px;
  border-radius: var(--r-sm); color: var(--text-2); font-size: var(--fs-sm); font-weight: 700; cursor: pointer; text-align: center;
}
.segmented label:hover{ color: var(--text); }
.segmented input:checked + label{ background: var(--surface); color: var(--primary-ink); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + label{ box-shadow: var(--focus-ring); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px){
  .content{ padding: var(--sp-5) var(--sp-5) var(--sp-8); }
  .topbar{ padding: var(--sp-3) var(--sp-5); }
  .two-col{ grid-template-columns: 1fr; }
  .two-col > .panel + .panel{ margin-top: 0; }
}

@media (max-width: 960px){
  .auth-wrap{ grid-template-columns: 1fr; }
  .auth-aside{ display: none; }
  .auth-main{ padding: calc(72px + env(safe-area-inset-top)) var(--sp-4) var(--sp-8); align-items: flex-start; }
  .auth-card .mobile-brand{ display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-6); }
  .auth-card .mobile-brand img{ width: 48px; height: 48px; border-radius: var(--r-md); }
  .auth-card .mobile-brand strong{ display: block; font: 800 16px/1.2 var(--font-display); }
  .auth-card .mobile-brand span{ font-size: 12.5px; color: var(--text-2); font-weight: 600; }
}

@media (max-width: 899px){
  .shell{ display: block; background: none; }
  .sidebar{ display: none; }
  .content{ padding: var(--sp-4) var(--sp-3) calc(var(--bottom-nav-h) + 28px + env(safe-area-inset-bottom)); }
  .topbar{ padding: calc(10px + env(safe-area-inset-top)) var(--sp-3) 10px; }
  .topbar h1{ font-size: var(--fs-lg); }
  .topbar-eyebrow{ font-size: 12px; }
  .topbar-date{ display: none; }
  .facility-logo{ width: 38px; height: 38px; }
  .topbar .phone-only{ display: inline-flex; }
  .topbar [data-action="install"] span{ display: none; }
  .topbar [data-action="install"]{ width: 42px; padding: 0; }
  .grid-2{ grid-template-columns: 1fr; }
  .panel, .card{ padding: var(--sp-4); border-radius: var(--r-md); margin-bottom: var(--sp-4); }
  .panel > h2, .card-header{ margin-bottom: var(--sp-4); }
  .strip, .stats{ grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-4); }
  .stat{ padding: var(--sp-4); }
  .stat-icon{ width: 32px; height: 32px; }
  .stat-value{ font-size: 19px; }

  .bottom-nav{
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(15,27,51,.08);
  }
  .bn-item{
    position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 54px; padding: 4px 2px; border: 0; border-radius: var(--r-md); background: transparent;
    color: var(--text-3); font: 700 11.5px/1.1 var(--font-sans); cursor: pointer;
  }
  .bn-item .ic{ width: 23px; height: 23px; }
  .bn-item.active{ color: var(--primary); }
  .bn-item.active .bn-ic-wrap{ background: var(--primary-soft); }
  .bn-ic-wrap{ display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 30px; border-radius: var(--r-pill); transition: background-color .15s var(--ease); }
  .bn-item .badge-count{ position: absolute; top: 2px; left: calc(50% + 6px); margin: 0; min-width: 18px; height: 18px; font-size: 10.5px; }

  /* Tables become stacked cards (labels come from data-label, set in js/ui/blocks.js) */
  #tabContent .table-wrap:has(table.stackable){ border: 0; overflow: visible; }
  table.stackable, table.stackable tbody, table.stackable tr, table.stackable td{ display: block; width: 100%; }
  table.stackable thead{ display: none; }
  table.stackable tr{ margin-bottom: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); padding: 6px 0; box-shadow: var(--shadow-xs); }
  table.stackable tbody tr:hover td{ background: transparent; }
  table.stackable td{ display: grid; grid-template-columns: auto minmax(0,1fr); column-gap: var(--sp-4); align-items: baseline; padding: 7px 14px; border: 0; text-align: right; }
  table.stackable td > *{ grid-column: 2; justify-self: end; }
  table.stackable td::before{ content: attr(data-label); grid-column: 1; grid-row: 1 / span 3; text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }
  table.stackable td:not([data-label])::before, table.stackable td[data-label=""]::before{ display: none; }
  table.stackable td:first-child{ font-size: var(--fs-md); }
  table.stackable td .cell-sub{ text-align: right; }
  table.stackable td.actions{ display: flex; width: 100%; justify-content: flex-end; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 10px; }
  table.stackable td.actions .row-actions{ flex-wrap: wrap; }
  table.stackable td.num{ white-space: normal; }

  .toast{ top: calc(12px + env(safe-area-inset-top)); bottom: auto; left: 12px; right: 12px; max-width: none; transform: translateY(-12px); }
  .toast.show{ transform: translateY(0); }

  .modal-overlay{ align-items: flex-end; padding: 0; }
  .modal-box{ max-width: none; border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92vh; padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom)); animation: slide-up .22s var(--ease); }
  .modal-box.wide{ max-width: none; }
  .modal-box::before{ content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: -8px auto var(--sp-3); }
  .modal-actions{ flex-direction: column-reverse; }
  .modal-actions .btn{ width: 100%; }
}

/* ---------- Sync status pill (top bar) ---------- */
.sync-pill{
  display: inline-flex; align-items: center; gap: 7px; max-width: 440px;
  padding: 6px 12px; border-radius: var(--r-pill); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font: inherit; font-size: var(--fs-xs); font-weight: 600;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 36px;
}
.sync-pill:hover{ border-color: var(--border-strong); background: var(--surface-2); }
.sync-pill:focus-visible{ outline: none; box-shadow: var(--focus-ring); }
.sync-pill .sp-long{ min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sync-pill .sp-short{ display: none; }
.sync-dot{ width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--text-3); }
.sync-pill.is-ok .sync-dot{ background: var(--success); }
.sync-pill.is-busy .sync-dot{ background: var(--info); animation: syncPulse 1.2s var(--ease) infinite; }
.sync-pill.is-offline{ background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.sync-pill.is-offline .sync-dot{ background: var(--warning); }
.sync-pill.is-warn{ background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.sync-pill.is-warn .sync-dot{ background: var(--danger); }
@keyframes syncPulse{ 50%{ opacity: .3; } }
@media (prefers-reduced-motion: reduce){ .sync-pill.is-busy .sync-dot{ animation: none; } }
@media (max-width: 899px){
  .sync-pill{ padding: 6px 10px; }
  .sync-pill .sp-long{ display: none; }
  .sync-pill .sp-short{ display: inline; }
}
