/* =========================================================
   Guardios app: shell (sidebar, app bar, tab bar, focus layout), toasts, preview marks and the
   utility classes that replace the mockup's style="" attributes (CSP: style-src 'self').
   Plan 04-p2-design-system.md §4.1. Loaded after theme.css. App-only: the future website does
   not load this file.
   The mockup keyed the shell on <body data-layout="app">; here it is the class .g-layout-app,
   and data-tabbar="off" is .g-no-tabbar (set by the layouts, §7.2-7.3).
   ========================================================= */

/* ---------- KB 04 minimum ---------- */
/* Alpine: hide x-cloak elements until Alpine initializes them. */
[x-cloak] { display: none !important; }
/* HTMX request indicators (htmx's injected defaults are disabled for CSP). */
.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

/* ---------- Shell (mockup "APP SHELL") ---------- */
.g-shell { min-height: 100dvh; display: flex; flex-direction: column; }

.g-appbar { position: sticky; top: 0; z-index: 1020; height: calc(var(--g-appbar-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 0.6rem 0; display: flex; align-items: center; gap: 0.4rem; background: rgba(5, 9, 11, 0.82); backdrop-filter: saturate(160%) blur(16px); -webkit-backdrop-filter: saturate(160%) blur(16px); border-bottom: 1px solid var(--g-line); }
.g-appbar .g-appbar-title { flex: 1; min-width: 0; font-family: var(--g-display); font-weight: 600; font-size: 1.02rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-appbar .btn-icon { background: transparent; border: 0; color: var(--g-text); }
.g-appbar .btn-icon:hover { background: var(--g-surface-2); }
.g-appbar .btn-icon.disabled { opacity: 0.55; }
.g-appbar .g-badge-dot { position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--g-red); border: 2px solid var(--g-bg); }

.g-main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 1rem 1rem calc(var(--g-tabbar-h) + 1.5rem + env(safe-area-inset-bottom)); }
.g-main.wide { max-width: 1120px; }
.g-main.narrow { max-width: 460px; }
.g-no-tabbar .g-main { padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }

.g-page-head { margin: 0.4rem 0 1.1rem; }
.g-page-head h1 { font-size: 1.55rem; margin: 0 0 0.2rem; }
.g-page-head p { color: var(--g-muted); margin: 0; }

/* bottom tab bar (phones). Labels use --g-dim-text (Q1): primary navigation text. */
.g-tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; height: calc(var(--g-tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: rgba(8, 16, 20, 0.92); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-top: 1px solid var(--g-line); }
.g-tabbar > a, .g-tabbar > span { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--g-dim-text); font-size: 0.68rem; font-weight: 600; background: none; border: 0; }
.g-tabbar > span[aria-disabled="true"] { cursor: default; }
.g-tabbar i { font-size: 1.3rem; }
.g-tabbar > a.active { color: var(--g-mint); }
.g-tabbar .g-tab-cta { position: relative; top: -14px; color: var(--g-text); }
.g-tabbar .g-tab-cta span.g-fab { width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; background: var(--g-mint); color: #04130d; font-size: 1.5rem; box-shadow: 0 10px 30px -8px rgba(46, 229, 157, 0.7); }
.g-tabbar span.g-tab-cta span.g-fab { opacity: 0.6; box-shadow: none; }

/* sidebar (offcanvas below lg, pinned at lg in the app layout) */
.g-sidebar { --bs-offcanvas-width: var(--g-sidebar-w); background: var(--g-bg-2); border-right: 1px solid var(--g-line) !important; }
.g-sidebar .offcanvas-header { padding: calc(0.9rem + env(safe-area-inset-top)) 1rem 0.9rem; border-bottom: 1px solid var(--g-line); }
.g-sidebar .offcanvas-body { padding: 0.6rem 0.6rem 2rem; display: flex; flex-direction: column; }
.g-nav-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--g-dim-text); font-weight: 600; padding: 1rem 0.75rem 0.4rem; }
.g-nav a, .g-nav .g-nav-disabled { display: flex; align-items: center; gap: 0.75rem; padding: 0.55rem 0.75rem; border-radius: 10px; color: var(--g-muted); font-weight: 500; font-size: 0.92rem; }
.g-nav a i, .g-nav .g-nav-disabled i { font-size: 1.05rem; width: 20px; text-align: center; }
.g-nav a:hover { background: var(--g-surface-2); color: #fff; }
.g-nav a.active { background: var(--g-mint-soft); color: var(--g-mint); }
.g-nav .g-nav-disabled { cursor: default; }
.g-nav .g-pill { margin-left: auto; font-size: 0.64rem; padding: 0.1rem 0.45rem; }
.g-sidebar-account { margin-top: auto; padding: 0.75rem; border-top: 1px solid var(--g-line); display: flex; gap: 0.7rem; align-items: center; }
.g-sidebar-account form { margin: 0; }

/* plain icon button (sidebar sign-out): no surface, muted icon */
.g-btn-plain { --bs-btn-bg: transparent; --bs-btn-border-color: transparent; --bs-btn-color: var(--g-muted); --bs-btn-hover-bg: var(--g-surface-2); --bs-btn-hover-color: #fff; --bs-btn-hover-border-color: transparent; --bs-btn-active-bg: var(--g-surface-3); --bs-btn-active-border-color: transparent; width: 36px; height: 36px; font-size: 1rem; }

@media (min-width: 992px) {
  .g-layout-app .g-shell { padding-left: var(--g-sidebar-w); }
  .g-layout-app .g-sidebar.offcanvas-lg { position: fixed; top: 0; bottom: 0; left: 0; width: var(--g-sidebar-w); overflow-y: auto; display: flex; flex-direction: column; }
  .g-layout-app .g-sidebar.offcanvas-lg .offcanvas-header { display: flex !important; }
  /* Bootstrap's offcanvas-lg body does not grow at lg; growing keeps the account footer at the bottom. */
  .g-layout-app .g-sidebar.offcanvas-lg .offcanvas-body { flex-grow: 1; padding: 0.6rem 0.6rem 1rem; }
  .g-layout-app .g-tabbar { display: none; }
  .g-layout-app .g-main { padding-bottom: 3rem; }
  .g-layout-app .g-appbar .g-menu-btn { display: none; }
  .g-layout-app .g-appbar { padding-left: 1.2rem; padding-right: 1.2rem; }
  .g-main { padding-top: 1.6rem; }
}

/* focus layout (auth, invitation, onboarding): brand bar, no sidebar, no tab bar */
.g-focusbar { display: flex; align-items: center; justify-content: center; gap: 0.4rem; position: relative; padding: calc(0.9rem + env(safe-area-inset-top)) 1rem 0.9rem; }
.g-focusbar > .btn-icon { position: absolute; left: 0.6rem; background: transparent; border: 0; color: var(--g-text); }

/* ---------- Option cards: states the mockup did not need ---------- */
.g-option input:focus-visible + .g-option-body { box-shadow: 0 0 0 0.22rem rgba(46, 229, 157, 0.35); }
.g-option.is-disabled { cursor: not-allowed; }
.g-option.is-disabled .g-option-body { opacity: 0.6; }

/* ---------- Toasts (Django messages, ui/shell/toasts.html) ---------- */
/* Bottom centre, above the tab bar where it shows (mobile app layout); over the content column
   when the sidebar is fixed (lg+). Not at the top: there it covered the form being submitted. */
.g-toasts { position: fixed; bottom: env(safe-area-inset-bottom); left: 50%; transform: translateX(-50%); z-index: 1090; padding: 1rem; width: min(100%, 420px); }
.g-layout-app:not(.g-no-tabbar) .g-toasts { bottom: calc(var(--g-tabbar-h) + env(safe-area-inset-bottom)); }
@media (min-width: 992px) {
  .g-layout-app:not(.g-no-tabbar) .g-toasts { bottom: env(safe-area-inset-bottom); }
  .g-layout-app .g-toasts { left: calc(50% + var(--g-sidebar-w) / 2); }
}
.g-toast { background: var(--g-surface-3); color: #fff; border: 1px solid var(--g-line-2); border-radius: 14px; width: 100%; }
.g-toast .g-toast-icon { color: var(--g-blue); font-size: 1.05rem; }
.g-toast.success .g-toast-icon { color: var(--g-mint); }
.g-toast.warning .g-toast-icon { color: var(--g-amber); }
.g-toast.danger { border-color: rgba(255, 77, 94, 0.45); }
.g-toast.danger .g-toast-icon { color: var(--g-red); }

/* ---------- Preview / sample marks (pre-plan §4.9; used from P5) ---------- */
.g-preview-banner b { font-weight: 600; }
.g-sample-badge { vertical-align: middle; }
.g-sample { position: relative; border-style: dashed !important; }

/* ---------- Empty state ---------- */
.g-empty { text-align: center; padding: 2rem 1rem; color: var(--g-muted); display: flex; flex-direction: column; align-items: center; }

/* ---------- Segmented filter: entries without a page yet ---------- */
.g-seg .g-seg-disabled { flex: 0 0 auto; border-radius: 999px; padding: 0.4rem 0.9rem; font-size: 0.84rem; font-weight: 600; background: var(--g-surface-2); border: 1px solid var(--g-line); color: var(--g-dim-text); cursor: default; }

/* =========================================================
   Utilities replacing the mockup's style="" attributes. Named after what they are for; the
   per-page remainder is ported with its page (P3/P5) against this vocabulary.
   ========================================================= */
/* text sizes (mockup: font-size .6rem-.95rem on labels and captions) */
.g-text-2xs { font-size: 0.62rem; }
.g-text-xs { font-size: 0.75rem; }
.g-text-sm { font-size: 0.85rem; }
.g-caption { font-size: 0.72rem; } /* quick-action labels */
.g-pill.xs { font-size: 0.62rem; padding: 0.12rem 0.45rem; }
/* icon tiles and buttons */
.g-ico.sm { width: 34px; height: 34px; flex-basis: 34px; border-radius: 10px; font-size: 1rem; }
.g-ico.md { width: 38px; height: 38px; flex-basis: 38px; }
.g-ico.xl { width: 56px; height: 56px; flex-basis: 56px; font-size: 1.1rem; }
.btn-icon.sm { width: 32px; height: 32px; font-size: 0.9rem; }
.g-ico.wa, .text-wa { color: #25d366; }
.text-blue { color: var(--g-blue) !important; }
/* fixed-width cards in horizontal scrollers (mockup: width:136px) */
.g-tile { width: 136px; }
/* chart canvases (mockup: height 120/170/220/280px) */
.g-chart { position: relative; width: 100%; height: 220px; }
.g-chart.h-sm { height: 120px; }
.g-chart.h-md { height: 170px; }
.g-chart.h-lg { height: 280px; }
/* input group with a trailing button (password reveal) */
.g-input-group-end > .form-control { border-right: 0; }
.g-input-group-end > .btn { border-radius: 0 var(--g-radius-sm) var(--g-radius-sm) 0; }
/* dashed "add" card */
.g-dashed { border-style: dashed !important; cursor: pointer; }
/* live-call banner on the cockpit (white dot, translucent button) */
.g-risk .g-live-dot.on-risk { background: #fff; }
.g-risk .btn-on-risk { background: rgba(255, 255, 255, 0.18); color: #fff; }
.g-risk.compact { padding: 0.8rem 1rem; }
.g-border-red { border-color: rgba(255, 77, 94, 0.4) !important; }

/* ---- P3 port ---------------------------------------------------------------------------- */
.btn-icon-lg { width: 56px; flex: 0 0 56px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.g-quick { display: block; text-align: center; padding: 0.9rem 0.25rem; color: #fff; }
.g-quick.is-disabled { opacity: 0.55; cursor: default; }
.g-quick i { font-size: 1.5rem; }
.g-settings-section { scroll-margin-top: calc(var(--g-appbar-h) + 1rem); }
.g-avatar.lg { width: 56px; height: 56px; flex-basis: 56px; font-size: 1.1rem; }

/* ---------- P3 organizations ---------- */
.g-role-select { max-width: 130px; }
@media (min-width: 576px) { .g-invite-btn { min-width: 120px; } }
.g-filter-select { max-width: 320px; }
/* A row whose actions drop below the text on phones (pending invitation links). */
.g-row.g-row-wrap { flex-wrap: wrap; }
/* Explanatory row text that must stay readable (rows truncate by default). */
.g-row .g-row-sub.g-wrap, .g-row .g-row-title.g-wrap { white-space: normal; }
.g-row.g-row-wrap .g-row-main { flex-basis: 12rem; }

/* ---------- P3 calls ---------- */
/* Search field icon (history): the input group's addon on the field surface. */
.input-group-text.g-input-icon { background: var(--g-surface-2); border-color: var(--g-line-2); color: var(--g-muted); }
.g-debug-log { max-height: 240px; overflow-y: auto; white-space: pre-wrap; background: var(--g-surface-2); border: 1px solid var(--g-line); border-radius: var(--g-radius-sm); padding: 0.6rem; color: var(--g-muted); }
