@import 'tailwindcss';
@import '$lib/styles/tokens.css';
@import '@fontsource/inter/400.css';
@import '@fontsource/inter/500.css';
@import '@fontsource/inter/600.css';
@import '@fontsource/inter/700.css';
@import '@fontsource/jetbrains-mono/400.css';
@import '@fontsource/jetbrains-mono/500.css';
@import '@fontsource/jetbrains-mono/700.css';

/* ── Base Styles ──────────────────────────────────────────────────── */

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-family-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: var(--surface-page);
  color: var(--text-primary);
}

/* Hide default number input spinners — use a cleaner look */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

/* Screen reader only helper */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ── Focus Ring Utility ───────────────────────────────────────────── */

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

/* ── Custom Scrollbar ─────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ═══════════════════════════════════════════════════════════════════
   FORGE DESIGN SYSTEM — global utilities
   ═══════════════════════════════════════════════════════════════════ */

:root {
  /* Display font now uses the app's standard sans stack.
     --forge-serif is kept as an alias so all existing usages switch with one edit. */
  --forge-serif: var(--font-family-sans);
  --forge-display: var(--font-family-sans);
  --forge-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace;
  --forge-accent: var(--color-brand-600);
  --forge-accent-soft: color-mix(in srgb, var(--color-brand-500) 14%, transparent);
  --forge-glow: color-mix(in srgb, var(--color-brand-500) 32%, transparent);
}

/* ── Dot-grid backdrop ─────────────────────────────────────────── */
.forge-backdrop {
  position: relative;
  isolation: isolate;
}
.forge-backdrop::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 480px;
  background-image: radial-gradient(var(--border-primary) 1px, transparent 1px);
  background-size: 22px 22px;
  -webkit-mask-image: radial-gradient(ellipse at 20% 0%, #000 0%, transparent 70%);
  mask-image: radial-gradient(ellipse at 20% 0%, #000 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
  opacity: 0.8;
}

/* ── Eyebrow label (mono caps) ─────────────────────────────────── */
.forge-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--forge-mono);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.forge-eyebrow .sep { opacity: 0.5; }

/* ── Ember (breathing accent dot) ──────────────────────────────── */
.forge-ember {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--forge-accent);
  box-shadow: 0 0 0 3px var(--forge-accent-soft);
  animation: forge-breathe 2.4s ease-in-out infinite;
}
@keyframes forge-breathe {
  0%, 100% { box-shadow: 0 0 0 3px var(--forge-accent-soft); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--color-brand-500) 20%, transparent); }
}
@keyframes forge-blink {
  0%, 60%, 100% { opacity: 1; }
  70%, 90% { opacity: 0.3; }
}

/* ── Display heading ──────────────────────────────────────────── */
.forge-display {
  font-family: var(--forge-display);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--text-primary);
}
.forge-display .accent { color: var(--forge-accent); font-weight: 700; }
.forge-display em { color: var(--forge-accent); font-style: normal; font-weight: 700; }

/* ── Lede paragraph ───────────────────────────────────────────── */
.forge-lede {
  font-family: var(--font-family-sans);
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.55;
  max-width: 62ch;
  margin: 0.75rem 0 0;
}
.forge-lede em { color: var(--forge-accent); font-style: normal; font-weight: 500; }
.forge-lede code {
  font-family: var(--forge-mono);
  font-size: 0.8em;
  padding: 0.1rem 0.4rem;
  background: var(--surface-card-hover);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

/* ── Status pill with pulse ────────────────────────────────────── */
.forge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--surface-card-hover);
  font-family: var(--forge-mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.forge-pill .pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-tertiary);
}
.forge-pill.is-running { background: var(--color-success-light); color: var(--color-success-dark); }
.forge-pill.is-running .pulse { background: var(--color-success); animation: forge-blink 1.8s infinite; }
.forge-pill.is-info { background: var(--color-info-light); color: var(--color-info-dark); }
.forge-pill.is-info .pulse { background: var(--color-info); animation: forge-blink 0.8s infinite; }
.forge-pill.is-warn { background: var(--color-warning-light); color: var(--color-warning-dark); }
.forge-pill.is-warn .pulse { background: var(--color-warning); animation: forge-blink 0.9s infinite; }
.forge-pill.is-fail { background: var(--color-danger-light); color: var(--color-danger-dark); }
.forge-pill.is-fail .pulse { background: var(--color-danger); animation: forge-blink 0.5s infinite; }

[data-theme='dark'] .forge-pill.is-running { background: color-mix(in srgb, var(--color-success) 16%, transparent); color: #86efac; }
[data-theme='dark'] .forge-pill.is-info { background: color-mix(in srgb, var(--color-info) 16%, transparent); color: #93c5fd; }
[data-theme='dark'] .forge-pill.is-warn { background: color-mix(in srgb, var(--color-warning) 16%, transparent); color: #fcd34d; }
[data-theme='dark'] .forge-pill.is-fail { background: color-mix(in srgb, var(--color-danger) 16%, transparent); color: #fca5a5; }

/* ── Buttons ───────────────────────────────────────────────────── */
.forge-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--text-primary);
  color: var(--surface-card);
  border: 0;
  border-radius: var(--radius-lg);
  font-family: var(--forge-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease;
  box-shadow: 0 0 0 0 var(--forge-glow);
}
.forge-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 0 4px var(--forge-glow);
}
.forge-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.forge-btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.85rem;
  background: var(--surface-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  font-family: var(--forge-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: all 150ms ease;
}
.forge-btn-ghost:hover:not(:disabled) {
  background: var(--surface-card-hover);
  color: var(--text-primary);
  border-color: var(--color-brand-300);
}
.forge-btn-ghost:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}
.forge-btn-ghost:disabled { opacity: 0.5; cursor: not-allowed; }

.forge-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: var(--surface-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 150ms ease;
}
.forge-btn-icon:hover:not(:disabled) {
  background: var(--surface-card-hover);
  color: var(--text-primary);
  border-color: var(--color-brand-300);
}
.forge-btn-icon:disabled { opacity: 0.5; cursor: not-allowed; }

.forge-btn-danger { color: var(--color-danger); border-color: var(--border-primary); }
.forge-btn-danger:hover:not(:disabled) {
  background: var(--color-danger-light);
  border-color: var(--color-danger);
  color: var(--color-danger-dark);
}
[data-theme='dark'] .forge-btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-danger) 14%, transparent);
  color: #fca5a5;
}

/* ── Panel / Card with registration marks ──────────────────────── */
.forge-panel {
  background: var(--surface-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
}
.forge-panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 1rem 1.35rem 0.85rem;
  border-bottom: 1px solid var(--border-secondary);
}
.forge-panel-title {
  font-family: var(--forge-display);
  font-size: 1.35rem;
  margin: 0;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
.forge-panel-title .accent { color: var(--forge-accent); font-weight: 600; }
.forge-panel-body { padding: 1.15rem 1.35rem 1.35rem; }

/* ── Stat tile ─────────────────────────────────────────────────── */
.forge-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: var(--surface-card);
}
.forge-stat {
  padding: 1rem 1.15rem;
  border-right: 1px solid var(--border-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.forge-stat:last-child { border-right: 0; }
.forge-stat-label {
  font-family: var(--forge-mono);
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.forge-stat-value {
  font-family: var(--forge-display);
  font-size: 2.25rem;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.forge-stat-value.accent { color: var(--forge-accent); }
.forge-stat-value.warn { color: var(--color-warning-dark); }
.forge-stat-value.fail { color: var(--color-danger); }
.forge-stat-sub {
  font-family: var(--forge-mono);
  font-size: 0.66rem;
  color: var(--text-tertiary);
}

/* ── Registration corner marks (reveal on hover) ───────────────── */
.forge-regs {
  position: relative;
}
.forge-regs::before,
.forge-regs::after,
.forge-regs > .reg-bl,
.forge-regs > .reg-br {
  content: '';
  position: absolute;
  width: 8px; height: 8px;
  border-color: var(--color-brand-500);
  border-style: solid;
  border-width: 0;
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}
.forge-regs::before { top: -1px; left: -1px; border-top-width: 2px; border-left-width: 2px; }
.forge-regs::after  { top: -1px; right: -1px; border-top-width: 2px; border-right-width: 2px; }
.forge-regs:hover::before,
.forge-regs:hover::after { opacity: 1; }

/* ── Alert ─────────────────────────────────────────────────────── */
.forge-alert {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.7rem 0.9rem;
  background: var(--color-danger-light);
  color: var(--color-danger-dark);
  border: 1px solid var(--color-danger);
  border-left-width: 4px;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
}
.forge-alert-tag {
  font-family: var(--forge-mono);
  font-weight: 700;
  font-size: 0.65rem;
  letter-spacing: 0.16em;
  padding: 0.15rem 0.4rem;
  background: var(--color-danger);
  color: #fff;
  border-radius: var(--radius-sm);
}
[data-theme='dark'] .forge-alert {
  background: color-mix(in srgb, var(--color-danger) 14%, transparent);
  color: #fca5a5;
}

/* ── Terminal frame ────────────────────────────────────────────── */
.forge-terminal {
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  background: #0b1020;
  overflow: hidden;
}
[data-theme='dark'] .forge-terminal { background: #05070f; }
.forge-terminal-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  background: #141a2e;
  border-bottom: 1px solid #0a0e1c;
}
[data-theme='dark'] .forge-terminal-head { background: #0a0e1c; }
.forge-terminal-head .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: rgba(255,255,255,0.12);
}
.forge-terminal-head .dot:nth-child(1) { background: color-mix(in srgb, var(--color-danger) 70%, black); }
.forge-terminal-head .dot:nth-child(2) { background: color-mix(in srgb, var(--color-warning) 70%, black); }
.forge-terminal-head .dot:nth-child(3) { background: color-mix(in srgb, var(--color-success) 70%, black); }
.forge-terminal-head .title {
  margin-left: 0.6rem;
  font-family: var(--forge-mono);
  font-size: 0.7rem;
  color: rgba(255,255,255,0.45);
}
.forge-terminal-body {
  margin: 0;
  padding: 1rem 1.1rem;
  font-family: var(--forge-mono);
  font-size: 0.76rem;
  line-height: 1.55;
  color: #c7d0e0;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 480px;
  overflow: auto;
}

/* ── Native heading tune-up ────────────────────────────────────── */
h1.forge, h2.forge, h3.forge {
  font-family: var(--forge-display);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ── Table refresh ─────────────────────────────────────────────── */
.forge-table {
  width: 100%;
  border-collapse: collapse;
}
.forge-table thead th {
  font-family: var(--forge-mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  font-weight: 600;
  text-align: left;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border-primary);
  background: var(--surface-card-hover);
}
.forge-table tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-secondary);
  font-size: 0.88rem;
  color: var(--text-primary);
}
.forge-table tbody tr:last-child td { border-bottom: 0; }
.forge-table tbody tr:hover { background: var(--surface-card-hover); }

/* ── Spin & fade ───────────────────────────────────────────────── */
@keyframes forge-spin { to { transform: rotate(360deg); } }
.forge-spinner {
  width: 12px; height: 12px;
  border: 2px solid var(--text-tertiary);
  border-right-color: transparent;
  border-radius: 50%;
  animation: forge-spin 0.9s linear infinite;
}
