/**
 * Cognifiy component primitives
 */

/* —— Buttons —— */
.cg-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-height);
  min-width: 0;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-size: var(--font-base);
  font-weight: 600;
  line-height: 1;
  background: var(--surface-secondary);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    transform 120ms var(--ease),
    box-shadow 140ms ease,
    color 140ms ease,
    opacity 140ms ease;
}

.cg-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.cg-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.985);
}

.cg-btn:disabled,
.cg-btn.is-loading {
  cursor: not-allowed;
}

.cg-btn:disabled {
  opacity: 0.5;
  transform: none;
  box-shadow: none;
}

.cg-btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}
.cg-btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: var(--shadow-primary-hover);
}
.cg-btn--primary:active:not(:disabled) {
  background: var(--primary-active);
  box-shadow: none;
}

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

.cg-btn--ghost {
  background: transparent;
  box-shadow: none;
}
.cg-btn--ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  transform: none;
}

.cg-btn--danger {
  background: var(--danger);
  color: #fff;
}

.cg-btn--ai {
  background: var(--ai-soft);
  color: var(--ai);
  border-color: rgba(128, 104, 245, 0.18);
}
.cg-btn--ai:hover:not(:disabled) {
  background: var(--primary-soft-hover);
}

.cg-btn--sm { min-height: var(--control-height-sm); padding: 0 12px; font-size: var(--font-sm); }
.cg-btn--lg { min-height: var(--control-height-lg); padding: 0 18px; }
.cg-btn--full { width: 100%; }

.cg-btn.is-loading {
  pointer-events: none;
}
.cg-btn.is-loading .cg-btn__label { opacity: 0.85; }
.cg-btn.is-loading .cg-btn__spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: cg-spin 0.7s linear infinite;
  flex-shrink: 0;
}

.cg-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--motion-base) var(--ease), color var(--motion-base) var(--ease);
}
.cg-icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.cg-icon-btn:active { background: var(--surface-active); }
.cg-icon-btn svg { width: 18px; height: 18px; }

/* —— Cards —— */
.cg-card {
  background: var(--surface-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: none;
  padding: var(--space-5);
}

.cg-card--lg {
  border-radius: var(--radius-card-lg);
  padding: var(--space-6);
}

.cg-card--interactive {
  cursor: pointer;
  transition:
    transform 160ms var(--ease),
    border-color 160ms var(--ease),
    background 160ms var(--ease);
}
.cg-card--interactive:hover {
  transform: translateY(-1px);
  border-color: var(--border-interactive-hover);
  background: var(--surface-hover);
}
.cg-card--interactive:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.cg-card--emphasis {
  border-color: rgba(91, 92, 226, 0.18);
  background:
    linear-gradient(180deg, rgba(91, 92, 226, 0.035), rgba(255, 255, 255, 0) 70%),
    var(--surface-primary);
}
[data-theme="dark"] .cg-card--emphasis {
  background:
    linear-gradient(180deg, rgba(91, 92, 226, 0.08), rgba(25, 26, 33, 0) 70%),
    var(--surface-primary);
}

.cg-metric-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: var(--space-5);
  background: var(--surface-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
}
.cg-metric-card__label {
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-tertiary);
}
.cg-metric-card__value {
  font-size: var(--font-2xl);
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.cg-metric-card__hint {
  font-size: var(--font-xs);
  color: var(--text-secondary);
}

/* —— Forms —— */
.cg-field { display: flex; flex-direction: column; gap: 6px; }
.cg-label {
  font-size: var(--font-sm);
  font-weight: 550;
  color: var(--text-secondary);
}

.cg-input,
.cg-textarea,
.cg-select {
  width: 100%;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-control);
  background: var(--surface-primary);
  color: var(--text-primary);
  font-size: var(--font-base);
  transition:
    border-color var(--motion-base) var(--ease),
    box-shadow var(--motion-base) var(--ease),
    background var(--motion-base) var(--ease);
}

.cg-input,
.cg-select {
  height: var(--input-height);
  padding: 0 12px;
}

.cg-textarea {
  min-height: 120px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

.cg-input:hover,
.cg-textarea:hover,
.cg-select:hover { border-color: var(--border-strong); }

.cg-input:focus,
.cg-textarea:focus,
.cg-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring-soft);
}

.cg-input::placeholder,
.cg-textarea::placeholder {
  color: var(--text-secondary);
}

.cg-field.is-error .cg-input,
.cg-field.is-error .cg-textarea,
.cg-field.is-error .cg-select {
  border-color: var(--danger);
}

.cg-field__error,
.cg-field__hint {
  font-size: var(--font-xs);
  margin-top: 5px;
}
.cg-field__error { color: var(--danger); }
.cg-field__hint { color: var(--text-secondary); }

.cg-search {
  position: relative;
  display: flex;
  align-items: center;
}
.cg-search__icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
}
.cg-search__input {
  width: 100%;
  height: var(--input-height);
  padding: 0 64px 0 36px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-control);
  background: var(--surface-primary);
  color: var(--text-primary);
  font-size: var(--font-base);
}
.cg-search__input::placeholder { color: var(--text-secondary); }
.cg-search__input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring-soft);
}
.cg-search__kbd {
  position: absolute;
  right: 10px;
  padding: 3px 6px;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--surface-secondary);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
  pointer-events: none;
}

.cg-check,
.cg-radio {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: var(--font-base);
  color: var(--text-primary);
}
.cg-check input,
.cg-radio input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.cg-check__box,
.cg-radio__dot {
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--motion-base) var(--ease), background var(--motion-base) var(--ease);
}
.cg-check__box { border-radius: 5px; }
.cg-radio__dot { border-radius: 50%; }
.cg-check input:checked + .cg-check__box {
  background: var(--primary);
  border-color: var(--primary);
}
.cg-check__box svg {
  width: 12px;
  height: 12px;
  stroke: #fff;
  stroke-width: 2.5;
  fill: none;
  stroke-dasharray: 16;
  stroke-dashoffset: 16;
  opacity: 0;
}
.cg-check input:checked + .cg-check__box svg {
  opacity: 1;
  animation: cg-check-draw 180ms var(--ease) forwards;
}
.cg-radio input:checked + .cg-radio__dot { border-color: var(--primary); }
.cg-radio__dot::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  transform: scale(0);
  opacity: 0;
}
.cg-radio input:checked + .cg-radio__dot::after {
  animation: cg-dot-in 160ms var(--ease) forwards;
}

.cg-toggle {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--border-strong);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background var(--motion-base) var(--ease);
}
.cg-toggle[aria-checked="true"] { background: var(--primary); }
.cg-toggle__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 180ms var(--ease);
}
.cg-toggle[aria-checked="true"] .cg-toggle__thumb { transform: translateX(18px); }

/* —— Badges / status —— */
.cg-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-badge);
  font-size: 11px;
  font-weight: 550;
  background: var(--surface-secondary);
  color: var(--text-secondary);
  border: 1px solid transparent;
  white-space: nowrap;
}
.cg-badge--primary { background: var(--primary-soft); color: var(--primary); }
.cg-badge--success { background: var(--success-soft); color: var(--success); }
.cg-badge--warning { background: var(--warning-soft); color: var(--warning); }
.cg-badge--danger { background: var(--danger-soft); color: var(--danger); }
.cg-badge--ai { background: var(--ai-soft); color: var(--ai); }
.cg-badge--neutral { background: var(--surface-secondary); color: var(--text-tertiary); }

.cg-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-sm);
  font-weight: 500;
  color: var(--text-secondary);
}
.cg-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
}
.cg-status--success .cg-status__dot { background: var(--success); }
.cg-status--warning .cg-status__dot { background: var(--warning); }
.cg-status--danger .cg-status__dot { background: var(--danger); }
.cg-status--ai .cg-status__dot { background: var(--ai); }

/* —— Progress —— */
.cg-progress {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-secondary);
  overflow: hidden;
}
.cg-progress--thin { height: 5px; }
.cg-progress__bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--primary);
  transition: width var(--motion-learn) var(--ease);
}
.cg-progress__bar--success { background: var(--success); }
.cg-progress__bar--warning { background: var(--warning); }

.cg-progress--indeterminate .cg-progress__bar {
  width: 32%;
  animation: cg-indeterminate 1.3s ease infinite;
}

/* —— Skeleton —— */
.cg-skeleton {
  display: block;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--surface-secondary) 25%,
    var(--surface-hover) 37%,
    var(--surface-secondary) 63%
  );
  background-size: 400% 100%;
  animation: cg-skeleton 1.4s ease infinite;
}
.cg-skeleton--text { height: 13px; width: 100%; }
.cg-skeleton--heading { height: 20px; width: 46%; }
.cg-skeleton--title { height: 16px; width: 38%; }
.cg-skeleton--avatar { width: 32px; height: 32px; border-radius: 50%; }
.cg-skeleton--btn { height: 40px; width: 100px; border-radius: var(--radius-control); }
.cg-skeleton--chart { height: 180px; width: 100%; border-radius: var(--radius-card); }
.cg-skeleton--row { height: 64px; width: 100%; }

/* —— Empty / error —— */
.cg-empty {
  text-align: center;
  padding: 56px 24px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  background: var(--surface-primary);
}
.cg-empty__icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
}
.cg-empty__icon svg { width: 20px; height: 20px; }
.cg-empty__title {
  font-size: var(--font-lg);
  font-weight: 600;
  margin: 0 0 8px;
}
.cg-empty__text {
  font-size: var(--font-base);
  color: var(--text-secondary);
  margin: 0 auto 20px;
  max-width: 440px;
  line-height: 1.55;
}
.cg-error-state {
  text-align: center;
  padding: 48px 24px;
  max-width: 440px;
  margin: 0 auto;
}
.cg-error-state__title { margin: 0 0 8px; font-size: var(--font-xl); font-weight: 650; }
.cg-error-state__text { margin: 0 0 20px; color: var(--text-secondary); }

/* —— Avatar —— */
.cg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--font-xs);
  font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
}
.cg-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* —— Breadcrumb / page header —— */
.cg-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: var(--font-sm);
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}
.cg-breadcrumb a:hover { color: var(--text-primary); }
.cg-breadcrumb__sep { opacity: 0.5; }
.cg-breadcrumb__current { color: var(--text-secondary); font-weight: 500; }

.cg-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  min-height: 0;
}
.cg-page-header__copy { min-width: 0; flex: 1; }
.cg-page-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.cg-page-header__eyebrow {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  margin: 0 0 6px;
}
.cg-page-header__desc {
  margin: 8px 0 0;
  max-width: 54ch;
  color: var(--text-secondary);
  font-size: var(--font-base);
  line-height: 1.55;
}

@media (max-width: 768px) {
  .cg-page-header { flex-direction: column; }
}

/* —— Tabs / Segmented —— */
.cg-tabs {
  position: relative;
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-subtle);
}
.cg-tabs__btn {
  position: relative;
  z-index: 1;
  height: 38px;
  padding: 0 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--font-base);
  font-weight: 500;
  cursor: pointer;
}
.cg-tabs__btn[aria-selected="true"] {
  color: var(--primary);
  font-weight: 600;
}
.cg-tabs__indicator {
  position: absolute;
  bottom: -1px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px;
  transition: left var(--motion-slow) var(--ease), width var(--motion-slow) var(--ease);
}

.cg-segmented {
  position: relative;
  display: inline-flex;
  padding: 3px;
  background: var(--surface-secondary);
  border-radius: var(--radius-control);
  gap: 2px;
}
.cg-segmented__btn {
  position: relative;
  z-index: 1;
  height: 34px;
  padding: 0 12px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: var(--font-sm);
  font-weight: 550;
  color: var(--text-secondary);
  cursor: pointer;
}
.cg-segmented__btn[aria-selected="true"] {
  color: var(--text-primary);
  font-weight: 600;
}
.cg-segmented__pill {
  position: absolute;
  top: 3px;
  bottom: 3px;
  background: var(--surface-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  transition: left var(--motion-slow) var(--ease), width var(--motion-slow) var(--ease);
  z-index: 0;
}

/* —— Tooltip / dropdown —— */
.cg-tooltip {
  position: absolute;
  z-index: var(--z-tooltip);
  max-width: 260px;
  padding: 7px 9px;
  border-radius: 7px;
  background: #1E2028;
  color: #fff;
  font-size: var(--font-xs);
  font-weight: 500;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 120ms var(--ease), transform 120ms var(--ease);
}
.cg-tooltip.is-open {
  opacity: 1;
  transform: translateY(0);
}

.cg-popover,
.cg-dropdown {
  position: absolute;
  z-index: var(--z-dropdown);
  min-width: 220px;
  padding: 6px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-dropdown);
  box-shadow: var(--shadow-dropdown);
  opacity: 0;
  transform: translateY(-4px);
  transform-origin: top center;
  pointer-events: none;
  transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}
.cg-popover.is-open,
.cg-dropdown.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.cg-dropdown__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--font-base);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.cg-dropdown__item:hover,
.cg-dropdown__item:focus-visible,
.cg-dropdown__item[aria-selected="true"] {
  background: var(--surface-hover);
}
.cg-dropdown__item.is-selected {
  background: var(--primary-soft);
  color: var(--primary);
}
.cg-dropdown__item--danger { color: var(--danger); }
.cg-dropdown__sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border-subtle);
}

/* —— Modal / sheet / drawer / toast —— */
.cg-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-overlay);
  background: var(--overlay);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 150ms var(--ease), visibility 150ms var(--ease);
}
.cg-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.cg-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
  visibility: hidden;
}
.cg-modal.is-open {
  pointer-events: auto;
  visibility: visible;
}
.cg-modal__panel {
  width: min(520px, calc(100vw - 32px));
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-modal);
  opacity: 0;
  transform: translateY(8px) scale(0.985);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
  pointer-events: none;
  max-height: min(86dvh, calc(100vh - 48px));
  overflow: auto;
}
.cg-modal.is-open .cg-modal__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.cg-modal--lg .cg-modal__panel { width: min(680px, calc(100vw - 32px)); }
.cg-modal__header,
.cg-modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.cg-modal__header { padding: 20px 22px; }
.cg-modal__body { padding: 0 22px 22px; }
.cg-modal__footer {
  padding: 16px 22px 20px;
  justify-content: flex-end;
  border-top: 1px solid var(--border-subtle);
}
.cg-modal__title { margin: 0; font-size: var(--font-lg); font-weight: 650; }
.cg-modal__copy {
  margin: 0 auto;
  max-width: 480px;
  text-align: center;
  color: var(--text-secondary);
}

.cg-sheet-handle {
  display: none;
  width: 32px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 10px auto 0;
}

@media (max-width: 640px) {
  .cg-modal:not(.cg-modal--confirm) {
    align-items: flex-end;
    padding: 0;
  }
  .cg-modal:not(.cg-modal--confirm) .cg-modal__panel {
    width: 100%;
    max-height: 88dvh;
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
    transform: translateY(12px);
  }
  .cg-modal.is-open:not(.cg-modal--confirm) .cg-modal__panel {
    transform: translateY(0);
  }
  .cg-modal:not(.cg-modal--confirm) .cg-sheet-handle { display: block; }
  .cg-modal__footer { flex-direction: column-reverse; }
  .cg-modal__footer .cg-btn { width: 100%; }
}

.cg-drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer-overlay);
  background: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms var(--ease), visibility 180ms var(--ease);
}
.cg-drawer-overlay.is-open { opacity: 1; visibility: visible; }

.cg-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  z-index: var(--z-drawer);
  width: min(var(--drawer-width), 92vw);
  background: var(--surface-elevated);
  border-left: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-dropdown);
  transform: translateX(100%);
  transition: transform var(--motion-panel) var(--ease);
  display: flex;
  flex-direction: column;
}
.cg-drawer.is-open { transform: translateX(0); }
.cg-drawer__header { padding: 18px 20px; border-bottom: 1px solid var(--border-subtle); }
.cg-drawer__body { padding: 20px; flex: 1; overflow: auto; }

@media (max-width: 640px) {
  .cg-drawer {
    width: 100%;
    top: auto;
    height: 88dvh;
    border-left: none;
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
    transform: translateY(100%);
  }
  .cg-drawer.is-open { transform: translateY(0); }
}

.cg-toast-host {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.cg-toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-dropdown);
  box-shadow: var(--shadow-dropdown);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}
.cg-toast.is-open { opacity: 1; transform: translateY(0); }
.cg-toast--success { border-color: color-mix(in srgb, var(--success) 35%, var(--border-default)); }
.cg-toast--danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--border-default)); }
.cg-toast--warning { border-color: color-mix(in srgb, var(--warning) 35%, var(--border-default)); }

@media (max-width: 768px) {
  .cg-toast-host {
    left: 16px;
    right: 16px;
    bottom: calc(var(--mobile-nav-height) + 12px + env(safe-area-inset-bottom, 0px));
    width: auto;
    align-items: center;
  }
}

/* —— Tables —— */
.cg-table-wrap {
  background: var(--surface-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  overflow: hidden;
}
.cg-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.cg-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-secondary);
  border-bottom: 1px solid var(--border-subtle);
}
.cg-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--font-base);
  height: 48px;
}
.cg-table tr:last-child td { border-bottom: 0; }
.cg-table tbody tr:hover td { background: var(--surface-hover); }

/* —— Drop zone —— */
.cg-dropzone {
  min-height: 180px;
  max-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  border: 1.5px dashed var(--border-default);
  border-radius: var(--radius-card);
  background: var(--surface-secondary);
  transition: border-color 150ms var(--ease), background 150ms var(--ease);
}
.cg-dropzone.is-dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.cg-dropzone__icon { width: 32px; height: 32px; color: var(--text-tertiary); }
.cg-dropzone__title { font-size: var(--font-md); font-weight: 600; margin: 0; }
.cg-dropzone__hint { font-size: var(--font-sm); color: var(--text-secondary); margin: 0; }

/* —— AI instructional panel (not a chat bubble) —— */
.cg-ai-panel {
  border: 1px solid rgba(128, 104, 245, 0.18);
  background: var(--surface-primary);
  border-radius: var(--radius-card);
  padding: 16px 18px;
}
.cg-ai-panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.cg-ai-panel__mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--ai-soft);
  color: var(--ai);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.04em;
  flex-shrink: 0;
}
.cg-ai-panel__label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ai);
}
.cg-ai-panel__body {
  font-size: var(--font-base);
  line-height: 1.55;
  color: var(--text-primary);
  max-width: 680px;
}
.cg-ai-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.cg-ai-status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: var(--font-sm);
}
.cg-ai-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ai);
  animation: cg-ai-pulse 1.6s ease infinite;
}
.cg-ai-caret {
  display: inline-block;
  width: 1px;
  height: 1em;
  margin-left: 2px;
  background: var(--ai);
  vertical-align: text-bottom;
  animation: cg-caret 700ms step-end infinite;
}

.cg-hint {
  margin-top: 12px;
  padding: 14px 16px;
  border-left: 2px solid var(--primary);
  background: var(--surface-secondary);
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  font-size: var(--font-base);
  line-height: 1.55;
}

.cg-choice {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border-default);
  border-radius: 9px;
  background: var(--surface-primary);
  text-align: left;
  cursor: pointer;
  transition: background 140ms var(--ease), border-color 140ms var(--ease);
}
.cg-choice:hover { background: var(--surface-hover); }
.cg-choice.is-selected,
.cg-choice[aria-checked="true"] {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.cg-confetti-host {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-modal) - 10);
  pointer-events: none;
}

.cg-command .cg-modal__panel { width: min(560px, 100%); }
.cg-command__input {
  width: 100%;
  height: 52px;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  border-radius: var(--radius-modal) var(--radius-modal) 0 0;
  padding: 0 20px;
  font-size: 16px;
  background: transparent;
}
.cg-command__list { padding: 10px; max-height: 360px; overflow: auto; }
.cg-command__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.cg-command__item:hover,
.cg-command__item.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}
.cg-command__hint {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

.cg-sticky-actions {
  position: sticky;
  bottom: 0;
  display: none;
  background: var(--surface-primary);
  border-top: 1px solid var(--border-subtle);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-sticky);
}
@media (max-width: 768px) {
  .cg-sticky-actions.is-on { display: block; }
}

/* Autofill / date fields in dark mode */
[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] textarea:-webkit-autofill,
[data-theme="dark"] select:-webkit-autofill {
  -webkit-text-fill-color: var(--text-primary);
  box-shadow: 0 0 0 1000px var(--surface-primary) inset;
  transition: background-color 9999s ease-out;
}
[data-theme="dark"] input[type="date"] {
  color-scheme: dark;
}
