/* deploy-marker: glass-fix-v3 */
/* Liquid glass material layer v2 (LIQUID_GLASS_CSS_SPEC.md). Loaded LAST so
   it wins the cascade over the component sheets. The v1 pass read as flat:
   panels were translucent but the page behind them was a near-white wash, so
   there was nothing to refract. v2 = vivid animated blob field + lower-alpha
   fills + the four-part specular rim + layered depth. */

:root {
  --glass-fill:        rgba(255, 255, 255, 0.62);
  --glass-fill-strong: rgba(255, 255, 255, 0.78);
  --glass-fill-tab:    rgba(245, 245, 247, 0.55);
  --glass-sat: 180%;
  --edge-light:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 1px 0 0 rgba(255, 255, 255, 0.45),
    inset -1px 0 0 rgba(255, 255, 255, 0.20),
    inset 0 -1px 0 rgba(0, 0, 0, 0.04);
  --rim: 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  --depth-1: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
  --depth-2: 0 2px 6px rgba(0,0,0,0.06), 0 18px 50px rgba(0,0,0,0.12);
  --depth-3: 0 4px 14px rgba(0,0,0,0.10), 0 40px 90px rgba(0,0,0,0.22);
  --blob-a: rgba(110, 165, 255, 0.70);
  --blob-b: rgba(185, 150, 255, 0.58);
  --blob-c: rgba(255, 180, 145, 0.52);
  --blob-d: rgba(135, 170, 255, 0.55); /* center blob — gives centered cards color to refract */
  --gate-fill: rgba(255, 255, 255, 0.45);
  --bg-base: #eef0f7;
  --sheen: linear-gradient(180deg, rgba(255,255,255,0.22), rgba(255,255,255,0) 38%);
  --spring-soft: 360ms cubic-bezier(0.22, 1, 0.36, 1);
}
[data-theme="dark"] {
  --glass-fill:        rgba(28, 28, 30, 0.58);
  --glass-fill-strong: rgba(28, 28, 30, 0.72);
  --glass-fill-tab:    rgba(40, 40, 44, 0.5);
  --edge-light:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    inset 1px 0 0 rgba(255, 255, 255, 0.07),
    inset 0 -1px 0 rgba(0, 0, 0, 0.5);
  --rim: 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  --depth-1: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.5);
  --depth-2: 0 2px 6px rgba(0,0,0,0.5), 0 18px 50px rgba(0,0,0,0.6);
  --depth-3: 0 4px 14px rgba(0,0,0,0.6), 0 40px 90px rgba(0,0,0,0.75);
  --blob-a: rgba(60, 90, 200, 0.40);
  --blob-b: rgba(110, 70, 200, 0.32);
  --blob-c: rgba(120, 30, 30, 0.10); /* the barely-there red glow, danger-adjacent only */
  --blob-d: rgba(80, 100, 220, 0.28);
  --gate-fill: rgba(28, 28, 30, 0.55);
  --bg-base: #16161a;
  --sheen: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0) 40%);
}
/* System dark when no manual override */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --glass-fill:        rgba(28, 28, 30, 0.58);
    --glass-fill-strong: rgba(28, 28, 30, 0.72);
    --glass-fill-tab:    rgba(40, 40, 44, 0.5);
    --edge-light:
      inset 0 1px 0 rgba(255, 255, 255, 0.14),
      inset 1px 0 0 rgba(255, 255, 255, 0.07),
      inset 0 -1px 0 rgba(0, 0, 0, 0.5);
    --rim: 0 0 0 0.5px rgba(255, 255, 255, 0.08);
    --depth-1: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.5);
    --depth-2: 0 2px 6px rgba(0,0,0,0.5), 0 18px 50px rgba(0,0,0,0.6);
    --depth-3: 0 4px 14px rgba(0,0,0,0.6), 0 40px 90px rgba(0,0,0,0.75);
    --blob-a: rgba(60, 90, 200, 0.40);
    --blob-b: rgba(110, 70, 200, 0.32);
    --blob-c: rgba(120, 30, 30, 0.10);
    --blob-d: rgba(80, 100, 220, 0.28);
    --gate-fill: rgba(28, 28, 30, 0.55);
    --bg-base: #16161a;
    --sheen: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0) 40%);
  }
}

/* ---- Refracting background: a REAL painted layer the glass can sample.
   (A body::before at z-index:-1 behind an isolated body is invisible to
   descendants' backdrop-filter — Comet's compositing find — so the field
   is a fixed element at z-index:0 with all content raised above it.) ---- */
body {
  background: var(--bg-base);
}
.bg-field {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(40vw 40vw at 12% 18%, var(--blob-a), transparent 60%),
    radial-gradient(45vw 45vw at 85% 12%, var(--blob-b), transparent 62%),
    radial-gradient(36vw 36vw at 48% 58%, var(--blob-d, var(--blob-b)), transparent 58%),
    radial-gradient(50vw 50vw at 70% 90%, var(--blob-c), transparent 65%);
  filter: blur(60px) saturate(120%);
  animation: glass-drift 28s ease-in-out infinite alternate;
}
/* everything else paints above the field — so every backdrop-filter
   between a card and the field samples it */
body > *:not(.bg-field) {
  position: relative;
  z-index: 1;
}
/* …except overlays, which must stay fixed: the rule above outranks the
   plain class selectors (0,1,1 vs 0,1,0) and was pinning body-level modals,
   menus and overlays into the document flow below the fold. Re-assert their
   position and stacking at matching specificity. */
body > .modal-backdrop { position: fixed; z-index: 60; }
body > .tab-menu { position: fixed; z-index: 200; }
body > .gqa-modal-overlay { position: fixed; z-index: 300; }
body > .session-overlay { position: fixed; z-index: 300; }
@keyframes glass-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-3%, 2%, 0) scale(1.08); }
}

/* ---- The material. The sheen rides as a background layer (no ::after, so
   nothing inside ever gets clipped). ---- */
.app-header,
.card,
.gate-card,
.gqa-modal,
.modal-card,
.session-box,
.tab-menu,
.usage-pop,
#ec2-flyout,
.admin-panel,
.handoff-panel,
.cost-glass {
  background: var(--sheen), var(--glass-fill);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  border: none;
  box-shadow: var(--edge-light), var(--rim), var(--depth-2);
}
.gate-card,
.gqa-modal,
.modal-card,
.session-box {
  background: var(--sheen), var(--glass-fill-strong);
}
#ec2-widget {
  background: var(--glass-fill-tab);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border: none;
  box-shadow: var(--edge-light), var(--rim), var(--depth-1);
}

/* Floating menus/popovers sit on the deepest shadow tier. */
.gqa-modal, .modal-card, .session-box, .tab-menu, .usage-pop, #ec2-flyout {
  box-shadow: var(--edge-light), var(--rim), var(--depth-3);
}

/* Cards lift on hover (config/findings are work surfaces — keep them calm,
   lift only the explicitly interactive glass). */
#ec2-widget, .finding-row, .seg-btn {
  transition: transform var(--spring-soft), box-shadow var(--spring-soft);
}
#ec2-widget:hover { transform: translateY(-2px); box-shadow: var(--edge-light), var(--rim), var(--depth-2); }
#ec2-widget:active { transform: translateY(0); }

/* ---- Modal backdrops: heavy frost so the page recedes. ---- */
.gqa-modal-overlay,
.session-overlay,
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 8, 10, 0.38);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  animation: glass-fade-in var(--dur-out) var(--ease-out);
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: min(440px, 92vw);
  border-radius: 20px;
  padding: 24px;
  animation: glass-pop-in var(--dur-in) var(--ease-spring);
}
.modal-card h2 { margin: 0 0 14px; font-size: 19px; }
.modal-card .field { margin-bottom: 14px; }
.modal-row { display: flex; gap: 8px; align-items: center; }
.modal-row[hidden] { display: none; } /* author display would beat the UA hidden rule */
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-note { font-size: 12.5px; color: var(--text-tertiary); margin: 6px 0 0; }

@keyframes glass-pop-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes glass-fade-in { from { opacity: 0; } to { opacity: 1; } }
.tab-menu, .usage-pop:not([hidden]), #ec2-flyout { animation: glass-pop-in var(--dur-in) var(--ease-spring); }

/* ---- Inputs: translucent wells on the glass. ---- */
.card input[type="text"], .card input[type="number"], .card input[type="password"],
.card textarea, .card select,
.modal-card input, .modal-card select,
.gate-card input,
.admin-panel input, .admin-panel select {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.13);
}
[data-theme="dark"] .card input[type="text"], [data-theme="dark"] .card input[type="number"],
[data-theme="dark"] .card input[type="password"], [data-theme="dark"] .card textarea,
[data-theme="dark"] .card select, [data-theme="dark"] .modal-card input,
[data-theme="dark"] .modal-card select, [data-theme="dark"] .gate-card input,
[data-theme="dark"] .admin-panel input, [data-theme="dark"] .admin-panel select {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}
.card :is(input, textarea, select):focus-visible,
.modal-card :is(input, select):focus-visible,
.gate-card input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
}

/* Frosted secondary buttons. */
.btn-secondary {
  background: var(--glass-fill-strong);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border: none;
  box-shadow: var(--edge-light), var(--rim);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--r-field, 10px);
  padding: 9px 16px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(255,59,48,0.4), 0 6px 18px rgba(255,59,48,0.32);
}
.btn-danger:active { transform: scale(0.97); }

/* ---- Segmented control (QA mode). ---- */
.segmented {
  display: flex;
  padding: 4px;
  gap: 2px;
  border-radius: 14px;
  background: var(--glass-fill-tab);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  box-shadow: var(--rim), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  margin-bottom: 16px;
}
[data-theme="dark"] .segmented { box-shadow: var(--rim), inset 0 1px 0 rgba(255, 255, 255, 0.08); }
.segmented .seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 14px;
  border-radius: 10px;
  font: 600 13px/1 inherit;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--dur-out) var(--ease-out), background var(--spring-soft), box-shadow var(--spring-soft);
}
.segmented .seg-btn[aria-selected="true"] {
  color: var(--text);
  background: var(--glass-fill-strong);
  box-shadow: var(--edge-light), var(--depth-1);
}

/* ---- Gate card: the FIRST glass anyone sees — lighter fill than the work
   surfaces, heavier blur, intensified specular rim, deepest shadow tier,
   floating on the blob field. (auth.css's solid base is overridden here;
   the @supports fallback below re-solidifies when blur is unavailable.) ---- */
.gate-card {
  background: var(--sheen), var(--gate-fill);
  -webkit-backdrop-filter: blur(36px) saturate(190%);
  backdrop-filter: blur(36px) saturate(190%);
  border: none;
  border-radius: 22px;
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, 0.95),
    inset 1px 0 0 rgba(255, 255, 255, 0.5),
    inset -1px 0 0 rgba(255, 255, 255, 0.25),
    inset 0 -1px 0 rgba(0, 0, 0, 0.05),
    var(--rim), var(--depth-3);
}
[data-theme="dark"] .gate-card {
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, 0.18),
    inset 1px 0 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(0, 0, 0, 0.5),
    var(--rim), var(--depth-3);
}
.gate-card input {
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.12);
}
[data-theme="dark"] .gate-card input {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.13);
}

/* ---- Gate landing (GitHub SSO): stacked glass actions. ---- */
.gate-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.gate-actions .btn-primary, .gate-actions .btn-secondary {
  width: 100%;
  padding: 12px 18px;
}
.btn-github {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}
.gate-actions .gh-link {
  background: none;
  border: none;
  box-shadow: none;
  color: var(--text-tertiary);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
}
.gate-actions .gh-link:hover { color: var(--text-secondary); text-decoration: underline; }
#form-code .gh-link {
  background: none; border: none; box-shadow: none;
  color: var(--text-tertiary); font-size: 13px; cursor: pointer;
  margin-top: 8px; padding: 4px;
}

/* Header username doubles as the settings trigger. */
.username-btn {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.username-btn:hover { text-decoration: underline; }

/* ---- Help "?" tooltip. ---- */
.help-tip {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  border-radius: 50%;
  font: 700 11px/1 inherit;
  font-family: inherit;
  letter-spacing: 0;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--text-tertiary) 22%, transparent);
  cursor: help;
  position: relative;
  vertical-align: middle;
  text-transform: none;
}
.help-tip:hover::after, .help-tip:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 140%;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  padding: 8px 11px;
  border-radius: 10px;
  font: 500 12px/1.45 inherit;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  background: var(--sheen), var(--glass-fill-strong);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--edge-light), var(--rim), var(--depth-2);
  animation: glass-tip-in var(--spring-soft);
  z-index: 70;
}
@keyframes glass-tip-in {
  from { opacity: 0; transform: translate(-50%, 4px) scale(0.96); }
}

/* ---- Expense warning: the one place the red-laser energy lives. ---- */
.expense-card {
  text-align: center;
  box-shadow:
    var(--edge-light), var(--rim), var(--depth-3),
    0 0 0 1px color-mix(in srgb, var(--danger) 35%, transparent),
    0 0 44px -6px color-mix(in srgb, var(--danger) 45%, transparent);
}
.expense-card .expense-price {
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 10px 0 2px;
}
.expense-card .expense-breakdown {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: var(--text-secondary);
}
.expense-card .expense-glyph { color: var(--danger); margin-bottom: 4px; }

/* ---- Cost meter inner glow warms toward red as --p (0–100) rises. ---- */
.cost-glass {
  box-shadow:
    var(--edge-light), var(--rim), var(--depth-1),
    inset 0 0 26px -8px color-mix(in srgb,
      color-mix(in srgb, var(--danger) calc(var(--p, 0) * 1%), var(--ok)) 55%,
      transparent);
}

/* ---- Settings: GitHub connection card (modal-card idiom). ---- */
.gh-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--glass-fill-tab);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  box-shadow: var(--edge-light), var(--rim), var(--depth-1);
  margin-bottom: 10px;
}
.gh-avatar {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  font: 700 16px/1 inherit;
  color: var(--text-secondary);
  background: color-mix(in srgb, var(--text-tertiary) 18%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--rim);
}
[data-theme="dark"] .gh-avatar { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), var(--rim); }
.gh-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gh-card-id {
  flex: 1 1 130px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.gh-card-id strong {
  font-size: 14px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gh-card-id .modal-note { margin: 0; }
.gh-card-actions { display: flex; gap: 6px; flex: none; margin-left: auto; }
.gh-card-actions button { padding: 7px 12px; font-size: 12px; }
.gh-card-actions button[hidden] { display: none; }
.set-gh-manual { margin-bottom: 0; }
.set-gh-manual .modal-row { margin-top: 8px; }
.set-gh-manual input[type="password"] { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ---- Admin tables sit inside glass panels; keep rows airy. ---- */
.admin-panel { border-radius: 16px; padding: 16px; }
.admin-table tbody tr { transition: background var(--dur-out) var(--ease-out); }
.admin-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }

/* ---- Fallback: no backdrop-filter → near-solid surfaces, static field. ---- */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .app-header, .card, .gate-card, .gqa-modal, .modal-card, .session-box,
  .tab-menu, .usage-pop, #ec2-flyout, .admin-panel, .handoff-panel,
  #ec2-widget, .cost-glass, .btn-secondary, .segmented {
    background: color-mix(in srgb, var(--bg-elev-1) 97%, transparent);
  }
  .gqa-modal-overlay, .session-overlay, .modal-backdrop { background: rgba(8, 8, 10, 0.55); }
}

@media (prefers-reduced-motion: reduce) {
  .bg-field { animation: none; }
  .gqa-modal, .modal-card, .session-box, .tab-menu, .usage-pop:not([hidden]), #ec2-flyout {
    animation: glass-fade-in 1ms linear;
  }
  .help-tip:hover::after, .help-tip:focus-visible::after { animation: none; }
  #ec2-widget:hover, #ec2-widget:active, .segmented .seg-btn { transform: none; transition: none; }
}
