/* ==========================================================================
   Cyberbox Manager — design tokens
   Neutral, document-like admin surface. MIRA blue is reserved for primary
   actions, links, focus and the brand mark; everything else is either
   neutral or semantic (connected / pending / problem).
   ========================================================================== */
:root {
  /* MIRA brand */
  --mira-eisvogelblau: #006092;
  --mira-himmelblau: #007ec0;
  --mira-lichtblau: #40b0e0;
  --mira-arktisblau: #00a3b4;
  --mira-genevergruen: #05663f;
  --mira-limettengruen: #b1c800;
  --mira-persischorange: #ec6726;
  --mira-waescheblau: #a4acb1;
  --mira-werkzeugblau: #6b7c85;

  /* Surfaces */
  --page-bg: #f7f8f9;
  --surface: #ffffff;
  --surface-muted: #f7f8f9;
  --surface-sunken: #f1f3f5;
  --border: #e4e7eb;
  --border-strong: #d3d8de;

  /* Text */
  --text: #1a1d21;
  --text-muted: #4e565d;
  --text-subtle: #6d757c;

  /* Accent */
  --primary: var(--mira-eisvogelblau);
  --primary-hover: #004d75;
  --primary-soft: #e8f1f7;

  /* Semantic */
  --success: #157f3d;
  --success-bg: #eaf7ee;
  --success-border: #b7e3c4;

  --warning: #9a4a12;
  --warning-bg: #fdf3ec;
  --warning-border: #f4d3bb;

  --danger: #b3261e;
  --danger-hover: #93180f;
  --danger-bg: #fdf2f2;
  --danger-border: #f3c9c7;

  --info: #0b5f8a;
  --info-bg: #edf5fa;
  --info-border: #c3dcec;

  /* Card-level state colours. The tint is lighter than the badge background
     so a whole card can carry it without shouting; the border is a step
     stronger than the neutral one so the state reads at a glance. */
  --state-connected-tint: #edf8f1;
  --state-connected-border: #86cea1;
  --state-online-tint: #eef6fb;
  --state-online-border: #93c4de;
  --state-pending-tint: #fdf4ec;
  --state-pending-border: #eeb089;
  --state-problem-tint: #fdf0ef;
  --state-problem-border: #e9a5a1;

  /* Hairlines. Translucent rather than solid so a border sitting on a tinted
     card darkens that tint instead of cutting a grey line through it. */
  --hairline: rgba(16, 24, 40, 0.08);
  --hairline-strong: rgba(16, 24, 40, 0.14);

  /* Radii — generous and consistent, the way stock macOS/iOS controls sit. */
  --radius-sm: 0.5rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;
  --radius-xl: 1.125rem;
  --radius-2xl: 1.25rem;
  --radius-full: 9999px;

  /* Elevation — two layers each: a tight contact shadow plus a wide soft one. */
  --shadow-xs: 0 1px 1px rgba(16, 24, 40, 0.04);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 2px 6px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 1px 3px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.09);
  --shadow-lg: 0 2px 8px rgba(16, 24, 40, 0.06), 0 28px 64px rgba(16, 24, 40, 0.2);

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  /* Apple's standard interface easing: leaves fast, lands slow, no overshoot. */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --transition: 0.28s var(--ease);
  --transition-fast: 0.16s var(--ease);

  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "SF Pro Display", system-ui, "Segoe UI", "Roboto", "Helvetica Neue", Arial,
    sans-serif;
  --font-mono: "SF Mono", "SFMono-Regular", ui-monospace, "Roboto Mono",
    Consolas, "Courier New", monospace;
}

/* ==========================================================================
   Base
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  font-size: 0.875rem;
  line-height: 1.5;
  letter-spacing: -0.005em;
  color: var(--text);
  background: var(--page-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Tighter tracking as text gets larger, the way SF's optical sizes behave. */
h1,
h2,
h3 {
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--text);
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* A soft translucent ring rather than a hard outline. */
:focus-visible {
  outline: 3px solid rgba(0, 126, 192, 0.4);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

/* Data regions dim slightly while we know the numbers are out of date. */
.stale {
  opacity: 0.6;
  transition: opacity var(--transition);
}

/* ==========================================================================
   Header
   ========================================================================== */
/* Translucent toolbar: content scrolling underneath stays faintly visible
   through the blur, the way a macOS titlebar behaves. */
.app-header {
  background: rgba(255, 255, 255, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  z-index: 20;
}

/* Browsers without backdrop-filter would show the page straight through. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .app-header {
    background: var(--surface);
  }
}

.app-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.75rem var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.brand-logo {
  height: 1.375rem;
  width: auto;
  color: var(--primary);
  fill: currentColor;
  flex-shrink: 0;
}

.brand-divider {
  width: 1px;
  height: 1.25rem;
  background: var(--border-strong);
  flex-shrink: 0;
}

.brand-name {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.last-updated {
  font-size: 0.75rem;
  color: var(--text-subtle);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.25rem 0.25rem 0.6875rem;
  border: 1px solid var(--hairline);
  background: var(--surface);
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  color: var(--text-muted);
  max-width: 16rem;
}

.user-chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Status pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.status-dot {
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status-pill.online {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success-border);
}

.status-pill.warning {
  color: var(--warning);
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.status-pill.offline {
  color: var(--text-muted);
  background: var(--surface-sunken);
  border-color: var(--border);
}

/* ==========================================================================
   Page layout
   ========================================================================== */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.nodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(24rem, 1fr));
  gap: var(--space-lg);
}

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: 0.9375rem var(--space-lg);
  border-bottom: 1px solid var(--hairline);
  /* The tunnels header carries a sort control as well as a count, which is
     more than fits on one line on the narrowest screens. */
  flex-wrap: wrap;
}

.card-header h2 {
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
}

.card-body {
  padding: var(--space-lg);
}

/* Card bodies that stack a skeleton, an error, an empty state and a list.
   Only ever a subset is visible, so the container owns the spacing: hidden
   siblings contribute no gap, and whatever shows is inset by the same amount
   on every side. Children must not add their own margins here. */
.card-body.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.card-body.stack > .alert.inline {
  margin-top: 0;
}

/* The list container is always in the DOM but empty until nodes arrive; as a
   flex item it would still earn a gap and leave dead space under the card. */
.card-body.stack > :empty {
  display: none;
}

.card-description {
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

/* Segmented control ----------------------------------------------------
   A sunken track with a single white pill that slides between the two
   options, the way UISegmentedControl behaves. */
.segmented {
  position: relative;
  display: inline-flex;
  padding: 0.1875rem;
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-full);
}

.segmented::before {
  content: "";
  position: absolute;
  top: 0.1875rem;
  bottom: 0.1875rem;
  left: 0.1875rem;
  /* Both segments are flex: 1 1 0, so each is exactly half the track. */
  width: calc(50% - 0.1875rem);
  background: var(--surface);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}

.segmented[data-sort="asc"]::before {
  transform: translateX(100%);
}

.segment {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  padding: 0.25rem 0.6875rem;
  border: none;
  background: none;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--transition-fast);
}

.segment[aria-pressed="true"] {
  color: var(--text);
  font-weight: 600;
}

.segment:hover[aria-pressed="false"] {
  color: var(--text);
}

.count-badge {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-full);
  padding: 0.1875rem 0.5625rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Stat strip
   ========================================================================== */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: var(--space-md);
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  transition: box-shadow var(--transition), transform var(--transition);
}

.stat-tile:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.875rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-value.is-offline {
  color: var(--text-muted);
}

.stat-value.is-online {
  color: var(--success);
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--text-subtle);
  min-height: 1.125rem;
}

.stat-sub.attention {
  color: var(--warning);
}

/* ==========================================================================
   Alerts
   ========================================================================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem var(--space-md);
  border: 1px solid var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-lg);
}

.alert.inline {
  margin-top: var(--space-md);
  font-size: 0.8125rem;
}

.alert.warning {
  border-color: var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning);
}

.alert.info {
  border-color: var(--info-border);
  background: var(--info-bg);
  color: var(--info);
}

.alert-icon {
  margin-top: 0.125rem;
  flex-shrink: 0;
}

.alert-text {
  flex: 1;
  color: var(--text);
}

.alert-close {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
  padding: 0 0.125rem;
  line-height: 1;
}

.alert-close:hover {
  opacity: 1;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: var(--space-md);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-group label,
.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* Combobox ------------------------------------------------------------- */
.combobox {
  position: relative;
}

.combobox-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  width: 100%;
  padding: 0.5625rem 0.8125rem;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.combobox-trigger:hover:not(:disabled) {
  border-color: var(--text-subtle);
}

.combobox-trigger[aria-expanded="true"] {
  border-color: var(--primary);
  box-shadow: 0 0 0 3.5px rgba(0, 126, 192, 0.18);
}

.combobox-trigger:disabled {
  background: var(--surface-sunken);
  color: var(--text-subtle);
  cursor: not-allowed;
}

.combobox-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.combobox-value.is-placeholder {
  color: var(--text-subtle);
}

.combobox-arrow {
  font-size: 0.6875rem;
  color: var(--text-subtle);
  flex-shrink: 0;
  transition: transform var(--transition);
}

.combobox-trigger[aria-expanded="true"] .combobox-arrow {
  transform: rotate(180deg);
}

/* Aligned directly under the trigger, matching its width. */
.combobox-panel {
  position: absolute;
  top: calc(100% + 0.375rem);
  left: 0;
  right: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transform-origin: top center;
  animation: popover-in 0.22s var(--ease);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .combobox-panel {
    background: var(--surface);
  }
}

@keyframes popover-in {
  from {
    opacity: 0;
    transform: translateY(-0.25rem) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.combobox-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--hairline);
  color: var(--text-subtle);
  font-size: 0.75rem;
}

.combobox-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: none;
  font-size: 0.8125rem;
  color: var(--text);
}

.combobox-input::placeholder {
  color: var(--text-subtle);
}

.combobox-list {
  list-style: none;
  max-height: 15rem;
  overflow-y: auto;
  padding: 0.25rem;
}

.combobox-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4375rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  cursor: pointer;
}

/* The keyboard/hover highlight is a filled accent row, as in a native menu. */
.combobox-option.active {
  background: var(--primary);
  color: #fff;
}

.combobox-option.active.selected {
  color: #fff;
}

.combobox-option.selected {
  color: var(--primary);
  font-weight: 500;
}

.combobox-check {
  font-size: 0.6875rem;
  width: 0.75rem;
  flex-shrink: 0;
  visibility: hidden;
}

.combobox-option.selected .combobox-check {
  visibility: visible;
}

.combobox-option-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.combobox-empty {
  padding: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-subtle);
  text-align: center;
}

.connect-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-subtle);
  flex: 1 1 12rem;
  min-width: 0;
}

/* Inline status line under the connect form: in-flight, pending, resolved. */
.inline-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: var(--space-md);
  padding: 0.625rem 0.8125rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.inline-status.pending {
  border-color: var(--warning-border);
  background: var(--warning-bg);
  color: var(--warning);
}

.inline-status.success {
  border-color: var(--success-border);
  background: var(--success-bg);
  color: var(--success);
}

.inline-status.error {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5625rem 1.125rem;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    color var(--transition-fast), transform var(--transition-fast),
    box-shadow var(--transition-fast), opacity var(--transition-fast);
}

.button:hover:not(:disabled) {
  background: var(--surface-sunken);
}

/* Controls shrink under the pointer instead of changing colour on press. */
.button:active:not(:disabled) {
  transform: scale(0.97);
  box-shadow: none;
}

.button:disabled {
  opacity: 0.4;
  box-shadow: none;
  cursor: not-allowed;
}

.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.button.danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.button.small {
  padding: 0.4375rem 0.875rem;
  font-size: 0.8125rem;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.125rem;
  height: 2.125rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
    transform var(--transition-fast);
}

.icon-button:hover:not(:disabled) {
  background: var(--surface-sunken);
  color: var(--text);
}

.icon-button:active:not(:disabled) {
  transform: scale(0.92);
}

.icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icon-button.subtle {
  border-color: transparent;
  width: 1.75rem;
  height: 1.75rem;
}

.icon-button.spin i {
  animation: spin 0.7s linear infinite;
}

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

/* ==========================================================================
   Empty / loading states
   ========================================================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: var(--space-xl) var(--space-md);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  text-align: center;
}

.empty-state i {
  font-size: 1.25rem;
  color: var(--text-subtle);
  margin-bottom: 0.125rem;
}

.empty-hint {
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.skeleton-card {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.skeleton-line {
  height: 0.625rem;
  border-radius: var(--radius-full);
  background: linear-gradient(
    90deg,
    var(--surface-sunken) 25%,
    #e9edf1 37%,
    var(--surface-sunken) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton-line.w-60 {
  width: 60%;
}
.skeleton-line.w-40 {
  width: 40%;
}
.skeleton-line.w-80 {
  width: 80%;
}

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

/* ==========================================================================
   Node cards
   ========================================================================== */
.nodes-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* State reads from the tint and the matching badge; no heavy accent slab, so
   the card keeps one continuous rounded outline. */
.node-item {
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition), background var(--transition),
    box-shadow var(--transition);
}

.node-item.connected {
  border-color: var(--state-connected-border);
  background: var(--state-connected-tint);
}

.node-item.pending {
  border-color: var(--state-pending-border);
  background: var(--state-pending-tint);
}

.node-item.error {
  border-color: var(--state-problem-border);
  background: var(--state-problem-tint);
}

.node-item.online {
  border-color: var(--state-online-border);
  background: var(--state-online-tint);
}

/* A card whose action is dispatched but not yet confirmed by a poll. */
.node-item.busy {
  border-color: var(--state-pending-border);
  background: var(--state-pending-tint);
}

/* Panels and badges nested inside a tinted card go white so they keep their
   shape against the card's own state colour. */
.node-item .cert-details,
.node-item .node-network-list,
.node-item .node-status,
.node-item .node-busy-chip {
  background: var(--surface);
}

.node-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: 0.75rem;
}

.node-id {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  word-break: break-word;
  min-width: 0;
}

.node-status {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.1875rem 0.5625rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--hairline);
  background: var(--surface-sunken);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.node-status.connected {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success-border);
}

.node-status.pending {
  color: var(--warning);
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.node-status.error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.node-status.online {
  color: var(--info);
  background: var(--info-bg);
  border-color: var(--info-border);
}

/* In-flight action chip, sits under the header until a poll confirms it. */
.node-busy-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
  padding: 0.1875rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning);
}

.node-details {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.node-detail-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  font-size: 0.8125rem;
}

.node-detail-label {
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.node-detail-value {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  word-break: break-all;
}

.node-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--hairline);
}

/* Transport badges ---------------------------------------------------- */
.transport-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: flex-end;
}

.transport-badge {
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 0.1875rem 0.5rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--hairline);
  background: var(--surface-sunken);
  color: var(--text-muted);
  white-space: nowrap;
}

.transport-badge.ipsec {
  color: var(--info);
  background: var(--info-bg);
  border-color: var(--info-border);
}

.transport-badge.mp-iroh {
  color: #5b3fa8;
  background: #f1eefb;
  border-color: #d9d0f2;
}

.transport-badge.none {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.transport-badge.active {
  font-weight: 600;
}

/* Certificate section -------------------------------------------------- */
.cert-info-section {
  margin-top: 0.25rem;
}

.cert-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.cert-security-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3125rem;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.1875rem 0.5625rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--hairline);
  background: var(--surface-sunken);
  color: var(--text-muted);
  cursor: help;
}

.cert-security-badge.bsi {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success-border);
}

.cert-security-badge.standard {
  color: var(--info);
  background: var(--info-bg);
  border-color: var(--info-border);
}

.cert-security-badge.weak {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.cert-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.25rem 0.6875rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
    transform var(--transition-fast);
}

.cert-toggle-btn:hover,
.cert-toggle-btn.active {
  background: var(--surface-sunken);
  color: var(--text);
}

.cert-toggle-btn:active {
  transform: scale(0.95);
}

.cert-details {
  display: none;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: var(--space-sm);
  padding: 0.6875rem 0.8125rem;
  background: var(--surface-muted);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
}

.cert-details.expanded {
  display: flex;
}

.cert-detail-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-sm);
  font-size: 0.8125rem;
}

.cert-detail-label {
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.cert-detail-value {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  word-break: break-all;
}

.cert-detail-value.expired {
  color: var(--danger);
  font-weight: 600;
}

.cert-detail-value.expiring-soon {
  color: var(--warning);
  font-weight: 600;
}

.cert-tooltip {
  position: fixed;
  z-index: 60;
  max-width: 20rem;
  padding: 0.5rem 0.6875rem;
  background: rgba(26, 29, 33, 0.92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #fff;
  font-size: 0.6875rem;
  line-height: 1.45;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition);
  pointer-events: none;
}

.cert-tooltip.visible {
  opacity: 1;
  visibility: visible;
}

/* Collapsible network device list -------------------------------------- */
.node-network-section {
  margin-top: 0.25rem;
}

.node-network-toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  padding: 0.1875rem 0;
}

.node-network-toggle:hover {
  color: var(--text);
}

.node-network-count {
  color: var(--text-subtle);
}

.node-network-arrow {
  margin-left: auto;
  font-size: 0.625rem;
  transition: transform var(--transition);
}

.node-network-section.expanded .node-network-arrow {
  transform: rotate(90deg);
}

.node-network-list {
  display: none;
  flex-direction: column;
  gap: 0.1875rem;
  margin-top: 0.375rem;
  padding: 0.5625rem 0.8125rem;
  background: var(--surface-muted);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
}

.node-network-section.expanded .node-network-list {
  display: flex;
}

.tunnel-detail-multiline {
  white-space: pre-line;
}

.node-uplink-summary {
  font-weight: 600;
  color: var(--success);
}

.node-uplink-summary.offline {
  color: var(--danger);
}

.node-uplink-summary.unknown {
  font-weight: 500;
  color: var(--text-subtle);
}

.node-network-device {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

/* ==========================================================================
   Tunnel cards
   ========================================================================== */
.tunnels-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
  gap: var(--space-md);
  /* Each card keeps its natural height, so expanding one tunnel's details
     does not stretch its neighbours into a column of dead space. */
  align-items: start;
}

.tunnel-card {
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition), background var(--transition);
}

.tunnel-card.tunnel-connected {
  border-color: var(--state-connected-border);
  background: var(--state-connected-tint);
}

.tunnel-card.tunnel-pending {
  border-color: var(--state-pending-border);
  background: var(--state-pending-tint);
}

.tunnel-card.tunnel-problem {
  border-color: var(--state-problem-border);
  background: var(--state-problem-tint);
}

/* Panels and badges nested in a tinted card go white so they keep their shape. */
.tunnel-card .tunnel-endpoints,
.tunnel-card .tunnel-state-badge,
.tunnel-card .tunnel-details-toggle,
.tunnel-card .tunnel-details,
.tunnel-card .transport-badge {
  background: var(--surface);
}

.tunnel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: 0.75rem;
}

.tunnel-header-meta {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

.tunnel-con-id {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.tunnel-state-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.1875rem 0.5625rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--hairline);
  background: var(--surface-sunken);
  color: var(--text-muted);
  white-space: nowrap;
}

.tunnel-state-badge.connected {
  color: var(--success);
  background: var(--success-bg);
  border-color: var(--success-border);
}

.tunnel-state-badge.pending {
  color: var(--warning);
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.tunnel-state-badge.problem {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.tunnel-endpoints {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0.6875rem 0.8125rem;
  background: var(--surface-muted);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
}

.tunnel-endpoint {
  display: flex;
  flex-direction: column;
  gap: 0.0625rem;
  flex: 1;
  min-width: 0;
}

.tunnel-endpoint-role {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.tunnel-endpoint-name {
  font-size: 0.8125rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tunnel-endpoint-id,
.tunnel-endpoint-subnet {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tunnel-arrow {
  color: var(--text-subtle);
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* Collapsible details --------------------------------------------------
   The card is a summary by default: identity, endpoints, state and uptime.
   Everything measured about the tunnel lives one disclosure down. */
.tunnel-details-section {
  margin-top: 0.75rem;
}

.tunnel-details-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

button.tunnel-details-toggle:hover {
  background: var(--surface-sunken);
  color: var(--text);
}

/* No details to show — the strip still carries the uptime, but does nothing. */
.tunnel-details-toggle.is-static {
  cursor: default;
}

.tunnel-details-arrow {
  font-size: 0.625rem;
  color: var(--text-subtle);
  transition: transform var(--transition);
}

.tunnel-details-section.expanded .tunnel-details-arrow {
  transform: rotate(90deg);
}

.tunnel-details-count {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-subtle);
  background: var(--surface-sunken);
  border-radius: var(--radius-full);
  padding: 0.0625rem 0.4375rem;
  font-variant-numeric: tabular-nums;
}

.tunnel-details-uptime {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.tunnel-details-uptime i {
  color: var(--text-subtle);
}

/* 0fr → 1fr on a grid row is the one way to animate to a content-sized
   height without measuring it in JS. */
.tunnel-details-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--transition);
}

.tunnel-details-section.expanded .tunnel-details-wrap {
  grid-template-rows: 1fr;
}

.tunnel-details-clip {
  overflow: hidden;
  min-height: 0;
}

.tunnel-details {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.375rem;
  padding: 0.625rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
}

.tunnel-detail-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

.tunnel-detail-icon {
  width: 0.875rem;
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 0.75rem;
}

.tunnel-detail-label {
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.tunnel-detail-value {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  word-break: break-word;
}

.tunnel-detail-value.security-bsi {
  color: var(--success);
  font-weight: 600;
}

.tunnel-detail-value.security-standard {
  color: var(--info);
}

.tunnel-detail-value.security-weak {
  color: var(--danger);
  font-weight: 600;
}

.tunnel-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--hairline);
}

.tunnel-actions .node-busy-chip {
  margin-bottom: 0;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(16, 24, 40, 0.28);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  backdrop-filter: blur(8px) saturate(140%);
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

/* Without the blur the dim alone is too weak to separate sheet from page. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .modal {
    background: rgba(16, 24, 40, 0.45);
  }
}

.modal.open {
  display: flex;
  animation: backdrop-in 0.28s var(--ease);
}

.modal-content {
  width: 100%;
  max-width: 28rem;
  background: var(--surface);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.34s var(--ease);
}

@keyframes backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Scales up from slightly small, the way a sheet presents. */
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--hairline);
}

.modal-header h3 {
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.modal-body {
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-body strong {
  font-weight: 600;
  word-break: break-word;
}

.modal-details {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--hairline);
  background: var(--surface-muted);
  border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-width: calc(100vw - 2 * var(--space-lg));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  width: 22rem;
  max-width: 100%;
  padding: 0.8125rem var(--space-md);
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  opacity: 1;
  transform: none;
  transition: opacity var(--transition), transform var(--transition);
  animation: toast-in 0.34s var(--ease);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .toast {
    background: var(--surface);
  }
}

/* State is carried by the icon colour alone — no accent slab down the side. */
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(1.25rem) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.toast-icon {
  margin-top: 0.0625rem;
  flex-shrink: 0;
}

.toast.success .toast-icon {
  color: var(--success);
}
.toast.error .toast-icon {
  color: var(--danger);
}
.toast.warning .toast-icon {
  color: var(--mira-persischorange);
}
.toast.info .toast-icon {
  color: var(--primary);
}

.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-size: 0.8125rem;
  font-weight: 600;
}

.toast-message {
  font-size: 0.75rem;
  color: var(--text-muted);
  word-break: break-word;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 0 0.125rem;
  line-height: 1;
}

.toast-close:hover {
  color: var(--text);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 64rem) {
  .page {
    padding: var(--space-md);
  }

  .app-header-inner {
    padding: 0.75rem var(--space-md);
  }
}

@media (max-width: 48rem) {
  .nodes-grid,
  .tunnels-container {
    grid-template-columns: 1fr;
  }

  .last-updated {
    display: none;
  }

  .card-body {
    padding: var(--space-md);
  }

  .toast-container {
    left: var(--space-md);
    right: var(--space-md);
    bottom: var(--space-md);
  }

  .toast {
    width: 100%;
  }
}

@media (max-width: 30rem) {
  .app-header-inner {
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .brand-name {
    font-size: 0.875rem;
  }

  .user-chip {
    max-width: 9rem;
  }

  .stat-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-tile {
    padding: 0.75rem var(--space-md);
  }

  .stat-value {
    font-size: 1.375rem;
  }

  .node-detail-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.125rem;
  }

  .node-detail-value,
  .transport-badges {
    text-align: left;
    justify-content: flex-start;
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer .button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .app-header,
  .toast-container,
  .modal,
  .connect-actions,
  .node-actions,
  .icon-button {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .card,
  .stat-tile {
    break-inside: avoid;
  }
}
