/* =========================================================================
   Component library
   Buttons · Cards · Forms · Tables · Pills · Toasts · Modals · Tabs · Empty
   ========================================================================= */

/* -------------------------------------------------------------------------
   Icons
   ------------------------------------------------------------------------- */
.icon { flex: 0 0 auto; display: block; }
.icon-inline { display: inline-block; vertical-align: -0.15em; }

@keyframes zs-spin { to { transform: rotate(360deg); } }
.is-spinning { animation: zs-spin 900ms linear infinite; transform-origin: 50% 50%; }

/* -------------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------------- */
.btn {
  --btn-bg: var(--color-surface);
  --btn-fg: var(--color-text);
  --btn-border: var(--color-border);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 38px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-snug);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-xs);
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
}
.btn:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-xs); }
.btn:focus-visible { box-shadow: var(--shadow-focus); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none;
}

.btn-primary {
  --btn-bg: var(--color-primary);
  --btn-fg: var(--color-on-primary);
  --btn-border: transparent;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { --btn-bg: var(--color-primary-hover); box-shadow: var(--shadow-md); }

.btn-accent {
  --btn-bg: var(--color-accent);
  --btn-fg: #FFFFFF;
  --btn-border: transparent;
}
.btn-accent:hover { filter: brightness(1.06); }

.btn-danger {
  --btn-bg: var(--color-danger);
  --btn-fg: #FFFFFF;
  --btn-border: transparent;
}
.btn-danger:hover { filter: brightness(1.06); }

.btn-ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  box-shadow: none;
}
.btn-ghost:hover { --btn-bg: var(--color-surface-sunken); box-shadow: none; }

.btn-outline-danger {
  --btn-bg: transparent;
  --btn-fg: var(--color-danger);
  --btn-border: var(--color-danger);
  box-shadow: none;
}
.btn-outline-danger:hover { --btn-bg: var(--color-danger-soft); }

.btn-sm { min-height: 30px; padding: var(--space-1) var(--space-3); font-size: var(--text-sm); }
.btn-lg { min-height: 46px; padding: var(--space-3) var(--space-6); font-size: var(--text-md); }
.btn-block { width: 100%; }
.btn-pill { border-radius: var(--radius-pill); }

.btn-icon {
  min-height: 36px; width: 36px; padding: 0;
  border-radius: var(--radius-md);
}
.btn-icon.btn-sm { min-height: 30px; width: 30px; }

.btn-group { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; }

/* Loading state driven by JS (data-loading) */
.btn[data-loading="true"] { pointer-events: none; opacity: 0.75; }
.btn[data-loading="true"] .btn-label { opacity: 0.6; }

/* -------------------------------------------------------------------------
   Cards
   ------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-hover {
  transition: transform var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out),
              border-color var(--duration-base) var(--ease-out);
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--color-border-strong);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.card-header-stack { flex-direction: column; align-items: flex-start; }
.card-title {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-snug);
}
.card-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: var(--weight-regular);
  margin-top: 2px;
}
.card-body { padding: var(--space-5); }
.card-body-flush { padding: 0; }
.card-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-sunken);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap;
}

.glass-card {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), var(--shadow-inset);
}

/* -------------------------------------------------------------------------
   Stat tiles (KPI row)
   ------------------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-4);
}
.stat {
  position: relative;
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat::after {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--stat-accent, var(--color-primary));
  opacity: 0.9;
}
.stat-accent-blue   { --stat-accent: var(--color-primary); }
.stat-accent-amber  { --stat-accent: var(--color-accent); }
.stat-accent-green  { --stat-accent: var(--color-success); }
.stat-accent-red    { --stat-accent: var(--color-danger); }
.stat-accent-slate  { --stat-accent: var(--color-neutral); }

.stat-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2); margin-bottom: var(--space-2);
}
.stat-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--color-text-muted);
}
.stat-icon {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-soft);
  color: var(--stat-accent, var(--color-primary));
}
.stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-meta {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  display: flex; align-items: center; gap: var(--space-1);
}
.stat-delta { font-weight: var(--weight-medium); }
.stat-delta-up { color: var(--color-success); }
.stat-delta-down { color: var(--color-danger); }

/* -------------------------------------------------------------------------
   Pills / badges
   ------------------------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.5;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: 0 0 auto;
}
.pill-positive { color: var(--color-success); background: var(--color-success-soft);
                 border-color: color-mix(in srgb, var(--color-success) 26%, transparent); }
.pill-warning  { color: var(--color-warning); background: var(--color-warning-soft);
                 border-color: color-mix(in srgb, var(--color-warning) 26%, transparent); }
.pill-danger   { color: var(--color-danger);  background: var(--color-danger-soft);
                 border-color: color-mix(in srgb, var(--color-danger) 26%, transparent); }
.pill-info     { color: var(--color-info);    background: var(--color-info-soft);
                 border-color: color-mix(in srgb, var(--color-info) 26%, transparent); }
.pill-neutral  { color: var(--color-neutral); background: var(--color-neutral-soft);
                 border-color: color-mix(in srgb, var(--color-neutral) 26%, transparent); }

.pill-lg { padding: 5px var(--space-3); font-size: var(--text-sm); }

.badge-count {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--color-danger); color: #fff;
  font-size: var(--text-2xs); font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.tag {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
}

/* -------------------------------------------------------------------------
   Forms
   ------------------------------------------------------------------------- */
.field { margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}
.field-label .req { color: var(--color-danger); margin-left: 2px; }

.field-input {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: var(--text-base);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out);
}
.field-input::placeholder { color: var(--color-text-subtle); }
.field-input:hover:not(:disabled) { border-color: var(--color-text-subtle); }
.field-input:focus {
  border-color: var(--color-ring);
  box-shadow: var(--shadow-focus);
  outline: none;
}
.field-input:disabled {
  background: var(--color-surface-sunken);
  color: var(--color-text-subtle);
  cursor: not-allowed;
}
textarea.field-input { min-height: 96px; resize: vertical; line-height: var(--leading-normal); }
.field-code { font-family: var(--font-mono); font-size: var(--text-sm); }

select.field-input {
  appearance: none;
  padding-right: var(--space-8);
  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='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  cursor: pointer;
}

.field-hint {
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  line-height: var(--leading-snug);
}
.field-error {
  display: flex; align-items: flex-start; gap: var(--space-1);
  margin-top: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-danger);
  font-weight: var(--weight-medium);
}
.field-has-error .field-input { border-color: var(--color-danger); }
.field-has-error .field-input:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-danger) 26%, transparent);
}

/* Checkbox / radio */
.field-check, .field-radio {
  appearance: none;
  flex: 0 0 auto;
  width: 18px; height: 18px;
  margin: 0;
  border: 1.5px solid var(--color-border-strong);
  background: var(--color-surface);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}
.field-check { border-radius: 5px; }
.field-radio { border-radius: 50%; }

.field-check:checked, .field-radio:checked {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}
.field-check:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  background-size: 12px; background-position: center; background-repeat: no-repeat;
}
.field-radio:checked {
  box-shadow: inset 0 0 0 3.5px var(--color-surface);
}
.field-check:focus-visible, .field-radio:focus-visible { box-shadow: var(--shadow-focus); }
.field-check:disabled, .field-radio:disabled { opacity: 0.5; cursor: not-allowed; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out);
}
.check-row:hover { border-color: var(--color-border-strong); background: var(--color-surface-sunken); }
.check-row:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}
.check-row-text { min-width: 0; }
.check-row-title { font-size: var(--text-base); font-weight: var(--weight-medium); }
.check-row-desc {
  font-size: var(--text-xs); color: var(--color-text-muted);
  margin-top: 2px; line-height: var(--leading-snug);
}

/* Switch */
.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  width: 40px; height: 22px;
  border-radius: var(--radius-pill);
  background: var(--color-border-strong);
  transition: background-color var(--duration-base) var(--ease-out);
  flex: 0 0 auto;
}
.switch-track::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-base) var(--ease-spring);
}
.switch input:checked + .switch-track { background: var(--color-primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--shadow-focus); }

/* File input */
.field-file {
  display: block; width: 100%;
  padding: var(--space-3);
  border: 1.5px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-sunken);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out),
              background-color var(--duration-fast) var(--ease-out);
}
.field-file:hover { border-color: var(--color-primary); background: var(--color-primary-soft); }
.field-file::file-selector-button {
  margin-right: var(--space-3);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.input-group { display: flex; gap: var(--space-2); align-items: stretch; }
.input-group .field-input { flex: 1 1 auto; }

.form-grid { display: grid; gap: var(--space-4); }
.form-grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

fieldset { border: 0; padding: 0; margin: 0; }
.fieldset-legend {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}

/* -------------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table { width: 100%; font-size: var(--text-sm); }
.table th, .table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--color-border);
}
.table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--color-surface-sunken);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--color-text-muted);
  white-space: nowrap;
}
.table tbody tr { transition: background-color var(--duration-fast) var(--ease-out); }
.table tbody tr:hover { background: var(--color-surface-sunken); }
.table tbody tr:last-child td { border-bottom: 0; }
.table-num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table-compact th, .table-compact td { padding: var(--space-2) var(--space-3); }
.table-fixed { table-layout: fixed; }
.cell-truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* -------------------------------------------------------------------------
   Tabs
   ------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  background: none; border-top: 0; border-left: 0; border-right: 0;
  transition: color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out);
}
.tab:hover { color: var(--color-text); }
.tab.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  gap: 2px;
}
.segmented a, .segmented button {
  padding: var(--space-1) var(--space-3);
  border: 0; background: transparent;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
.segmented a:hover, .segmented button:hover { color: var(--color-text); }
.segmented .is-active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-xs);
}

/* -------------------------------------------------------------------------
   Alerts / banners
   ------------------------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}
.alert-icon { flex: 0 0 auto; margin-top: 1px; }
.alert-body { min-width: 0; flex: 1 1 auto; }
.alert-title { font-weight: var(--weight-semibold); margin-bottom: 2px; }
.alert-success { background: var(--color-success-soft); color: var(--color-success);
                 border-color: color-mix(in srgb, var(--color-success) 28%, transparent); }
.alert-warning { background: var(--color-warning-soft); color: var(--color-warning);
                 border-color: color-mix(in srgb, var(--color-warning) 28%, transparent); }
.alert-danger  { background: var(--color-danger-soft);  color: var(--color-danger);
                 border-color: color-mix(in srgb, var(--color-danger) 28%, transparent); }
.alert-info    { background: var(--color-info-soft);    color: var(--color-info);
                 border-color: color-mix(in srgb, var(--color-info) 28%, transparent); }

/* -------------------------------------------------------------------------
   Toasts
   ------------------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  top: calc(var(--topbar-height) + var(--space-3));
  right: var(--space-5);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--space-2);
  width: min(380px, calc(100vw - var(--space-8)));
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--toast-accent, var(--color-info));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--duration-base) var(--ease-out);
}
.toast.is-leaving { animation: toast-out var(--duration-fast) var(--ease-in-out) forwards; }
.toast-success { --toast-accent: var(--color-success); }
.toast-warning { --toast-accent: var(--color-warning); }
.toast-error   { --toast-accent: var(--color-danger); }
.toast-info    { --toast-accent: var(--color-info); }
.toast-icon { color: var(--toast-accent); flex: 0 0 auto; margin-top: 1px; }
.toast-text { flex: 1 1 auto; min-width: 0; font-size: var(--text-sm); line-height: var(--leading-snug); }
.toast-close {
  flex: 0 0 auto; border: 0; background: none; cursor: pointer;
  color: var(--color-text-subtle); padding: 2px; border-radius: var(--radius-xs);
}
.toast-close:hover { color: var(--color-text); background: var(--color-surface-sunken); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px) scale(0.97); }
}

/* -------------------------------------------------------------------------
   Modals / dialogs
   ------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  z-index: var(--z-modal);
  display: grid; place-items: center;
  padding: var(--space-4);
  background: var(--color-overlay);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in var(--duration-fast) var(--ease-out);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(520px, 100%);
  max-height: calc(100vh - var(--space-12));
  display: flex; flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  animation: modal-in var(--duration-base) var(--ease-out);
}
.modal-lg { width: min(760px, 100%); }
.modal-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-3);
}
.modal-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.modal-desc { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: var(--space-1); }
.modal-body { padding: 0 var(--space-5) var(--space-4); overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-sunken);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* -------------------------------------------------------------------------
   Dropdowns / popovers
   ------------------------------------------------------------------------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: var(--z-dropdown);
  min-width: 220px;
  padding: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: dropdown-in var(--duration-fast) var(--ease-out);
}
.dropdown-menu[hidden] { display: none; }
.dropdown-menu-wide { min-width: 340px; }
.dropdown-item {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0; background: none;
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out);
}
.dropdown-item:hover { background: var(--color-surface-sunken); color: var(--color-text); }
.dropdown-item-danger { color: var(--color-danger); }
.dropdown-item-danger:hover { background: var(--color-danger-soft); color: var(--color-danger); }
.dropdown-divider { height: 1px; margin: var(--space-2) 0; background: var(--color-border); }
.dropdown-header {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--color-text-subtle);
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* -------------------------------------------------------------------------
   Empty states / loaders / progress
   ------------------------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  padding: var(--space-12) var(--space-6);
  gap: var(--space-3);
}
.empty-icon {
  display: grid; place-items: center;
  width: 56px; height: 56px;
  border-radius: var(--radius-xl);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  margin-bottom: var(--space-1);
}
.empty-title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.empty-text {
  font-size: var(--text-sm); color: var(--color-text-muted);
  max-width: 42ch; line-height: var(--leading-relaxed);
}

.progress {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunken);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--color-primary);
  transition: width var(--duration-slow) var(--ease-out);
}
.progress-bar-success { background: var(--color-success); }
.progress-bar-warning { background: var(--color-warning); }
.progress-bar-danger { background: var(--color-danger); }
.progress-indeterminate .progress-bar {
  width: 35% !important;
  animation: progress-slide 1.3s var(--ease-in-out) infinite;
}
@keyframes progress-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg,
    var(--color-surface-sunken) 25%,
    var(--color-border) 37%,
    var(--color-surface-sunken) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: zs-spin 700ms linear infinite;
}

/* -------------------------------------------------------------------------
   Pagination
   ------------------------------------------------------------------------- */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
}
.pagination-info { font-size: var(--text-xs); color: var(--color-text-muted); }
.pagination-links { display: flex; gap: var(--space-1); align-items: center; }
.page-link {
  display: grid; place-items: center;
  min-width: 32px; height: 32px; padding: 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  transition: all var(--duration-fast) var(--ease-out);
}
.page-link:hover { border-color: var(--color-primary); color: var(--color-primary); }
.page-link.is-active {
  background: var(--color-primary); border-color: var(--color-primary);
  color: var(--color-on-primary); font-weight: var(--weight-medium);
}
.page-link.is-disabled { opacity: 0.4; pointer-events: none; }

/* -------------------------------------------------------------------------
   Misc
   ------------------------------------------------------------------------- */
.avatar {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
  flex: 0 0 auto;
}
.avatar-lg { width: 44px; height: 44px; font-size: var(--text-base); }

.divider-label {
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--color-text-subtle); font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: var(--tracking-caps);
  margin: var(--space-5) 0;
}
.divider-label::before, .divider-label::after {
  content: ""; flex: 1 1 auto; height: 1px; background: var(--color-border);
}

.code-block {
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-relaxed);
  overflow-x: auto;
  white-space: pre;
  color: var(--color-text-muted);
}

.copy-field {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}
.copy-field code { flex: 1 1 auto; overflow-x: auto; white-space: nowrap; }

.chart-box { position: relative; width: 100%; }
.chart-box canvas { max-width: 100%; }

.tooltip-host { position: relative; }
.tooltip-host[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  background: var(--color-text);
  color: var(--color-surface);
  border-radius: var(--radius-xs);
  font-size: var(--text-2xs);
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-dropdown);
  box-shadow: var(--shadow-md);
}

/* ---------------------------------------------------------------------------
   OAuth callback tab
   The consent flow ends in a tab of its own with no nav and nothing to do but
   read one line and close it, so it gets a centred card instead of the shell.
   --------------------------------------------------------------------------- */
.callback-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  background: var(--color-surface-sunken);
}

.callback-card {
  width: 100%;
  max-width: 30rem;
  text-align: center;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8, 2rem) var(--space-6);
  box-shadow: var(--shadow-md, 0 6px 24px rgb(0 0 0 / 8%));
}

.callback-icon {
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto var(--space-4, 1rem);
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.callback-icon.is-ok  { background: var(--color-success-soft); color: var(--color-success); }
.callback-icon.is-bad { background: var(--color-danger-soft);  color: var(--color-danger); }

.callback-title {
  font-size: var(--text-xl, 1.25rem);
  font-weight: 600;
  line-height: 1.35;
  margin: 0 0 var(--space-2);
  color: var(--color-text);
}

.callback-text {
  font-size: var(--text-sm, 0.875rem);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-6);
}

.callback-hint {
  font-size: var(--text-xs, 0.8125rem);
  color: var(--color-text-muted);
  margin: var(--space-3, 0.75rem) 0 0;
}
