/* ==========================================================================
   Distributor — design system
   shadcn/ui tokens (HSL CSS vars) + Thinking Machines / Tinker calm.
   Hand-written. No framework, no build step, no network.
   ========================================================================== */

/* ---- Design tokens (light) ---- */
:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 72% 51%;
  --destructive-foreground: 0 0% 98%;

  /* status accents (state only) */
  --ok: 142 71% 36%;
  --ok-foreground: 142 71% 96%;
  --warn: 38 92% 45%;
  --warn-foreground: 38 92% 97%;
  --bad: 0 72% 51%;
  --bad-foreground: 0 0% 98%;

  --radius: 0.625rem;

  --shadow-sm: 0 1px 2px 0 hsl(240 6% 10% / 0.04);
  --shadow: 0 1px 3px 0 hsl(240 6% 10% / 0.06), 0 1px 2px -1px hsl(240 6% 10% / 0.06);
  --shadow-md: 0 4px 12px -2px hsl(240 6% 10% / 0.08), 0 2px 6px -3px hsl(240 6% 10% / 0.06);
  --shadow-lg: 0 16px 40px -12px hsl(240 8% 10% / 0.18);

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "PingFang SC", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --background: 240 10% 4.5%;
  --foreground: 0 0% 96%;
  --card: 240 8% 7%;
  --card-foreground: 0 0% 96%;
  --popover: 240 9% 6%;
  --popover-foreground: 0 0% 96%;
  --muted: 240 5% 14%;
  --muted-foreground: 240 5% 60%;
  --border: 240 5% 16%;
  --input: 240 5% 18%;
  --ring: 240 5% 70%;
  --primary: 0 0% 96%;
  --primary-foreground: 240 6% 10%;
  --secondary: 240 5% 14%;
  --secondary-foreground: 0 0% 96%;
  --accent: 240 5% 15%;
  --accent-foreground: 0 0% 96%;
  --destructive: 0 62% 52%;
  --destructive-foreground: 0 0% 98%;

  --ok: 142 60% 45%;
  --warn: 38 90% 55%;
  --bad: 0 70% 58%;

  --shadow-sm: 0 1px 2px 0 hsl(0 0% 0% / 0.3);
  --shadow: 0 1px 3px 0 hsl(0 0% 0% / 0.4), 0 1px 2px -1px hsl(0 0% 0% / 0.4);
  --shadow-md: 0 6px 16px -4px hsl(0 0% 0% / 0.5);
  --shadow-lg: 0 20px 48px -12px hsl(0 0% 0% / 0.65);
}

/* ---- Reset ---- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.011em;
  line-height: 1.25;
}

p { margin: 0; }
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }

::selection {
  background: hsl(var(--primary) / 0.18);
}

/* Scrollbars (subtle) */
* {
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--border)) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: hsl(var(--border));
  border-radius: 999px;
  border: 3px solid hsl(var(--background));
}
*::-webkit-scrollbar-track { background: transparent; }

/* ==========================================================================
   Layout shell
   ========================================================================== */
.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
  padding: 0 20px;
  background: hsl(var(--background) / 0.82);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid hsl(var(--border));
}

.topbar__brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.topbar__name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.topbar__sub {
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  margin-right: 4px;
}
.topbar__mark svg { width: 15px; height: 15px; }
.topbar__spacer { flex: 1 1 auto; }
.topbar__tools {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar__target {
  display: flex;
  align-items: center;
  gap: 7px;
}
.topbar__target-label {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}

.shell {
  display: grid;
  grid-template-columns: 224px 1fr;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 60px;
  align-self: start;
  height: calc(100vh - 60px);
  padding: 18px 12px;
  border-right: 1px solid hsl(var(--border));
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.sidebar__group-label {
  padding: 12px 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
}
.navitem {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: calc(var(--radius) - 2px);
  color: hsl(var(--muted-foreground));
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}
.navitem svg { width: 16px; height: 16px; flex: 0 0 auto; }
.navitem:hover {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}
.navitem.is-active {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  font-weight: 600;
}
.navitem__badge {
  margin-left: auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: hsl(var(--muted-foreground));
  font-family: var(--font-mono);
}

.main {
  min-width: 0;
  padding: 32px 36px 80px;
  max-width: 1180px;
}

.page-head {
  margin-bottom: 28px;
}
.page-head h1 {
  font-size: 22px;
  letter-spacing: -0.02em;
}
.page-head .lead {
  margin-top: 7px;
  color: hsl(var(--muted-foreground));
  font-size: 14px;
  max-width: 70ch;
}
.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  margin-bottom: 20px;
  align-items: center;
}

.section-gap { margin-top: 28px; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  --btn-h: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--btn-h);
  padding: 0 14px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease,
    box-shadow 0.13s ease, opacity 0.13s ease;
}
.btn svg { width: 15px; height: 15px; }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring) / 0.55);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.btn--default {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn--default:hover { background: hsl(var(--primary) / 0.9); }

.btn--secondary {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}
.btn--secondary:hover { background: hsl(var(--secondary) / 0.7); }

.btn--outline {
  background: hsl(var(--background));
  border-color: hsl(var(--border));
  color: hsl(var(--foreground));
}
.btn--outline:hover { background: hsl(var(--muted)); }

.btn--ghost {
  background: transparent;
  color: hsl(var(--foreground));
}
.btn--ghost:hover { background: hsl(var(--muted)); }

.btn--destructive {
  background: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
}
.btn--destructive:hover { background: hsl(var(--destructive) / 0.9); }

.btn--sm { --btn-h: 30px; padding: 0 10px; font-size: 12.5px; gap: 6px; }
.btn--sm svg { width: 14px; height: 14px; }
.btn--icon { --btn-h: 36px; width: 36px; padding: 0; }
.btn--icon.btn--sm { --btn-h: 30px; width: 30px; }

.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: hsl(var(--primary-foreground));
  animation: spin 0.6s linear infinite;
}
.btn--outline.is-loading::after,
.btn--ghost.is-loading::after,
.btn--secondary.is-loading::after { color: hsl(var(--foreground)); }

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

/* ==========================================================================
   Card
   ========================================================================== */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card__head {
  padding: 18px 20px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.card__head-text { min-width: 0; flex: 1; }
.card__title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.card__desc {
  margin-top: 4px;
  font-size: 13px;
  color: hsl(var(--muted-foreground));
}
.card__head-actions { display: flex; gap: 8px; flex: 0 0 auto; }
/* A headless card body must space itself off the top border; when a head is
   present it already supplies the top gap, so drop the body's top padding. */
.card__body { padding: 18px 20px 20px; }
.card__head + .card__body { padding-top: 0; }
.card__body--flush { padding: 0; }
.skeleton-body { padding: 16px 20px; }
.card + .card { margin-top: 18px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }

.stat {
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  padding: 14px 16px;
  background: hsl(var(--card));
}
.stat__label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground));
  font-weight: 600;
}
.stat__value {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat__value .mono { font-family: var(--font-mono); font-size: 19px; }
.stat__sub { margin-top: 2px; font-size: 12px; color: hsl(var(--muted-foreground)); }

/* ==========================================================================
   Form controls
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: 13px;
  font-weight: 500;
}
.field__hint { font-size: 12px; color: hsl(var(--muted-foreground)); }
.field__error { font-size: 12.5px; color: hsl(var(--destructive)); }
.field-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.input, .textarea, .select {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.input::placeholder, .textarea::placeholder { color: hsl(var(--muted-foreground)); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.16);
}
.textarea {
  height: auto;
  min-height: 84px;
  padding: 10px 12px;
  line-height: 1.55;
  resize: vertical;
}
.textarea.mono, .input.mono { font-family: var(--font-mono); font-size: 12.5px; }
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  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='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

/* Switch (enable toggle) */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: hsl(var(--input));
  border: none;
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
  transition: background 0.16s ease;
}
.switch::after {
  content: "";
  position: absolute;
  left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: hsl(var(--background));
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease;
}
.switch[aria-checked="true"] { background: hsl(var(--primary)); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }
.switch:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring) / 0.5);
}

.checkline { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }

/* multi-select chips */
.multiselect {
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  background: hsl(var(--background));
}
.multiselect__opt {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 7px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.multiselect__opt:hover { background: hsl(var(--muted)); }
.multiselect__opt input { accent-color: hsl(var(--primary)); width: 15px; height: 15px; }
.multiselect__opt .mono { font-family: var(--font-mono); font-size: 12px; color: hsl(var(--muted-foreground)); }
.multiselect__empty { font-size: 12.5px; color: hsl(var(--muted-foreground)); padding: 6px; }

/* ==========================================================================
   Badge
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 21px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.005em;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1;
}
.badge--outline {
  border-color: hsl(var(--border));
  color: hsl(var(--muted-foreground));
  background: hsl(var(--background));
}
.badge--neutral { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.badge--ok { background: hsl(var(--ok) / 0.13); color: hsl(var(--ok)); border-color: hsl(var(--ok) / 0.25); }
.badge--warn { background: hsl(var(--warn) / 0.14); color: hsl(var(--warn)); border-color: hsl(var(--warn) / 0.28); }
.badge--bad { background: hsl(var(--bad) / 0.12); color: hsl(var(--bad)); border-color: hsl(var(--bad) / 0.28); }
.badge--primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* latency chip */
.lat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 21px;
  padding: 0 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
}
.lat--ok { background: hsl(var(--ok) / 0.12); color: hsl(var(--ok)); border-color: hsl(var(--ok) / 0.22); }
.lat--warn { background: hsl(var(--warn) / 0.13); color: hsl(var(--warn)); border-color: hsl(var(--warn) / 0.26); }
.lat--bad { background: hsl(var(--bad) / 0.11); color: hsl(var(--bad)); border-color: hsl(var(--bad) / 0.24); }
.lat--dead {
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  border-color: hsl(var(--border));
}

/* ==========================================================================
   Table
   ========================================================================== */
.table-wrap {
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.table thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  border-bottom: 1px solid hsl(var(--border));
  white-space: nowrap;
  background: hsl(var(--card));
}
.table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid hsl(var(--border));
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover { background: hsl(var(--muted) / 0.55); }
.table tbody tr.is-disabled td:not(.col-actions) { opacity: 0.5; }
.table .mono { font-family: var(--font-mono); font-size: 12.5px; }
.table .col-actions { text-align: right; white-space: nowrap; }
.table .cell-name { font-weight: 600; }
.table .cell-sub { color: hsl(var(--muted-foreground)); font-size: 12px; margin-top: 2px; }
.row-actions { display: inline-flex; gap: 4px; justify-content: flex-end; }

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 48px 24px;
  color: hsl(var(--muted-foreground));
}
.empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  margin-bottom: 4px;
}
.empty__icon svg { width: 22px; height: 22px; }
.empty__title { font-size: 14.5px; font-weight: 600; color: hsl(var(--foreground)); }
.empty__desc { font-size: 13px; max-width: 46ch; }
.empty__actions { margin-top: 12px; display: flex; gap: 8px; }
.empty--inline { padding: 32px 20px; }

/* ==========================================================================
   Code / YAML / diff blocks
   ========================================================================== */
.code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: hsl(var(--muted) / 0.5);
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  padding: 14px 16px;
  overflow: auto;
  white-space: pre;
  color: hsl(var(--foreground));
  max-height: 520px;
  tab-size: 2;
}
.code--block { white-space: pre; }

.diff {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  overflow: auto;
  max-height: 520px;
  background: hsl(var(--card));
}
.diff__line {
  display: block;
  padding: 0 14px;
  white-space: pre;
}
.diff__line--add { background: hsl(var(--ok) / 0.12); color: hsl(var(--ok)); }
.diff__line--del { background: hsl(var(--bad) / 0.1); color: hsl(var(--bad)); }
.diff__line--ctx { color: hsl(var(--muted-foreground)); }
.diff__line--meta { color: hsl(var(--foreground)); font-weight: 600; background: hsl(var(--muted) / 0.5); }

/* ==========================================================================
   Tabs (inline)
   ========================================================================== */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: hsl(var(--muted));
  border-radius: calc(var(--radius) - 2px);
}
.tab {
  border: none;
  background: transparent;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.tab:hover { color: hsl(var(--foreground)); }
.tab.is-active {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Dialog / modal
   ========================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: hsl(240 10% 4% / 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 7vh 16px 16px;
  overflow-y: auto;
  animation: overlay-in 0.14s ease;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.dialog {
  width: 100%;
  max-width: 560px;
  background: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: dialog-in 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}
.dialog--wide { max-width: 820px; }
.dialog--lg { max-width: 920px; }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.dialog__head {
  padding: 20px 22px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid hsl(var(--border));
}
.dialog__head-text { flex: 1; min-width: 0; }
.dialog__title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.dialog__desc { margin-top: 4px; font-size: 13px; color: hsl(var(--muted-foreground)); }
.dialog__close {
  flex: 0 0 auto;
}
.dialog__body {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 64vh;
  overflow-y: auto;
}
.dialog__foot {
  padding: 14px 22px 18px;
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  border-top: 1px solid hsl(var(--border));
}

.kv-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.kv-block__label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.toasts {
  position: fixed;
  /* Clear the 60px sticky topbar so toasts never cover the user chip / language /
     sign-out controls in the top-right corner. */
  top: 72px;
  right: 16px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 360px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 14px;
  background: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.is-leaving { animation: toast-out 0.18s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(14px); } }
.toast__icon { flex: 0 0 auto; margin-top: 1px; }
.toast__icon svg { width: 17px; height: 17px; }
.toast--ok .toast__icon { color: hsl(var(--ok)); }
.toast--error .toast__icon { color: hsl(var(--destructive)); }
.toast--info .toast__icon { color: hsl(var(--muted-foreground)); }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-size: 13.5px; font-weight: 600; }
.toast__msg { margin-top: 2px; font-size: 12.5px; color: hsl(var(--muted-foreground)); word-break: break-word; }
.toast__close { flex: 0 0 auto; cursor: pointer; color: hsl(var(--muted-foreground)); background: none; border: none; padding: 2px; border-radius: 5px; }
.toast__close:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }

/* ==========================================================================
   Misc helpers
   ========================================================================== */
.mono { font-family: var(--font-mono); }
.muted { color: hsl(var(--muted-foreground)); }
.tnum { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; }
.row--wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.divider { height: 1px; background: hsl(var(--border)); border: none; margin: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.nowrap { white-space: nowrap; }
.text-sm { font-size: 12.5px; }
.hidden { display: none !important; }

.skeleton {
  border-radius: 8px;
  background: linear-gradient(90deg, hsl(var(--muted)) 25%, hsl(var(--muted) / 0.55) 50%, hsl(var(--muted)) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton-row { height: 14px; margin: 10px 0; }

.inline-issues {
  border: 1px solid hsl(var(--destructive) / 0.4);
  background: hsl(var(--destructive) / 0.06);
  border-radius: calc(var(--radius) - 2px);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.inline-issues__title {
  font-size: 13px;
  font-weight: 600;
  color: hsl(var(--destructive));
  display: flex;
  align-items: center;
  gap: 7px;
}
.inline-issues ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.inline-issues li { font-size: 12.5px; color: hsl(var(--foreground)); }

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--border));
  font-size: 13px;
  background: hsl(var(--muted) / 0.4);
}
.banner svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 1px; }
.banner--warn { border-color: hsl(var(--warn) / 0.4); background: hsl(var(--warn) / 0.08); color: hsl(var(--foreground)); }
.banner--warn svg { color: hsl(var(--warn)); }

.proxy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.proxy-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 3px);
  font-size: 12.5px;
}
.proxy-pill.is-now { border-color: hsl(var(--primary) / 0.5); background: hsl(var(--muted) / 0.4); }
.proxy-pill__name { font-family: var(--font-mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proxy-pill__now { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; color: hsl(var(--primary)); text-transform: uppercase; }

/* Quick-link cards (Home dashboard + import dialog) */
.qlink-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.qlink {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  color: inherit; text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
}
.qlink:hover { border-color: hsl(var(--primary) / 0.5); background: hsl(var(--muted) / 0.4); }
.qlink:focus-visible { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring) / 0.55); }
.qlink:focus-visible .qlink__icon { color: hsl(var(--primary)); }
.qlink:active { transform: translateY(1px); }
.qlink__icon { display: flex; flex: 0 0 auto; color: hsl(var(--muted-foreground)); }
.qlink:hover .qlink__icon { color: hsl(var(--primary)); }
.qlink__text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.qlink__label { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.qlink__desc { font-size: 12px; color: hsl(var(--muted-foreground)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qlink__chev { display: flex; flex: 0 0 auto; color: hsl(var(--muted-foreground)); }

.spin { animation: spin 0.8s linear infinite; }

/* ==========================================================================
   Auth / login screen
   ========================================================================== */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}
.auth__toolbar {
  position: absolute;
  top: 18px;
  right: 18px;
}
.auth-card {
  width: 100%;
  max-width: 408px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 34px 32px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.auth-card__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px; height: 52px;
  border-radius: 14px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  margin-bottom: 18px;
}
.auth-card__mark svg { width: 26px; height: 26px; }
.auth-card__title { font-size: 22px; letter-spacing: -0.02em; }
.auth-card__desc {
  margin-top: 8px;
  font-size: 13.5px;
  color: hsl(var(--muted-foreground));
  max-width: 34ch;
}
.auth-card__btn { margin-top: 24px; width: 100%; }
.auth-card__note { margin-top: 18px; text-align: left; }
.auth-card__review { color: hsl(var(--primary)); font-weight: 600; text-decoration: none; }
.auth-card__review:hover { text-decoration: underline; }

.btn--lg { --btn-h: 42px; padding: 0 18px; font-size: 14px; }
.btn--lg svg { width: 16px; height: 16px; }

/* ==========================================================================
   Avatar + user chip (top bar, users table)
   ========================================================================== */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 999px;
  overflow: hidden;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border));
  flex: 0 0 auto;
}
.avatar--sm { width: 26px; height: 26px; }
.avatar__img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar__fallback {
  font-size: 12px;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 4px;
}
.user-chip__login {
  font-size: 13px;
  font-weight: 600;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* badge with a leading inline icon (role badges) */
.badge svg { width: 12px; height: 12px; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 980px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid hsl(var(--border));
    padding: 8px 12px;
    gap: 4px;
    overflow-x: auto;
  }
  .sidebar__group-label { display: none; }
  .navitem { width: auto; }
  .navitem__badge { display: none; }
  .main { padding: 22px 18px 64px; }
}

@media (max-width: 720px) {
  .topbar { gap: 10px; padding: 0 14px; }
  .topbar__sub { display: none; }
  .topbar__target-label { display: none; }
  .user-chip__login { display: none; }
  .page-head h1 { font-size: 19px; }
}
