/* ============================================================
   S2S Auth with SPIFFE — ACME Shop Demo
   Dark theme matching app.gyatso.me
   ============================================================ */

/* ── Custom Properties ───────────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #1c2128;
  --bg4:         #21262d;
  --border:      rgba(255, 255, 255, 0.08);
  --border-med:  rgba(255, 255, 255, 0.15);
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --text-dim:    #6e7681;

  --green:       #3fb950;
  --green-dim:   rgba(63, 185, 80, 0.15);
  --red:         #f85149;
  --red-dim:     rgba(248, 81, 73, 0.15);
  --orange:      #d29922;
  --orange-dim:  rgba(210, 153, 34, 0.15);
  --blue:        #58a6ff;
  --blue-dim:    rgba(88, 166, 255, 0.15);
  --purple:      #a855f7;
  --purple-dim:  rgba(168, 85, 247, 0.15);

  --radius-sm:   4px;
  --radius:      8px;
  --radius-lg:   12px;

  --font-mono:   'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-sans:   -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Helvetica, Arial, sans-serif;

  --header-h:    56px;
  --tabs-h:      48px;
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Mobile Gate ─────────────────────────────────────────────── */
#mobile-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  padding: 2rem;
}

.gate-content {
  max-width: 320px;
}

.gate-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  display: block;
}

.gate-content h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.gate-content p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ── Main App ────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────── */
.app-header {
  flex-shrink: 0;
  height: var(--header-h);
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  background: var(--bg2);
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: color 0.15s;
  flex-shrink: 0;
}

.back-link:hover {
  color: var(--blue);
}

.header-center {
  flex: 1;
  min-width: 0;
}

.app-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.app-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.header-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ── Scenario Tabs ───────────────────────────────────────────── */
.scenario-tabs {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  height: auto;
}

.tab-btn {
  background: var(--bg2);
  border: none;
  border-right: 1px solid var(--border);
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.85rem 1rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  text-align: center;
}

.tab-btn:last-child {
  border-right: none;
}

.tab-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.tab-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tab-btn:hover {
  color: var(--text);
  background: var(--bg3);
}

.tab-btn.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
  background: var(--bg3);
}

/* ── Main Content Layout ─────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  min-height: 0;
}

/* ── Diagram Section ─────────────────────────────────────────── */
.diagram-section {
  flex: 1 1 0;
  min-width: 0;
  border-right: 1px solid var(--border);
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

#diagram-container {
  width: 100%;
  height: 100%;
  display: block;
}

#diagram-container svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── SVG Zone Bands ──────────────────────────────────────────── */
.zone-band {
  fill: var(--bg2);
  stroke: var(--border);
  stroke-width: 1;
}

.zone-external {
  fill: rgba(16, 24, 32, 0.9);
}

.zone-internal {
  fill: rgba(22, 30, 40, 0.85);
}

.zone-edge {
  fill: rgba(18, 26, 36, 0.9);
}

.zone-label {
  fill: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── SVG Service Nodes ───────────────────────────────────────── */
.svc-node {
  fill: var(--bg3);
  stroke: var(--border-med);
  stroke-width: 1.5;
  transition: fill 0.2s, stroke 0.2s, filter 0.2s;
}

.svc-node:hover {
  fill: var(--bg4);
  stroke: rgba(255, 255, 255, 0.25);
}

/* SPIRE Server — diamond shape, purple accent */
.spire-node {
  fill: var(--purple-dim);
  stroke: var(--purple);
  stroke-width: 2;
  transition: fill 0.2s, stroke 0.2s, filter 0.2s;
}

/* Rogue service — red tint */
.rogue-node {
  fill: var(--red-dim);
  stroke: var(--red);
  stroke-width: 2;
}

/* Highlighted node — glow effect */
.node-highlighted .svc-node,
.node-highlighted .spire-node,
.node-highlighted .rogue-node {
  filter: drop-shadow(0 0 6px rgba(88, 166, 255, 0.5));
  stroke: var(--blue);
}

.node-highlighted .rogue-node {
  filter: drop-shadow(0 0 6px rgba(248, 81, 73, 0.5));
  stroke: var(--red);
}

/* Node labels */
.node-label {
  fill: var(--text);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  pointer-events: none;
  dominant-baseline: central;
}

/* Node group hover cursor */
.node-group {
  cursor: default;
}

/* SPIRE pulse animation */
@keyframes spire-pulse-ring {
  0% {
    filter: drop-shadow(0 0 0px rgba(168, 85, 247, 0));
    stroke-width: 2;
  }
  40% {
    filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.8));
    stroke-width: 3;
  }
  100% {
    filter: drop-shadow(0 0 0px rgba(168, 85, 247, 0));
    stroke-width: 2;
  }
}

.spire-pulse {
  animation: spire-pulse-ring 2s ease-out forwards;
}

/* Reject mark in SVG */
.reject-mark {
  font-size: 20px;
  font-family: var(--font-sans);
  fill: var(--red);
  font-weight: 700;
}

/* ── Arrow Animation ─────────────────────────────────────────── */
@keyframes draw-arrow {
  from {
    stroke-dashoffset: 300;
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  to {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

@keyframes fade-arrow {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Inspector Section ───────────────────────────────────────── */
.inspector-section {
  flex: 0 0 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.5rem;
  gap: 0.75rem;
  min-height: 0;
  background: var(--bg2);
}

/* Custom scrollbar */
.inspector-section::-webkit-scrollbar {
  width: 6px;
}
.inspector-section::-webkit-scrollbar-track {
  background: transparent;
}
.inspector-section::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
.inspector-section::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* ── Inspector Content ───────────────────────────────────────── */
#inspector-content {
  flex: 1;
  min-height: 0;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.inspector-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
}

/* ── Step Header ─────────────────────────────────────────────── */
.step-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.step-counter {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.step-route {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.svc-tag {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text);
}

/* ── Result Badges ───────────────────────────────────────────── */
.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.result-badge.success {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(63, 185, 80, 0.3);
}

.result-badge.rejected {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(248, 81, 73, 0.3);
}

/* ── Narrative Text ──────────────────────────────────────────── */
.narrative-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 0.75rem;
}

/* ── Why Block ───────────────────────────────────────────────── */
.why-block {
  border-left: 3px solid var(--blue);
  padding: 0.6rem 0.85rem;
  background: var(--blue-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 0.75rem;
}

.why-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--blue);
  margin-bottom: 0.3rem;
}

.why-block p {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Explanation Text ────────────────────────────────────────── */
.explanation-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin-top: 0.5rem;
  font-style: italic;
}

/* ── Credentials Details (collapsible) ───────────────────────── */
.credentials-details {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 0.5rem;
}

.credentials-details summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
  transition: color 0.15s, background 0.15s;
  position: relative;
}

.credentials-details summary::-webkit-details-marker {
  display: none;
}

.credentials-details summary::before {
  content: '▶';
  font-size: 0.65rem;
  color: var(--text-dim);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.credentials-details[open] summary::before {
  transform: rotate(90deg);
}

.credentials-details summary:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.expired-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.4rem;
  background: var(--red-dim);
  border: 1px solid rgba(248, 81, 73, 0.3);
  color: var(--red);
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-left: 0.25rem;
}

.credentials-body {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── SVID Meta ───────────────────────────────────────────────── */
.svid-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.spiffe-id-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--purple);
  white-space: nowrap;
}

.spiffe-id-val {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text);
  word-break: break-all;
}

/* ── SVID Tab Bar ────────────────────────────────────────────── */
.svid-tabs-bar {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.svid-tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.svid-tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.svid-tab-btn.active {
  background: var(--blue-dim);
  border-color: rgba(88, 166, 255, 0.4);
  color: var(--blue);
}

/* ── SVID Panel ──────────────────────────────────────────────── */
.svid-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ── Field Rows ──────────────────────────────────────────────── */
.jwt-fields,
.x509-fields {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
}

.field-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.8rem;
  line-height: 1.5;
}

.field-key {
  flex-shrink: 0;
  min-width: 60px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding-top: 0.05rem;
}

.field-val {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text);
  word-break: break-all;
  flex: 1;
}

/* ── Expiry Bar ──────────────────────────────────────────────── */
.expiry-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.78rem;
}

.expiry-label {
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 70px;
}

.expiry-bar {
  flex: 1;
  height: 6px;
  background: var(--bg4);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.expiry-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.expiry-fill.expired {
  background: var(--red);
}

.expiry-pct {
  color: var(--text-dim);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  min-width: 32px;
  text-align: right;
}

/* ── Token Raw ───────────────────────────────────────────────── */
.token-raw-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.token-raw-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.token-raw {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  overflow: hidden;
}

.token-raw code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* ── Copy Button ─────────────────────────────────────────────── */
.copy-btn {
  flex-shrink: 0;
  background: var(--bg4);
  border: 1px solid var(--border-med);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.copy-btn:hover {
  background: var(--blue-dim);
  border-color: rgba(88, 166, 255, 0.4);
  color: var(--blue);
}

.copy-btn:active {
  transform: scale(0.97);
}

/* ── Step Controls (now lives in .tabs-right inside the tab bar) ── */

/* ── Step Dots ───────────────────────────────────────────────── */
.step-dots {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: background 0.2s, transform 0.2s;
  display: inline-block;
}

.step-dot.visited {
  background: var(--text-dim);
  border-color: var(--text-dim);
}

.step-dot.active {
  background: var(--text);
  border-color: var(--text);
  transform: scale(1.3);
}

/* ── Nav Buttons ─────────────────────────────────────────────── */
.nav-buttons {
  display: flex;
  gap: 0.5rem;
}

.nav-btn {
  background: var(--bg3);
  border: 1px solid var(--border-med);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.4rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.nav-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.2);
  background: var(--bg4);
}

.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.nav-btn.primary {
  background: var(--blue-dim);
  border-color: rgba(88, 166, 255, 0.4);
  color: var(--blue);
}

.nav-btn.primary:hover:not(:disabled) {
  background: rgba(88, 166, 255, 0.22);
  border-color: rgba(88, 166, 255, 0.6);
}

/* ── Summary Card ────────────────────────────────────────────── */
.summary-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  background: var(--bg2);
}

.summary-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
}

.summary-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}

.summary-points {
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.summary-points li {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding-left: 1.25rem;
  position: relative;
  line-height: 1.55;
}

.summary-points li::before {
  content: '✓';
  position: absolute;
  left: 0;
  font-weight: 700;
}

.summary-cta {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
}

/* Summary color variants */
.summary-green {
  border-color: rgba(63, 185, 80, 0.25);
}
.summary-green .summary-title,
.summary-green .summary-points li::before {
  color: var(--green);
}

.summary-orange {
  border-color: rgba(210, 153, 34, 0.25);
}
.summary-orange .summary-title,
.summary-orange .summary-points li::before {
  color: var(--orange);
}

.summary-blue {
  border-color: rgba(88, 166, 255, 0.25);
}
.summary-blue .summary-title,
.summary-blue .summary-points li::before {
  color: var(--blue);
}

.summary-red {
  border-color: rgba(248, 81, 73, 0.25);
}
.summary-red .summary-title,
.summary-red .summary-points li::before {
  color: var(--red);
}

/* ── Free-play: Service SVID view ────────────────────────────── */
.svc-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.spiffe-id {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--purple);
  word-break: break-all;
}

/* ── SVG Arrow Colors (utility, for JS reference) ───────────── */
.arrow-green   { stroke: var(--green); }
.arrow-red     { stroke: var(--red); }
.arrow-orange  { stroke: var(--orange); }
.arrow-blue    { stroke: var(--blue); }
.arrow-blue-dashed { stroke: var(--blue); stroke-dasharray: 6 4; }

/* ── Responsive: 768–1023px ──────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  .header-left {
    gap: 0.75rem;
  }

  .app-title {
    font-size: 0.9rem;
  }

  .app-subtitle {
    display: none;
  }

  .back-link {
    font-size: 0.8rem;
  }

  .scenario-tabs {
    padding: 0 1rem;
  }

  .tab-btn {
    padding: 0.6rem 0.75rem;
    font-size: 0.82rem;
  }

  .inspector-section {
    flex: 0 0 320px;
    padding: 1rem;
  }

  .tab-btn {
    padding: 0.65rem 0.5rem;
  }

  .tab-icon {
    font-size: 1.1rem;
  }
}

/* ── Responsive: < 768px ─────────────────────────────────────── */
@media (max-width: 767px) {
  #mobile-gate {
    display: flex;
  }

  #app {
    display: none;
  }
}

/* ── Responsive: >= 1280px ───────────────────────────────────── */
@media (min-width: 1280px) {
  .inspector-section {
    flex: 0 0 480px;
  }
}

/* ── Utility ─────────────────────────────────────────────────── */
button {
  font-family: var(--font-sans);
}

code {
  font-family: var(--font-mono);
}
