/* Governance overlay styles. All elements are appended to document.body as
   position:fixed so they're independent of React's DOM tree. The native
   Metabase error remains visible underneath the centered card — accepted by
   the spec. */

/* ── Design tokens ───────────────────────────────────────────────────────────
   Two layers: (1) Radix Colors primitive scales (slate / red / orange / green /
   blue), (2) semantic tokens that reference them. Dark mode swaps only the
   primitives — semantic names stay constant, so the rules below never change.
   Dark mode activates only via an explicit `[data-theme="dark"]` or `html.dark`
   selector (see below); it deliberately does NOT follow prefers-color-scheme. */
:root {
  /* ── Radix primitive scales (light) ── */
  --slate-1:  #fcfcfd;
  --slate-2:  #f9f9fb;
  --slate-3:  #f0f0f3;
  --slate-6:  #d9d9e0;
  --slate-7:  #cdced6;
  --slate-11: #60646c;
  --slate-12: #1c2024;

  --red-3:  #feebec;
  --red-9:  #e5484d;
  --red-11: #ce2c31;

  --orange-3:  #ffefd6;
  --orange-9:  #f76b15;
  --orange-10: #ef5f00;
  --orange-11: #cc4e00;

  --green-11: #218358;
  --blue-11:  #0d74ce;

  /* alpha layers — swapped in dark mode where it matters */
  --inset-translucent:        rgba(255, 255, 255, 0.6);
  --inset-translucent-strong: rgba(255, 255, 255, 0.7);
  --hover-alpha:              rgba(0, 0, 0, 0.06);
  --shadow-alpha-sm:          rgba(0, 0, 0, 0.06);
  --shadow-alpha-md:          rgba(0, 0, 0, 0.15);
  --shadow-alpha-lg:          rgba(0, 0, 0, 0.18);
  --shadow-alpha-xl:          rgba(0, 0, 0, 0.22);
  --backdrop-color:           rgba(15, 23, 42, 0.55);
  --warning-border-alpha:     rgba(247, 107, 21, 0.25);

  /* ── Semantic tokens (used everywhere below) ── */
  --gov-surface:                    var(--slate-1);
  --gov-surface-muted:              var(--slate-3);
  --gov-surface-translucent:        var(--inset-translucent);
  --gov-surface-translucent-strong: var(--inset-translucent-strong);

  --gov-text-strong:    var(--slate-12);
  --gov-text:           var(--slate-12);
  --gov-text-secondary: var(--slate-12);
  --gov-text-body:      var(--slate-11);
  --gov-text-muted:     var(--slate-11);
  --gov-text-subtle:    var(--slate-11);
  --gov-text-on-solid:  #fff;          /* text on filled brand buttons — constant */

  --gov-border:        var(--slate-6);
  --gov-border-strong: var(--slate-7);
  --gov-border-subtle: var(--slate-3);

  --gov-danger:                     var(--red-11);
  --gov-danger-bg:                  var(--red-3);
  --gov-warning:                    var(--orange-11);
  --gov-warning-solid:              var(--orange-9);
  --gov-warning-strong:             var(--orange-10);
  --gov-warning-bg:                 var(--orange-3);
  --gov-warning-bg-yellow:          var(--orange-3);
  --gov-warning-border-translucent: var(--warning-border-alpha);
  --gov-success:                    var(--green-11);
  --gov-info:                       var(--blue-11);

  --gov-shadow-sm: 0 2px 12px  var(--shadow-alpha-sm);
  --gov-shadow-md: 0 6px 24px  var(--shadow-alpha-md);
  --gov-shadow-lg: 0 8px 32px  var(--shadow-alpha-lg);
  --gov-shadow-xl: 0 16px 48px var(--shadow-alpha-xl);
  --gov-hover-bg:  var(--hover-alpha);

  --gov-backdrop:  var(--backdrop-color);

  --gov-font-sans: -apple-system, "BlinkMacSystemFont", "Segoe UI", sans-serif;
}

/* ── Dark mode: dormant until Metabase ships a dark toggle ──
   We deliberately do NOT use @media (prefers-color-scheme: dark) — Metabase
   itself stays light regardless of OS preference today, so a dark overlay
   would float on a white page. When Metabase adds a toggle, it will set one
   of the selectors below and the overlay will follow. Only primitive scales
   swap here; semantic tokens auto-follow. */
[data-theme="dark"], html.dark {
  --slate-1:  #18191b;
  --slate-2:  #18191b;
  --slate-3:  #212225;
  --slate-6:  #363a3f;
  --slate-7:  #43484e;
  --slate-11: #b0b4ba;
  --slate-12: #edeef0;
  --red-3:    #3b1219;
  --red-9:    #e5484d;
  --red-11:   #ff9592;
  --orange-3: #331e0b;
  --orange-9: #f76b15;
  --orange-10:#ff801f;
  --orange-11:#ffa057;
  --green-11: #3dd68c;
  --blue-11:  #70b8ff;
  --inset-translucent:        rgba(255, 255, 255, 0.04);
  --inset-translucent-strong: rgba(255, 255, 255, 0.06);
  --hover-alpha:              rgba(255, 255, 255, 0.06);
  --shadow-alpha-sm:          rgba(0, 0, 0, 0.4);
  --shadow-alpha-md:          rgba(0, 0, 0, 0.5);
  --shadow-alpha-lg:          rgba(0, 0, 0, 0.6);
  --shadow-alpha-xl:          rgba(0, 0, 0, 0.7);
  --backdrop-color:           rgba(0, 0, 0, 0.65);
  --warning-border-alpha:     rgba(247, 107, 21, 0.35);
}

.gov-card,
.gov-toast,
.gov-profile-card {
  font-family: var(--gov-font-sans);
  font-size: 13px;
  line-height: 1.6;
}

/* ── Error cards ─────────────────────────────────────────────────────────── */

.gov-card {
  position: fixed;
  z-index: 100;
  background: var(--gov-surface);
  border-radius: 8px;
  padding: 16px 20px 18px;
  box-shadow: var(--gov-shadow-lg);
  border-left: 6px solid var(--gov-danger);
  max-width: 640px;
  animation: gov-card-in 0.18s ease-out;
}

.gov-card-block {
  background: var(--gov-danger-bg);
  border-left-color: var(--gov-danger);
}

.gov-card-amber {
  background: var(--gov-warning-bg);
  border-left-color: var(--gov-warning);
}

.gov-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--gov-text-strong);
  margin-bottom: 6px;
  padding-right: 24px;
}

.gov-card-body {
  color: var(--gov-text-body);
  margin-bottom: 10px;
}

.gov-card-fix {
  background: var(--gov-surface-translucent);
  border-radius: 5px;
  padding: 8px 10px;
  margin-bottom: 10px;
  color: var(--gov-text);
}

.gov-card-fix-label {
  font-weight: 700;
  color: var(--gov-text-strong);
}

.gov-card-countdown {
  font-weight: 600;
  color: var(--gov-danger);
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
}

.gov-card-countdown-ready {
  color: var(--gov-success);
}

.gov-card-help {
  color: var(--gov-text-subtle);
  font-size: 12px;
  margin-top: 6px;
}

.gov-card-dismiss {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--gov-text-subtle);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.gov-card-dismiss:hover {
  background: var(--gov-hover-bg);
  color: var(--gov-text);
}

@keyframes gov-card-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Overlay anchored to native error block ────────────────────────────────
   Positioned via JS on top of Metabase's native error container. We don't
   modify React's tree at all — just hide its block with visibility:hidden
   and float ours on top. */

.gov-overlay {
  position: fixed;
  /* Below typical app modal layers (Mantine defaults to ~400 for Modal,
     ~300 for Popover). Above static page content. If Metabase ever opens
     a modal, its backdrop covers the card naturally — the user's not left
     with a governance card peeking through the dim. */
  z-index: 100;
  background: var(--gov-danger-bg);
  border-radius: 8px;
  padding: 14px 18px 16px;
  border-left: 6px solid var(--gov-danger);
  box-shadow: var(--gov-shadow-sm);
  text-align: left;
  box-sizing: border-box;
}

.gov-overlay-block {
  background: var(--gov-danger-bg);
  border-left-color: var(--gov-danger);
}

.gov-overlay-amber {
  background: var(--gov-warning-bg);
  border-left-color: var(--gov-warning);
}

/* ── Warn toast (top-right) ──────────────────────────────────────────────── */

.gov-toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  background: var(--gov-warning-bg-yellow);
  border-left: 4px solid var(--gov-warning);
  border-radius: 6px;
  padding: 12px 14px 14px;
  width: 360px;
  box-shadow: var(--gov-shadow-md);
  animation: gov-toast-in 0.2s ease-out;
}

.gov-toast-title {
  font-weight: 700;
  color: var(--gov-text-strong);
  margin-bottom: 4px;
  padding-right: 22px;
}

.gov-toast-body {
  color: var(--gov-text-body);
  font-size: 12.5px;
  margin-bottom: 6px;
}

.gov-toast-fix {
  font-size: 12.5px;
  color: var(--gov-text);
}

.gov-toast-dismiss {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 18px;
  color: var(--gov-text-subtle);
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}

.gov-toast-dismiss:hover {
  color: var(--gov-text);
}

@keyframes gov-toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Profile stats card ──────────────────────────────────────────────────── */

.gov-profile-card {
  background: var(--gov-surface);
  border: 1px solid var(--gov-border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 20px;
}

.gov-profile-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--gov-text-strong);
  margin-bottom: 14px;
}

.gov-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.gov-stat {
  text-align: center;
  background: var(--gov-surface-muted);
  border-radius: 6px;
  padding: 12px 8px;
}

.gov-stat-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--gov-info);
  font-variant-numeric: tabular-nums;
}

.gov-stat-val.gov-red   { color: var(--gov-danger); }
.gov-stat-val.gov-amber { color: var(--gov-warning); }

.gov-stat-label {
  font-size: 10.5px;
  color: var(--gov-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.gov-profile-qpm {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--gov-border-subtle);
  color: var(--gov-danger);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.gov-profile-qpm-ok {
  color: var(--gov-success);
}

/* ── Confirm modal (enforce_warn_mode=confirm) ───────────────────────────
   Centered "are you sure?" dialog shown when the proxy returned a confirm-
   kind gov payload. Backdrop is a full-viewport semi-transparent layer; the
   card is anchored at top-third for prominence. Styling matches the amber
   warning palette to signal "non-blocking but worth your attention". */

.gov-confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--gov-backdrop);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 18vh;
  animation: gov-card-in 0.16s ease-out;
  font-family: var(--gov-font-sans);
  font-size: 14px;
  line-height: 1.6;
}

.gov-confirm-card {
  background: var(--gov-warning-bg);
  border-radius: 10px;
  border-left: 6px solid var(--gov-warning);
  box-shadow: var(--gov-shadow-xl);
  padding: 22px 26px 20px;
  max-width: 560px;
  width: calc(100% - 32px);
}

.gov-confirm-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--gov-text-strong);
  margin-bottom: 10px;
}

.gov-confirm-body {
  color: var(--gov-text-body);
  margin-bottom: 12px;
  white-space: pre-wrap;
}

.gov-confirm-fix {
  background: var(--gov-surface-translucent-strong);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
  color: var(--gov-text);
}

.gov-confirm-help {
  color: var(--gov-text-muted);
  font-size: 12px;
  margin-bottom: 16px;
}

.gov-confirm-prompt {
  font-size: 14px;
  font-weight: 600;
  color: var(--gov-text-strong);
  margin: 6px 0 14px;
  padding-top: 12px;
  border-top: 1px solid var(--gov-warning-border-translucent);
}

.gov-confirm-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.gov-confirm-cancel,
.gov-confirm-proceed {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.1s ease;
}

.gov-confirm-cancel {
  background: var(--gov-surface);
  border-color: var(--gov-border-strong);
  color: var(--gov-text-body);
}

.gov-confirm-cancel:hover:not(:disabled) {
  background: var(--gov-surface-muted);
}

.gov-confirm-proceed {
  background: var(--gov-warning-solid);
  color: var(--gov-text-on-solid);
}

.gov-confirm-proceed:hover:not(:disabled) {
  background: var(--gov-warning-strong);
}

.gov-confirm-cancel:disabled,
.gov-confirm-proceed:disabled {
  opacity: 0.65;
  cursor: progress;
}

/* Inline "Query not run" note shown after Cancel. Anchored where the native
   error frame used to be (we keep that hidden — see clearConfirmModal). */
.gov-confirm-cancelled {
  z-index: 50;
  background: var(--gov-surface-muted);
  border: 1px dashed var(--gov-border-strong);
  border-radius: 8px;
  padding: 18px 22px;
  max-width: 520px;
  margin: 0 auto;
  font-family: var(--gov-font-sans);
  color: var(--gov-text-body);
  text-align: center;
  animation: gov-card-in 0.18s ease-out;
}

.gov-confirm-cancelled-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gov-text-secondary);
  margin-bottom: 4px;
}

.gov-confirm-cancelled-body {
  font-size: 13px;
  line-height: 1.5;
}
