/* ─── shadcn design tokens (zinc theme) ─────────────────────────────── */
:root {
  --background:           0 0% 100%;
  --foreground:           240 10% 3.9%;

  --card:                 0 0% 100%;
  --card-foreground:      240 10% 3.9%;

  --popover:              0 0% 100%;
  --popover-foreground:   240 10% 3.9%;

  --primary:              240 5.9% 10%;
  --primary-foreground:   0 0% 98%;

  --secondary:            240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;

  --muted:                240 4.8% 95.9%;
  --muted-foreground:     240 3.8% 46.1%;

  --accent:               240 4.8% 95.9%;
  --accent-foreground:    240 5.9% 10%;

  --destructive:          0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;

  --border:               240 5.9% 90%;
  --input:                240 5.9% 90%;
  --ring:                 240 5.9% 10%;

  --radius:               0.5rem;

  /* v2.1 — one branded accent used sparingly: active nav underline,
     Save button highlight, project default-color dot, welcome avatar ring. */
  --accent-brand:           217 91% 60%;
  --accent-brand-foreground: 0 0% 100%;
}

/* v2.1 — Save button accent (subtle outline glow, not a full color override). */
.save-accent {
  box-shadow: 0 0 0 1px hsl(var(--accent-brand) / 0.35);
}
.save-accent:hover {
  box-shadow: 0 0 0 2px hsl(var(--accent-brand) / 0.45);
}

/* v2.1 — primary header nav for signed-in users. */
.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.8125rem;
  color: hsl(var(--muted-foreground));
  border-radius: calc(var(--radius) - 2px);
  text-decoration: none;
  transition: color 120ms ease, background-color 120ms ease;
}
.nav-link:hover {
  color: hsl(var(--foreground));
  background-color: hsl(var(--accent) / 0.5);
}
.nav-link-active {
  color: hsl(var(--foreground));
  font-weight: 500;
}
.nav-link-active::after {
  content: "";
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: -0.5rem;
  height: 2px;
  background-color: hsl(var(--accent-brand));
  border-radius: 1px;
}

/* v2.1 — empty state container shared across pages. */
.empty-state {
  border-style: dashed;
}

/* v2.1 — project card visuals. */
.project-card {
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.project-card:hover {
  border-color: hsl(var(--accent-brand) / 0.4);
  box-shadow: 0 1px 4px hsl(var(--accent-brand) / 0.08);
}
.project-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 9999px;
  display: inline-block;
}
.project-dot-blue    { background-color: #3b82f6; }
.project-dot-emerald { background-color: #10b981; }
.project-dot-amber   { background-color: #f59e0b; }
.project-dot-rose    { background-color: #f43f5e; }
.project-dot-violet  { background-color: #8b5cf6; }
.project-dot-slate   { background-color: #64748b; }

/* v2.1 — filter bar (projects + history). */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.625rem;
  background: hsl(var(--muted) / 0.4);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}
.filter-bar .input { height: 2rem; font-size: 0.8125rem; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  height: 1.375rem;
  padding: 0 0.5rem;
  font-size: 0.6875rem;
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
  border-radius: 9999px;
}
.tag-chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.875rem;
  height: 0.875rem;
  margin-left: 0.125rem;
  border-radius: 9999px;
  color: hsl(var(--accent-foreground) / 0.6);
}
.tag-chip button:hover {
  color: hsl(var(--accent-foreground));
  background-color: hsl(var(--accent-foreground) / 0.12);
}
.tag-input-host {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.25rem 0.5rem;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: var(--radius);
}
.tag-input-host:focus-within {
  outline: 2px solid hsl(var(--ring));
  outline-offset: -1px;
}
.tag-input-host input {
  flex: 1 1 6rem;
  min-width: 6rem;
  border: 0;
  background: transparent;
  font-size: 0.8125rem;
  padding: 0.25rem 0.125rem;
  outline: none;
}

/* ─── Base reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── shadcn components ──────────────────────────────────────────────── */

/* Card */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
}

.card-header  { padding: 1.5rem; padding-bottom: 0; }
.card-content { padding: 1.5rem; }
.card-footer  { padding: 1.5rem; padding-top: 0; }

/* Separator */
.separator {
  height: 1px;
  background: hsl(var(--border));
  margin: 0;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.6;
  border: 1px solid transparent;
}
.badge-default   { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.badge-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); border-color: hsl(var(--border)); }
.badge-outline   { background: transparent; color: hsl(var(--foreground)); border-color: hsl(var(--border)); }
.badge-success   { background: hsl(142 71% 93%); color: hsl(142 71% 25%); }

/* Button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: calc(var(--radius) - 2px);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  height: 2.5rem;
  padding: 0 1rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
}

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

.btn:disabled, .btn[disabled] {
  pointer-events: none;
  opacity: 0.5;
}

.btn-default {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn-default:hover { background: hsl(var(--primary) / 0.9); }

.btn-secondary {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border));
}
.btn-secondary:hover { background: hsl(var(--accent)); }

.btn-outline {
  background: transparent;
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}
.btn-outline:hover {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.btn-ghost {
  background: transparent;
  color: hsl(var(--foreground));
  border-color: transparent;
}
.btn-ghost:hover { background: hsl(var(--accent)); }

.btn-destructive {
  background: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
}
.btn-destructive:hover { background: hsl(var(--destructive) / 0.9); }

.btn-sm {
  height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.8rem;
  border-radius: calc(var(--radius) - 4px);
}

.btn-lg {
  height: 3rem;
  padding: 0 2rem;
  font-size: 1rem;
}

.btn-icon {
  width: 2.5rem;
  padding: 0;
}

/* Input */
.input {
  display: flex;
  width: 100%;
  height: 2.5rem;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--input));
  background: hsl(var(--background));
  padding: 0 0.75rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.input::placeholder { color: hsl(var(--muted-foreground)); }
.input:focus {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.1);
}
.input:disabled { cursor: not-allowed; opacity: 0.5; background: hsl(var(--muted)); }

.input-sm {
  height: 2rem;
  padding: 0 0.5rem;
  font-size: 0.8rem;
  border-radius: calc(var(--radius) - 4px);
}

/* Label */
.label {
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  display: block;
  margin-bottom: 6px;
}

/* ─── Dropzone ───────────────────────────────────────────────────────── */
.dropzone-border {
  border: 2px dashed hsl(var(--border));
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
  background: hsl(var(--muted) / 0.4);
}

.dropzone-border:hover {
  background: hsl(var(--muted) / 0.7);
  border-color: hsl(var(--muted-foreground) / 0.4);
}

.dropzone-border.dragging {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary) / 0.04);
}

.dropzone-icon-wrap {
  width: 52px;
  height: 52px;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
  color: hsl(var(--muted-foreground));
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.dropzone-border.dragging .dropzone-icon-wrap {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  transform: scale(1.08);
}

/* ─── HTMX indicator ─────────────────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: flex; }

/* ─── Alpine cloak ───────────────────────────────────────────────────── */
[x-cloak] { display: none !important; }

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

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid hsl(var(--border));
  border-top-color: hsl(var(--foreground));
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ─── Result panel ───────────────────────────────────────────────────── */
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-animate {
  animation: fade-in-up 0.3s ease both;
}

/* Segmented control (view toggle) */
.seg-ctrl {
  display: inline-flex;
  background: hsl(var(--muted));
  border-radius: calc(var(--radius) - 2px);
  padding: 3px;
  gap: 2px;
}

.seg-ctrl button {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 3px 12px;
  border-radius: calc(var(--radius) - 4px);
  border: none;
  cursor: pointer;
  color: hsl(var(--muted-foreground));
  background: transparent;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.seg-ctrl button.active {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

/* Markdown rendered styles */
.md-content {
  font-size: 0.875rem;
  line-height: 1.75;
  color: hsl(var(--foreground));
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 4px;
}

.md-content::-webkit-scrollbar { width: 5px; }
.md-content::-webkit-scrollbar-track { background: transparent; }
.md-content::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 99px; }

.md-content h1,.md-content h2,.md-content h3,
.md-content h4,.md-content h5,.md-content h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-top: 1.25em;
  margin-bottom: 0.5em;
  color: hsl(var(--foreground));
}
.md-content h1 { font-size: 1.5em; }
.md-content h2 { font-size: 1.25em; }
.md-content h3 { font-size: 1.1em; }

.md-content p { margin: 0.75em 0; }
.md-content a { color: hsl(var(--primary)); text-decoration: underline; text-underline-offset: 2px; }
.md-content strong { font-weight: 600; }
.md-content em { font-style: italic; }

.md-content code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8em;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  border-radius: 4px;
  padding: 0.15em 0.45em;
}

.md-content pre {
  background: hsl(240 10% 8%);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1em 0;
}
.md-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.82rem;
  color: hsl(0 0% 92%);
}

.md-content blockquote {
  border-left: 3px solid hsl(var(--border));
  padding-left: 1rem;
  color: hsl(var(--muted-foreground));
  margin: 1em 0;
}

.md-content table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: 0.82rem; }
.md-content th {
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  padding: 0.4rem 0.75rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
}
.md-content td {
  border: 1px solid hsl(var(--border));
  padding: 0.35rem 0.75rem;
}
.md-content tr:nth-child(even) td { background: hsl(var(--muted) / 0.4); }

.md-content ul,.md-content ol { padding-left: 1.5rem; margin: 0.5em 0; }
.md-content li { margin: 0.2em 0; }
.md-content hr { border: none; border-top: 1px solid hsl(var(--border)); margin: 1.5em 0; }
.md-content img { max-width: 100%; border-radius: var(--radius); margin: 0.5em 0; }

/* Raw markdown */
.md-raw {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-y: auto;
  max-height: 62vh;
  color: hsl(var(--muted-foreground));
  padding: 0.25rem 0;
}
.md-raw::-webkit-scrollbar { width: 5px; }
.md-raw::-webkit-scrollbar-track { background: transparent; }
.md-raw::-webkit-scrollbar-thumb { background: hsl(var(--border)); border-radius: 99px; }

/* ─── Error ──────────────────────────────────────────────────────────── */
.alert-destructive {
  background: hsl(var(--destructive) / 0.08);
  border: 1px solid hsl(var(--destructive) / 0.3);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  color: hsl(var(--destructive));
  animation: fade-in-up 0.25s ease both;
}

/* ─── Metadata table ─────────────────────────────────────────────────── */
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
}
.meta-row + .meta-row { border-top: 1px solid hsl(var(--border)); }
.meta-key { font-size: 0.78rem; color: hsl(var(--muted-foreground)); font-weight: 500; }
.meta-val { font-size: 0.8rem; font-weight: 500; color: hsl(var(--foreground)); font-family: 'JetBrains Mono', monospace; font-size: 0.72rem; }

/* ─── Toast banner ─────────────────────────────────────────────────────── */
#toast-host .toast-banner {
  animation: fade-in-up 0.25s ease both;
}

/* ─── Upsell card (anonymous CTA) ─────────────────────────────────────── */
.upsell-card {
  border-style: dashed;
}
