/* App shell — left sidebar (desktop) / slide-in drawer (phone, tablet) + top bar.
   Mounted by public/js/app-shell.js after showDashboard(). All rules are scoped
   to body.has-shell so the login page and the public /report page are untouched.
   Stacking: shell sits below every full-screen overlay (admin 400, forms 500+),
   above the FAB (50). */

:root {
  --shell-w: 260px;
  --shell-bar-h: 56px;
  --shell-bg: var(--navy-900, #061F35);
  --shell-bg-2: #0B2D49;
  --shell-line: rgba(255, 255, 255, 0.10);
  --shell-text: rgba(255, 255, 255, 0.78);
  --shell-text-strong: #fff;
  --shell-active-bg: rgba(43, 191, 212, 0.16);
  --shell-active-bar: var(--cyan, #2BBFD4);
}

/* The old hero (logo, buttons, wrapping site tabs) is replaced by the shell.
   Elements stay in the DOM because switchSite() and the admin alert code still
   look them up by id; they are just not displayed. */
body.has-shell .cur-dhero { display: none; }
body.has-shell #dashboardRoot { padding-top: var(--shell-bar-h); }

/* ── Top bar ───────────────────────────────────────────── */
#shellTopbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--shell-bar-h);
  z-index: 100; display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--cur-gray-100, #EEF2F2);
  color: var(--ink, #06243B); font-family: var(--f-sans, inherit);
}
#shellTopbar .sh-burger {
  width: 44px; height: 44px; border: none; background: transparent; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: inherit;
}
#shellTopbar .sh-burger:active { background: var(--aqua-50, #EFFAFB); }
#shellTopbar .sh-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#shellTopbar .sh-sub { font-size: 11.5px; color: var(--cur-gray-500, #6E8085); margin-left: 2px; white-space: nowrap; }
#shellTopbar .sh-spacer { flex: 1; }

/* Sync chip — connection state + pending count. Always visible, drawer open or not. */
#shellSyncChip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  font: 600 12px/1 var(--f-sans, inherit); background: rgba(31, 158, 110, 0.12); color: var(--cur-success, #1F9E6E);
}
#shellSyncChip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
#shellSyncChip.offline { background: #FFF1E0; color: var(--amber-700, #B26A12); }
#shellSyncChip.pending { background: #FFF1E0; color: var(--amber-700, #B26A12); }

/* ── Sidebar / drawer ───────────────────────────────────── */
#shellSidebar {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, var(--shell-w));
  z-index: 160; display: flex; flex-direction: column;
  background: var(--shell-bg); color: var(--shell-text);
  transform: translateX(-102%); transition: transform 0.22s ease;
  font-family: var(--f-sans, inherit); overflow-y: auto; -webkit-overflow-scrolling: touch;
}
body.shell-open #shellSidebar { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, 0.45); }
#shellScrim {
  position: fixed; inset: 0; z-index: 150; background: rgba(6, 36, 59, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
body.shell-open #shellScrim { opacity: 1; pointer-events: auto; }

#shellSidebar .sh-brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; }
#shellSidebar .sh-brand img { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; background: #fff; }
#shellSidebar .sh-brand b { color: var(--shell-text-strong); font-size: 16px; display: block; line-height: 1.1; }
#shellSidebar .sh-brand span { font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; }
#shellSidebar .sh-close { margin-left: auto; width: 40px; height: 40px; border: none; background: transparent; color: inherit; font-size: 22px; cursor: pointer; border-radius: 10px; }

#shellSidebar .sh-org { margin: 4px 12px 8px; border: 1px solid var(--shell-line); border-radius: 14px; background: var(--shell-bg-2); }
#shellSidebar .sh-org-btn {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-height: 52px;
  background: transparent; border: none; color: inherit; cursor: pointer; text-align: left; font: inherit;
}
#shellSidebar .sh-org-btn .ini {
  width: 32px; height: 32px; border-radius: 9px; background: var(--sea-800, #0E7490); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex: none;
}
#shellSidebar .sh-org-btn .nm { color: var(--shell-text-strong); font-weight: 600; font-size: 13.5px; display: block; }
#shellSidebar .sh-org-btn .sb { font-size: 11px; opacity: 0.7; display: block; }
#shellSidebar .sh-org-btn .chev { margin-left: auto; transition: transform 0.15s ease; }
#shellSidebar .sh-org.open .chev { transform: rotate(180deg); }
#shellSidebar .sh-org-list { display: none; padding: 0 6px 6px; }
#shellSidebar .sh-org.open .sh-org-list { display: block; }

#shellSidebar .sh-group { padding: 10px 20px 4px; font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.55; }
#shellSidebar .sh-item {
  display: flex; align-items: center; gap: 12px; width: calc(100% - 16px); margin: 1px 8px; padding: 0 12px;
  min-height: 44px; border: none; border-radius: 12px; background: transparent; color: inherit;
  font: 600 14px/1.2 var(--f-sans, inherit); text-align: left; cursor: pointer; position: relative;
}
#shellSidebar .sh-item:hover { background: rgba(255, 255, 255, 0.06); }
#shellSidebar .sh-item.on { background: var(--shell-active-bg); color: var(--shell-text-strong); }
#shellSidebar .sh-item.on::before { content: ""; position: absolute; left: -8px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--shell-active-bar); }
#shellSidebar .sh-org-list .sh-item { min-height: 40px; font-weight: 500; font-size: 13px; }
#shellSidebar .sh-flex { flex: 1; min-height: 12px; }
#shellSidebar .sh-foot { border-top: 1px solid var(--shell-line); padding: 8px 0 12px; }
#shellSidebar .sh-user { display: flex; align-items: center; gap: 10px; padding: 8px 20px 4px; font-size: 12px; }
#shellSidebar .sh-user .av { width: 30px; height: 30px; border-radius: 50%; background: var(--sand-200, #E8DCC2); color: var(--ink, #06243B); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px; }
#shellSidebar .sh-user .nm { color: var(--shell-text-strong); font-weight: 600; }
#shellSidebar button:focus-visible, #shellTopbar button:focus-visible { outline: 2px solid var(--cyan, #2BBFD4); outline-offset: 2px; }

/* ── Desktop / large tablet: sidebar is permanent ───────── */
@media (min-width: 1024px) {
  #shellSidebar { transform: none; width: var(--shell-w); box-shadow: none; }
  #shellScrim { display: none; }
  #shellTopbar { left: var(--shell-w); }
  #shellTopbar .sh-burger, #shellSidebar .sh-close { display: none; }
  body.has-shell #app { padding-left: var(--shell-w); }
  /* The FAB tracks the centred content column, which is now offset by half the sidebar. */
  body.has-shell .cur-fab { right: calc(50% - (var(--shell-w) / 2) - 320px + 18px); }
}
@media (min-width: 1100px) {
  body.has-shell .cur-fab { right: calc(50% - (var(--shell-w) / 2) - 360px + 18px); }
}

/* ── Nav badge ───────────────────────────────────────────── */
#shellSidebar .sh-badge {
  margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--amber, #E8A13C); color: #3b2500; font: 700 11.5px/22px var(--f-sans, inherit); text-align: center;
}
#shellSidebar .sh-badge[hidden] { display: none; }

/* ── In-shell views (Sync & offline, future pages) ──────────
   Fills the content area so the sidebar and top bar stay visible.
   Sits above the dashboard and FAB, below the shell chrome and every overlay. */
#shellView {
  position: fixed; top: var(--shell-bar-h); left: 0; right: 0; bottom: 0; z-index: 90;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, var(--aqua-50, #EFFAFB) 0%, #fff 30%, var(--aqua-50, #EFFAFB) 100%);
  font-family: var(--f-sans, inherit); color: var(--ink, #06243B);
}
#shellView .sv-wrap { max-width: 640px; margin: 0 auto; padding: 18px 16px 48px; }
#shellView .sv-title { font-size: 22px; margin: 4px 0 14px; }
#shellView .sv-card { background: #fff; border-radius: 16px; padding: 16px; margin-bottom: 14px; box-shadow: 0 6px 20px -12px rgba(6, 36, 59, 0.3); border: 1px solid var(--cur-gray-100, #EEF2F2); }
#shellView .sv-h { font-weight: 700; font-size: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
#shellView .sv-n { margin-left: auto; background: var(--aqua-100, #DEF6F9); color: var(--sea-900, #0B4A5A); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
#shellView .sv-row { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--cur-gray-100, #EEF2F2); font-size: 14px; }
#shellView .sv-state { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
#shellView .sv-state .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
#shellView .sv-state.ok { color: var(--cur-success, #1F9E6E); }
#shellView .sv-state.warn { color: var(--amber-700, #B26A12); }
#shellView .sv-empty, #shellView .sv-help { font-size: 13px; color: var(--cur-gray-500, #6E8085); line-height: 1.45; }
#shellView .sv-help { margin: 12px 0 0; }
#shellView .sv-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
#shellView .sv-btn { min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1.5px solid var(--aqua-200, #B9EBF1); background: #fff; color: var(--sea-800, #0E7490); font: 600 14px var(--f-sans, inherit); cursor: pointer; }
#shellView .sv-btn.primary { background: linear-gradient(180deg, var(--sea-600, #16A6C4), var(--sea-800, #0E7490)); color: #fff; border-color: transparent; }
#shellView .sv-btn:disabled { opacity: 0.5; cursor: default; }
@media (min-width: 1024px) { #shellView { left: var(--shell-w); } }

@media (prefers-reduced-motion: reduce) {
  #shellSidebar, #shellScrim { transition: none; }
}
#shellTopbar .sh-back { border: 1px solid var(--aqua-200, #BFE7EC); background: #fff; color: var(--teal-700, #0E7490); font: 600 14px/1 inherit; padding: 8px 12px; border-radius: 10px; cursor: pointer; margin-right: 8px; min-height: 36px; }
#shellTopbar .sh-back[hidden] { display: none; }
#shellTopbar .sh-back:hover { background: var(--aqua-50, #EFFAFB); }
