/* Components. Class vocabulary used across the app:
   .glass .glass-strong | .btn .btn-primary .btn-ghost .btn-danger .btn-sm .btn-lg .btn-block
   .icon-btn (.sm .lg) | .chip (.active) | .badge .badge-hdr | .card | .section-title
   .field .field-label .input .select | .switch | .segmented .seg | .range
   .progress | .ring | .spinner | .empty | .list .list-row | .kbd
   sheets (.sheet*), menus (.menu*), dialogs (.dialog*), toasts (.toast*) */

/* ---- glass ------------------------------------------------------------------ */
.glass, .glass-strong {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
}
.glass-strong { background: var(--glass-strong); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass, .glass-strong { background: var(--glass-solid); }
}

/* ---- buttons ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--glass-border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: var(--fs-sm);
  letter-spacing: .01em;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--glass-border-strong); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 8px 24px -12px var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--hover); border-color: transparent; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in oklab, var(--danger) 30%, transparent); }
.btn-danger:hover:not(:disabled) { background: color-mix(in oklab, var(--danger) 22%, transparent); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: var(--fs-xs); }
.btn-sm svg { width: 16px; height: 16px; }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: var(--fs-md); }
.btn-block { width: 100%; }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  color: var(--text);
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.icon-btn:active:not(:disabled) { transform: scale(.92); }
.icon-btn.glass:hover:not(:disabled) { background: var(--glass-strong); }
.icon-btn.sm { width: 36px; height: 36px; }
.icon-btn.sm svg { width: 19px; height: 19px; }
.icon-btn.lg { width: var(--bar-btn); height: var(--bar-btn); }
.icon-btn.lg svg { width: 24px; height: 24px; }
.icon-btn.active { color: var(--accent); }
.icon-btn .dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg), 0 0 10px var(--accent);
}

/* ---- chips, badges, cards ------------------------------------------------------ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--glass-border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.chip svg { width: 16px; height: 16px; }
.chip:hover { background: var(--surface-3); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: color-mix(in oklab, var(--accent) 45%, transparent); color: var(--accent); }
.chip .count { color: var(--muted); font-weight: 400; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--r-pill);
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.badge svg { width: 12px; height: 12px; }
.badge-hdr {
  color: var(--copper);
  border: 1px solid color-mix(in oklab, var(--copper) 45%, transparent);
  letter-spacing: .06em;
}
/* HDR ink: on HDR screens in HDR mode the label glows brighter than white
   (a 16-bit PQ swatch clipped to the text, like the CV site). */
@media (dynamic-range: high) {
  @supports (dynamic-range-limit: standard) {
    :root[data-hdr="on"][data-theme="dark"] .hdr-ink {
      background-image: url("/assets/hdr/ui-gold.png");
      background-size: 100% 100%;
      -webkit-background-clip: text;
      background-clip: text;
      -webkit-text-fill-color: transparent;
    }
    :root[data-hdr="on"][data-theme="dark"] .hdr-ink-blue {
      background-image: url("/assets/hdr/ui-blue.png");
      background-size: 100% 100%;
      -webkit-background-clip: text;
      background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }
}

.card {
  border-radius: var(--r-lg);
  padding: 18px;
}
.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 28px 0 12px;
  font-size: var(--fs-lg);
  font-weight: 600;
}
.section-title .muted { font-size: var(--fs-sm); font-weight: 400; }
.kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--glass-border-strong);
  background: var(--surface-2);
  font: 600 11px/18px var(--font-mono);
  text-align: center;
}

/* ---- forms ---------------------------------------------------------------------- */
.field { display: grid; gap: 6px; }
.field-label { font-size: var(--fs-sm); color: var(--text-2); font-weight: 500; }
.input, .select {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--glass-border-strong);
  background: var(--input-bg);
  color: var(--text);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.input::placeholder { color: var(--muted); }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative;
  width: 44px;
  height: 26px;
  flex: none;
  border-radius: 13px;
  background: var(--surface-3);
  border: 1px solid var(--glass-border-strong);
  transition: background var(--t-med) var(--ease), border-color var(--t-med) var(--ease);
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 2px 6px var(--knob-shadow);
  transition: transform var(--t-med) var(--ease-out);
}
.switch input:checked + .track { background: var(--accent); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--knob); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--r-pill);
  background: var(--input-bg);
  border: 1px solid var(--glass-border);
}
.segmented .seg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.segmented .seg svg { width: 16px; height: 16px; }
.segmented .seg:hover { color: var(--text); }
.segmented .seg.active { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 0 var(--glass-hi) inset, 0 2px 6px var(--shadow-ink-soft); }
.segmented.block { display: flex; }
.segmented.block .seg { flex: 1; justify-content: center; }

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  cursor: pointer;
  --pct: 50%;
}
.range::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--accent) var(--pct), var(--surface-3) var(--pct)); }
.range::-moz-range-track { height: 4px; border-radius: 2px; background: var(--surface-3); }
.range::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--knob); box-shadow: 0 1px 6px var(--knob-shadow); border: 0; }
.range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--knob); box-shadow: 0 1px 6px var(--knob-shadow); border: 0; }

/* ---- progress ------------------------------------------------------------------- */
.progress { position: relative; height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.progress > span { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: var(--accent); transition: width var(--t-med) linear; }
.progress.ok > span { background: var(--ok); }
.progress.err > span { background: var(--danger); }
.progress.indeterminate > span { width: 35%; animation: progress-slide 1.1s var(--ease) infinite; }
@keyframes progress-slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.ring { width: 44px; height: 44px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring .ring-bg { stroke: var(--surface-3); }
.ring .ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset var(--t-med) linear; }

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid color-mix(in oklab, var(--text) 18%, transparent);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- empty states, lists ---------------------------------------------------------- */
.empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  max-width: 440px;
  margin: 12vh auto 0;
  padding: 32px 24px;
  text-align: center;
  border-radius: var(--r-xl);
}
.empty .empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
}
.empty .empty-icon svg { width: 30px; height: 30px; }
.empty h2 { font-size: var(--fs-xl); }
.empty p { color: var(--muted); }

.list { display: grid; gap: 2px; }
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--glass-border);
}
.list-row:last-child { border-bottom: 0; }
.list-row .label { color: var(--text-2); }
.list-row .value { text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ---- HDR lights (hdr.js) --------------------------------------------------------------- */
.hdr-light {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: inherit;
  background-size: 100% 100%;
  pointer-events: none;
  dynamic-range-limit: no-limit;
}
.bb-light.hdr-lit { background: none; }

/* ---- overlays: backdrop -------------------------------------------------------------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity var(--t-med) var(--ease);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.backdrop.show { opacity: 1; }

/* ---- sheets (bottom sheet on phones, floating panel on wide screens) ------------------- */
.sheet-layer { position: fixed; inset: 0; z-index: var(--z-sheet); }
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(88vh, 88dvh);
  display: flex;
  flex-direction: column;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding-bottom: var(--safe-b);
  background: var(--glass-strong);
  transform: translateY(100%);
  transition: transform var(--t-slow) var(--ease-out);
  will-change: transform;
  overscroll-behavior: contain;
}
.sheet.show { transform: translateY(0); }
.sheet.dragging { transition: none; }
.sheet.full { height: min(92vh, 92dvh); max-height: none; }
.sheet-handle { width: 40px; height: 5px; margin: 10px auto 2px; border-radius: 3px; background: color-mix(in oklab, var(--text) 25%, transparent); flex: none; }
.sheet-header { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 22px; flex: none; }
.sheet-title { flex: 1; font-size: var(--fs-lg); font-weight: 600; }
.sheet-body { padding: 6px 22px 22px; overflow: auto; flex: 1 1 auto; -webkit-overflow-scrolling: touch; }
.sheet-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 22px 18px; border-top: 1px solid var(--glass-border); flex: none; }
@media (min-width: 760px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: min(560px, calc(100vw - 48px));
    max-height: min(82vh, 760px);
    border-radius: var(--r-xl);
    padding-bottom: 0;
    transform: translate(-50%, calc(-50% + 24px)) scale(.97);
    opacity: 0;
    transition: transform var(--t-slow) var(--ease-out), opacity var(--t-med) var(--ease);
  }
  .sheet.show { transform: translate(-50%, -50%); opacity: 1; }
  .sheet.wide { width: min(920px, calc(100vw - 48px)); }
  .sheet.full { height: min(86vh, 900px); width: min(1100px, calc(100vw - 48px)); }
  .sheet-handle { display: none; }
  .sheet-header { padding: 16px 14px 8px 24px; }
}

/* ---- menus ---------------------------------------------------------------------------- */
.menu-layer { position: fixed; inset: 0; z-index: var(--z-menu); }
.menu {
  position: fixed;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  overflow: auto;
  padding: 6px;
  border-radius: var(--r-lg);
  background: var(--glass-strong);
  transform-origin: var(--origin, top right);
  transform: scale(.92);
  opacity: 0;
  transition: transform var(--t-med) var(--ease-out), opacity var(--t-fast) var(--ease);
}
.menu.show { transform: scale(1); opacity: 1; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-md);
  text-align: left;
}
.menu-item svg { width: 20px; height: 20px; color: var(--text-2); flex: none; }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); box-shadow: none; }
.menu-item.danger, .menu-item.danger svg { color: var(--danger); }
.menu-item:disabled { opacity: .45; }
.menu-item .menu-check { margin-left: auto; color: var(--accent); }
.menu-item .menu-hint { margin-left: auto; color: var(--muted); font-size: var(--fs-xs); }
.menu-divider { height: 1px; margin: 6px 8px; background: var(--glass-border); }
.menu-label { padding: 8px 12px 4px; font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

/* ---- dialogs ---------------------------------------------------------------------------- */
.dialog-layer { position: fixed; inset: 0; z-index: var(--z-dialog); display: grid; place-items: center; padding: 20px; }
.dialog {
  position: relative;
  width: min(420px, 100%);
  padding: 24px;
  border-radius: var(--r-xl);
  background: var(--glass-strong);
  transform: scale(.94);
  opacity: 0;
  transition: transform var(--t-med) var(--ease-out), opacity var(--t-fast) var(--ease);
}
.dialog.show { transform: scale(1); opacity: 1; }
.dialog-title { font-size: var(--fs-xl); font-weight: 600; margin-bottom: 8px; }
.dialog-message { color: var(--text-2); margin-bottom: 18px; white-space: pre-line; }
.dialog .field { margin-bottom: 18px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- toasts ------------------------------------------------------------------------------ */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--content-bottom) + 4px);
  z-index: var(--z-toast);
  display: grid;
  gap: 8px;
  width: min(460px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}
:root.viewer-open .toasts { bottom: calc(96px + var(--safe-b)); }
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 10px 10px 10px 16px;
  border-radius: var(--r-lg);
  background: var(--glass-strong);
  color: var(--text);
  font-size: var(--fs-sm);
  pointer-events: auto;
  transform: translateY(16px) scale(.98);
  opacity: 0;
  transition: transform var(--t-med) var(--ease-out), opacity var(--t-med) var(--ease);
}
.toast.show { transform: none; opacity: 1; }
.toast svg { width: 20px; height: 20px; flex: none; }
.toast .toast-msg { flex: 1; min-width: 0; }
.toast.ok svg { color: var(--ok); }
.toast.error svg { color: var(--danger); }
.toast.warn svg { color: var(--warn); }
.toast.info svg { color: var(--accent); }
.toast-action {
  flex: none;
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  color: var(--accent);
  font-weight: 600;
  font-size: var(--fs-sm);
}
.toast-action:hover { background: var(--accent-soft); }
