/* ═══════════════════════════════════════════════════════════════
   LEASH — Master Design System (v1.0, IMMUTABLE)
   A flight instrument panel printed on fine paper.
   Calm like a Swiss railway timetable. Precise like a cockpit.
   ═══════════════════════════════════════════════════════════════ */

/* ─── 3. Color & Tokens ─── */
:root {
  color-scheme: light;

  /* Paper Backgrounds (warm, fine paper) */
  --paper-0: #FCFBF8;
  --paper-1: #F6F4EF;
  --paper-2: #EFECE4;

  /* Ink Text (warm near-black, never #000) */
  --ink-900: #1A1815;
  --ink-600: #57534A;
  --ink-400: #8A857A;

  /* Hairlines & Borders */
  --line: #E5E1D8;
  --line-strong: #CFC9BC;

  /* Primary Accent (deep instrument green) */
  --accent: #2F5D3A;
  --accent-ink: #FFFFFF;

  /* Semantic States (functional, never decorative) */
  --state-granted: #2F5D3A;
  --state-watch: #B7791F;
  --state-revoked: #B3261E;
  --state-neutral: #57534A;

  --state-granted-bg: rgba(47, 93, 58, 0.08);
  --state-watch-bg: rgba(183, 121, 31, 0.08);
  --state-revoked-bg: rgba(179, 38, 30, 0.08);
  --state-neutral-bg: rgba(87, 83, 74, 0.08);

  /* Typography */
  --font-serif: 'Fraunces', Georgia, serif;
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Radii */
  --radius-container: 8px;
  --radius-control: 6px;
  --radius-badge: 4px;

  /* Shadow (hard ban on heavy drop shadows) */
  --shadow-subtle: 0 1px 2px rgba(26, 24, 21, 0.04);

  /* Motion */
  --ease-quint: cubic-bezier(0.22, 1, 0.36, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
}

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

html, body {
  background-color: var(--paper-0);
  color: var(--ink-900);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  font-feature-settings: 'cv11', 'ss01', 'tnum';
  -webkit-font-smoothing: antialiased;
}

/* Film-grain texture */
.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  opacity: 0.025;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

::selection {
  background-color: var(--accent);
  color: var(--accent-ink);
}

/* ─── Layout Shell ─── */
.shell {
  max-width: 1140px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ─── Demotion Revoked Banner ─── */
.revoked-banner {
  background-color: var(--state-revoked);
  color: #FFFFFF;
  padding: 0.75rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.4;
  animation: slide-down 250ms var(--ease-quint);
}

.banner-inner {
  max-width: 1140px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.banner-tag {
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.1rem 0.4rem;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.banner-text { flex: 1; }

.trace-link {
  color: #FFFFFF;
  text-decoration: underline;
  font-weight: 500;
}
.trace-link:hover { opacity: 0.85; }

.banner-close {
  background: transparent;
  border: 0;
  color: #FFFFFF;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

/* ─── Header / Topbar ─── */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.wordmark {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  color: var(--ink-900);
}

.brand-dot { color: var(--accent); }

.brand-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-400);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-600);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--state-granted);
}
.status-dot.active { animation: pulse-green 2s infinite var(--ease-quint); }

.evidence-tag {
  padding: 0.2rem 0.5rem;
  background-color: var(--paper-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-badge);
}

/* ─── Hero ─── */
.hero {
  padding: 3.5rem 0 2.5rem;
  max-width: 68ch;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.hero-display {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 4rem;
  line-height: 1.05;
  letter-spacing: -0.035em;
  color: var(--ink-900);
  margin-bottom: 1rem;
}

.hero-sub {
  font-size: 1.125rem;
  line-height: 1.65;
  color: var(--ink-600);
}

/* ─── Instrument Panels ─── */
.instrument-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.panel-section {
  background-color: var(--paper-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-container);
  padding: 1.5rem;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-600);
}

.mono-id, .section-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-400);
}

/* ─── Tier Badge Protagonist ─── */
.tier-container {
  text-align: center;
  padding: 0.5rem 0 1rem;
}

.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-badge);
  border: 1px solid var(--line);
  transition: all var(--duration-normal) var(--ease-quint);
}

.tier-badge.granted {
  color: var(--state-granted);
  border-color: var(--state-granted);
  background-color: var(--state-granted-bg);
}

.tier-badge.watch {
  color: var(--state-watch);
  border-color: var(--state-watch);
  background-color: var(--state-watch-bg);
}

.tier-badge.revoked {
  color: var(--state-revoked);
  border-color: var(--state-revoked);
  background-color: var(--state-revoked-bg);
  animation: badge-pulse-red 1.5s 2 var(--ease-quint);
}

.tier-reason {
  font-size: 0.82rem;
  color: var(--ink-600);
  margin-top: 0.5rem;
}

/* ─── Flat 270° SVG Arc Gauge ─── */
.gauge-container {
  position: relative;
  width: 170px;
  height: 140px;
  margin: 0.5rem auto 1rem;
}

.gauge-svg {
  width: 100%;
  height: 100%;
}

.gauge-track {
  fill: none;
  stroke: var(--line);
  stroke-width: 4;
}

.gauge-fill {
  fill: none;
  stroke: var(--state-granted);
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset 600ms var(--ease-quint), stroke 400ms var(--ease-quint);
}

.gauge-fill.watch { stroke: var(--state-watch); }
.gauge-fill.revoked { stroke: var(--state-revoked); }

.gauge-center {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  line-height: 1;
}

.gauge-value {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 600;
  color: var(--ink-900);
  font-feature-settings: 'tnum';
}

.gauge-unit {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--ink-600);
}

.gauge-caption {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-400);
  margin-top: 0.2rem;
}

/* Telemetry table rows */
.telemetry-table {
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
  margin-top: 0.5rem;
}

.telemetry-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  padding: 0.3rem 0;
}

.tel-label { color: var(--ink-600); }
.tel-value { font-family: var(--font-mono); font-weight: 500; color: var(--ink-900); }

/* ─── Tier Ladder ─── */
.tier-ladder {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 1.5rem;
}

.ladder-step {
  display: flex;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.ladder-step:last-child { border-bottom: 0; }

.ladder-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  padding-top: 0.2rem;
}

.rung-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--line-strong);
  transition: all var(--duration-normal) var(--ease-quint);
}

.ladder-step.active .rung-dot {
  background-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 93, 58, 0.15);
  animation: pulse-dot 2s infinite var(--ease-quint);
}

.ladder-step.revoked .rung-dot {
  background-color: var(--state-revoked);
  box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.15);
}

.ladder-content { flex: 1; }

.ladder-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.rung-code {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink-900);
}

.rung-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-900);
}

.rung-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-400);
  margin-left: auto;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rung-rule {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-600);
  margin-top: 0.15rem;
}

/* Envelope Box */
.envelope-box {
  background-color: var(--paper-0);
  border: 1px solid var(--line);
  border-radius: var(--radius-container);
  padding: 1rem;
}

.box-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-400);
  margin-bottom: 0.75rem;
}

.envelope-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.envelope-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 0.4rem 0.6rem;
  background-color: var(--paper-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--ink-400);
  transition: all var(--duration-fast) var(--ease-quint);
}

.envelope-item.active {
  color: var(--ink-900);
  background-color: var(--paper-0);
  border-color: var(--line-strong);
}

.env-tool { flex: 1; font-weight: 500; }
.env-risk { font-size: 11px; font-weight: 700; text-transform: uppercase; }
.risk-read { color: var(--ink-600); }
.risk-write { color: var(--state-watch); }
.risk-destructive { color: var(--state-revoked); }
.env-req { font-size: 11px; color: var(--ink-400); }

/* ─── Controls Section ─── */
.controls-panel {
  margin-bottom: 1.5rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--line-strong);
  background-color: var(--paper-0);
  color: var(--ink-900);
  text-align: left;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-quint);

  /* Max shadow allowed: 0 1px 2px rgb(0 0 0 / 0.04) */
  box-shadow: var(--shadow-subtle);
}

.btn:hover {
  background-color: var(--paper-2);
  border-color: var(--ink-600);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.btn-primary:hover {
  background-color: #264a2e;
  border-color: #264a2e;
  color: var(--accent-ink);
}

.btn-warn {
  border-color: var(--state-watch);
}
.btn-warn .btn-text { color: var(--state-watch); }

.btn-danger {
  border-color: var(--state-revoked);
}
.btn-danger .btn-text { color: var(--state-revoked); }

.btn-step {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  opacity: 0.7;
}

.btn-text {
  font-size: 14px;
  font-weight: 600;
  margin-top: 0.2rem;
  line-height: 1.25;
}

.btn-sub {
  font-size: 12px;
  color: var(--ink-600);
  margin-top: 0.25rem;
  line-height: 1.3;
}
.btn-primary .btn-sub { color: rgba(255, 255, 255, 0.8); }

.controls-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.btn-text-link {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.btn-text-link:hover { text-decoration: underline; }
.divider-dot { color: var(--ink-400); }

/* ─── Tufte Hairline Ledger / Live Decision Feed ─── */
.feed-panel {
  padding: 1.5rem;
}

.table-header {
  display: grid;
  grid-template-columns: 110px 180px 1fr 100px;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line-strong);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-400);
}

.feed-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  max-height: 360px;
  overflow-y: auto;
}

.feed-item {
  display: grid;
  grid-template-columns: 110px 180px 1fr 100px;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  border-left: 2px solid transparent;
  animation: feed-slide 150ms var(--ease-quint);
}

.feed-item.allowed {
  border-left-color: var(--state-granted);
  background-color: rgba(47, 93, 58, 0.03);
}

.feed-item.denied {
  border-left-color: var(--state-revoked);
  background-color: var(--state-revoked-bg);
}

.feed-item.failed {
  border-left-color: var(--state-watch);
  background-color: var(--state-watch-bg);
}

.verdict-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  border-radius: var(--radius-badge);
  border: 1px solid var(--line);
}

.verdict-pill.allowed {
  color: var(--state-granted);
  border-color: var(--state-granted);
  background-color: var(--state-granted-bg);
}

.verdict-pill.denied {
  color: var(--state-revoked);
  border-color: var(--state-revoked);
  background-color: var(--state-revoked-bg);
}

.verdict-pill.failed {
  color: var(--state-watch);
  border-color: var(--state-watch);
  background-color: var(--state-watch-bg);
}

.col-action {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink-900);
}

.col-reason {
  font-size: 13px;
  color: var(--ink-600);
}

.trace-code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}
.trace-code:hover { text-decoration: underline; }

.col-time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-400);
  text-align: right;
}

.feed-empty {
  padding: 1.5rem;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--ink-600);
}

/* ─── Footer ─── */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-600);
}

.footer-left { display: flex; align-items: baseline; gap: 0.75rem; }
.footer-brand { font-family: var(--font-serif); font-weight: 600; font-size: 1rem; }
.footer-copy { color: var(--ink-400); }
.footer-right { display: flex; gap: 0.75rem; }
.footer-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 0.2rem 0.5rem;
  background-color: var(--paper-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-badge);
}

/* ─── Keyframe Animations ─── */
@keyframes slide-down {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

@keyframes badge-pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(179, 38, 30, 0); }
}

@keyframes feed-slide {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .instrument-grid { grid-template-columns: 1fr; }
  .controls-grid { grid-template-columns: repeat(2, 1fr); }
  .table-header, .feed-item { grid-template-columns: 90px 140px 1fr 80px; gap: 0.5rem; }
  .hero-display { font-size: 2.8rem; }
}

@media (max-width: 600px) {
  .controls-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; gap: 0.5rem; }
  .site-footer { flex-direction: column; gap: 1rem; align-items: flex-start; }
}

/* ─── Accessibility: Reduced Motion ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
