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

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,300;0,14..32,400;0,14..32,500;0,14..32,600;0,14..32,700;0,14..32,800;1,14..32,400&display=swap');

/* ─── Design Tokens ──────────────────────────────────────────────────────── */
@layer base {
  :root {
    --bg: 220 20% 97%;
    --surface-2: 220 18% 95%;
    --text: 222 47% 11%;
    --text-muted: 217 19% 47%;
    --danger: 0 84% 60%;

    /* Backgrounds */
    --background: 0 0% 100%;
    --background-subtle: 220 20% 97%;     /* slate-50 equivalent — page bg */
    --surface: 0 0% 100%;                 /* card / panel surface */
    --surface-raised: 0 0% 100%;          /* elevated modals / dropdowns */

    /* Foreground */
    --foreground: 222 47% 11%;            /* slate-900 — primary text */
    --foreground-muted: 217 19% 47%;      /* slate-500 — secondary text */
    --foreground-subtle: 215 16% 65%;     /* slate-400 — placeholder / hint */

    /* Card */
    --card: 0 0% 100%;
    --card-foreground: 222 47% 11%;

    /* Popover */
    --popover: 0 0% 100%;
    --popover-foreground: 222 47% 11%;

    /* Primary — Violet */
    --primary: 258 90% 58%;               /* violet-600 — slightly stronger */
    --primary-foreground: 0 0% 100%;
    --primary-hover: 263 90% 51%;         /* violet-700 */
    --primary-subtle: 258 100% 97%;       /* violet-50 */
    --primary-muted: 259 94% 88%;         /* violet-200 */

    /* Secondary — neutral */
    --secondary: 220 14% 96%;
    --secondary-foreground: 222 47% 11%;

    /* Muted */
    --muted: 220 14% 96%;
    --muted-foreground: 217 19% 47%;

    /* Accent */
    --accent: 220 14% 96%;
    --accent-foreground: 222 47% 11%;

    /* Semantic */
    --destructive: 0 84% 60%;
    --destructive-foreground: 0 0% 100%;
    --success: 160 84% 39%;               /* emerald-600 */
    --warning: 38 92% 50%;               /* amber-500 */
    --info: 217 91% 60%;                  /* blue-500 */

    /* Borders */
    --border: 220 13% 91%;               /* slate-200 */
    --border-strong: 215 20% 83%;        /* slate-300 */
    --input: 220 13% 91%;
    --ring: 258 90% 58%;

    /* Sidebar */
    --sidebar-bg: 0 0% 100%;
    --sidebar-border: 220 13% 93%;
    --sidebar-item-active-bg: 258 100% 97%;
    --sidebar-item-active-text: 263 90% 46%;
    --sidebar-item-active-icon: 263 90% 58%;
    --sidebar-label: 215 16% 65%;

    /* Radius */
    --radius: 0.625rem;                   /* 10px — slightly tighter than before */
    --radius-sm: 0.375rem;               /* 6px */
    --radius-lg: 0.875rem;               /* 14px */
    --radius-xl: 1.125rem;              /* 18px */

    /* Shadows */
    --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.04);
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.06), 0 1px 2px -1px rgb(0 0 0 / 0.04);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.06), 0 2px 4px -2px rgb(0 0 0 / 0.04);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.06), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  }

  /* ── Dark mode overrides ──────────────────────────────────────────────── */
  .dark {
    --bg: 222 47% 8%;
    --surface-2: 222 40% 13%;
    --text: 213 31% 95%;
    --text-muted: 215 20% 60%;
    --danger: 0 72% 56%;

    --background: 222 47% 6%;
    --background-subtle: 222 47% 8%;
    --surface: 222 47% 10%;
    --surface-raised: 222 47% 12%;

    --foreground: 213 31% 95%;
    --foreground-muted: 215 20% 60%;
    --foreground-subtle: 215 16% 45%;

    --card: 222 47% 10%;
    --card-foreground: 213 31% 95%;

    --popover: 222 47% 10%;
    --popover-foreground: 213 31% 95%;

    --secondary: 222 47% 15%;
    --secondary-foreground: 213 31% 95%;

    --muted: 222 47% 13%;
    --muted-foreground: 215 20% 55%;

    --accent: 222 47% 13%;
    --accent-foreground: 213 31% 95%;

    --border: 222 35% 18%;
    --border-strong: 222 30% 25%;
    --input: 222 35% 18%;

    --sidebar-bg: 222 47% 7%;
    --sidebar-border: 222 35% 14%;
    --sidebar-item-active-bg: 258 60% 15%;
    --sidebar-item-active-text: 259 80% 75%;
    --sidebar-item-active-icon: 259 80% 70%;
    --sidebar-label: 215 16% 40%;
  }

  * {
    @apply border-border;
  }

  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    @apply bg-[hsl(var(--background-subtle))] text-foreground;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv11', 'ss01';
    line-height: 1.5;
  }

  h1, h2, h3, h4, h5, h6 {
    letter-spacing: -0.025em;
    line-height: 1.25;
  }
}

/* ─── Component Utilities ────────────────────────────────────────────────── */
@layer utilities {
  /* Typography */
  .text-display { @apply text-2xl font-bold tracking-tight text-slate-900; }
  .text-title    { @apply text-lg font-semibold tracking-tight text-slate-900; }
  .text-heading  { @apply text-base font-semibold text-slate-900; }
  .text-label    { @apply text-xs font-semibold uppercase tracking-widest text-slate-400; }
  .text-body     { @apply text-sm text-slate-600; }
  .text-caption  { @apply text-xs text-slate-500; }

  /* Tabular numbers (data tables, metrics) */
  .tabular { font-variant-numeric: tabular-nums; }

  /* Page section */
  .page-section { @apply space-y-1.5; }

  /* Divider */
  .divider { @apply border-t border-slate-100; }

  /* Focus ring — replace the default ring-offset approach */
  .focus-ring {
    @apply focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-500/40 focus-visible:ring-offset-1;
  }

  /* Sidebar nav label */
  .nav-label {
    @apply px-3 pb-1 pt-4 text-[10px] font-semibold uppercase tracking-[0.1em] text-slate-400 first:pt-2;
  }

  /* Shadow tokens as utilities */
  .shadow-xs  { box-shadow: var(--shadow-xs); }
  .shadow-card { box-shadow: var(--shadow-sm); }
  .shadow-panel { box-shadow: var(--shadow-md); }
}

@layer components {
  .marketplace-shell {
    background: hsl(var(--bg));
    color: hsl(var(--text));
  }

  .marketplace-divider {
    border-color: hsl(var(--border));
  }

  .marketplace-panel {
    background: hsl(var(--surface));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--text));
    box-shadow: var(--shadow-sm);
  }

  .marketplace-panel-muted {
    background: hsl(var(--surface-2));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--text));
  }

  .marketplace-card {
    background: hsl(var(--surface));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--text));
    box-shadow: var(--shadow-sm);
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  }

  .marketplace-card:hover {
    transform: translateY(-4px);
    border-color: hsl(var(--border-strong));
    box-shadow: var(--shadow-lg);
  }

  .marketplace-text-muted {
    color: hsl(var(--text-muted));
  }

  .marketplace-label {
    color: hsl(var(--text-muted));
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 700;
  }

  .marketplace-input {
    background: hsl(var(--surface));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--text));
  }

  .marketplace-input::placeholder {
    color: hsl(var(--text-muted));
  }

  .marketplace-input:focus {
    outline: none;
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.14);
  }

  .marketplace-button-primary {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: 1px solid hsl(var(--primary));
    transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
  }

  .marketplace-button-primary:hover {
    background: hsl(var(--primary-hover));
    border-color: hsl(var(--primary-hover));
  }

  .marketplace-button-secondary {
    background: hsl(var(--surface));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--text));
    transition: background-color 180ms ease, border-color 180ms ease;
  }

  .marketplace-button-secondary:hover {
    background: hsl(var(--surface-2));
    border-color: hsl(var(--border-strong));
  }

  .marketplace-button-soft {
    background: hsl(var(--surface-2));
    border: 1px solid hsl(var(--border));
    color: hsl(var(--text));
    transition: background-color 180ms ease, border-color 180ms ease;
  }

  .marketplace-button-soft:hover {
    border-color: hsl(var(--primary) / 0.35);
    background: hsl(var(--primary) / 0.08);
  }

  .marketplace-status {
    border: 1px solid hsl(var(--border));
    background: hsl(var(--surface-2));
    color: hsl(var(--text-muted));
  }

  .marketplace-status-success {
    border-color: hsl(var(--success) / 0.24);
    background: hsl(var(--success) / 0.12);
    color: hsl(var(--success));
  }

  .marketplace-status-primary {
    border-color: hsl(var(--primary) / 0.24);
    background: hsl(var(--primary) / 0.12);
    color: hsl(var(--primary));
  }

  .marketplace-status-warning {
    border-color: hsl(var(--warning) / 0.28);
    background: hsl(var(--warning) / 0.14);
    color: hsl(var(--warning));
  }

  .marketplace-status-danger {
    border-color: hsl(var(--danger) / 0.24);
    background: hsl(var(--danger) / 0.12);
    color: hsl(var(--danger));
  }

  .marketplace-featured {
    border-color: hsl(var(--primary) / 0.2);
    background:
      linear-gradient(180deg, hsl(var(--surface)) 0%, hsl(var(--surface-2)) 100%);
  }

  .marketplace-icon-tile {
    background: hsl(var(--primary) / 0.14);
    color: hsl(var(--primary));
  }

  .marketplace-empty {
    border: 1px dashed hsl(var(--border));
    background: hsl(var(--surface-2));
    color: hsl(var(--text-muted));
  }
}

/* ─── Animation ──────────────────────────────────────────────────────────── */
@layer utilities {
  .animate-in  { animation: animate-in 0.18s ease; }
  .fade-in     { animation: fade-in 0.15s ease; }
  .zoom-in-95  { animation: zoom-in 0.15s ease; }
  .slide-in-from-top { animation: slide-in-from-top 0.2s ease; }
}

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

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

@keyframes zoom-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

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

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: hsl(215 16% 80%);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: hsl(215 16% 65%);
}

/* ─── Selection ──────────────────────────────────────────────────────────── */
::selection {
  background: hsl(258 100% 93%);
  color: hsl(263 90% 35%);
}
