/* =========================================================
   shadcn/ui — Base styles + component classes
   ---------------------------------------------------------
   Pair with tokens.css. Hand-written equivalents of the
   most-used shadcn primitives so static HTML can mimic the
   look without React/Radix/Tailwind.
   ========================================================= */

* { box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Typography ------------------------------------------------ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: hsl(var(--foreground));
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-4) 0;
}
h1 { font-size: var(--text-4xl); letter-spacing: -0.025em; }
h2 { font-size: var(--text-3xl); letter-spacing: -0.025em; }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p { margin: 0 0 var(--space-3) 0; color: hsl(var(--foreground)); }
small, .text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-base { font-size: var(--text-base); }
.text-lg  { font-size: var(--text-lg); }
.text-xl  { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.text-4xl { font-size: var(--text-4xl); }
.text-5xl { font-size: var(--text-5xl); }

.text-muted    { color: hsl(var(--muted-foreground)); }
.text-primary  { color: hsl(var(--primary)); }
.text-destructive { color: hsl(var(--destructive)); }
.font-mono     { font-family: var(--font-mono); }
.font-display  { font-family: var(--font-display); }
.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

a {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  transition: color var(--dur-fast) var(--ease-out);
}
a:hover { color: hsl(var(--primary) / 0.8); }

code, kbd, samp, pre { font-family: var(--font-mono); }
code {
  background: hsl(var(--muted));
  border-radius: calc(var(--radius) - 4px);
  padding: 2px 6px;
  font-size: 0.875em;
  color: hsl(var(--foreground));
}
pre {
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow: auto;
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: hsl(var(--foreground));
}
hr {
  border: none;
  border-top: 1px solid hsl(var(--border));
  margin: var(--space-6) 0;
}
::selection {
  background: hsl(var(--primary) / 0.25);
  color: hsl(var(--foreground));
}

/* Scrollbar (subtle, like shadcn defaults) ------------------ */
* { scrollbar-width: thin; scrollbar-color: hsl(var(--border)) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: hsl(var(--border));
  border-radius: 999px;
  border: 2px solid hsl(var(--background));
}
*::-webkit-scrollbar-thumb:hover {
  background-color: hsl(var(--muted-foreground) / 0.5);
}

/* =========================================================
   Button — shadcn variants: default, secondary, outline,
   ghost, link, destructive. Sizes: sm / default / lg / icon
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  height: 2.25rem;        /* 36px — default */
  padding: 0 var(--space-4);
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) var(--ease-out);
}
.btn:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}
.btn svg { width: 1rem; height: 1rem; flex-shrink: 0; }

/* Sizes */
.btn-sm   { height: 2rem;     padding: 0 var(--space-3); font-size: var(--text-xs); border-radius: calc(var(--radius) - 4px); }
.btn-lg   { height: 2.5rem;   padding: 0 var(--space-6); font-size: var(--text-sm); border-radius: var(--radius); }
.btn-icon { height: 2.25rem;  width: 2.25rem;   padding: 0; }

/* Variants */
.btn-primary, .btn-default {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover, .btn-default:hover {
  background: hsl(var(--primary) / 0.9);
}

.btn-secondary {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: hsl(var(--secondary) / 0.8); }

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

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

.btn-link {
  background: transparent;
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 4px;
  height: auto;
  padding: 0;
}
.btn-link:hover { color: hsl(var(--primary) / 0.8); }

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

/* =========================================================
   Input / Textarea / Label
   ========================================================= */
.label {
  display: inline-block;
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  color: hsl(var(--foreground));
  margin-bottom: var(--space-2);
}

.input, .textarea, .select {
  display: flex;
  align-items: center;
  width: 100%;
  height: 2.25rem;
  padding: 0 var(--space-3);
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: 1;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  appearance: none;
  outline: none;
}
.input::placeholder, .textarea::placeholder { color: hsl(var(--muted-foreground)); }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
  border-color: hsl(var(--ring));
}
.input:disabled, .textarea:disabled, .select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.textarea {
  height: auto;
  min-height: 5rem;
  padding: var(--space-2) var(--space-3);
  line-height: var(--leading-normal);
  resize: vertical;
}
.select {
  padding-right: var(--space-8);
  background-image:
    linear-gradient(45deg, transparent 50%, hsl(var(--muted-foreground)) 50%),
    linear-gradient(135deg, hsl(var(--muted-foreground)) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

/* =========================================================
   Card
   ========================================================= */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.card-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-6);
}
.card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 0;
}
.card-description {
  font-size: var(--text-sm);
  color: hsl(var(--muted-foreground));
  margin: 0;
}
.card-content {
  padding: 0 var(--space-6) var(--space-6);
}
.card-content:first-child { padding-top: var(--space-6); }
.card-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-6) var(--space-6);
}

/* =========================================================
   Badge — variants: default / secondary / outline / destructive
   ========================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
  height: 1.25rem;
  white-space: nowrap;
}
.badge-default { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.badge-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge-outline { background: transparent; color: hsl(var(--foreground)); border-color: hsl(var(--border)); }
.badge-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.badge-success { background: hsl(var(--success)); color: hsl(var(--success-foreground)); }

/* =========================================================
   Alert
   ========================================================= */
.alert {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: var(--space-3);
  row-gap: var(--space-1);
  padding: var(--space-4);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
}
.alert > svg { width: 1rem; height: 1rem; margin-top: 2px; color: hsl(var(--foreground)); }
.alert-title {
  font-weight: 600;
  font-size: var(--text-sm);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0;
}
.alert-description {
  font-size: var(--text-sm);
  color: hsl(var(--muted-foreground));
  line-height: var(--leading-snug);
  grid-column: 2;
  margin: 0;
}
.alert-destructive {
  border-color: hsl(var(--destructive) / 0.5);
  color: hsl(var(--destructive));
}
.alert-destructive > svg { color: hsl(var(--destructive)); }
.alert-destructive .alert-description { color: hsl(var(--destructive) / 0.85); }

/* =========================================================
   Separator / Divider
   ========================================================= */
.separator {
  background: hsl(var(--border));
  flex-shrink: 0;
}
.separator-h { height: 1px; width: 100%; }
.separator-v { width: 1px; height: 100%; }

/* =========================================================
   Avatar
   ========================================================= */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  overflow: hidden;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  width: 2.5rem;
  height: 2.5rem;
  font-size: var(--text-sm);
  font-weight: 500;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-sm { width: 2rem; height: 2rem; font-size: var(--text-xs); }
.avatar-lg { width: 3rem; height: 3rem; font-size: var(--text-base); }

/* =========================================================
   Tabs
   ========================================================= */
.tabs { display: flex; flex-direction: column; gap: var(--space-3); }
.tabs-list {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1);
  background: hsl(var(--muted));
  border-radius: var(--radius);
  height: 2.25rem;
}
.tabs-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.tabs-trigger[data-state="active"], .tabs-trigger.active {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: var(--shadow-xs);
}

/* =========================================================
   Switch / Checkbox / Radio
   ========================================================= */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 2.25rem;
  height: 1.25rem;
  background: hsl(var(--input));
  border-radius: 999px;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
}
.switch[data-state="checked"], .switch.checked {
  background: hsl(var(--primary));
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 1rem; height: 1rem;
  border-radius: 999px;
  background: hsl(var(--background));
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease-out);
}
.switch[data-state="checked"]::after, .switch.checked::after {
  transform: translateX(1rem);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem; height: 1rem;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  flex-shrink: 0;
  color: hsl(var(--primary-foreground));
}
.checkbox[data-state="checked"], .checkbox.checked {
  background: hsl(var(--primary));
  border-color: hsl(var(--primary));
}
.checkbox[data-state="checked"]::after, .checkbox.checked::after {
  content: "";
  width: 10px; height: 10px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='M3 8.5l3.5 3.5L13 5'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='M3 8.5l3.5 3.5L13 5'/></svg>") center / contain no-repeat;
}

.radio {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem; height: 1rem;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}
.radio[data-state="checked"]::after, .radio.checked::after {
  content: "";
  width: 0.5rem; height: 0.5rem;
  border-radius: 999px;
  background: hsl(var(--primary));
}

/* =========================================================
   Table
   ========================================================= */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table thead tr { border-bottom: 1px solid hsl(var(--border)); }
.table th {
  text-align: left;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  padding: var(--space-3) var(--space-4);
  height: 2.5rem;
}
.table td { padding: var(--space-4); vertical-align: middle; }
.table tbody tr {
  border-bottom: 1px solid hsl(var(--border));
  transition: background-color var(--dur-fast) var(--ease-out);
}
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: hsl(var(--muted) / 0.5); }

/* =========================================================
   Dialog (presentational only — no JS modal lifecycle)
   ========================================================= */
.dialog-overlay {
  position: fixed; inset: 0;
  background: hsl(var(--foreground) / 0.5);
}
.dialog-content {
  position: relative;
  display: grid;
  gap: var(--space-4);
  width: min(32rem, calc(100vw - 2rem));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: var(--space-6);
  box-shadow: var(--shadow-lg);
}
.dialog-header { display: flex; flex-direction: column; gap: var(--space-1); text-align: left; }
.dialog-title { font-size: var(--text-lg); font-weight: 600; line-height: 1; letter-spacing: -0.02em; margin: 0; }
.dialog-description { font-size: var(--text-sm); color: hsl(var(--muted-foreground)); margin: 0; }
.dialog-footer {
  display: flex; gap: var(--space-2);
  justify-content: flex-end; flex-wrap: wrap;
}

/* =========================================================
   Tooltip / Kbd / Skeleton
   ========================================================= */
.tooltip {
  display: inline-block;
  padding: 0 var(--space-2);
  height: 1.5rem;
  line-height: 1.5rem;
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  font-size: var(--text-xs);
  border-radius: calc(var(--radius) - 4px);
  box-shadow: var(--shadow-md);
}

.kbd {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-1);
  height: 1.25rem;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  border-bottom-width: 2px;
  border-radius: calc(var(--radius) - 4px);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: hsl(var(--muted-foreground));
}

.skeleton {
  background: hsl(var(--muted));
  border-radius: calc(var(--radius) - 2px);
  animation: skeleton-pulse 2s ease-in-out infinite;
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* =========================================================
   Progress
   ========================================================= */
.progress {
  position: relative;
  width: 100%;
  height: 0.5rem;
  background: hsl(var(--secondary));
  border-radius: 999px;
  overflow: hidden;
}
.progress-indicator {
  height: 100%;
  background: hsl(var(--primary));
  border-radius: 999px;
  transition: width var(--dur-base) var(--ease-out);
}

/* =========================================================
   Layout helpers (small set, used in previews)
   ========================================================= */
.container { max-width: 1280px; margin: 0 auto; padding: 0 var(--space-6); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row   { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.grid  { display: grid; gap: var(--space-4); }
