@import "tailwindcss";

/* ==================================================================== */
/* Layer 1 — Raw tokens (source values, Anthropic/Claude Labs palette)   */
/* Light theme is the default at :root; dark overrides below.            */
/* ==================================================================== */
:root {
  --color-paper: #FBF8F3;
  --color-surface: #FFFFFF;
  --color-ink: #191919;
  --color-ink-muted: #5A5651;
  --color-rule: #E8E1D6;
  --color-accent: #D4A27F;
  --color-accent-ink: #7A4A24;
  --color-installed: #2F6A4A;
  --color-own: #8A5A1F;
  --color-focus: #3B6EA8;
  /* 0700 polish — primary-action token for CTAs (solid button fill).
     The accent tan reads as "muted/disabled" when used as a button background
     against paper. This token is deliberately saturated + high-contrast. */
  --color-action: #2F5B8E;
  --color-action-hover: #264A73;
  --color-action-ink: #FFFFFF;

  --font-serif: "Source Serif 4 Variable", "Source Serif 4", Georgia, serif;
  --font-sans: "Inter Tight Variable", "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono Variable", "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --duration-fast: 120ms;
  --duration-base: 180ms;
  --duration-modal: 240ms;
}

[data-theme="light"] {
  --color-paper: #FBF8F3;
  --color-surface: #FFFFFF;
  --color-ink: #191919;
  --color-ink-muted: #5A5651;
  --color-rule: #E8E1D6;
  --color-accent: #D4A27F;
  --color-accent-ink: #7A4A24;
  --color-installed: #2F6A4A;
  --color-own: #8A5A1F;
  --color-focus: #3B6EA8;
  --color-action: #2F5B8E;
  --color-action-hover: #264A73;
  --color-action-ink: #FFFFFF;
}

[data-theme="dark"] {
  --color-paper: #1A1814;
  --color-surface: #221F1A;
  --color-ink: #F2ECE1;
  --color-ink-muted: #A59D8F;
  --color-rule: #2E2A24;
  --color-accent: #E0B793;
  --color-accent-ink: #F2ECE1;
  --color-installed: #86C9A5;
  --color-own: #E6B877;
  --color-focus: #7CA8D9;
  --color-action: #4A82C8;
  --color-action-hover: #6093D6;
  --color-action-ink: #0B1420;
}

/* High-contrast overlay — tightens text vs background separation. */
[data-contrast="more"] {
  --color-ink-muted: #3D3A36;
  --color-rule: #B8AD9A;
}

[data-theme="dark"][data-contrast="more"] {
  --color-ink-muted: #D4CBBA;
  --color-rule: #4A453D;
}

/* ==================================================================== */
/* Layer 2 — Semantic tokens (resolve through Layer 1 via var())         */
/* Components reference these, never raw --color-* tokens.               */
/* ==================================================================== */
:root {
  --bg-canvas: var(--color-paper);
  --bg-surface: var(--color-surface);
  /* Account-cabinet panels (AccountShell/SideNav, PlanCard, TokensTable,
     ProfileForm, NotificationsForm, DangerZone, ConnectedReposTable) reference
     --bg-elevated. It was never defined → fell back to #fff, so in DARK theme
     those panels rendered white with light --text-primary text (1.18:1, the
     "My queue"/Account tabs were unreadable). Map it to the theme-aware surface
     so it is dark in dark theme and light in light theme. */
  --bg-elevated: var(--color-surface);
  --text-primary: var(--color-ink);
  --text-secondary: var(--color-ink-muted);
  --text-accent: var(--color-accent-ink);
  --border-default: var(--color-rule);
  --border-focus: var(--color-focus);
  --status-installed: var(--color-installed);
  --status-own: var(--color-own);
  --accent-surface: var(--color-accent);
}

/* ==================================================================== */
/* Layer 3 — Legacy aliases (existing components during migration)       */
/* Will be removed in Phase 4 polish; components gradually migrate to    */
/* Layer 2 semantic names.                                               */
/* ==================================================================== */
:root {
  --surface-0: var(--color-paper);
  --surface-1: var(--color-surface);
  --surface-2: var(--color-surface);
  --surface-3: var(--color-rule);
  --surface-4: var(--color-rule);
  --border-subtle: var(--color-rule);
  --border-hover: var(--color-accent);
  --border-active: var(--color-focus);
  --text-tertiary: var(--color-ink-muted);
  --accent: var(--color-accent);
  --accent-hover: var(--color-accent-ink);
  --accent-muted: color-mix(in srgb, var(--color-accent) 20%, transparent);
  --green: var(--color-installed);
  --green-muted: color-mix(in srgb, var(--color-installed) 18%, transparent);
  --red: #b54444;
  --red-muted: color-mix(in srgb, #b54444 18%, transparent);
  --yellow: var(--color-own);
  --yellow-muted: color-mix(in srgb, var(--color-own) 18%, transparent);
  --orange: var(--color-own);
  --orange-muted: color-mix(in srgb, var(--color-own) 18%, transparent);
  --purple: var(--color-accent);
  --purple-muted: color-mix(in srgb, var(--color-accent) 18%, transparent);
  --ease-out-expo: var(--ease-standard);
  --ease-spring: var(--ease-standard);
}

[data-theme="dark"] {
  --red: #D48A8A;
  --red-muted: color-mix(in srgb, #D48A8A 22%, transparent);
}

/* ==================================================================== */
/* Base                                                                  */
/* ==================================================================== */
html {
  background: var(--bg-canvas);
  color: var(--text-primary);
}

body {
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: color-mix(in srgb, var(--color-accent) 35%, transparent);
  color: var(--text-primary);
}

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

/* ==================================================================== */
/* Scrollbar                                                             */
/* ==================================================================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ==================================================================== */
/* Motion — restrained, single curve                                     */
/* ==================================================================== */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes slide-in-right {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

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

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

@keyframes spin-slow {
  to { transform: rotate(360deg); }
}

/* 0823 F-001: dedicated keyframe for CheckNowButton spinner. The component
 * declares `animation: check-now-spin 800ms linear infinite` inline; without
 * this @keyframes block the spinner used to render as a static circle. */
@keyframes check-now-spin {
  to { transform: rotate(360deg); }
}

.animate-fade-in        { animation: fade-in var(--duration-base) var(--ease-standard) both; }
.animate-fade-in-scale  { animation: fade-in-scale var(--duration-base) var(--ease-standard) both; }
.animate-slide-in-right { animation: slide-in-right var(--duration-base) var(--ease-standard) both; }
.animate-overlay-in     { animation: overlay-in var(--duration-fast) var(--ease-standard) both; }
.animate-modal-in       { animation: modal-in var(--duration-modal) var(--ease-standard) both; }

/* Staggered children kept for legacy compat; delays simplified. */
.stagger-children > * { animation: fade-in var(--duration-base) var(--ease-standard) both; }
.stagger-children > *:nth-child(1) { animation-delay: 0ms; }
.stagger-children > *:nth-child(2) { animation-delay: 30ms; }
.stagger-children > *:nth-child(3) { animation-delay: 60ms; }
.stagger-children > *:nth-child(4) { animation-delay: 90ms; }
.stagger-children > *:nth-child(n+5) { animation-delay: 120ms; }

/* Reduced motion — collapse all animations. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0ms !important;
    transition-delay: 0ms !important;
  }
}

/* ==================================================================== */
/* Placeholder (replaces .skeleton shimmer — static, no animation)       */
/* .skeleton is a legacy alias mapping to the same static style.         */
/* ==================================================================== */
.placeholder,
.skeleton {
  background: var(--border-default);
  border-radius: 4px;
  opacity: 0.6;
}

/* ==================================================================== */
/* Card — flat warm surface, 1px rule, no shadow                         */
/* ==================================================================== */
.glass-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  transition: border-color var(--duration-fast) var(--ease-standard);
}

.glass-card:hover { border-color: var(--color-accent); }

.glass-card-interactive:hover {
  border-color: var(--color-accent);
}

/* ==================================================================== */
/* Badge — base layout. The leading dot is opt-in via .pill-installed /  */
/* .pill-own (status indicators). Filled badges (StatusPill, verdict     */
/* pills, etc.) inherit only the layout, never the bullet.               */
/* ==================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.4;
  color: var(--text-secondary);
}

/* status indicators render as text + leading dot */
.pill-installed::before,
.pill-own::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill-installed { color: var(--status-installed); }
.pill-own       { color: var(--status-own); }

/* ==================================================================== */
/* Eval-cases grid (Studio Tests panel) — desktop side-by-side, narrow  */
/* viewports collapse to a single stacked column. Replaces the prior    */
/* inline `gridTemplateColumns` so the breakpoint can be honored.       */
/* ==================================================================== */
.eval-cases-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 700px) {
  .eval-cases-grid {
    grid-template-columns: 1fr;
  }
}

/* ==================================================================== */
/* Input                                                                 */
/* ==================================================================== */
.input-field {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  transition: border-color var(--duration-fast) var(--ease-standard);
  outline: none;
  width: 100%;
}

.input-field:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-focus) 18%, transparent);
}

.input-field::placeholder { color: var(--text-secondary); }

/* ==================================================================== */
/* Buttons — flat, no gradients, ink-filled primary                      */
/* ==================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  height: 36px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard),
              color var(--duration-fast) var(--ease-standard),
              border-color var(--duration-fast) var(--ease-standard);
  border: 1px solid transparent;
  outline: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--color-ink);
  color: var(--color-paper);
}
.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-ink) 88%, var(--color-accent));
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--text-primary);
}

.btn-purple { /* legacy alias — mapped to primary for migration period */
  background: var(--color-ink);
  color: var(--color-paper);
}
.btn-purple:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-ink) 88%, var(--color-accent));
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
}
.btn-danger:hover:not(:disabled) {
  background: var(--red-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
  height: auto;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--border-default);
}

/* ==================================================================== */
/* Spinner                                                               */
/* ==================================================================== */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-default);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin-slow 0.6s linear infinite;
}

.spinner-lg {
  width: 24px;
  height: 24px;
  border-width: 2.5px;
}

/* ==================================================================== */
/* Score ring — themed through tokens                                    */
/* ==================================================================== */
.score-ring {
  --size: 56px;
  --stroke: 4px;
  width: var(--size);
  height: var(--size);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.score-ring svg {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.score-ring circle {
  fill: none;
  stroke-width: var(--stroke);
  stroke-linecap: round;
}

.score-ring .track { stroke: var(--border-default); }
.score-ring .fill {
  transition: stroke-dashoffset 0.8s var(--ease-standard);
}

/* ==================================================================== */
/* Divider — never full-width; stops at column padding                   */
/* ==================================================================== */
.divide-y > * + * { border-top-color: var(--border-default); }

hr {
  border: none;
  border-top: 1px solid var(--border-default);
  margin: 0;
}

/* ==================================================================== */
/* Theme transition (T-042 / AC-US2-08, AC-US2-09)                       */
/* A restrained 150ms crossfade on theme swap for bg/color/border only.  */
/* Focus outlines MUST NOT transition — the ring should appear instantly */
/* so keyboard users get immediate feedback. Reduced-motion block below  */
/* already collapses all transition durations to 0ms.                    */
/* ==================================================================== */
:root {
  --theme-transition: background-color 150ms var(--ease-standard),
                      color 150ms var(--ease-standard),
                      border-color 150ms var(--ease-standard);
}

html,
body {
  transition: var(--theme-transition);
}

/* Opt surfaces into the same crossfade, but keep layout properties static. */
.glass-card,
.pill,
.input-field,
.btn,
aside,
header,
footer,
main,
nav,
section,
[data-theme-surface] {
  transition: var(--theme-transition);
}

/* Do NOT transition focus outlines — the ring must appear instantly when
   keyboard focus lands. The existing :focus-visible block owns the outline;
   we just make sure no inherited transition is delaying it. */
:focus-visible {
  transition-property: none;
}

input:focus,
textarea:focus,
select:focus,
button:focus {
  transition: none;
}

/* ==================================================================== */
/* Focus-visible rings (T-045 / AC-US8-03, AC-US8-06)                    */
/* 2px ring in --border-focus with 2px offset. `.focus-ring` is a helper */
/* so custom-rendered elements (e.g. role="button" divs) can opt in.     */
/* [data-contrast="more"] widens the ring to 3px.                        */
/* ==================================================================== */
.focus-ring:focus-visible,
[role="button"]:focus-visible,
[role="menuitem"]:focus-visible,
[role="tab"]:focus-visible,
[role="option"]:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

[data-contrast="more"] :focus-visible,
[data-contrast="more"] .focus-ring:focus-visible {
  outline-width: 3px;
}

/* ==================================================================== */
/* Studio Grid Responsive                                                */
/* ==================================================================== */
@media (max-width: 1024px) and (min-width: 768px) {
  .studio-grid {
    grid-template-columns: 240px 1px 1fr !important;
  }
}

@media (max-width: 767px) {
  .studio-grid {
    grid-template-columns: 1fr !important;
  }
  .studio-grid > :nth-child(2),
  .studio-grid > :nth-child(3) {
    display: none;
  }
}

/* ==================================================================== */
/* SkillOverview right-rail (0774): collapse to single column < 900px    */
/* ==================================================================== */
@media (max-width: 899px) {
  .skill-overview {
    grid-template-columns: 1fr !important;
  }
}
