/* =============================================================================
   Components: topbar, dock, buttons, chips, cards, rows, switches, toasts
   ========================================================================== */

/* ------------------------------- Topbar ---------------------------------- */
/* Status only — never controls. Controls live in the dock, inside thumb reach. */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) calc(var(--sp-3) + var(--safe-r)) 0 calc(var(--sp-3) + var(--safe-l));
  background: linear-gradient(to bottom, var(--scrim), transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.brand .icon { color: var(--accent); }

.topbar-spacer { flex: 1 1 auto; pointer-events: none; }

/* --------------------------- Status pills -------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--r-full);
  background: var(--surface-glass);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
  color: var(--text);
}
.pill--ok   { color: var(--ok); }
.pill--warn { color: var(--warn); }
.pill--bad  { color: var(--bad); }

/* Never colour alone — the dot is paired with a word in every state. */
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: currentColor;
}
.dot--ok   { color: var(--ok); }
.dot--warn { color: var(--warn); }
.dot--bad  { color: var(--bad); }

.dot--live { position: relative; }
.dot--live::after {
  content: '';
  position: absolute; inset: -3px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: 0.6;
  animation: ping 2.4s var(--ease) infinite;
}
@keyframes ping {
  0%   { transform: scale(0.7); opacity: 0.7; }
  70%  { transform: scale(1.9); opacity: 0; }
  100% { transform: scale(1.9); opacity: 0; }
}

/* --------------------------------- Dock ---------------------------------- */
/* The primary control surface. Bottom-centred so it is reachable one-handed. */

.dock {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-3) + var(--safe-b));
  transform: translateX(-50%);
  z-index: var(--z-dock);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1);
  border-radius: var(--r-xl);
  background: var(--surface-glass);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
  max-width: calc(100vw - var(--sp-4) * 2);
}
/* Slide the dock away while the sheet is raised, so it never covers content. */
.dock[data-tucked="true"] {
  transform: translateX(-50%) translateY(calc(100% + var(--sp-6)));
  opacity: 0;
  pointer-events: none;
}

.dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: var(--tap-lg);
  height: var(--tap-lg);
  padding: 0 var(--sp-2);
  border-radius: var(--r-lg);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.dock-btn:active { background: var(--surface-3); }
.dock-btn[aria-pressed="true"], .dock-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}
.dock-btn .icon { width: 22px; height: 22px; }

.dock-sep {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 2px;
  flex: 0 0 auto;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-4);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 600;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:active { transform: scale(0.97); background: var(--surface-3); }
.btn--primary { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn--danger  { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn--ghost   { background: transparent; }
.btn--block   { width: 100%; }
.btn--sm      { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* Square icon button. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  flex: 0 0 auto;
  border-radius: var(--r-md);
  color: var(--text-dim);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:active { background: var(--surface-3); color: var(--text); }

/* Floating map buttons (top-right stack). */
.map-fabs {
  position: fixed;
  right: calc(var(--sp-3) + var(--safe-r));
  top: calc(var(--topbar-h) + var(--safe-t) + var(--sp-2));
  z-index: var(--z-map-ui);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.fab {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: var(--r-md);
  background: var(--surface-glass);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  color: var(--text);
}
.fab:active { background: var(--surface-3); }
.fab.is-active { color: var(--accent); background: var(--accent-soft); }

/* A floating banner offering to resume follow after the user panned away. */
.resume-follow {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + var(--sp-5) + var(--safe-b));
  transform: translateX(-50%);
  z-index: var(--z-map-ui);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 38px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--accent-text);
  font-size: var(--fs-sm);
  font-weight: 700;
  box-shadow: var(--shadow-2);
}

/* -------------------------------- Chips ---------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}
.chip:active { background: var(--surface-3); }
.chip[aria-pressed="true"], .chip.is-active {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}
.chip--sm { height: 30px; padding: 0 10px; font-size: var(--fs-xs); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-dim);
}
.badge--ok   { background: var(--ok-soft);   color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--bad  { background: var(--bad-soft);  color: var(--bad); }

/* -------------------------------- Cards ---------------------------------- */

.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card + .card { margin-top: var(--sp-3); }

.card-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.card-head .icon { width: 15px; height: 15px; }
.card-body { padding: 0 var(--sp-4) var(--sp-4); }
.card-body--flush { padding: 0; }

/* Key/value grid. Values are selectable; keys are not. */
.kv {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  gap: var(--sp-2) var(--sp-4);
  align-items: baseline;
}
.kv dt { color: var(--text-dim); font-size: var(--fs-sm); }
.kv dd {
  margin: 0;
  text-align: right;
  font-size: var(--fs-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Metric tiles. The minimum is wide enough that four tiles land as a 2x2 block
   on a phone rather than 3 across with one stranded underneath. */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: var(--sp-2);
}
.tile {
  padding: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-align: left;
  min-width: 0;
}
.tile-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: block;
  margin-bottom: 2px;
}
.tile-value {
  font-size: var(--fs-lg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-unit { font-size: var(--fs-xs); font-weight: 600; color: var(--text-faint); }
/* Tiles that open a chart advertise it. */
.tile--chartable { cursor: pointer; position: relative; }
.tile--chartable:active { background: var(--surface-3); }
.tile--chartable::after {
  content: '';
  position: absolute; top: 8px; right: 8px;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  opacity: 0.55;
}

/* -------------------------------- Rows ----------------------------------- */

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  color: inherit;
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-3); }
/* .row-main is often a <button>, which the UA centres by default. */
.row-main { flex: 1 1 auto; min-width: 0; text-align: left; }
.row-title { font-size: var(--fs-md); font-weight: 600; }
.row-sub { font-size: var(--fs-sm); color: var(--text-dim); }
.row-end { flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-2); color: var(--text-faint); }

/* ------------------------------- Switch ---------------------------------- */

.switch {
  position: relative;
  width: 50px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--border);
  transition: background var(--dur-fast) var(--ease);
  padding: 0;
  min-height: 0;
  min-width: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-fast) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); border-color: transparent; }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

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

.segmented {
  display: flex;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  gap: 2px;
}
.segmented > button {
  flex: 1 1 0;
  min-width: 0;
  height: 36px;
  border-radius: 9px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6px;
}
.segmented > button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* ------------------------------- Slider ---------------------------------- */

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 30px;
  min-height: 0;
  background: transparent;
  border: 0;
  padding: 0;
}
.slider::-webkit-slider-runnable-track {
  height: 6px; border-radius: var(--r-full); background: var(--surface-3);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: var(--shadow-1);
}
.slider::-moz-range-track { height: 6px; border-radius: var(--r-full); background: var(--surface-3); }
.slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
}

/* ------------------------------- States ---------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  color: var(--text-faint);
}
.empty .icon { width: 34px; height: 34px; opacity: 0.5; }
.empty-title { font-size: var(--fs-md); font-weight: 600; color: var(--text-dim); }
.empty-text { font-size: var(--fs-sm); max-width: 30ch; }

.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ------------------------------- Toasts ---------------------------------- */

.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(var(--topbar-h) + var(--safe-t) + var(--sp-2));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(440px, calc(100vw - var(--sp-4) * 2));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--surface-glass);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  font-size: var(--fs-sm);
  font-weight: 600;
  pointer-events: auto;
  animation: toast-in var(--dur) var(--ease);
}
.toast[data-leaving="true"] { animation: toast-out var(--dur) var(--ease) forwards; }
.toast .icon { width: 18px; height: 18px; flex: 0 0 auto; }
.toast--ok   .icon { color: var(--ok); }
.toast--warn .icon { color: var(--warn); }
.toast--bad  .icon { color: var(--bad); }
.toast-body { flex: 1 1 auto; min-width: 0; }
.toast-action {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 700;
}
@keyframes toast-in  { from { opacity: 0; transform: translateY(-10px) scale(0.97); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(-10px) scale(0.97); } }

/* -------------------------------- Modal ---------------------------------- */
/* Only used where a real decision is required (rename, confirm). */

.modal-scrim {
  position: fixed; inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--sp-4);
  padding-bottom: calc(var(--sp-4) + var(--safe-b));
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in var(--dur-fast) var(--ease);
}
@media (min-width: 700px) { .modal-scrim { align-items: center; } }
.modal {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  padding: var(--sp-5);
  animation: modal-in var(--dur) var(--ease);
}
.modal-title { font-size: var(--fs-lg); margin-bottom: var(--sp-2); }
.modal-text { font-size: var(--fs-sm); color: var(--text-dim); margin-bottom: var(--sp-4); }
.modal-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-4); }
.modal-actions > * { flex: 1 1 0; }
@keyframes fade-in  { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(0.97); } }

/* ------------------------------- Sections -------------------------------- */

/* A section heading with an action on the right. */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}
.section-head .section-title { flex: 1 1 auto; }

/* Flush with the cards, chips and tiles beneath it. The horizontal padding this
   used to carry indented the heading 16px further than everything it labelled. */
.section-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: var(--sp-5) 0 var(--sp-2);
}
.help {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  line-height: 1.4;
  margin-top: 2px;
}
.note {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-xs);
  line-height: 1.45;
}
.note .icon { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 1px; }
