/* =======================================================
   KVWarden Architecture Panel — Phase 1 styles
   Liquid-glass dialog with static worked-example diagram.
   ======================================================= */

/* Panel tokens: scoped via CSS custom properties so we don't
   pollute the global stylesheet. All referenced root tokens
   (--accent, etc.) come from landing_page/styles.css. */
.arch-panel {
  --arch-bg:          #0a0a0f;
  --arch-glass:       rgba(22, 20, 28, 0.62);
  --arch-glass-2:     rgba(18, 16, 24, 0.82);
  --arch-border:      rgba(255, 255, 255, 0.08);
  --arch-text:        #ffffff;
  --arch-text-2:      #b8b8c8;
  --arch-text-muted:  #9898a8;
  --arch-text-dim:    #6e6e80;
  --arch-accent:      #8B7CF6;
  --arch-quiet:       #60A5FA;
  --arch-throttle:    #F5A454;

  /* Reset dialog UA styles */
  padding: 0;
  border: 1px solid var(--arch-border);
  color: var(--arch-text);
  background: var(--arch-glass);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Desktop: floating card */
  width: min(1100px, 94vw);
  max-width: 94vw;
  height: min(88vh, 900px);
  max-height: 88vh;
  border-radius: 20px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 24px 64px -16px rgba(0, 0, 0, 0.65),
    0 4px 16px -4px rgba(0, 0, 0, 0.45);

  /* Liquid glass — 24px blur + saturate/brightness */
  backdrop-filter: blur(24px) saturate(1.6) brightness(1.05);
  -webkit-backdrop-filter: blur(24px) saturate(1.6) brightness(1.05);

  overflow: hidden;
  isolation: isolate;
}

/* Native <dialog> scrim — our scrim color + 24px blur fallback */
.arch-panel::backdrop {
  background: rgba(6, 5, 10, 0.55);
  backdrop-filter: blur(6px) saturate(1.1);
  -webkit-backdrop-filter: blur(6px) saturate(1.1);
}

/* Inner highlight gradient (top-edge bright, bottom-edge dark) */
.arch-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.08) 0%,
      rgba(255, 255, 255, 0.00) 22%,
      rgba(0, 0, 0, 0.00) 78%,
      rgba(0, 0, 0, 0.22) 100%);
  mix-blend-mode: overlay;
  z-index: 0;
}

/* 4% SVG noise overlay (inline data URI keeps the request count at 0) */
.arch-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
  mix-blend-mode: soft-light;
  z-index: 0;
}

/* Inner layout: header / body / footer (body scrolls) */
.arch-panel-inner {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  width: 100%;
}

/* ---------- HEADER ---------- */
.arch-panel-head {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  padding: 28px 28px 16px;
  border-bottom: 1px solid var(--arch-border);
}
.arch-panel-head-text { flex: 1 1 auto; min-width: 0; }
.arch-panel-eyebrow {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--arch-text-muted);
  margin-bottom: 8px;
}
.arch-panel-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 400;
  font-size: clamp(22px, 2.4vw, 30px);
  line-height: 1.22;
  letter-spacing: -0.01em;
  color: var(--arch-text);
  margin-bottom: 8px;
}
.arch-panel-lede {
  font-size: 14px;
  line-height: 1.55;
  color: var(--arch-text-2);
  max-width: 68ch;
}

.arch-panel-close {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  color: var(--arch-text-2);
  border: 1px solid var(--arch-border);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.arch-panel-close:hover {
  background: rgba(255, 255, 255, 0.10);
  color: var(--arch-text);
  transform: rotate(90deg);
}
.arch-panel-close:focus-visible {
  outline: 2px solid var(--arch-accent);
  outline-offset: 2px;
}

/* ---------- BODY (the scroller — Phase 1 lets it scroll natively) ---------- */
.arch-panel-body {
  padding: 24px 28px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 1fr);
  gap: 28px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Diagram container */
.arch-diagram-wrap {
  position: sticky;
  top: 0;
  align-self: start;
  background: rgba(10, 10, 15, 0.3);
  border: 1px solid var(--arch-border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.arch-diagram {
  width: 100%;
  height: auto;
  display: block;
}
.arch-label {
  font: 500 13px/1 'Inter', sans-serif;
}
.arch-label-strong { font-weight: 600; }
.arch-label-sm {
  font: 500 11px/1 'Inter', sans-serif;
  letter-spacing: 0.02em;
}

/* ---------- FRAMES (right column) ---------- */
.arch-frames {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0; margin: 0;
}
.arch-frame {
  position: relative;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 14px;
  align-items: baseline;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--arch-border);
  border-radius: 12px;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.arch-frame:hover {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
}
.arch-frame-index {
  font: 600 11px/1 'Inter', sans-serif;
  letter-spacing: 0.12em;
  color: var(--arch-text-dim);
  padding-top: 3px;
}
.arch-frame-body {
  font-size: 14px;
  line-height: 1.6;
  color: var(--arch-text-2);
}
.arch-frame-body strong { color: var(--arch-text); font-weight: 600; }

/* Inline tenant/throttle marks inside the frames */
.arch-mark { font-weight: 600; }
.arch-mark-noisy    { color: var(--arch-accent); }
.arch-mark-quiet    { color: var(--arch-quiet); }
.arch-mark-throttle { color: var(--arch-throttle); }

/* ---------- FOOTER ---------- */
.arch-panel-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  border-top: 1px solid var(--arch-border);
  font-size: 12px;
  color: var(--arch-text-dim);
}
.arch-foot-note { line-height: 1; }
.arch-foot-spacer { flex: 1 1 auto; }
.arch-kbd {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid var(--arch-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.04);
  font: 500 11px/1 'Inter', sans-serif;
  color: var(--arch-text-2);
}

/* ---------- OPEN / CLOSE TRANSITIONS (subtle, no Phase-2 motion) ---------- */
.arch-panel[open] { animation: archPanelIn 0.28s ease-out both; }
.arch-panel[open]::backdrop { animation: archScrimIn 0.22s ease-out both; }
@keyframes archPanelIn {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes archScrimIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- MOBILE: bottom sheet at <640px ---------- */
@media (max-width: 640px) {
  .arch-panel {
    width: 100vw;
    max-width: 100vw;
    height: 92vh;
    max-height: 92vh;
    /* Override UA dialog centering: pin to bottom of viewport */
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    border-radius: 24px 24px 0 0;

    /* Mobile blur cap */
    backdrop-filter: blur(10px) saturate(1.5) brightness(1.05);
    -webkit-backdrop-filter: blur(10px) saturate(1.5) brightness(1.05);
  }
  .arch-panel::before {
    /* Soften the top highlight for rounded-top corners */
    border-radius: 24px 24px 0 0;
  }

  /* Drag affordance (visual only — Phase 4 adds the gesture) */
  .arch-panel-inner::before {
    content: "";
    position: absolute;
    top: 8px; left: 50%;
    width: 44px; height: 4px;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.18);
    border-radius: 2px;
    z-index: 2;
  }

  .arch-panel-head {
    padding: 28px 20px 14px;
    gap: 12px;
  }
  .arch-panel-title  { font-size: 20px; }
  .arch-panel-lede   { font-size: 13px; }

  .arch-panel-body {
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 16px 20px 20px;
  }
  .arch-diagram-wrap { position: static; padding: 12px; }
  .arch-frame { padding: 12px 14px; }
  .arch-frame-body { font-size: 13px; line-height: 1.55; }

  .arch-panel-foot { padding: 10px 20px; font-size: 11px; }
}

/* ---------- REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  .arch-panel[open],
  .arch-panel[open]::backdrop {
    animation: none;
  }
  .arch-panel-close { transition: none; }
  .arch-panel-close:hover { transform: none; }
}

/* ---------- GRACEFUL FALLBACK when <dialog> unsupported ---------- */
.arch-panel.arch-panel-fallback-hidden { display: none; }

/* Slim non-glass fallback if backdrop-filter isn't supported */
@supports not (backdrop-filter: blur(1px)) {
  .arch-panel { background: rgba(14, 13, 18, 0.96); }
}

/* Lock the body behind the panel (Lenis also stops, this is the belt) */
body.arch-panel-locked { overflow: hidden; }
