/* Plain black palette lives in tokens.css (shared file) � this :root
   only maps legacy local names onto the shared tokens. */

:root {
  --surface: var(--panel);
  --surface-2: var(--card);
  --text-muted: var(--muted);
  --border: var(--line);
  --brand: var(--accent);
  --brand-dark: var(--accent-deep);
  --success: var(--ok);
  --warning: var(--warn);
  --radius: var(--rc);
  --act: 28px;
}

* {
  box-sizing: border-box;
}

/* Spec scrollbar on every scroll region: 10px lane, 4px rounded thumb,
   transparent track, text-tinted. Touch keeps native bars. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--sb-thumb) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--sb-thumb);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--sb-thumb-h);
  border-width: 2px;
  background-clip: padding-box;
}
::-webkit-scrollbar-corner,
::-webkit-scrollbar-button { background: transparent; display: none; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
}

/* -- App shell (structure spec): root grid, three bordered panels.
   Sidebar clamp(220px,17vw,300px) spans both rows; topbar is 60px;
   only the main panel's content scrolls. Page itself never scrolls. */
.shell {
  display: grid;
  grid-template-columns: clamp(220px, 17vw, 300px) minmax(0, 1fr);
  grid-template-rows: 60px minmax(0, 1fr);
  grid-template-areas: 'side top' 'side main';
  gap: 12px;
  padding: 12px;
  height: 100dvh;
}

.sidebar,
.app-header,
.content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--rp);
}

.app-header {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  min-width: 0;
}

.header-actions {
  margin-left: auto;
}

.logo {
  height: 2rem;
  width: auto;
}

.auth {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 0.75rem 1.25rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
  border-bottom: 2px solid transparent;
}

.tab[aria-selected="true"] {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.panel[hidden] {
  display: none;
}

.panel.is-active {
  display: block;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table th,
.data-table td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.data-table th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 2;
}

/* one line + ellipsis; stampCellLabels sets title=full value */
.data-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}
.data-table td.log-msg,
.data-table td .log-msg {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  max-width: none;
}

.data-table tbody tr:hover {
  background: var(--hover-bg);
}

.button {
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--rk);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.button:hover {
  border-color: var(--text-muted);
}

.button.primary {
  background: var(--accent-btn);
  border: none;
  color: var(--accent-ink);
}

.button.primary:hover {
  filter: brightness(1.08);
  border-color: var(--brand);
}

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

.button + .button {
  margin-left: 0.5rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="url"],
select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--rk);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.button:focus-visible,
.icon-btn:focus-visible,
.side-item:focus-visible,
.crumb-back:focus-visible,
.notif-item:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
  backdrop-filter: blur(6px);
  z-index: 50;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(90vw, 30rem);
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  border-radius: var(--rp);
  box-shadow: var(--shadow);
}

.modal-card.is-wide {
  width: min(95vw, 60rem);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.125rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 1rem;
  display: grid;
  gap: 0.75rem;
}

.toast-stack {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 320px;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--brand);
  pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: none; }
}

.toast.is-out {
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.18s ease-in, transform 0.18s ease-in;
}

.toast-icon {
  flex-shrink: 0;
  margin-top: 1px;
}
.toast-icon svg { width: 16px; height: 16px; display: block; }
.toast-msg {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  line-height: 1.4;
}
.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  cursor: pointer;
}
.toast-close svg { width: 14px; height: 14px; display: block; }
.toast-close:hover { color: var(--text); }

.toast-info { border-left-color: var(--brand); }
.toast-info .toast-icon { color: var(--brand); }
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-error { border-left-color: var(--danger); }
.toast-error .toast-icon { color: var(--danger); }

.section-title {
  font-size: 14px;
  font-weight: 600;
  margin: 18px 0 8px;
}
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 8px;
}
.health-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--rk);
  font-size: 13px;
}
.health-row.is-bad {
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
.health-row code {
  font-size: 12px;
  word-break: break-all;
}
.log-view {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  border-radius: var(--rk);
  padding: 12px;
  font-size: 11px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.log-table td {
  vertical-align: top;
}
.log-table td:nth-child(-n + 4) {
  white-space: nowrap;
}
.log-msg {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.logo-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

/* ── Sidebar shell layout (new menu style) ───────────────────*/
/* -- Sidebar (spec �2): brand row, captions, 40px items, accent bar -- */
.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  min-height: 0;
  overflow: hidden;
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 12px 14px;
}
.side-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.side-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 8px;
}
.side-footer .auth-user {
  display: block;
  padding: 0 11px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-footer .side-item {
  margin-bottom: 0;
}
.side-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 14px 12px 6px;
}
.side-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: var(--rk);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 2px;
  text-align: left;
  font-family: inherit;
  position: relative;
}
.side-item:hover {
  background: var(--hover-bg);
  color: var(--text);
}
.side-item.is-active {
  background: var(--active-bg);
  color: var(--active-text);
  font-weight: 600;
}
.side-item.is-active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.side-icon {
  width: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.side-icon svg {
  width: 17px;
  height: 17px;
}

/* -- Main panel: only its content scrolls; header/footer pinned -- */
.content {
  grid-area: main;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.content .panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 20px 24px;
}
.content .panel[hidden] {
  display: none;
}
.panel-header {
  flex-shrink: 0;
}
.table-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
}
.panel-footer {
  flex-shrink: 0;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.modal-body .label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 14px 0 6px;
}
.modal-body .label:first-child {
  margin-top: 0;
}
#log-detail-status {
  margin: 0 0 4px;
  font-weight: 600;
}

.key-created-warning {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: var(--rk);
  padding: 10px 12px;
}
.key-created-row {
  display: flex;
  gap: 8px;
}
.key-created-row input {
  flex: 1;
  font-family: monospace;
  font-size: 13px;
}

/* ── Icon action buttons ─────────────────────────────────────*/
.row-actions {
  white-space: nowrap;
}
.icon-btn {
  width: var(--act);
  height: var(--act);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--rk);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  margin-right: 4px;
  vertical-align: middle;
}
.icon-btn:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--hover-bg);
}
.icon-btn.danger {
  color: var(--danger);
}
.icon-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
.icon-btn.ok {
  color: var(--success);
}
.icon-btn.ok:hover {
  color: var(--success);
  border-color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent);
}
.icon-btn svg {
  width: 15px;
  height: 15px;
}
.icon-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ── Job detail breadcrumb + info ────────────────────────────*/
.crumb {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.crumb-back {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--brand);
  cursor: pointer;
}
.crumb-back:hover {
  text-decoration: underline;
}
.crumb-sep {
  color: var(--text-muted);
}
.panel-actions {
  display: flex;
  gap: 8px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0;
  margin: 0 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.detail-grid dt {
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.detail-grid dd {
  margin: 0;
  padding: 9px 14px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}
.detail-grid dt:last-of-type,
.detail-grid dd:last-of-type {
  border-bottom: none;
}

/* ── Login screen ────────────────────────────────────────────*/
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
#login-screen[hidden] {
  display: none;
}
.login-card {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rc);
  padding: 32px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.login-card .logo {
  height: 36px;
  width: auto;
  align-self: center;
  margin-bottom: 20px;
}
.login-card h1 {
  margin: 0;
  font-size: 20px;
  text-align: center;
}
.login-sub {
  margin: 4px 0 20px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}
.login-card label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}
.login-card input {
  margin-bottom: 14px;
}
.login-error {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--danger);
}
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  font-size: 12px;
  color: var(--text-muted);
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border);
}
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-left: 0;
}
.google-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}
.auth-user {
  font-size: 13px;
  color: var(--text-muted);
}
.auth {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Step forms + filters ────────────────────────────────────*/
.step-form {
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.step-form label:not(.checkbox-label) {
  font-size: 13px;
  font-weight: 600;
  margin-top: 10px;
}
.step-form fieldset {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.step-form fieldset legend {
  font-size: 13px;
  font-weight: 600;
  padding: 0 4px;
}
.form-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.panel-actions.filters {
  align-items: center;
}
.panel-actions.filters select,
.panel-actions.filters input {
  font-size: 13px;
  padding: 6px 10px;
}
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}
.chip-active {
  background: var(--active-bg);
  border-color: var(--accent-deep);
  color: var(--text);
}
.chip-clear {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}
.log-detail-status {
  margin: 0 0 4px;
  font-weight: 600;
}

/* ── Settings ────────────────────────────────────────────────*/
.settings-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.settings-row input {
  flex: 1;
}
.settings-hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ── Sidebar group + meters ──────────────────────────────────*/
.side-caret {
  width: 14px;
  height: 14px;
  margin-left: auto;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}
.side-item.is-open .side-caret {
  transform: rotate(180deg);
}
.side-sub {
  padding-left: 22px;
}
.side-subitem {
  font-size: 13px;
  padding: 8px 11px;
}
.meter {
  margin-bottom: 18px;
  max-width: 640px;
}
.meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}
.meter-label {
  font-weight: 600;
  font-size: 13.5px;
}
.meter-value {
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: right;
}
.meter-track {
  height: 8px;
  border-radius: 999px;
  background: var(--hover-bg);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
}
.meter-ok {
  background: var(--ok);
}
.meter-warn {
  background: var(--warn);
}
.meter-bad {
  background: var(--danger);
}

/* Migrator section */
.mig-table-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 2px 14px;
  margin-bottom: 12px;
  font-size: 13px;
}
.mig-table-picker label {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.mig-table-count {
  color: var(--text-muted);
  font-size: 12px;
}
.mig-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex-shrink: 0;
}
.mig-dot-ok { background: var(--success); }
.mig-dot-warn { background: var(--warning); }
.mig-dot-muted { background: var(--text-muted); }
.mig-mapping-editor {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  resize: vertical;
}
.log-msg {
  word-break: break-word;
  white-space: normal;
}
.acc-head {
  cursor: pointer;
  user-select: none;
}
.acc-head td {
  background: var(--hover-bg);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
}
.acc-caret {
  display: inline-block;
  transition: transform 0.15s;
}
.acc-head.open .acc-caret {
  transform: rotate(90deg);
}
.acc-body.hidden {
  display: none;
}
.section-gap {
  margin: 20px 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.stat-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Slim app footer (spec E) — one line at the end of the content panel */
.app-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 24px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.app-footer .af-brand { font-weight: 600; }
.app-footer .af-ver { font-weight: 400; margin-left: 6px; }
.app-footer .af-status { display: inline-flex; align-items: center; gap: 7px; }
.app-footer .af-links { margin-left: auto; display: inline-flex; gap: 16px; }
.app-footer a { color: var(--text-muted); text-decoration: none; }
.app-footer a:hover { color: var(--text); }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.ok { background: var(--ok); }

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}
.stat-ok .stat-value { color: var(--ok); }
.stat-warn .stat-value { color: var(--warning); }
.stat-bad .stat-value { color: var(--danger); }
.text-warn {
  color: var(--warning);
}
#mig-run-live {
  margin-top: 16px;
}

/* ── Status badges ───────────────────────────────────────────*/
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.6;
}
.badge-ok {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 14%, transparent);
}
.badge-bad {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}
.badge-warn {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
}
.badge-muted {
  color: var(--text-muted);
  background: var(--hover-bg);
}
.mig-route-select {
  min-width: 140px;
}

/* ── Notifications panel ─────────────────────────────────────*/
.notif-bell {
  position: relative;
  width: 36px;
  height: 36px;
}
.notif-count {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.notif-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(6px);
  z-index: 60;
}
.notif-panel {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: min(400px, calc(100vw - 16px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rp);
  box-shadow: var(--shadow);
  z-index: 70;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.notif-panel[hidden],
.notif-backdrop[hidden] {
  display: none;
}
.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notif-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}
.notif-head-count {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
}
.notif-list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}
.notif-item {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.notif-item:hover {
  background: var(--hover-bg);
}
.notif-item.is-unread {
  background: var(--active-bg);
}
.notif-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-top: 6px;
  flex-shrink: 0;
}
.notif-dot-ok { background: var(--success); }
.notif-dot-bad { background: var(--danger); }
.notif-dot-warn { background: var(--warning); }
.notif-dot-muted { background: var(--text-muted); }
.notif-body {
  min-width: 0;
  flex: 1;
}
.notif-title {
  font-size: 13.5px;
  font-weight: 600;
}
.notif-msg {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notif-time {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}
.notif-empty {
  padding: 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Empty state (spec): ghost rows behind a message card ───*/
.es {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: 20px;
  overflow: hidden;
}
.es-ghost {
  position: absolute;
  inset: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0.5;
  -webkit-mask-image: linear-gradient(#000, transparent 85%);
  mask-image: linear-gradient(#000, transparent 85%);
}
.es-ghost i {
  display: grid;
  grid-template-columns: 20px 1.2fr 1fr 0.6fr;
  gap: 14px;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.es-ghost b {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
}
.es-msg {
  position: relative;
  max-width: 300px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.es-msg h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.es-msg p { margin: 0; font-size: 12.5px; color: var(--text-muted); }
.es-acts { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
tr.es-row > td { padding: 0 !important; }
.notif-empty .es { min-height: 140px; }

/* ── Running-job spinner ─────────────────────────────────────*/
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: -1px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

/* ── Running-jobs nav indicator ──────────────────────────────*/
.runs-bell .runs-icon {
  width: 22px;
  height: 22px;
  object-fit: cover;
  object-position: center 28%;
  border-radius: 5px;
  /* waiting.png is dark-on-white � invert so the figure reads on the dark header */
  filter: invert(0.9);
}
.runs-bell .runs-gif {
  display: none;
  width: 22px;
  height: 22px;
  object-fit: contain;
}
/* While a job runs, the animated runner gif replaces the static icon. */
.runs-bell.is-running .runs-icon {
  display: none;
}
.runs-bell.is-running .runs-gif {
  display: block;
}
.runs-count {
  background: var(--warning);
  color: var(--bg);
}

/* Busy state for icon buttons mid-action */
.icon-btn.is-busy {
  opacity: 0.5;
  cursor: progress;
}
.icon-btn:active:not(:disabled) {
  transform: scale(0.9);
}

/* ── Header actions group ────────────────────────────────────*/
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Confirmation modal ──────────────────────────────────────*/
.confirm-card {
  width: min(90vw, 22rem);
}
.confirm-body {
  text-align: center;
}
.confirm-icon {
  width: 44px;
  height: 44px;
  margin: 4px auto 0;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}
.confirm-icon svg { width: 22px; height: 22px; }
.confirm-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.confirm-text {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
  white-space: pre-line;
}
.button.danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--accent-ink);
}
.button.danger-solid:hover:not(:disabled) {
  filter: brightness(0.92);
}
.confirm-body .button {
  width: 100%;
}

/* Retention panel */
#retention-result { background: var(--surface); border: 1px solid var(--border); border-radius: var(--rk); padding: 12px 14px; margin: 12px 0 0; font-family: ui-monospace, monospace; font-size: 12px; white-space: pre-wrap; }
.retention-days { width: 90px; }

/* -- Mobile nav ---------------------------------------------- */
.nav-toggle {
  display: none;
  width: 38px;
  height: 38px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.2s;
}
body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(6px);
  z-index: 75;
}
.nav-backdrop[hidden] { display: none; }

/* Shell collapses to topbar over main at =820px; sidebar becomes an
   off-canvas drawer: min(280px, 100%-56px), 8px inset, 280ms slide. */
@media (max-width: 820px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 56px minmax(0, 1fr);
    grid-template-areas: 'top' 'main';
    gap: 8px;
    padding: 8px;
  }
  .nav-toggle { display: inline-flex; }
  .app-header { padding: 0 10px; }
  .sidebar {
    position: fixed;
    top: 8px;
    bottom: 8px;
    left: 8px;
    width: min(280px, calc(100% - 56px));
    z-index: 80;
    transform: translateX(calc(-100% - 16px));
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: var(--shadow-deep);
    overflow-y: auto;
  }
  .sidebar.is-open { transform: none; }
  body.nav-open { overflow: hidden; }
  .content .panel { padding: 14px; }
}

@media (max-width: 900px) {

  .panel-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .panel-header h1,
  .crumb-back {
    font-size: 1.15rem;
  }
  .panel-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  .panel-actions.filters select,
  .panel-actions.filters input {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
  }

  /* Tables collapse to label-per-line cards � cells get data-label
     stamped by ui.js from the thead */
  .data-table {
    border-radius: 0;
  }
  .data-table thead {
    display: none;
  }
  .data-table tbody tr {
    display: block;
    padding: 6px 10px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--rc);
    background: var(--surface-2);
  }
  .data-table th,
  .data-table td {
    padding: 0.45rem 0;
    font-size: 0.85rem;
    border-bottom: none;
  }
  .data-table td {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    text-align: right;
  }
  .data-table td::before {
    content: attr(data-label);
    margin-right: auto;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    text-align: left;
  }
  .data-table td[colspan],
  .data-table td:not([data-label]) {
    display: block;
    text-align: left;
  }
  .data-table td[colspan]::before,
  .data-table td:not([data-label])::before {
    content: none;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
  .detail-grid dd {
    border-bottom: 1px solid var(--border);
    padding-top: 0;
  }
  .detail-grid dt {
    border-bottom: none;
    padding-bottom: 4px;
  }

  .step-form { max-width: 100%; }

  .health-grid {
    grid-template-columns: 1fr;
  }
  .stat-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .mig-table-picker {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }

  .modal {
    align-items: flex-end;
    justify-content: stretch;
  }
  .modal-card,
  .modal-card.is-wide,
  .confirm-card {
    width: 100%;
    max-height: 88dvh;
    border-radius: var(--rp) var(--rp) 0 0;
  }

  .toast-stack {
    top: auto;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
  }
  .toast {
    width: auto;
  }

  .notif-panel {
    top: 8px;
    right: 8px;
    bottom: 8px;
    width: calc(100vw - 16px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* Session-expiry dialogs — shared UI-guide pattern. */
.ses-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--scrim);
  backdrop-filter: blur(6px);
  animation: ses-fade 150ms ease-out;
}
.ses {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 32px 28px 24px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  animation: ses-pop 180ms ease-out;
}
.ses__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.ses__close:hover { color: var(--text); }
.ses__ring-wrap { position: relative; width: 72px; height: 72px; margin: 0 auto 16px; }
.ses__ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ses__ring circle { fill: none; stroke-width: 5; }
.ses__ring-track { stroke: var(--line); }
.ses__ring-arc { stroke: var(--warn); stroke-linecap: round; transition: stroke-dashoffset 1s linear, stroke 300ms; }
.ses__ring-arc--low { stroke: var(--danger); }
.ses__clock {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.ses__clock--low { color: var(--danger); }
.ses__power {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
  border-radius: 50%;
  color: var(--danger);
  background: rgba(229, 115, 106, 0.12);
}
.ses__title { margin: 0 0 8px; font-size: 18px; font-weight: 700; color: var(--text); }
.ses__text { margin: 0 0 20px; font-size: 14px; color: var(--muted); }
.ses__actions { display: flex; gap: 10px; }
.ses__actions > * { flex: 1; justify-content: center; }
@media (max-width: 640px) {
  .ses-overlay { align-items: flex-end; padding: 0; }
  .ses {
    max-width: none;
    border-radius: 12px 12px 0 0;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    animation: ses-sheet 200ms ease-out;
  }
}
@keyframes ses-fade { from { opacity: 0; } }
@keyframes ses-pop { from { opacity: 0; transform: scale(0.96); } }
@keyframes ses-sheet { from { transform: translateY(24px); } }
