/*
 * Generic, namespaced components — the reusable core of File Sweep's UI, with
 * every app-specific selector (.file-row, .watch-*, .hist-*) left behind.
 *
 * Every rule is a `.ds-*` class; every value resolves to a token from
 * `tokens.css`; there are no colour literals here. The file is layer-agnostic —
 * `index.css` imports it into `@layer brand.primitives` so a consuming app's own
 * rules win without an !important war. A consumer that loads this file directly,
 * unlayered (like File Sweep), instead gets it on plain specificity/order: load
 * it BEFORE the app stylesheet so app rules win ties.
 *
 * `[hidden]` is deliberately NOT handled here. It lives in `reset.css` as
 * `[hidden] { display: none !important }`, and it needs that `!important`:
 * the `hidden` attribute is only a UA rule, so any `.ds-*` rule carrying a
 * `display` — `.ds-btn`, `.ds-menu`, `.ds-navitem`, `.ds-count` — outranks it
 * and the element stays on screen while every build gate passes.
 *
 * A consumer that vendors this file WITHOUT `reset.css` must ship that
 * one-liner in its own stylesheet. Every extension in the tinware.tools set
 * does exactly that: their `sync-brand.mjs` copies tokens/fonts/primitives and
 * skips the reset, so `hidden` on a `.ds-*` element is a silent no-op until
 * the app's own CSS declares the guard. This file used to carry a
 * `.ds-count[hidden]` patch for that; per-class patches only ever cover the
 * case someone already tripped over, so it was removed in 0.3.0 in favour of
 * the guard being the consumer's responsibility.
 */

/*
 * Buttons. Base has no padding/size of its own — each variant sets it, so a
 * ghost and a primary can differ without fighting a base. Values match File
 * Sweep's shipping `.ghost-btn` / `.primary-btn` / `.link-btn` exactly.
 */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

.ds-btn:disabled,
.ds-btn[aria-disabled='true'] {
  cursor: not-allowed;
}

/* Ghost — the default secondary action. */
.ds-btn--ghost {
  padding: 6px 10px;
  border-color: var(--line-strong);
  background: var(--bg-card-2);
  color: var(--text-dim);
  font-size: 12px;
  transition:
    color var(--transition),
    border-color var(--transition),
    background var(--transition);
}

.ds-btn--ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--blue);
  background: var(--blue-soft);
}

.ds-btn--ghost:disabled {
  opacity: 0.4;
}

/* Primary — one per view. */
.ds-btn--primary {
  padding: 13px 16px;
  border-color: var(--blue);
  border-radius: var(--radius-lg);
  background: var(--blue);
  color: var(--on-accent);
  font-size: 14px;
  letter-spacing: -0.2px;
  transition:
    transform var(--transition-fast),
    filter var(--transition);
}

.ds-btn--primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.ds-btn--primary:active:not(:disabled) {
  transform: scale(0.985);
}

.ds-btn--primary:disabled {
  opacity: 0.45;
}

/* Link — text-only affordance. */
.ds-btn--link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--blue-bright);
  font-size: 12px;
}

.ds-btn--link:hover:not(:disabled) {
  text-decoration: underline;
}

.ds-btn--sm {
  padding: 4px 8px;
  font-size: 11px;
}

.ds-btn--block {
  width: 100%;
}

/* Toggled state — a ghost button that's currently "on". */
.ds-btn--ghost.is-active {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--on-accent);
}

/* ─────────────────────────── Fields ─────────────────────────── */
.ds-field {
  width: 100%;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
}

textarea.ds-field {
  resize: vertical;
}

.ds-field::placeholder {
  color: var(--text-mute);
}

.ds-field:focus {
  outline: none;
  border-color: var(--blue);
}

.ds-field.has-error {
  border-color: var(--danger);
}

.ds-field--sm {
  padding: 6px 8px;
  font-size: 12px;
}

/* Compact pill select — the toolbar "sort / mode" control. */
.ds-select {
  flex: 0 0 auto;
  background: var(--bg-card-2);
  color: var(--text-dim);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ds-check {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  accent-color: var(--blue);
  cursor: pointer;
}

/* ─────────────────────────── Chips ─────────────────────────── */
.ds-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition:
    color var(--transition),
    border-color var(--transition),
    background var(--transition);
}

.ds-chip:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.ds-chip.is-active {
  color: var(--on-accent);
  background: var(--blue);
  border-color: var(--blue);
}

.ds-chip__count {
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--blue-soft);
  color: var(--blue-bright);
  font-size: 10px;
}

.ds-chip.is-active .ds-chip__count {
  background: var(--on-accent-soft);
  color: var(--on-accent);
}

/* ─────────────────────────── Badges / tags ─────────────────────────── */
.ds-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-card-2);
  color: var(--text-mute);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.ds-badge--info {
  background: var(--blue-soft);
  color: var(--blue-bright);
}

.ds-badge--success {
  background: var(--success-soft);
  color: var(--success);
}

.ds-badge--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.ds-badge--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ─────────────────────────── Status line ─────────────────────────── */
.ds-status {
  font-size: 12px;
  color: var(--blue); /* info: a status message is not an error */
}

.ds-status[data-tone='success'] {
  color: var(--success);
}

.ds-status[data-tone='warn'] {
  color: var(--warn);
}

.ds-status[data-tone='error'] {
  color: var(--danger);
}

/* ─────────────────────────── Menu (details/summary) ─────────────────────────── */
.ds-menu {
  position: relative;
  display: inline-block;
}

.ds-menu > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  list-style: none;
  user-select: none;
  cursor: pointer;
}

.ds-menu > summary::-webkit-details-marker {
  display: none;
}

.ds-menu[open] > summary.ds-select,
.ds-menu[open] > summary.ds-btn {
  color: var(--text);
  border-color: var(--blue);
  background: var(--blue-soft);
}

.ds-menu__panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  min-width: 160px;
  max-height: 240px;
  overflow-y: auto;
  padding: 6px;
  background: var(--bg-card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 12px 28px var(--shadow);
}

.ds-menu--up > .ds-menu__panel {
  top: auto;
  bottom: calc(100% + 4px);
}

.ds-menu__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}

.ds-menu__item:hover {
  background: var(--blue-soft);
  color: var(--text);
}

.ds-menu__item input {
  accent-color: var(--blue);
}

.ds-menu__action {
  width: 100%;
  border: 0;
  background: none;
  font-family: inherit;
  font-weight: 600;
  text-align: left;
}

/* ─────────────────────────── Card ─────────────────────────── */
.ds-card {
  padding: 16px 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}

.ds-card--flush {
  padding: 0;
}

.ds-card__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--text-mute);
}

/* ─────────────────────────── Tabs ─────────────────────────── */
.ds-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line-strong);
}

.ds-tab {
  padding: 8px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.ds-tab:hover {
  color: var(--text);
}

.ds-tab[aria-selected='true'] {
  color: var(--text);
  border-bottom-color: var(--blue);
}

/* ─────────────────────────── Nav item ─────────────────────────── */
.ds-navitem {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition:
    color var(--transition-fast),
    background var(--transition-fast);
}

.ds-navitem:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.ds-navitem.is-active {
  color: var(--on-accent);
  background: var(--blue);
}

/* ─────────────────────────── Count pill ─────────────────────────── */
.ds-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--blue);
  color: var(--on-accent);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ds-navitem.is-active .ds-count {
  background: var(--on-accent-soft);
}

/* ─────────────────────────── Spinner ─────────────────────────── */
.ds-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--blue-bright);
  border-radius: 50%;
  animation: ds-spin 1s linear infinite;
}

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

/* ─────────────────────────── Toast ─────────────────────────── */
.ds-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--blue);
  color: var(--on-accent);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 8px 20px var(--shadow);
}

/* ─────────────────────────── Wordmark ─────────────────────────── */
.ds-wordmark {
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.6px;
  line-height: 1;
  color: var(--text);
}

.ds-wordmark span {
  color: var(--blue-bright);
}

/* ─────────────────────────── Scroll area (opt-in) ─────────────────────────── */
.ds-scroll {
  scrollbar-width: auto;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.ds-scroll::-webkit-scrollbar {
  width: 10px;
  background: transparent;
}

.ds-scroll::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.ds-scroll::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
  border: 2px solid var(--bg-0);
  background-clip: padding-box;
}
