/* ============================================================================
 * app.css — Shopify-admin-style design system for the Stealth Health reporting
 * portal.
 *
 * Loaded on every page (injected by auth.js, which also builds the app shell:
 * a light left sidebar + slim top bar, and wraps each page's content into the
 * scrollable main area).
 *
 * Two layers live here:
 *   1. The SHELL  — .app-shell / .app-sidebar / .app-topbar / .app-main and the
 *      sidebar nav. These are brand-new class names so they never collide with
 *      a page's own inline CSS.
 *   2. COMPONENT OVERRIDES — the component classes that pages already use
 *      (.btn, .panel, table, .filters, .field, .switch, .toast, …) restyled to
 *      the new look. Every override is scoped under `body.app-shelled` so it
 *      reliably wins over a page's inline single-class rules without us having
 *      to delete the legacy CSS from 15 files.
 * ============================================================================ */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;450;500;600;700&display=swap");

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Surfaces */
  --canvas: #f1f2f4;
  --surface: #ffffff;
  --surface-subdued: #fafbfb;
  --surface-hover: #f6f6f7;
  --sidebar-bg: #fbfbfb;

  /* Lines */
  --border: #e3e3e3;
  --border-strong: #d2d5d8;

  /* Ink */
  --ink: #303030;
  --ink-muted: #616161;
  --ink-subtle: #8c9196;

  /* Brand (Stealth teal) — light tint for accents, strong shade for actions */
  --brand: #48aa8d;
  --brand-tint: #e8f5f0;
  --brand-strong: #1f7a63;
  --brand-strong-hover: #196552;
  --brand-ring: rgba(31, 122, 99, 0.28);

  /* Status */
  --success: #0f7b53; --success-bg: #ecfdf5;
  --warning: #b45309; --warning-bg: #fef3c7;
  --critical: #d72c0d; --critical-bg: #fef2f2;
  --info: #1f5199; --info-bg: #ebf2fc;

  /* Radii + shadow (Polaris-ish) */
  --r-sm: 8px; --r-md: 10px; --r-lg: 14px;
  --shadow-xs: 0 1px 0 rgba(26, 28, 33, 0.05);
  --shadow-sm: 0 1px 2px rgba(26, 28, 33, 0.07), 0 0 1px rgba(26, 28, 33, 0.10);
  --shadow-md: 0 4px 16px rgba(26, 28, 33, 0.08), 0 1px 3px rgba(26, 28, 33, 0.06);
  --shadow-lg: 0 18px 44px rgba(26, 28, 33, 0.16), 0 3px 10px rgba(26, 28, 33, 0.08);

  --sidebar-w: 240px;
  --topbar-h: 56px;
}

/* ===========================================================================
 * SHELL
 * ======================================================================== */

body.app-shelled {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

/* --- Sidebar ------------------------------------------------------------- */
.app-sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: var(--sidebar-w);
  height: 100vh;
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 40;
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 14px;
  text-decoration: none;
  color: var(--ink);
  position: sticky;
  top: 0;
  background: var(--sidebar-bg);
  z-index: 1;
}
.app-brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; letter-spacing: -0.5px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.app-brand-name { font-size: 15px; font-weight: 700; letter-spacing: -0.2px; line-height: 1.1; }
.app-brand-name span { display: block; font-size: 10.5px; font-weight: 600; color: var(--ink-subtle); letter-spacing: 0.4px; text-transform: uppercase; margin-top: 1px; }

.app-nav { padding: 4px 10px 16px; }
.app-nav-group { margin-top: 14px; }
.app-nav-group:first-child { margin-top: 4px; }
.app-nav-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--ink-subtle);
  padding: 6px 10px 4px;
}
.app-nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: var(--r-sm);
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}
.app-nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.app-nav-link:hover { background: var(--surface-hover); color: var(--ink); }
.app-nav-link:focus-visible { outline: 2px solid var(--brand-strong); outline-offset: 1px; }
.app-nav-link.active {
  background: var(--brand-tint);
  color: var(--brand-strong);
  font-weight: 600;
}
.app-nav-link.active svg { opacity: 1; }

/* --- Frame + topbar ------------------------------------------------------ */
.app-frame {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.app-topbar {
  position: sticky; top: 0;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.app-topbar-title { font-size: 15px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.app-hamburger {
  display: none;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: #fff; cursor: pointer; color: var(--ink-muted);
}
.app-hamburger svg { width: 18px; height: 18px; }

.app-search {
  flex: 1 1 200px;
  min-width: 0;
  max-width: 420px;
  margin: 0 16px;
  position: relative;
}
/* Scoped via .app-topbar so it outranks the generic body.app-shelled
   input[type=search] component override below (which would otherwise reset
   the padding/shape). */
body.app-shelled .app-topbar .app-search input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-subdued);
  padding: 0 14px 0 36px;
  font-size: 13.5px; color: var(--ink);
  font-family: inherit;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.app-search input::placeholder { color: var(--ink-subtle); }
body.app-shelled .app-topbar .app-search input:focus { background: #fff; border-color: var(--brand-strong); box-shadow: 0 0 0 3px var(--brand-ring); }
.app-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-subtle); pointer-events: none; }

.app-account { display: flex; align-items: center; gap: 10px; margin-left: auto; flex: 0 0 auto; }
.app-role {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px;
  color: var(--ink-muted); background: var(--surface-hover); border: 1px solid var(--border);
}
.app-role[data-role="admin"]           { color: #6d3bd6; background: #f1ecfd; border-color: #e0d4fb; }
.app-role[data-role="whiteLabelAdmin"]  { color: #9a6700; background: #fff6e0; border-color: #f6e2ad; }
.app-role[data-role="doctor"]           { color: var(--info); background: var(--info-bg); border-color: #cfe0f7; }
.app-role[data-role="prescriber"]       { color: #a3148a; background: #fdeaf8; border-color: #f6cdec; }
.app-role[data-role="pharmacy"],
.app-role[data-role="pharmacyTech"],
.app-role[data-role="pharmacyNetwork"]  { color: var(--success); background: var(--success-bg); border-color: #c6efdd; }

.app-domain {
  font-size: 11px; font-weight: 600; color: var(--info);
  background: var(--info-bg); border: 1px solid #cfe0f7;
  padding: 3px 9px; border-radius: 999px;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-email { font-size: 12.5px; color: var(--ink-muted); max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-logout {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-muted);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 6px 11px; background: #fff; cursor: pointer; text-decoration: none;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}
.app-logout svg { width: 14px; height: 14px; }
.app-logout:hover { color: var(--critical); background: var(--critical-bg); border-color: #f6cabf; }

/* --- Main content area --------------------------------------------------- */
.app-main {
  flex: 1 1 auto;
  min-width: 0;
}
/* The page's own `.container` is moved inside .app-main by auth.js. Normalise it. */
body.app-shelled .container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 26px 28px 64px;
}

/* Sidebar scrim (mobile) */
.app-scrim-nav {
  display: none;
  position: fixed; inset: 0;
  background: rgba(26, 28, 33, 0.4);
  z-index: 39;
}
.app-scrim-nav.open { display: block; }

/* ===========================================================================
 * COMPONENT OVERRIDES (scoped under body.app-shelled to beat inline page CSS)
 * ======================================================================== */

/* --- Page header pattern (page-head / page-title / page-subtitle) -------- */
body.app-shelled .page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; color: var(--ink); }
body.app-shelled .page-subtitle { color: var(--ink-muted); }
body.app-shelled .page-pill {
  background: var(--brand-tint); color: var(--brand-strong); border: 1px solid #cfeadf;
}

/* --- Buttons ------------------------------------------------------------- */
body.app-shelled .btn,
body.app-shelled .btn-primary,
body.app-shelled .btn-save,
body.app-shelled .btn-primary-action,
body.app-shelled button.primary {
  background: var(--brand-strong);
  border: 1px solid var(--brand-strong);
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  border-radius: var(--r-sm);
  padding: 9px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
  font-family: inherit;
}
body.app-shelled .btn:hover,
body.app-shelled .btn-primary:hover,
body.app-shelled .btn-save:hover,
body.app-shelled .btn-primary-action:hover,
body.app-shelled button.primary:hover { background: var(--brand-strong-hover); filter: none; }
body.app-shelled .btn:disabled,
body.app-shelled .btn-primary-action:disabled,
body.app-shelled .btn:disabled:hover { opacity: 0.5; cursor: not-allowed; }

body.app-shelled .btn-ghost,
body.app-shelled .btn-secondary,
body.app-shelled .btn-cancel {
  background: #fff;
  border: 1px solid var(--border-strong);
  color: var(--ink);
  font-weight: 600; font-size: 13.5px;
  border-radius: var(--r-sm);
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background 150ms ease, border-color 150ms ease;
  font-family: inherit;
}
body.app-shelled .btn-ghost:hover,
body.app-shelled .btn-secondary:hover,
body.app-shelled .btn-cancel:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--ink); }

/* --- Cards / panels / filters ------------------------------------------- */
body.app-shelled .panel,
body.app-shelled .filters,
body.app-shelled .card,
body.app-shelled .summary-card,
body.app-shelled .table-wrap,
body.app-shelled .table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
body.app-shelled .panel { padding: 22px 24px; }
body.app-shelled .filters { padding: 16px 18px; }

/* --- Stat / summary cards ------------------------------------------------ */
body.app-shelled .summary,
body.app-shelled .stats,
body.app-shelled .kpis { gap: 14px; }
body.app-shelled .summary-card,
body.app-shelled .stat-card,
body.app-shelled .stat,
body.app-shelled .kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}

/* --- Tables (resource-list look) ---------------------------------------- */
body.app-shelled table { width: 100%; border-collapse: collapse; background: var(--surface); }
body.app-shelled th {
  text-align: left;
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--ink-subtle);
  padding: 11px 14px;
  background: var(--surface-subdued);
  border-bottom: 1px solid var(--border);
}
body.app-shelled td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px; color: var(--ink);
  vertical-align: middle;
}
body.app-shelled tbody tr { transition: background 120ms ease; }
body.app-shelled tbody tr:hover { background: var(--surface-subdued); }
body.app-shelled tr:last-child td { border-bottom: none; }

/* --- Forms --------------------------------------------------------------- */
body.app-shelled input[type=text],
body.app-shelled input[type=url],
body.app-shelled input[type=number],
body.app-shelled input[type=search],
body.app-shelled input[type=email],
body.app-shelled input[type=date],
body.app-shelled input[type=password],
body.app-shelled select,
body.app-shelled textarea,
body.app-shelled .filter-group input,
body.app-shelled .filter-group select,
body.app-shelled .field input,
body.app-shelled .field select,
body.app-shelled .field textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 9px 11px;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  outline: none;
  font-family: inherit;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
body.app-shelled input:focus,
body.app-shelled select:focus,
body.app-shelled textarea:focus { border-color: var(--brand-strong); box-shadow: 0 0 0 3px var(--brand-ring); }
body.app-shelled label,
body.app-shelled .filter-group label,
body.app-shelled .field label { color: var(--ink-muted); }

/* --- Tabs (section-tabs / mode-tab / drawer-tab) ------------------------- */
body.app-shelled .section-tabs,
body.app-shelled .mode-tabs,
body.app-shelled .tabs { border-bottom: 1px solid var(--border); }
body.app-shelled .section-tab,
body.app-shelled .mode-tab,
body.app-shelled .tab {
  color: var(--ink-muted); font-weight: 600; font-size: 13.5px;
  background: transparent; border: none; cursor: pointer;
  padding: 10px 14px; border-bottom: 2px solid transparent;
}
body.app-shelled .section-tab:hover,
body.app-shelled .mode-tab:hover,
body.app-shelled .tab:hover { color: var(--ink); }
body.app-shelled .section-tab.active,
body.app-shelled .mode-tab.active,
body.app-shelled .tab.active { color: var(--brand-strong); border-bottom-color: var(--brand-strong); }

/* --- iOS switch ---------------------------------------------------------- */
body.app-shelled .switch input:checked + .slider { background: var(--brand-strong); }

/* --- Badges / pills / chips / flags ------------------------------------- */
body.app-shelled .flag { background: var(--surface-hover); color: var(--ink-muted); border-radius: 6px; }
body.app-shelled .flag.on { background: var(--success-bg); color: var(--success); }
body.app-shelled .flag.off { background: var(--critical-bg); color: var(--critical); }
body.app-shelled .chip { background: var(--brand-tint); color: var(--brand-strong); }
body.app-shelled .pill { border-radius: 999px; }

/* --- Drawer / scrim ------------------------------------------------------ */
body.app-shelled .drawer { box-shadow: var(--shadow-lg); }
body.app-shelled .drawer-head,
body.app-shelled .drawer-foot { border-color: var(--border); }

/* --- Toast --------------------------------------------------------------- */
body.app-shelled .toast { border-radius: var(--r-md); box-shadow: var(--shadow-lg); }

/* --- Empty / loading states --------------------------------------------- */
body.app-shelled .empty-state, body.app-shelled .loading { color: var(--ink-muted); }
body.app-shelled .spinner { border-top-color: var(--brand-strong); }

/* --- Links --------------------------------------------------------------- */
body.app-shelled a { color: var(--brand-strong); }

/* --- Common page aliases (report/finance pages) -------------------------- */
body.app-shelled .table-wrapper,
body.app-shelled .table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
body.app-shelled .table-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
body.app-shelled .table-header h2 { font-size: 15px; font-weight: 600; color: var(--ink); margin: 0; }
body.app-shelled .count { color: var(--ink-subtle); font-size: 12.5px; font-weight: 500; }
body.app-shelled .export-btn,
body.app-shelled .add-btn,
body.app-shelled .secondary-btn {
  background: #fff;
  border: 1px solid var(--border-strong);
  color: var(--ink);
  font-weight: 600; font-size: 13px;
  border-radius: var(--r-sm);
  padding: 7px 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 150ms ease, border-color 150ms ease;
}
body.app-shelled .export-btn:hover,
body.app-shelled .add-btn:hover,
body.app-shelled .secondary-btn:hover { background: var(--surface-hover); }
body.app-shelled .add-btn { background: var(--brand-strong); border-color: var(--brand-strong); color: #fff; }
body.app-shelled .add-btn:hover { background: var(--brand-strong-hover); }
body.app-shelled .btn-danger,
body.app-shelled .danger { background: var(--critical); border-color: var(--critical); color: #fff; }
body.app-shelled .toolbar { gap: 10px; }

/* ===========================================================================
 * RESPONSIVE — sidebar becomes an off-canvas drawer under 900px
 * ======================================================================== */
@media (max-width: 1120px) {
  .app-email { display: none; }
}

@media (max-width: 900px) {
  .app-hamburger { display: inline-flex; }
  .app-search { display: none; }
  .app-account .app-role { display: none; }
  .app-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open { transform: translateX(0); }
  body.app-shelled .container { padding: 18px 16px 48px; }
}

@media (prefers-reduced-motion: reduce) {
  .app-nav-link, .app-sidebar, .app-logout, body.app-shelled tbody tr { transition: none; }
}
