@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;450;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    --background: 240 8% 5%;
    --foreground: 210 20% 96%;
    --card: 225 8% 11%;
    --card-foreground: 210 20% 96%;
    --popover: 225 8% 9%;
    --popover-foreground: 210 20% 96%;
    --primary: 192 100% 50%;
    --primary-foreground: 210 40% 8%;
    --secondary: 225 8% 13%;
    --secondary-foreground: 210 20% 96%;
    --muted: 225 8% 14%;
    --muted-foreground: 215 16% 62%;
    --accent: 225 9% 16%;
    --accent-foreground: 210 20% 96%;
    --destructive: 0 70% 42%;
    --destructive-foreground: 210 20% 96%;
    --border: 225 8% 18%;
    --input: 225 8% 14%;
    --ring: 192 100% 50%;
    --chart-1: 187 85% 53%;
    --chart-2: 160 60% 45%;
    --chart-3: 30 80% 55%;
    --chart-4: 265 70% 65%;
    --chart-5: 340 75% 55%;
    --radius: 0.75rem;
    --font-heading: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
    --font-body: 'Inter', ui-sans-serif, system-ui, sans-serif;
    --font-display: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --sidebar-background: 240 8% 5%;
    --sidebar-foreground: 210 20% 96%;
    --sidebar-primary: 192 100% 50%;
    --sidebar-primary-foreground: 210 40% 8%;
    --sidebar-accent: 225 8% 11%;
    --sidebar-accent-foreground: 210 20% 96%;
    --sidebar-border: 225 8% 16%;
    --sidebar-ring: 192 100% 50%;
  }

  .dark {
    --background: 240 8% 5%;
    --foreground: 210 20% 96%;
    --card: 225 8% 11%;
    --card-foreground: 210 20% 96%;
    --popover: 225 8% 9%;
    --popover-foreground: 210 20% 96%;
    --primary: 192 100% 50%;
    --primary-foreground: 210 40% 8%;
    --secondary: 225 8% 13%;
    --secondary-foreground: 210 20% 96%;
    --muted: 225 8% 14%;
    --muted-foreground: 215 16% 62%;
    --accent: 225 9% 16%;
    --accent-foreground: 210 20% 96%;
    --destructive: 0 70% 42%;
    --destructive-foreground: 210 20% 96%;
    --border: 225 8% 18%;
    --input: 225 8% 14%;
    --ring: 192 100% 50%;
    --chart-1: 187 85% 53%;
    --chart-2: 160 60% 45%;
    --chart-3: 30 80% 55%;
    --chart-4: 265 70% 65%;
    --chart-5: 340 75% 55%;
    --sidebar-background: 240 8% 5%;
    --sidebar-foreground: 210 20% 96%;
    --sidebar-primary: 192 100% 50%;
    --sidebar-primary-foreground: 210 40% 8%;
    --sidebar-accent: 225 8% 11%;
    --sidebar-accent-foreground: 210 20% 96%;
    --sidebar-border: 225 8% 16%;
    --sidebar-ring: 192 100% 50%;
  }
}

@layer base {
  * {
    @apply border-border outline-ring/40;
  }
  *:focus-visible {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
    border-radius: 4px;
  }
  body {
    @apply bg-background text-foreground font-body antialiased;
    background-image:
      radial-gradient(ellipse 90% 55% at 50% -12%, rgba(34, 211, 238, 0.055), transparent 62%),
      radial-gradient(ellipse 60% 40% at 100% 0%, rgba(139, 92, 246, 0.04), transparent 60%),
      linear-gradient(rgba(148, 163, 184, 0.018) 1px, transparent 1px),
      linear-gradient(90deg, rgba(148, 163, 184, 0.018) 1px, transparent 1px);
    background-size: 100% 100%, 100% 100%, 46px 46px, 46px 46px;
    background-attachment: fixed;
  }
  ::selection { background: rgba(34, 211, 238, 0.25); color: #e0fbff; }
}

@layer components {
  /* Brushed dark-titanium panel with inner highlight + soft depth */
  .panel {
    @apply rounded-2xl border border-white/[0.06] p-5;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0) 44%),
      linear-gradient(135deg, #17181c, #121317);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 24px 50px -30px rgba(0, 0, 0, 0.85);
  }
  /* Smoked-glass overlay surface */
  .panel-glass {
    @apply rounded-2xl border border-white/10 p-5 backdrop-blur-xl;
    background: linear-gradient(180deg, rgba(30, 39, 49, 0.5), rgba(16, 21, 27, 0.62));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  }
  /* Dark titanium secondary surface (inset blocks, readouts) */
  .surface-ti {
    @apply rounded-xl border border-white/[0.06];
    background: linear-gradient(180deg, #191f29, #141922);
  }
  .section-title {
    @apply mb-4 flex items-center gap-2 text-sm font-semibold tracking-wide text-slate-200;
  }
  .section-title::before {
    content: '';
    @apply inline-block h-3.5 w-1 rounded-full bg-cyan-400/80;
    box-shadow: 0 0 8px rgba(34, 211, 238, 0.6);
  }

  .btn-primary {
    @apply inline-flex min-h-11 items-center justify-center gap-2 rounded-xl px-5 py-2.5 text-sm font-semibold text-slate-950 transition;
    background: linear-gradient(180deg, #38e0f2, #15b8d4);
    box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.4), 0 10px 28px -12px rgba(34, 211, 238, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  }
  .btn-primary:hover { filter: brightness(1.08); }
  .btn-primary:disabled { @apply cursor-not-allowed opacity-40; box-shadow: none; }
  .btn-secondary {
    @apply inline-flex min-h-11 items-center justify-center gap-2 rounded-xl border border-cyan-400/35 bg-cyan-400/[0.07] px-5 py-2.5 text-sm font-semibold text-cyan-200 transition hover:bg-cyan-400/[0.14] disabled:opacity-40;
  }
  .btn-ghost {
    @apply inline-flex min-h-11 items-center justify-center gap-2 rounded-xl border border-white/10 bg-white/[0.02] px-5 py-2.5 text-sm font-medium text-slate-300 transition hover:border-white/20 hover:text-white disabled:opacity-40;
  }
  .btn-violet {
    @apply inline-flex min-h-11 items-center justify-center gap-2 rounded-xl px-5 py-2.5 text-sm font-semibold text-white transition disabled:opacity-40;
    background: linear-gradient(180deg, #a78bfa, #7c3aed);
    box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.45), 0 10px 28px -12px rgba(139, 92, 246, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  }
  .tool-button {
    @apply inline-flex min-h-10 items-center gap-2 rounded-lg border border-white/10 bg-[#141a22] px-3 py-2 text-xs font-medium text-slate-300 transition hover:border-cyan-400/40 hover:text-white;
  }
  .active-tool {
    @apply border-cyan-400/55 text-cyan-100;
    background: linear-gradient(180deg, rgba(34, 211, 238, 0.18), rgba(34, 211, 238, 0.06));
    box-shadow: inset 0 0 0 1px rgba(34, 211, 238, 0.25);
  }
  .icon-button {
    @apply grid h-9 w-9 place-items-center rounded-lg border border-white/10 text-slate-300 transition hover:border-cyan-400/40 hover:text-white;
  }
  .field {
    @apply min-h-11 w-full rounded-lg border border-white/10 bg-[#0a0e13] px-3 py-2 text-sm text-white placeholder:text-slate-600 transition focus:border-cyan-400 focus:outline-none focus:ring-1 focus:ring-cyan-400/40;
  }
  .form-label {
    @apply mb-4 block space-y-2 text-xs font-medium text-slate-400;
  }
  .status-row {
    @apply flex items-center justify-between gap-3 rounded-lg border border-white/[0.06] bg-black/20 p-3 text-sm text-slate-300;
  }
  .warning-box {
    @apply rounded-lg border border-amber-400/30 bg-amber-400/[0.08] p-3 text-xs leading-5 text-amber-100;
  }
  .empty {
    @apply py-10 text-center text-sm text-slate-500;
  }
  .chip {
    @apply inline-flex items-center gap-1.5 rounded-full border border-white/10 bg-white/[0.03] px-3 py-1 text-xs text-slate-300 transition hover:border-cyan-400/40 hover:text-cyan-200;
  }
  .chip-ai {
    @apply border-violet-400/30 bg-violet-400/10 text-violet-200 hover:border-violet-400/50;
  }
  .chip-active {
    @apply border-cyan-400/50 bg-cyan-400/15 text-cyan-100;
  }
  .mono { @apply font-mono tracking-tight; }
  .eyebrow {
    @apply mb-2 inline-flex items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.22em] text-cyan-400;
  }
  .eyebrow::before {
    content: '';
    @apply inline-block h-px w-6 bg-cyan-400/70;
  }
  /* technical readout strip */
  .readout {
    @apply flex items-center justify-between gap-3 rounded-lg border border-white/[0.06] bg-black/25 px-3 py-2.5;
  }
  .readout-label { @apply text-[11px] font-medium uppercase tracking-wider text-slate-500; }
  .readout-value { @apply text-sm font-medium text-slate-100; }
  /* viewport technical grid backdrop */
  .viewport-grid {
    background:
      radial-gradient(circle at 50% 38%, rgba(34, 211, 238, 0.06), transparent 55%),
      linear-gradient(180deg, #0b1117, #060a0e 70%);
  }
  .viewport-grid::after {
    content: '';
    position: absolute; inset: 0;
    background-image:
      linear-gradient(rgba(34, 211, 238, 0.05) 1px, transparent 1px),
      linear-gradient(90deg, rgba(34, 211, 238, 0.05) 1px, transparent 1px);
    background-size: 40px 40px;
    mask-image: radial-gradient(ellipse 70% 60% at 50% 45%, #000 30%, transparent 75%);
    pointer-events: none;
  }
  .scanline {
    position: absolute; left: 0; right: 0; height: 2px;
    background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.5), transparent);
    animation: scan 4.5s ease-in-out infinite;
    pointer-events: none;
  }
  @keyframes scan {
    0% { top: 8%; opacity: 0; }
    20% { opacity: 0.7; }
    80% { opacity: 0.7; }
    100% { top: 92%; opacity: 0; }
  }
  .pulse-dot { animation: pulse-soft 1.8s ease-in-out infinite; }
  @keyframes pulse-soft { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
  .fade-in { animation: fade-in 0.35s ease-out; }
  @keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

  /* Workflow strip stages */
  .wf-node { @apply grid h-7 w-7 place-items-center rounded-md border text-[11px] font-semibold transition; }
  .wf-complete { @apply border-cyan-400/50 bg-cyan-400/10 text-cyan-200; }
  .wf-current {
    @apply border-cyan-400 bg-cyan-400/20 text-cyan-50;
    box-shadow: 0 0 0 1px rgba(0, 212, 255, 0.35), 0 0 18px -4px rgba(0, 212, 255, 0.6), inset 0 1px 0 rgba(255,255,255,0.18);
  }
  .wf-upcoming { @apply border-white/10 bg-white/[0.02] text-slate-600; }
  .wf-warn { @apply border-amber-400/50 bg-amber-400/10 text-amber-200; }
  .wf-fail { @apply border-red-500/50 bg-red-500/10 text-red-300; }
  .wf-sim { @apply border-violet-400/50 bg-violet-400/10 text-violet-200; }
  .wf-link { @apply border-cyan-400/40; }
  .wf-bar { @apply h-px flex-1; background: linear-gradient(90deg, rgba(0,212,255,0.5), rgba(255,255,255,0.06)); }

  .floor-watermark {
    font-family: var(--font-heading);
    letter-spacing: 0.5em;
    color: rgba(148, 163, 184, 0.22);
    text-transform: uppercase;
  }

  .tool-rail-btn { @apply grid h-9 w-9 place-items-center rounded-lg border border-white/10 bg-[#141a22] text-slate-300 transition hover:border-cyan-400/40 hover:text-white; }
  .tool-rail-btn.active { @apply border-cyan-400/55 text-cyan-100; background: linear-gradient(180deg, rgba(0,212,255,0.18), rgba(0,212,255,0.06)); box-shadow: inset 0 0 0 1px rgba(0,212,255,0.25); }

  .sim-badge { @apply inline-flex items-center gap-1 rounded border border-violet-400/40 bg-violet-400/10 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-violet-200; }
  .checkerboard {
    background-color: #0a0e13;
    background-image:
      linear-gradient(45deg, #161b22 25%, transparent 25%),
      linear-gradient(-45deg, #161b22 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #161b22 75%),
      linear-gradient(-45deg, transparent 75%, #161b22 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  }

  .collapse-chevron { transition: transform 0.2s ease; }
  .collapse-chevron.open { transform: rotate(90deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .scanline, .pulse-dot { display: none !important; }
}

/* Accessibility toggles driven by Settings → stored on the user record */
.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}
.reduced-motion .scanline, .reduced-motion .pulse-dot { display: none !important; }
.high-contrast {
  --foreground: 0 0% 100%;
  --muted-foreground: 210 30% 82%;
  --border: 200 55% 62%;
}