/* ============================================================
   ATOM.GUI.CSS — shadcn/ui-inspired component styles for Atom.js
   ============================================================ */

/* ── Theme Variables ──────────────────────────────────────── */
:root {
  --bg:              #ffffff;
  --fg:              #09090b;
  --card-bg:         #ffffff;
  --popover-bg:      #ffffff;
  --primary:         #18181b;
  --primary-fg:      #fafafa;
  --secondary:       #f4f4f5;
  --secondary-fg:    #18181b;
  --muted:           #f4f4f5;
  --muted-fg:        #71717a;
  --accent:          #f4f4f5;
  --accent-fg:       #18181b;
  --destructive:     #ef4444;
  --destructive-fg:  #fafafa;
  --success:         #22c55e;
  --success-fg:      #fafafa;
  --warning:         #f59e0b;
  --warning-fg:      #fafafa;
  --border:          #e4e4e7;
  --input-border:    #e4e4e7;
  --ring:            #18181b;
  --ring-offset:     #ffffff;
  --radius:          0.5rem;
  --radius-sm:       0.25rem;
  --radius-md:       0.375rem;
  --radius-lg:       0.75rem;
  --radius-xl:       1rem;
  --radius-full:     9999px;
  --font:            ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono:       ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --shadow-sm:       0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow:          0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md:       0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:       0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl:       0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --transition:      0.15s ease;
}

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

.gui * { font-family: var(--font); }

/* BUTTON */
Button {
  display: inline-flex;
  align-items: center;
  justify-content: left;
  gap: 0.5rem;
  white-space: nowrap;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  transition: background-color var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition), opacity var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
  outline: none;
  text-decoration: none;
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;

  &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
  &:disabled, &[disabled] { pointer-events: none; opacity: 0.5; }

  &.sm  { height: 2rem;    padding: 0 0.75rem; font-size: 0.8125rem; border-radius: var(--radius-md); }
  &.md  { height: 2.25rem; padding: 0 1rem; }
  &.lg  { height: 2.5rem;  padding: 0 1.5rem; font-size: 1rem; }
  &.icon { height: 2.25rem; width: 2.25rem; padding: 0; }

  &.primary { background-color: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
  &.primary:hover:not(:disabled) { background-color: #27272a; }
  &.secondary { background-color: var(--secondary); color: var(--secondary-fg); }
  &.secondary:hover:not(:disabled) { background-color: #e4e4e7; }
  &.destructive { background-color: var(--destructive); color: var(--destructive-fg); }
  &.destructive:hover:not(:disabled) { background-color: #dc2626; }
  &.outline { background-color: transparent; color: var(--fg); border-color: var(--border); }
  &.outline:hover:not(:disabled) { background-color: var(--accent); color: var(--accent-fg); }
  &.ghost { background-color: transparent; color: var(--fg); border-color: transparent; }
  &.ghost:hover:not(:disabled) { background-color: var(--accent); color: var(--accent-fg); }
  &.link { background-color: transparent; color: var(--primary); border-color: transparent; text-decoration: underline; text-underline-offset: 4px; }
  &.link:hover:not(:disabled) { opacity: 0.8; }
}

/* BADGE */
Badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: var(--radius-full);
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.25;
  border: 1px solid transparent;
  white-space: nowrap;
  font-family: var(--font);

  &.default     { background-color: var(--primary);    color: var(--primary-fg);    border-color: var(--primary); }
  &.secondary   { background-color: var(--secondary);  color: var(--secondary-fg);  border-color: var(--secondary); }
  &.destructive { background-color: var(--destructive);color: var(--destructive-fg);border-color: var(--destructive); }
  &.success     { background-color: var(--success);    color: var(--success-fg);    border-color: var(--success); }
  &.warning     { background-color: var(--warning);    color: var(--warning-fg);    border-color: var(--warning); }
  &.outline     { background-color: transparent; color: var(--fg); border-color: var(--border); }
  &.ghost       { background-color: var(--muted); color: var(--muted-fg); border-color: transparent; }
}

/* ALERT */
Alert {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  align-items: start;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background-color: var(--bg);
  font-family: var(--font);

  & > svg:first-child { grid-row: 1 / 3; margin-top: 0.1rem; width: 1rem; height: 1rem; flex-shrink: 0; }
  .action { grid-column: 2; margin-top: 0.5rem; }

  &.default     { background-color: var(--bg); border-color: var(--border); }
  &.destructive { background-color: #fef2f2; border-color: #fca5a5; color: #991b1b; }
  &.destructive AlertDescription { color: #b91c1c; }
  &.success { background-color: #f0fdf4; border-color: #86efac; color: #14532d; }
  &.success AlertDescription { color: #166534; }
  &.warning { background-color: #fffbeb; border-color: #fcd34d; color: #78350f; }
  &.warning AlertDescription { color: #92400e; }
}

AlertTitle {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.25;
  margin: 0;
  letter-spacing: -0.01em;
}

AlertDescription {
  display: block;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--muted-fg);
  margin: 0;
}

/* ALERT DIALOG */
AlertDialog {
  position: fixed; inset: 0; z-index: 50;
  background-color: rgb(0 0 0 / 0.8);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: fade-in 0.15s ease;
  font-family: var(--font);

  .panel {
    background-color: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%; max-width: 28rem;
    padding: 1.5rem;
    animation: zoom-in 0.15s ease;
  }
  .title { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 0.5rem; color: var(--fg); }
  .description { font-size: 0.875rem; color: var(--muted-fg); line-height: 1.5; margin: 0 0 1.25rem; }
  .footer { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; }
}

/* AVATAR */
Avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  overflow: hidden;
  background-color: var(--muted);
  color: var(--muted-fg);
  font-family: var(--font);
  flex-shrink: 0;
  position: relative;

  &.sm      { width: 2rem;   height: 2rem;   font-size: 0.75rem; }
  &.default { width: 2.5rem; height: 2.5rem; font-size: 0.875rem; }
  &.lg      { width: 3rem;   height: 3rem;   font-size: 1rem; }
  &.xl      { width: 4rem;   height: 4rem;   font-size: 1.25rem; }

  .image { width: 100%; height: 100%; object-fit: cover; }
  .fallback { font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
}

/* ACCORDION */
Accordion {
  display: flex;
  flex-direction: column;
  width: 100%;
  font-family: var(--font);
}

AccordionItem {
  display: block;
  border-bottom: 1px solid var(--border);
  &:last-child { border-bottom: none; }

  .trigger {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 1rem 0; font-size: 0.875rem; font-weight: 500;
    text-align: left; background: none; border: none; cursor: pointer;
    color: var(--fg); gap: 0.5rem; transition: color var(--transition); font-family: var(--font);
    &:hover { color: var(--primary); }
    &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--radius-sm); }
  }
  .icon {
    flex-shrink: 0; width: 1rem; height: 1rem;
    transition: transform 0.2s ease; display: inline-block;
    &::before { content: "▾"; font-size: 0.75rem; }
  }
  &.open .icon { transform: rotate(180deg); }
  .content-wrapper { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.2s ease; overflow: hidden; }
  &.open .content-wrapper { grid-template-rows: 1fr; }
  .content-inner { overflow: hidden; }
  .content { padding: 0 0 1rem; font-size: 0.875rem; line-height: 1.6; color: var(--muted-fg); }
}

/* BREADCRUMB */
Breadcrumb { display: block; font-family: var(--font); }

BreadcrumbList {
  display: flex; align-items: center; flex-wrap: wrap; gap: 0.375rem;
  list-style: none; margin: 0; padding: 0; font-size: 0.875rem; color: var(--muted-fg);
}

BreadcrumbItem { display: inline-flex; align-items: center; gap: 0.375rem; }

BreadcrumbLink a {
  color: var(--muted-fg); text-decoration: none; transition: color var(--transition);
  &:hover { color: var(--fg); }
}

BreadcrumbPage { color: var(--fg); font-weight: 500; }

BreadcrumbSeparator { color: var(--muted-fg); opacity: 0.5; user-select: none; }

BreadcrumbEllipsis {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; color: var(--muted-fg); cursor: pointer;
  &:hover { color: var(--fg); }
}

/* CARD */
Card, CardHeader, CardContent, CardFooter {
  display: block;
  font-family: var(--font);
}

Card {
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;

  .header, CardHeader { display: flex; flex-direction: column; gap: 0.375rem; padding: 1.5rem; padding-bottom: 0; }
  .header-row { display: flex; align-items: center; justify-content: space-between; }
  .title, CardTitle { font-size: 1.125rem; font-weight: 600; line-height: 1.25; letter-spacing: -0.02em; margin: 0; color: var(--fg); }
  .description, CardDescription { font-size: 0.875rem; color: var(--muted-fg); margin: 0; line-height: 1.5; }
  .actions { display: flex; gap: 0.5rem; }
  .content, CardContent { padding: 1.5rem; }
  .footer, CardFooter { padding: 1.5rem; padding-top: 0; display: flex; align-items: center; gap: 0.5rem; }
}

/* CHECKBOX */
Checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;

  input[type="checkbox"] {
    appearance: none; -webkit-appearance: none;
    width: 1rem; height: 1rem;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    background-color: var(--bg);
    cursor: pointer; position: relative; flex-shrink: 0;
    transition: background-color var(--transition), border-color var(--transition);
    &:checked { background-color: var(--primary); border-color: var(--primary); }
    &:checked::after {
      content: ""; position: absolute; left: 3px; top: 0px;
      width: 4px; height: 8px; border: 2px solid var(--primary-fg);
      border-top: none; border-left: none; transform: rotate(45deg);
    }
    &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
    &:disabled { opacity: 0.5; cursor: not-allowed; }
  }
  .label { color: var(--fg); line-height: 1.4; }
}

/* COLLAPSIBLE */
Collapsible {
  display: block;
  width: 100%;
  font-family: var(--font);

  .trigger { display: flex; align-items: center; justify-content: space-between; width: 100%; cursor: pointer; }
  .content-wrapper { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.2s ease; overflow: hidden; }
  &.open .content-wrapper { grid-template-rows: 1fr; }
  .content-inner { overflow: hidden; }
  .content { padding-top: 0.5rem; }
}

/* DIALOG */
Dialog {
  display: block;
  margin: auto;
  padding: 0;
  border: none;
  background-color: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 32rem;
  max-height: 90vh;
  overflow: auto;
  animation: zoom-in 0.15s ease;
  font-family: var(--font);
  color: var(--fg);

  &::backdrop {
    background-color: rgb(0 0 0 / 0.8);
    animation: fade-in 0.15s ease;
  }
  &.sm { max-width: 28rem; }
  &.md { max-width: 32rem; }
  &.lg { max-width: 48rem; }
  .header { display: flex; align-items: center; justify-content: space-between; padding: 1.5rem 1.5rem 0; }
  .title { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.02em; margin: 0; color: var(--fg); }
  .description { font-size: 0.875rem; color: var(--muted-fg); padding: 0.25rem 0 0; margin: 0; }
  .body { padding: 1.5rem; }
  .footer { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; padding: 0 1.5rem 1.5rem; }
}

/* MODAL */
Modal {
  position: fixed; inset: 0; z-index: 50;
  background-color: rgb(0 0 0 / 0.8);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: fade-in 0.15s ease;
  font-family: var(--font);

  .panel {
    background-color: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%; max-width: 32rem;
    max-height: 90vh; overflow: auto;
    animation: zoom-in 0.15s ease;
  }
  .header { display: flex; align-items: center; justify-content: space-between; padding: 1.5rem 1.5rem 0; }
  .title { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.02em; margin: 0; color: var(--fg); }
  .body { padding: 1.5rem; }
}

/* DROPDOWN MENU */
DropdownMenu {
  position: relative;
  display: inline-block;
  font-family: var(--font);

  .content {
    position: absolute; z-index: 50; top: calc(100% + 4px); left: 0;
    min-width: 10rem; background-color: var(--popover-bg);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-md); padding: 0.25rem;
    animation: fade-in-scale 0.1s ease;
    &.align-end { left: auto; right: 0; }
    &.align-start { left: 0; right: auto; }
  }
  .label { padding: 0.375rem 0.5rem; font-size: 0.75rem; font-weight: 600; color: var(--muted-fg); }
  .item {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.375rem 0.5rem; font-size: 0.75rem; color: var(--fg);
    cursor: pointer; border-radius: var(--radius-sm); border: none;
    background: none; width: 100%; text-align: left;
    transition: background-color var(--transition); font-family: var(--font);
    touch-action: manipulation;
    &:hover, &:focus { background-color: var(--accent); outline: none; }
    &:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
    &.destructive { color: var(--destructive); }
    &.destructive:hover { background-color: #fef2f2; }
  }
  .icon { width: 1rem; height: 1rem; opacity: 0.7; }
  .shortcut { margin-left: auto; font-size: 0.75rem; color: var(--muted-fg); font-family: var(--font-mono); }
  .separator { height: 1px; background-color: var(--border); margin: 0.25rem 0; }
}

/* FIELD */
Field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  font-family: var(--font);

  .label { font-size: 0.875rem; font-weight: 500; color: var(--fg); line-height: 1.25; }
  .hint { font-size: 0.8125rem; color: var(--muted-fg); line-height: 1.4; }
  .error { font-size: 0.8125rem; color: var(--destructive); line-height: 1.4; }
}

/* TEXT INPUT */
TextInput {
  display: flex;
  flex-direction: column;
  font-family: var(--font);

  &.invalid input { border-color: var(--destructive); }
  &.invalid input:focus { border-color: var(--destructive); box-shadow: 0 0 0 3px rgb(239 68 68 / 0.15); }

  input {
    display: flex; height: 2.25rem; width: 100%;
    border-radius: var(--radius-md); border: 1px solid var(--input-border);
    background-color: var(--bg); padding: 0 0.75rem;
    font-size: 0.875rem; color: var(--fg);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none; font-family: var(--font); min-width: 0;
    &::placeholder { color: var(--muted-fg); }
    &:focus { border-color: var(--ring); box-shadow: 0 0 0 3px rgb(24 24 27 / 0.1); }
    &:disabled { opacity: 0.5; cursor: not-allowed; }
  }
}

/* KBD */
Kbd {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.125rem 0.375rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background-color: var(--muted);
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 500;
  color: var(--fg); box-shadow: 0 1px 0 1px var(--border); white-space: nowrap;
}

/* LABEL */
Label {
  display: inline-block;
  font-size: 0.875rem; font-weight: 500; color: var(--fg);
  line-height: 1.25; cursor: default; font-family: var(--font);
  &[for] { cursor: pointer; }
}

/* PAGINATION */
Pagination {
  display: flex;
  align-items: center;
  font-family: var(--font);

  .content { display: flex; align-items: center; gap: 0.25rem; list-style: none; margin: 0; padding: 0; }
  .item { display: inline-flex; }
  .link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.25rem; height: 2.25rem; border-radius: var(--radius-md);
    font-size: 0.875rem; font-weight: 500; color: var(--fg);
    border: 1px solid transparent; cursor: pointer;
    transition: background-color var(--transition), border-color var(--transition);
    background: none; font-family: var(--font);
    &:hover { background-color: var(--accent); }
    &.active { background-color: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
    &.active:hover { background-color: #27272a; }
  }
  .prev, .next {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0 0.625rem; height: 2.25rem; border-radius: var(--radius-md);
    font-size: 0.875rem; color: var(--fg); cursor: pointer;
    transition: background-color var(--transition); border: none; background: none; font-family: var(--font);
    &:hover { background-color: var(--accent); }
    &:disabled { opacity: 0.5; pointer-events: none; }
  }
  .ellipsis {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.25rem; height: 2.25rem; font-size: 0.875rem; color: var(--muted-fg);
  }
}

/* POPOVER */
Popover {
  position: relative;
  display: inline-block;
  font-family: var(--font);

  .content {
    position: absolute; z-index: 50; top: calc(100% + 6px); left: 0;
    width: 18rem; background-color: var(--popover-bg);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-md); padding: 1rem;
    animation: fade-in-scale 0.1s ease;
    &.align-end { left: auto; right: 0; }
    &.align-start { left: 0; right: auto; }
    &.align-center { left: 50%; transform: translateX(-50%); }
  }
}

/* PROGRESS */
Progress {
  display: block;
  width: 100%;
  height: 0.5rem;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  border-radius: var(--radius-full);
  overflow: hidden;
  background-color: var(--secondary);
  font-family: var(--font);

  &::-webkit-progress-bar { background-color: var(--secondary); border-radius: var(--radius-full); }
  &::-webkit-progress-value { background-color: var(--primary); border-radius: var(--radius-full); transition: width 0.3s ease; }
  &::-moz-progress-bar { background-color: var(--primary); border-radius: var(--radius-full); }
  &.success::-webkit-progress-value, &.success::-moz-progress-bar { background-color: var(--success); }
  &.destructive::-webkit-progress-value, &.destructive::-moz-progress-bar { background-color: var(--destructive); }
  &.warning::-webkit-progress-value, &.warning::-moz-progress-bar { background-color: var(--warning); }
}

/* RADIO GROUP */
RadioGroup {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-family: var(--font);
  &.horizontal { flex-direction: row; flex-wrap: wrap; }
}

RadioItem {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--fg);
  user-select: none;
  -webkit-user-select: none;

  input[type="radio"] {
    appearance: none; -webkit-appearance: none;
    width: 1rem; height: 1rem;
    border: 1px solid var(--primary); border-radius: var(--radius-full);
    background-color: var(--bg); cursor: pointer; position: relative; flex-shrink: 0;
    transition: border-color var(--transition);
    &:checked::after { content: ""; position: absolute; inset: 3px; border-radius: var(--radius-full); background-color: var(--primary); }
    &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
    &:disabled { opacity: 0.5; cursor: not-allowed; }
  }
  .label { color: var(--fg); }
}

/* SCROLL AREA */
ScrollArea {
  display: block;
  position: relative;
  overflow: auto;
  font-family: var(--font);
  &::-webkit-scrollbar { width: 8px; height: 8px; }
  &::-webkit-scrollbar-track { background: transparent; }
  &::-webkit-scrollbar-thumb { background-color: var(--border); border-radius: var(--radius-full); border: 2px solid var(--bg); }
  &::-webkit-scrollbar-thumb:hover { background-color: var(--muted-fg); }
}

/* SELECT */
Select {
  display: flex;
  height: 2.25rem;
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--input-border);
  background-color: var(--bg);
  padding: 0 2rem 0 0.75rem;
  font-size: 0.875rem;
  color: var(--fg);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  font-family: var(--font);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  cursor: pointer;
  min-width: 0;

  &:focus { border-color: var(--ring); box-shadow: 0 0 0 3px rgb(24 24 27 / 0.1); }
  &:disabled { opacity: 0.5; cursor: not-allowed; }
  &.invalid { border-color: var(--destructive); }
}

/* SEPARATOR */
Separator {
  display: block;
  background-color: var(--border);
  flex-shrink: 0;
  &.horizontal { height: 1px; width: 100%; margin: 0; }
  &.vertical { width: 1px; height: 100%; display: inline-block; }
}

/* SHEET */
Sheet {
  display: contents;
  font-family: var(--font);

  .overlay {
    position: fixed; inset: 0; z-index: 50;
    background-color: rgb(0 0 0 / 0.8);
    animation: fade-in 0.15s ease;
  }
  .panel {
    position: fixed; z-index: 50;
    background-color: var(--bg);
    box-shadow: var(--shadow-xl);
    display: flex; flex-direction: column; overflow: auto;
  }
  &.right .panel  { top: 0; right: 0; bottom: 0; width: 26rem; max-width: 90vw; animation: slide-in-right 0.2s ease; }
  &.left .panel   { top: 0; left: 0; bottom: 0; width: 26rem; max-width: 90vw; animation: slide-in-left 0.2s ease; }
  &.top .panel    { top: 0; left: 0; right: 0; min-height: 25vh; animation: slide-in-top 0.2s ease; }
  &.bottom .panel { bottom: 0; left: 0; right: 0; min-height: 25vh; animation: slide-in-bottom 0.2s ease; }
  .header { display: flex; align-items: center; justify-content: space-between; padding: 1.5rem; border-bottom: 1px solid var(--border); }
  .title { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.02em; margin: 0; color: var(--fg); }
  .description { font-size: 0.875rem; color: var(--muted-fg); margin: 0; }
  .body { flex: 1; padding: 1.5rem; }
  .footer { padding: 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 0.5rem; justify-content: flex-end; }
}

/* SKELETON */
Skeleton {
  display: block;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--muted) 25%, #e8e8e8 50%, var(--muted) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* SLIDER */
Slider {
  display: block;
  width: 100%;

  .control {
    appearance: none; -webkit-appearance: none;
    height: 0.25rem; width: 100%;
    border-radius: var(--radius-full);
    background-color: var(--secondary);
    outline: none; cursor: pointer;
    accent-color: var(--primary);
    &::-webkit-slider-thumb {
      appearance: none; -webkit-appearance: none;
      width: 1.25rem; height: 1.25rem;
      border-radius: var(--radius-full);
      background-color: var(--bg);
      border: 2px solid var(--primary);
      cursor: pointer; box-shadow: var(--shadow-sm);
      transition: transform var(--transition);
      &:hover { transform: scale(1.1); }
    }
    &:focus-visible { outline: 2px solid var(--ring); outline-offset: 4px; }
    &:disabled { opacity: 0.5; cursor: not-allowed; }
    &::-moz-range-thumb {
      width: 1.25rem; height: 1.25rem;
      border-radius: var(--radius-full);
      background-color: var(--bg);
      border: 2px solid var(--primary);
      cursor: pointer; box-shadow: var(--shadow-sm);
    }
  }
}

/* SPINNER */
Spinner {
  display: inline-block;
  width: 1.5rem; height: 1.5rem;
  border: 2px solid var(--muted);
  border-top-color: var(--primary);
  border-radius: var(--radius-full);
  animation: spin 0.75s linear infinite;
  vertical-align: middle;
  font-size: 0; color: transparent;

  &.sm { width: 1rem; height: 1rem; border-width: 2px; }
  &.lg { width: 2.5rem; height: 2.5rem; border-width: 3px; }
}

/* STACK */
Stack { display: flex; font-family: var(--font); }

/* SWITCH */
Switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: auto;
  height: auto;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  outline: none;
  font-family: var(--font);
  font-size: 0.875rem;

  &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
  &:disabled { opacity: 0.5; cursor: not-allowed; }

  .thumb {
    position: relative;
    display: block;
    width: 2.75rem;
    height: 1.5rem;
    border-radius: var(--radius-full);
    background-color: var(--input-border);
    transition: background-color var(--transition);
    flex-shrink: 0;
    &::after {
      content: "";
      position: absolute;
      top: 0.1875rem;
      left: 0.1875rem;
      width: 1.125rem;
      height: 1.125rem;
      border-radius: var(--radius-full);
      background-color: var(--bg);
      box-shadow: var(--shadow-sm);
      transition: transform var(--transition);
      pointer-events: none;
    }
  }
  &.checked .thumb { background-color: var(--primary); }
  &.checked .thumb::after { transform: translateX(1.25rem); }
  .label { color: var(--fg); }
}

/* TABLE */
Table {
  display: table;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  color: var(--fg);
  font-family: var(--font);
}

TableHeader { display: table-header-group; }
TableBody { display: table-row-group; }
TableFooter { display: table-footer-group; background-color: var(--muted); font-weight: 500; }
TableRow {
  display: table-row;
  border-bottom: 1px solid var(--border);
  transition: background-color var(--transition);
}
TableHeader TableRow { border-bottom: 1px solid var(--border); }
TableBody TableRow:hover { background-color: var(--muted); }
TableHead {
  display: table-cell;
  padding: 0.75rem 1rem; text-align: left; font-weight: 500;
  color: var(--muted-fg); white-space: nowrap;
}
TableCell {
  display: table-cell;
  padding: 0.75rem 1rem; vertical-align: middle;
  &.right { text-align: right; }
}
TableCaption {
  display: table-caption;
  caption-side: bottom;
  margin-top: 1rem; font-size: 0.875rem; color: var(--muted-fg); text-align: center;
}

/* TABS */
Tabs {
  display: block;
  font-family: var(--font);

  .list {
    display: inline-flex; align-items: center;
    background-color: var(--muted); border-radius: var(--radius-md);
    padding: 0.25rem; gap: 0.125rem;
  }
  .tab {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.375rem 0.75rem; font-size: 0.875rem; font-weight: 500;
    border-radius: var(--radius-sm); border: none; background: none;
    cursor: pointer; color: var(--muted-fg); transition: all var(--transition);
    white-space: nowrap; font-family: var(--font); outline: none;
    touch-action: manipulation;
    &:hover:not(.active) { color: var(--fg); }
    &.active { background-color: var(--bg); color: var(--fg); box-shadow: var(--shadow-sm); }
    &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
  }
  .panel { margin-top: 0.5rem; outline: none; }
}

/* TEXTAREA */
Textarea {
  display: flex;
  width: 100%;
  min-height: 5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--input-border);
  background-color: var(--bg);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--fg);
  line-height: 1.5;
  resize: vertical;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  font-family: var(--font);
  min-width: 0;

  &::placeholder { color: var(--muted-fg); }
  &:focus { border-color: var(--ring); box-shadow: 0 0 0 3px rgb(24 24 27 / 0.1); }
  &:disabled { opacity: 0.5; cursor: not-allowed; resize: none; }
  &.invalid { border-color: var(--destructive); }
  &.invalid:focus { border-color: var(--destructive); box-shadow: 0 0 0 3px rgb(239 68 68 / 0.15); }
}

/* TOAST */
Toaster {
  position: fixed;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  font-family: var(--font);
  max-width: 24rem;
  width: 100%;

  &.bottom-right { bottom: 1.5rem; right: 1.5rem; align-items: flex-end; }
  &.bottom-left  { bottom: 1.5rem; left:  1.5rem; align-items: flex-start; }
  &.top-right    { top: 1.5rem;    right: 1.5rem; align-items: flex-end; }
  &.top-left     { top: 1.5rem;    left:  1.5rem; align-items: flex-start; }
  &.top-center   { top: 1.5rem;    left: 50%; transform: translateX(-50%); align-items: center; }
  &.bottom-center{ bottom: 1.5rem; left: 50%; transform: translateX(-50%); align-items: center; }
}

Toast {
  display: flex;
  pointer-events: all;
  align-items: flex-start;
  gap: 0.75rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.875rem 1rem;
  box-shadow: var(--shadow-lg);
  width: 100%;
  animation: slide-in-right 0.2s ease;

  .icon { flex-shrink: 0; width: 1.125rem; height: 1.125rem; margin-top: 0.0625rem; }
  .body { flex: 1; min-width: 0; }
  .title { font-size: 0.875rem; font-weight: 600; color: var(--fg); margin: 0 0 0.125rem; }
  .description { font-size: 0.8125rem; color: var(--muted-fg); line-height: 1.4; margin: 0; }
  .close {
    flex-shrink: 0; width: 1.5rem; height: 1.5rem;
    border-radius: var(--radius-sm); border: none; background: none;
    cursor: pointer; color: var(--muted-fg); font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
    transition: background-color var(--transition), color var(--transition);
    align-self: flex-start;
    &:hover { background-color: var(--accent); color: var(--fg); }
  }
  &.success { border-left: 4px solid var(--success); }
  &.destructive { border-left: 4px solid var(--destructive); }
  &.warning { border-left: 4px solid var(--warning); }
}

/* TOGGLE */
Toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background-color: transparent;
  color: var(--muted-fg);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
  font-family: var(--font);

  &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
  &:disabled { pointer-events: none; opacity: 0.5; }
  &:hover:not(:disabled):not(.outline) { background-color: var(--muted); color: var(--fg); }
  &.sm { height: 2rem; padding: 0 0.625rem; }
  &.lg { height: 2.5rem; padding: 0 1rem; }
  &.outline { border-color: var(--border); }
  &.outline:hover:not(:disabled) { background-color: var(--accent); color: var(--fg); }
  &.pressed { background-color: var(--accent); color: var(--accent-fg); }
  &.pressed.outline { background-color: var(--accent); border-color: var(--accent); }
}

/* TOOLTIP */
Tooltip {
  position: relative;
  display: inline-flex;

  .content {
    position: absolute; z-index: 50;
    background-color: var(--primary); color: var(--primary-fg);
    border-radius: var(--radius-md); padding: 0.375rem 0.75rem;
    font-size: 0.8125rem; font-weight: 500; white-space: nowrap;
    pointer-events: none; box-shadow: var(--shadow-md);
    animation: fade-in-scale 0.1s ease; font-family: var(--font);
    &::before { content: ""; position: absolute; border: 4px solid transparent; }
    &.top    { bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); &::before { top: 100%; left: 50%; transform: translateX(-50%); border-top-color: var(--primary); } }
    &.bottom { top: calc(100% + 6px); left: 50%; transform: translateX(-50%); &::before { bottom: 100%; left: 50%; transform: translateX(-50%); border-bottom-color: var(--primary); } }
    &.left   { right: calc(100% + 6px); top: 50%; transform: translateY(-50%); &::before { left: 100%; top: 50%; transform: translateY(-50%); border-left-color: var(--primary); } }
    &.right  { left: calc(100% + 6px); top: 50%; transform: translateY(-50%); &::before { right: 100%; top: 50%; transform: translateY(-50%); border-right-color: var(--primary); } }
  }
}

/* EMPTY STATE */
EmptyState {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  font-family: var(--font);

  .icon { margin-bottom: 1rem; color: var(--muted-fg); }
  .title { font-size: 1.125rem; font-weight: 600; color: var(--fg); margin: 0 0 0.5rem; }
  .text { font-size: 0.875rem; color: var(--muted-fg); line-height: 1.5; margin: 0 0 1.5rem; max-width: 28rem; }
  .action { margin-top: 0.5rem; }
}

/* SEGMENTED BUTTON */
SegmentedButton {
  display: inline-flex;
  align-items: center;
  background-color: transparent;
  border-radius: var(--radius-md);
  padding: 0;
  gap: 0.25rem;
  font-family: var(--font);

  .item {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
    border: none; background-color: var(--muted); border-radius: var(--radius-md);
    color: var(--muted-fg); font-size: 0.875rem; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: background-color var(--transition), color var(--transition);
    outline: none; font-family: var(--font);
    user-select: none; -webkit-user-select: none;
    touch-action: manipulation;
    &:hover:not(:disabled):not(.active) { background-color: var(--border); color: var(--fg); }
    &.active { background-color: var(--border); color: var(--fg); }
    &:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
    &:disabled { opacity: 0.5; cursor: not-allowed; }
  }
  &.sm .item  { height: 1.75rem; padding: 0 0.625rem; font-size: 0.8125rem; }
  &.default .item { height: 2rem; padding: 0 0.75rem; }
  &.lg .item  { height: 2.25rem; padding: 0 1rem; font-size: 1rem; }
}

/* MULTI-SELECT */
MultiSelect {
  display: block;
  position: relative;
  width: 100%;
  min-height: 2.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--input-border);
  background-color: var(--bg);
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  color: var(--fg);
  cursor: text;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font);

  &.open { border-color: var(--ring); box-shadow: 0 0 0 3px rgb(24 24 27 / 0.1); }
  &.invalid { border-color: var(--destructive); }
  &.invalid.open { box-shadow: 0 0 0 3px rgb(239 68 68 / 0.15); }
  &.disabled { opacity: 0.5; cursor: not-allowed; }

  .inner { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }
  .chip {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.125rem 0.5rem 0.125rem 0.625rem;
    border-radius: var(--radius-full); background-color: var(--secondary);
    color: var(--secondary-fg); font-size: 0.8125rem; font-weight: 500;
    line-height: 1.4; white-space: nowrap;
  }
  .chip-remove {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1rem; height: 1rem; border: none; background: transparent;
    color: var(--muted-fg); font-size: 1rem; line-height: 1;
    border-radius: var(--radius-full); cursor: pointer; padding: 0;
    transition: background-color var(--transition), color var(--transition);
    &:hover { background-color: var(--destructive); color: var(--destructive-fg); }
  }
  .input {
    flex: 1 1 4rem; min-width: 4rem; border: none; outline: none;
    background: transparent; font-size: 0.875rem; color: var(--fg);
    font-family: var(--font); padding: 0.125rem 0; height: 1.75rem;
    &::placeholder { color: var(--muted-fg); }
    &:disabled { cursor: not-allowed; }
  }
  .dropdown {
    position: absolute; top: calc(100% + 0.25rem); left: 0; right: 0; z-index: 50;
    background-color: var(--popover-bg); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-md);
    max-height: 14rem; overflow-y: auto;
    animation: fade-in-scale 0.1s ease;
  }
  .option {
    padding: 0.5rem 0.75rem; font-size: 0.875rem; cursor: pointer; color: var(--fg);
    transition: background-color var(--transition);
    &:hover { background-color: var(--accent); color: var(--accent-fg); }
  }
  .empty { padding: 0.5rem 0.75rem; font-size: 0.875rem; color: var(--muted-fg); text-align: center; }
}

/* COMBOBOX */
Combobox {
  display: block;
  position: relative;
  width: 100%;
  font-family: var(--font);
  font-size: 0.875rem;

  .trigger {
    display: flex; align-items: center; min-height: 2.25rem;
    border-radius: var(--radius-md); border: 1px solid var(--input-border);
    background-color: var(--bg); padding: 0 0.5rem 0 0.75rem; gap: 0.25rem;
    cursor: pointer; transition: border-color var(--transition), box-shadow var(--transition);
  }
  &.open .trigger { border-color: var(--ring); box-shadow: 0 0 0 3px rgb(24 24 27 / 0.1); }
  &.invalid .trigger { border-color: var(--destructive); }
  &.invalid.open .trigger { box-shadow: 0 0 0 3px rgb(239 68 68 / 0.15); }
  &.disabled .trigger { opacity: 0.5; cursor: not-allowed; }
  .input {
    flex: 1 1 0; min-width: 0; border: none; outline: none; background: transparent;
    font-size: 0.875rem; color: var(--fg); font-family: var(--font);
    padding: 0; height: 2rem; cursor: text;
    &::placeholder { color: var(--muted-fg); }
  }
  .value { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); line-height: 2rem; }
  .clear {
    flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
    width: 1.25rem; height: 1.25rem; border: none; background: transparent;
    color: var(--muted-fg); font-size: 1rem; line-height: 1;
    border-radius: var(--radius-full); cursor: pointer; padding: 0;
    transition: background-color var(--transition), color var(--transition);
    &:hover { background-color: var(--destructive); color: var(--destructive-fg); }
  }
  .chevron { flex-shrink: 0; font-size: 0.75rem; color: var(--muted-fg); pointer-events: none; user-select: none; line-height: 1; }
  .dropdown {
    position: absolute; top: calc(100% + 0.25rem); left: 0; right: 0; z-index: 50;
    background-color: var(--popover-bg); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-md);
    max-height: 14rem; overflow-y: auto;
    animation: fade-in-scale 0.1s ease;
  }
  .option {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.5rem 0.75rem; font-size: 0.875rem; cursor: pointer; color: var(--fg);
    transition: background-color var(--transition);
    &:hover, &.active { background-color: var(--accent); color: var(--accent-fg); }
    &.selected { font-weight: 500; }
  }
  .check { font-size: 0.8125rem; color: var(--primary); flex-shrink: 0; }
  .empty { padding: 0.5rem 0.75rem; font-size: 0.875rem; color: var(--muted-fg); text-align: center; }
}

/* KEYFRAMES */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in-scale { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes zoom-in { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes slide-in-right { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
@keyframes slide-in-left { from { opacity: 0; transform: translateX(-100%); } to { opacity: 1; transform: translateX(0); } }
@keyframes slide-in-top { from { opacity: 0; transform: translateY(-100%); } to { opacity: 1; transform: translateY(0); } }
@keyframes slide-in-bottom { from { opacity: 0; transform: translateY(100%); } to { opacity: 1; transform: translateY(0); } }
