.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.card-head.flush { border-bottom: 0; padding-bottom: 0; }
.card-title { display: grid; gap: 0.15rem; min-width: 0; }
.card-title strong { font-size: 0.96rem; letter-spacing: -0.01em; }
.card-title span { font-size: 0.79rem; color: var(--text-muted); }
.card-body { padding: 1rem 1.1rem; }
.card-body.tight { padding: 0.7rem 1.1rem; }
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1.1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.82rem;
}
.card-actions { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.section-title { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.65rem; }
.section-title h2, .section-title h3 { margin: 0; }
.section-title .muted { font-size: 0.8rem; }

/* KPI */
.stat-card {
  position: relative;
  display: grid;
  gap: 0.35rem;
  padding: 1rem 1.05rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  color: inherit;
}
a.stat-card:hover { text-decoration: none; border-color: var(--border-strong); transform: translateY(-1px); }
.stat-card::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--stat-accent, var(--primary));
  opacity: 0.85;
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.stat-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--stat-soft, var(--primary-soft));
  color: var(--stat-accent, var(--primary));
}
.stat-label { font-size: 0.78rem; font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.75rem; font-weight: 720; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-meta { display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; color: var(--text-muted); flex-wrap: wrap; }
.stat-meta .pill { font-size: 0.68rem; padding: 0.1rem 0.42rem; }
.stat-trend { display: inline-flex; align-items: center; gap: 0.2rem; font-weight: 650; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }
.stat-success { --stat-accent: var(--success); --stat-soft: var(--success-soft); }
.stat-warning { --stat-accent: var(--warning); --stat-soft: var(--warning-soft); }
.stat-danger { --stat-accent: var(--danger); --stat-soft: var(--danger-soft); }
.stat-info { --stat-accent: var(--info); --stat-soft: var(--info-soft); }

/* Badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.01em;
  background: var(--neutral-soft);
  color: var(--text-muted);
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-warning { background: var(--warning-soft); color: var(--warning); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-primary { background: var(--primary-soft); color: var(--primary); }
.pill-neutral { background: var(--neutral-soft); color: var(--text-muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: none; }
.dot.online { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 18%, transparent); }
.dot.offline { background: var(--text-faint); }
.pill .dot { width: 6px; height: 6px; }
.pill.online-badge .dot.online { box-shadow: 0 0 0 2px color-mix(in srgb, var(--success) 18%, transparent); }

/* Toolbar / filters */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.filter-bar select, .filter-bar input {
  width: auto;
  min-width: 140px;
  min-height: 38px;
  padding: 0.35rem 0.6rem;
  font-size: 0.84rem;
  background: var(--bg-surface);
}
.filter-bar .search-input { min-width: 220px; }
.filter-bar .search-wrap { position: relative; min-width: 220px; flex: 1 1 220px; max-width: 380px; }
.filter-bar .search-wrap .icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
.filter-bar .search-wrap input { width: 100%; padding-left: 2.15rem; min-width: 0; }
.filter-chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
}
.chip.active { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, transparent); color: var(--primary); }

/* Tabs */
.tabs {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 0.38rem 0.7rem;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 620;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--bg-surface); color: var(--text); box-shadow: var(--shadow-1); }
.tab .count { font-size: 0.7rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* Table */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  min-width: 720px;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 0.6rem 0.85rem;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 720;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}
.data-table td {
  padding: 0.68rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table .cell-main { display: grid; gap: 0.12rem; min-width: 0; }
.data-table .cell-main strong { font-weight: 620; }
.data-table .cell-main span { font-size: 0.76rem; color: var(--text-muted); }
.data-table td.cell-wrap {
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}
.data-table td.cell-wrap summary {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.data-table td.cell-wrap pre { max-width: 100%; }
.data-table td.cell-details { vertical-align: top; min-width: 96px; }
.data-table tbody tr.report-row { cursor: pointer; }
.report-details summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
}
.report-details .meta-grid {
  margin-top: 0.5rem;
  min-width: 260px;
  max-width: 520px;
}
.report-details .meta-item { min-width: 0; }
.report-details .meta-item .value {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.report-details pre {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.data-table .cell-actions { text-align: right; white-space: nowrap; }
.data-table .cell-actions .btn + .btn { margin-left: 0.25rem; }
.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.sort-btn:hover { color: var(--text); }
.sort-btn .icon { width: 13px; height: 13px; opacity: 0.6; }
.sort-btn.active { color: var(--primary); }
.sort-btn.active .icon { opacity: 1; }
.sort-indicator { opacity: 0.3; }
.sort-btn.active .sort-indicator { opacity: 1; }
.row-check { width: 36px; }
.row-check input { min-height: 0; }
.table-empty { padding: 2.5rem 1rem; text-align: center; color: var(--text-muted); display: grid; gap: 0.5rem; justify-items: center; }
.table-empty .icon { width: 30px; height: 30px; color: var(--text-faint); }
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.7rem 1.1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}
.pager-group { display: flex; align-items: center; gap: 0.3rem; }
.pager-btn {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.pager-btn:hover:not([disabled]) { border-color: var(--border-strong); color: var(--text); }
.pager-btn.active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.pager-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.pager select { width: auto; min-height: 32px; padding: 0.2rem 0.4rem; font-size: 0.78rem; }

/* Lists */
.list { display: grid; }
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--bg-hover); }
.list-main { display: grid; gap: 0.18rem; min-width: 0; }
.list-main strong { font-size: 0.9rem; font-weight: 620; }
.list-main span { font-size: 0.78rem; color: var(--text-muted); }
.list-main-wrap { flex: 1 1 auto; }
.list-main-wrap strong,
.list-main-wrap span {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.list-actions { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.queue-item { display: grid; gap: 0.35rem; padding: 0.8rem 1.1rem; border-bottom: 1px solid var(--border); }
.queue-item:last-child { border-bottom: 0; }
.queue-top { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; }
.queue-meta { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; color: var(--text-muted); font-size: 0.78rem; }

/* Meta / detail */
.meta-grid { display: grid; gap: 0.85rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.meta-item { display: grid; gap: 0.12rem; }
.meta-item .label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); }
.meta-item .value { font-size: 0.9rem; font-weight: 600; word-break: break-word; }
.ip-cell { display: inline-flex; align-items: center; gap: 0.4rem; min-width: 0; max-width: 100%; }
.ip-flag { flex: none; width: 1.15rem; height: 0.86rem; border-radius: 2px; box-shadow: 0 0 0 1px var(--border); }
.ip-text { min-width: 0; overflow-wrap: anywhere; }
.ip-note {
  flex: none; padding: 0.05rem 0.3rem; border-radius: 999px;
  background: var(--bg-subtle); color: var(--text-muted);
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.04em;
}
.detail-grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr); }
@media (max-width: 880px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; gap: 0.45rem; }
.kv-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding-bottom: 0.45rem; border-bottom: 1px dashed var(--border); font-size: 0.86rem; }
.kv-row:last-child { border-bottom: 0; }
.kv-row dt { color: var(--text-muted); }
.kv-row dd { margin: 0; font-weight: 600; text-align: right; }

/* Timeline */
.timeline { display: grid; gap: 0; position: relative; padding-left: 1.1rem; }
.timeline::before { content: ""; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding: 0 0 1rem 0.75rem; font-size: 0.86rem; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: -1.1rem;
  top: 0.35rem;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 3px var(--bg-surface);
}
.timeline-item .when { color: var(--text-muted); font-size: 0.76rem; }
.timeline-item .what { font-weight: 600; }

/* Progress */
.progress { height: 6px; border-radius: 999px; background: var(--bg-subtle); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.progress.warning > span { background: var(--warning); }
.progress.danger > span { background: var(--danger); }

/* Notices */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  font-size: 0.86rem;
  color: var(--text-muted);
}
.notice .icon { margin-top: 0.1rem; color: var(--info); }
.notice-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 25%, transparent); color: var(--success); }
.notice-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 25%, transparent); color: var(--warning); }
.notice-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 25%, transparent); color: var(--danger); }
.notice-success .icon, .notice-warning .icon, .notice-danger .icon { color: currentColor; }
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--warning) 28%, transparent);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 0.85rem;
}

/* Toast */
.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 100;
  display: grid;
  gap: 0.5rem;
  width: min(380px, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  font-size: 0.86rem;
  pointer-events: auto;
  animation: toast-in 180ms ease;
}
.toast .icon { color: var(--info); margin-top: 0.1rem; }
.toast.success .icon { color: var(--success); }
.toast.error .icon { color: var(--danger); }
.toast-close { margin-left: auto; border: 0; background: transparent; color: var(--text-faint); cursor: pointer; padding: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Dialog */
dialog.dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: min(86vh, 900px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
dialog.dialog.dialog-lg { width: min(860px, calc(100vw - 2rem)); }
dialog.dialog.dialog-sm { width: min(420px, calc(100vw - 2rem)); }
dialog.dialog::backdrop { background: rgba(5, 10, 22, 0.58); backdrop-filter: blur(2px); }
dialog.dialog > form, dialog.dialog > .dialog-inner { display: flex; flex-direction: column; max-height: inherit; }
.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.dialog-head h2 { font-size: 1.02rem; }
.dialog-head p { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.1rem; }
.dialog-body { padding: 1.1rem; overflow-y: auto; display: grid; gap: 0.9rem; }
.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.8rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}
.dialog-close { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; padding: 0.2rem; border-radius: 6px; }
.dialog-close:hover { background: var(--bg-hover); color: var(--text); }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 0.55rem; cursor: pointer; font-size: 0.86rem; font-weight: 600; color: var(--text); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background 140ms ease;
  flex: none;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 140ms ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid color-mix(in srgb, var(--focus) 65%, transparent); outline-offset: 2px; }

/* Empty / loading */
.empty { display: grid; justify-items: center; gap: 0.5rem; padding: 2rem 1rem; text-align: center; color: var(--text-muted); }
.empty .icon { width: 30px; height: 30px; color: var(--text-faint); }
.empty strong { color: var(--text); font-size: 0.92rem; }
.loading-inline { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--text-muted); font-size: 0.85rem; }
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--bg-hover) 37%, var(--bg-subtle) 63%); background-size: 400% 100%; animation: shimmer 1.2s ease infinite; border-radius: 6px; }
.skeleton-line { height: 12px; margin: 0.35rem 0; }
.skeleton-card { height: 110px; border-radius: var(--radius-lg); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Misc */
.code-row { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.token-value { font-family: var(--font-mono); font-size: 0.82rem; word-break: break-all; }
.source { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.76rem; color: var(--text-muted); }
.tag { display: inline-flex; align-items: center; padding: 0.1rem 0.4rem; border-radius: 5px; background: var(--bg-subtle); color: var(--text-muted); font-size: 0.72rem; font-weight: 600; }
.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.55rem 1.1rem;
  background: var(--primary-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
  font-size: 0.84rem;
  color: var(--primary);
}
.quick-grid { display: grid; gap: 0.7rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.quick-tile {
  display: grid;
  gap: 0.35rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: inherit;
}
.quick-tile:hover { text-decoration: none; border-color: var(--primary); background: var(--primary-soft); }
.quick-tile .icon { color: var(--primary); }
.quick-tile strong { font-size: 0.86rem; }
.quick-tile span { font-size: 0.76rem; color: var(--text-muted); }
.help-list { display: grid; gap: 0.5rem; color: var(--text-muted); font-size: 0.86rem; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.divider { height: 1px; background: var(--border); margin: 0.4rem 0; }

/* Custom modal (avoids native <dialog> focus quirks) */
body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(5, 10, 22, 0.6);
  backdrop-filter: blur(3px);
}
.modal {
  width: min(560px, calc(100vw - 2rem));
  max-height: min(86vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-2);
}
.modal.dialog-lg { width: min(880px, calc(100vw - 2rem)); }
.modal.dialog-sm { width: min(430px, calc(100vw - 2rem)); }
.modal .dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  min-height: 0;
}
.modal .dialog-body { overflow-y: auto; min-height: 0; }
