/* components.css - buttons, segmented control, chips, nav items, surfaces, forms, feedback, dialog, utilities (SPEC 8.6). */

/* ---------- Buttons ---------- */

/* Base .btn is the pearl secondary look, so a bare .btn still reads as a button. */
.btn {
  --btn-h: var(--h-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: var(--btn-h);
  min-height: var(--btn-h);
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-pill);
  background-color: var(--raised-1);
  background-image: var(--grad-raised);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
  font: 500 14px/1 var(--font-ui);
  letter-spacing: -0.005em;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s var(--ease-out), box-shadow 0.2s var(--ease-out), background-color 0.2s;
}

.btn:hover {
  box-shadow: inset 0 1px 0 #FFFFFF, 0 2px 4px rgba(19, 20, 22, 0.08), 0 8px 18px -8px rgba(19, 20, 22, 0.3);
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background-color: var(--graphite-2);
  background-image: var(--grad-graphite);
  color: var(--on-graphite);
  box-shadow: var(--shadow-pill);
}

.btn--primary:hover {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 2px 4px rgba(19, 20, 22, 0.35), 0 12px 22px -10px rgba(19, 20, 22, 0.7);
}

.btn--secondary {
  background-image: var(--grad-raised);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
}

.btn--sm {
  --btn-h: var(--h-sm);
  padding: 0 14px;
  font-size: 13px;
}

.btn--md {
  --btn-h: var(--h-md);
}

.btn--lg {
  --btn-h: var(--h-lg);
  padding: 0 22px;
  font-size: 15px;
}

.btn--icon {
  width: var(--h-md);
  min-width: var(--h-md);
  padding: 0;
  border-radius: 50%;
}

.btn--icon.btn--sm {
  width: var(--h-sm);
  min-width: var(--h-sm);
}

.btn--icon.btn--lg {
  width: var(--h-lg);
  min-width: var(--h-lg);
}

.btn--ghost {
  background-image: none;
  background-color: transparent;
  box-shadow: none;
  color: var(--ink-2);
}

.btn--ghost:hover {
  background-color: var(--soft);
  box-shadow: none;
  color: var(--ink);
}

.btn--danger {
  color: var(--ember);
}

.btn--ghost.btn--danger:hover {
  background-color: var(--ember-soft);
}

.btn__kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 5px;
  border-radius: var(--r-keycap);
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  font: 400 11px/1 var(--font-mono);
  opacity: 0.85;
}

.btn--secondary .btn__kbd,
.btn:not(.btn--primary) .btn__kbd {
  background: var(--well);
  box-shadow: inset 0 -1px 0 rgba(19, 20, 22, 0.08);
}

.btn[disabled],
.btn:disabled {
  background-image: var(--hatch), var(--grad-card);
  background-color: transparent;
  color: var(--ink-3);
  box-shadow: var(--shadow-inset);
  transform: none;
  opacity: 0.78;
}

.btn--primary[disabled],
.btn--primary:disabled {
  background-image: var(--hatch), linear-gradient(180deg, var(--soft), var(--soft));
  color: var(--ink-3);
  box-shadow: var(--shadow-inset);
}

/* Dashed link button: 36px, radius 12, trailing arrow (drawn in CSS; add .link-btn--plain to drop it) */
.link-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: var(--h-sm);
  min-height: var(--h-sm);
  padding: 0 14px;
  border: 1px dashed rgba(19, 20, 22, 0.32);
  border-radius: var(--r-link);
  background: transparent;
  color: var(--ink);
  font: 500 14px/1 var(--font-ui);
  white-space: nowrap;
  transition: background-color 0.2s, border-color 0.2s;
}

.link-btn:hover {
  background-color: rgba(255, 255, 255, 0.55);
  border-color: rgba(19, 20, 22, 0.5);
}

.link-btn::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-left: 2px;
  border-top: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
  transform: rotate(45deg);
  flex-shrink: 0;
}

.link-btn--plain::after {
  content: none;
}

.link-btn[disabled] {
  background-image: var(--hatch);
  color: var(--ink-3);
  border-style: solid;
  border-color: var(--line-strong);
}

/* ---------- Segmented control ---------- */

.seg {
  display: inline-flex;
  align-items: center;
  gap: 0;
  max-width: 100%;
  padding: 3px;
  border-radius: calc(var(--r-segment) + 3px);
  background: var(--well);
  box-shadow: var(--shadow-inset);
  overflow-x: auto;
  scrollbar-width: none;
}

.seg::-webkit-scrollbar {
  display: none;
}

.seg__item {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--r-segment);
  background: transparent;
  color: var(--ink-3);
  font: 500 14px/1 var(--font-ui);
  white-space: nowrap;
  transition: color 0.2s, background-color 0.2s, box-shadow 0.2s;
}

.seg__item:hover {
  color: var(--ink);
}

.seg__item.is-active {
  background-image: var(--grad-raised);
  background-color: var(--raised-1);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
}

.seg--icons .seg__item {
  width: 34px;
  padding: 0;
}

/* Tabs: underline */
.tabs {
  display: flex;
  align-items: flex-end;
  gap: var(--s-5);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line-strong);
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs__item {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: var(--h-sm);
  padding: 0 0 6px;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font: 500 15px/1 var(--font-ui);
  white-space: nowrap;
}

.tabs__item:hover {
  color: var(--ink);
}

.tabs__item::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: transparent;
}

.tabs__item.is-active {
  color: var(--ink);
}

.tabs__item.is-active::after {
  background: var(--ink);
}

/* ---------- Chips, badges, tags, keycaps ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  max-width: 100%;
  padding: 0 11px;
  border: 0;
  border-radius: var(--r-pill);
  background-color: var(--soft);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0));
  color: var(--ink-2);
  font: 400 13px/1 var(--font-ui);
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--line), 0 1px 1px rgba(19, 20, 22, 0.04);
}

.chip__dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
}

/* Healthy / ok: hollow dot with a lime ring (spec 8.6) */
.chip--ok .chip__dot {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--lime);
}

/* Live / waiting on you: lime fill, ink text */
.chip--live {
  background-color: var(--lime);
  background-image: none;
  color: var(--ink);
  font-weight: 500;
  box-shadow: 0 0 0 1px rgba(19, 20, 22, 0.06), 0 0 14px -2px rgba(212, 245, 74, 0.7);
}

.chip--live .chip__dot {
  background: var(--ink);
}

/* Failed / slow: ember dot, ember tint */
.chip--error {
  background-color: var(--ember-soft);
  background-image: none;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(229, 72, 42, 0.22);
}

.chip--error .chip__dot {
  background: var(--ember);
}

/* Queued / expected: hatched */
.chip--queued {
  background-color: var(--soft);
  background-image: var(--hatch);
  color: var(--ink-3);
}

.chip--queued .chip__dot {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--ink-3);
}

.count-badge {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--lime);
  color: var(--ink);
  font: 500 11px/1 var(--font-mono);
  box-shadow: 0 0 0 3px var(--lime-soft), 0 0 12px rgba(212, 245, 74, 0.55);
}

.id-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  max-width: 100%;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-tag);
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink-2);
  font: 400 12px/1 var(--font-mono);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--r-keycap);
  background-color: var(--raised-2);
  background-image: var(--grad-raised);
  color: var(--ink-3);
  font: 400 11px/1 var(--font-mono);
  box-shadow: 0 1px 0 rgba(19, 20, 22, 0.14), inset 0 -1px 0 rgba(19, 20, 22, 0.04), inset 0 0 0 1px rgba(19, 20, 22, 0.05);
  white-space: nowrap;
}

/* ---------- Navigation items ---------- */

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--h-md);
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-link);
  background: transparent;
  color: var(--ink-2);
  font: 400 14px/1.2 var(--font-ui);
  text-align: left;
  transition: background-color 0.2s, box-shadow 0.2s, color 0.2s;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.45);
  color: var(--ink);
}

.nav-item.is-active {
  background-color: var(--raised-1);
  background-image: var(--grad-raised);
  box-shadow: var(--shadow-raised);
  color: var(--ink);
  font-weight: 500;
}

.nav-item__icon {
  color: var(--ink-2);
  display: inline-flex;
  flex-shrink: 0;
}

.nav-item.is-active .nav-item__icon {
  color: var(--ink);
}

.nav-item__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item__meta {
  flex-shrink: 0;
  margin-left: auto;
  color: var(--ink-3);
  font: 400 12px/1 var(--font-mono);
}

.nav-item__meta .count-badge {
  font-size: 11px;
}

.nav-item__actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s;
}

.nav-item:hover .nav-item__actions,
.nav-item:focus-within .nav-item__actions,
.nav-item.is-active .nav-item__actions {
  opacity: 1;
}

.nav-item__actions .btn--icon {
  width: 28px;
  min-width: 28px;
  height: 28px;
}

/* Touch screens have no hover: keep actions visible */
@media (hover: none) {
  .nav-item__actions {
    opacity: 1;
  }
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: var(--s-4);
}

.nav-group__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  min-height: 28px;
  padding: 0 12px;
  font: 400 11px/1.2 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.nav-group__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  transition: transform 0.2s var(--ease-out), background-color 0.2s;
}

.nav-group__toggle:hover {
  background-color: rgba(255, 255, 255, 0.6);
  color: var(--ink);
}

.nav-group.is-collapsed .nav-group__toggle {
  transform: rotate(-90deg);
}

.nav-group.is-collapsed > :not(.nav-group__title) {
  display: none;
}

/* ---------- Surfaces ---------- */

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--s-6);
  border-radius: var(--r-card);
  background-color: var(--card-2);
  background-image: var(--grad-card);
  box-shadow: var(--shadow-card);
  color: var(--ink);
}

.card--raised {
  background-color: var(--raised-1);
  background-image: var(--grad-raised);
  box-shadow: var(--shadow-raised);
}

.card--hatch {
  background-color: var(--soft);
  background-image: var(--hatch), linear-gradient(180deg, var(--card-2), var(--soft));
  box-shadow: inset 0 0 0 1px var(--line);
}

.card--dots {
  background-image: var(--dots), var(--grad-card);
  background-size: 10px 10px, auto;
  background-repeat: repeat, no-repeat;
}

.card__title {
  font: 500 18px/1.25 var(--font-ui);
  letter-spacing: -0.01em;
  color: var(--ink);
}

.card__body {
  margin-top: var(--s-4);
  min-width: 0;
}

/* InsightBar: AI dot-grid strip with a graphite icon tile */
.insight {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-row);
  background-color: var(--card-2);
  background-image: var(--dots), var(--grad-card);
  background-size: 10px 10px, auto;
  background-repeat: repeat, no-repeat;
  box-shadow: var(--shadow-inset), 0 1px 2px rgba(19, 20, 22, 0.04);
}

.insight__icon {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--r-segment);
  background-image: var(--grad-graphite);
  background-color: var(--graphite-2);
  color: var(--on-graphite);
  box-shadow: var(--shadow-pill);
}

.well {
  min-width: 0;
  padding: var(--s-1);
  border-radius: var(--r-control);
  background: var(--well);
  box-shadow: var(--shadow-inset);
}

.row-panel {
  min-width: 0;
  padding: var(--s-4);
  border-radius: var(--r-row);
  background-color: var(--card-2);
  background-image: var(--grad-card);
  box-shadow: inset 0 0 0 1px var(--line), 0 1px 2px rgba(19, 20, 22, 0.04);
}

/* ---------- Forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field__label {
  font: 400 11px/1.2 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.field__hint {
  font: 400 13px/1.35 var(--font-ui);
  color: var(--ink-3);
}

.input,
.select,
.textarea {
  width: 100%;
  min-width: 0;
  min-height: var(--h-lg);
  padding: 0 14px;
  border: 0;
  border-radius: var(--r-control);
  background-color: var(--well);
  color: var(--ink);
  font: 400 15px/1.2 var(--font-ui);
  box-shadow: var(--shadow-inset);
  transition: box-shadow 0.2s, background-color 0.2s;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--ink-3);
  opacity: 0.8;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  background-color: var(--raised-1);
  box-shadow: inset 0 0 0 1px var(--line-strong), 0 0 0 2px var(--graphite-2);
}

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--line-strong), 0 0 0 2px var(--graphite-2);
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  box-shadow: inset 0 0 0 1.5px var(--ember);
}

.input[disabled],
.select[disabled],
.textarea[disabled] {
  background-image: var(--hatch);
  color: var(--ink-3);
  box-shadow: inset 0 0 0 1px var(--line);
}

.input--password {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235E646C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-color: var(--well);
  cursor: pointer;
}

.textarea {
  min-height: 96px;
  padding: 12px 14px;
  line-height: 1.45;
  resize: vertical;
}

/* ---------- Feedback: toasts, empty, spinner, skeleton ---------- */

.toasts {
  position: fixed;
  right: var(--s-4);
  bottom: var(--s-4);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s-2);
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  max-width: 100%;
  padding: 12px 16px;
  border-radius: var(--r-control);
  background-color: var(--raised-1);
  background-image: var(--grad-raised);
  box-shadow: var(--shadow-raised), 0 12px 28px -12px rgba(19, 20, 22, 0.35);
  color: var(--ink);
  font: 400 14px/1.35 var(--font-ui);
  pointer-events: auto;
  animation: toast-in 0.22s var(--ease-out) both;
}

.toast--error {
  background-color: var(--raised-1);
  background-image: linear-gradient(180deg, var(--ember-soft), var(--ember-soft)), var(--grad-raised);
  box-shadow: inset 0 0 0 1px rgba(229, 72, 42, 0.3), var(--shadow-raised);
}

.toast--ok {
  background-image: var(--grad-raised);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 220px;
  padding: var(--s-7) var(--s-6);
  border-radius: var(--r-card);
  background-color: var(--card-2);
  background-image: var(--dots), var(--grad-card);
  background-size: 10px 10px, auto;
  background-repeat: repeat, no-repeat;
  box-shadow: var(--shadow-card);
  text-align: center;
}

.empty__icon {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: var(--s-2);
  border-radius: 50%;
  background-image: var(--grad-raised);
  background-color: var(--raised-1);
  color: var(--ink-3);
  box-shadow: var(--shadow-raised);
}

.empty__title {
  font: 500 18px/1.25 var(--font-ui);
  color: var(--ink);
}

.empty__text {
  max-width: 42ch;
  font: 400 14px/1.45 var(--font-ui);
  color: var(--ink-3);
}

.spinner {
  display: inline-block;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--ink);
  animation: spin 0.8s linear infinite;
}

.skeleton {
  display: block;
  min-height: 14px;
  border-radius: var(--r-tag);
  background-color: var(--soft);
  background-image: linear-gradient(90deg, var(--soft) 0%, var(--card-1) 50%, var(--soft) 100%);
  background-size: 200% 100%;
  background-repeat: no-repeat;
  animation: shimmer 1.6s ease-in-out infinite;
}

/* ---------- Dialog ---------- */

.dialog {
  width: min(440px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: var(--s-6);
  border: 0;
  border-radius: var(--r-card);
  background-color: var(--raised-1);
  background-image: var(--grad-raised);
  color: var(--ink);
  box-shadow: var(--shadow-raised), 0 30px 60px -20px rgba(19, 20, 22, 0.45);
  overflow: auto;
}

.dialog[open] {
  animation: dialog-in 0.2s var(--ease-out) both;
}

.dialog::backdrop {
  background: rgba(19, 20, 22, 0.35);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: var(--s-5);
}

/* ---------- Utilities ---------- */

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-width: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

/* ---------- Icons ---------- */

/* Size and stroke come from the icon() attributes; only layout here. */
svg.icon {
  flex-shrink: 0;
  color: currentColor;
  vertical-align: middle;
}

/* ---------- Keyframes ---------- */

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

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

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

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