@import url('https://fonts.googleapis.com/css2?family=Exo+2:wght@300;400;500;600;700;800&family=Orbitron:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: dark;
  --bg: #07101f;
  --bg-raised: #0b1629;
  --panel: #0f1d33;
  --panel-strong: #142642;
  --panel-soft: #0b172b;
  --panel-hover: #172d4d;
  --line: #243957;
  --line-strong: #345071;
  --text: #f8fafc;
  --text-soft: #d9e2ef;
  --muted: #93a5bb;
  --muted-strong: #b6c5d6;
  --accent: #f59e0b;
  --accent-strong: #fbbf24;
  --accent-ink: #14100a;
  --accent-soft: rgba(245, 158, 11, .13);
  --accent-border: rgba(245, 158, 11, .42);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, .13);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, .13);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, .13);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, .13);
  --shadow-sm: 0 4px 14px rgba(2, 8, 23, .22);
  --shadow-md: 0 16px 40px rgba(2, 8, 23, .28);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --sidebar-width: 276px;
  --content-max: 1640px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fa;
  --bg-raised: #ffffff;
  --panel: #ffffff;
  --panel-strong: #f7f9fc;
  --panel-soft: #eef3f8;
  --panel-hover: #e8eff7;
  --line: #d7e0eb;
  --line-strong: #b7c6d8;
  --text: #0f172a;
  --text-soft: #24344d;
  --muted: #52627a;
  --muted-strong: #33445c;
  --accent: #b45309;
  --accent-strong: #92400e;
  --accent-ink: #ffffff;
  --accent-soft: rgba(180, 83, 9, .10);
  --accent-border: rgba(180, 83, 9, .38);
  --success: #15803d;
  --success-soft: rgba(21, 128, 61, .10);
  --danger: #b91c1c;
  --danger-soft: rgba(185, 28, 28, .10);
  --info: #0369a1;
  --info-soft: rgba(3, 105, 161, .10);
  --warning: #a16207;
  --warning-soft: rgba(161, 98, 7, .10);
  --shadow-sm: 0 4px 14px rgba(15, 23, 42, .08);
  --shadow-md: 0 16px 40px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Exo 2', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}
body::selection { background: var(--accent); color: var(--accent-ink); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a, select, input[type="checkbox"], input[type="radio"] { cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .55; }

h1, h2, h3, h4, .stat-value, .brand-mark, .eyebrow, .data-table th, .code, .stat-meta {
  font-family: 'Orbitron', 'Exo 2', sans-serif;
}
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.45rem, 1.8vw, 2rem); font-weight: 700; line-height: 1.2; letter-spacing: -.04em; }
h2 { margin-bottom: 8px; font-size: 1.05rem; font-weight: 700; letter-spacing: -.02em; }
h3 { margin-bottom: 6px; font-size: .93rem; font-weight: 700; }
strong { font-weight: 700; }

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 16px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  transform: translateY(-160%);
  transition: transform .18s ease;
}
.skip-link:focus { transform: translateY(0); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.app-shell { min-height: 100vh; background: var(--bg); }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel-soft);
}
.sidebar-header { padding: 28px 22px 20px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: -.08em;
  box-shadow: 0 8px 20px rgba(245, 158, 11, .18);
}
.brand strong { display: block; font-size: .87rem; letter-spacing: -.02em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-section { padding: 24px 14px 0; }
.sidebar-label { padding: 0 12px 8px; color: var(--muted); font-family: 'Orbitron', sans-serif; font-size: .62rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.side-nav { display: grid; gap: 4px; }
.nav-link {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--muted-strong);
  font-size: .91rem;
  font-weight: 600;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .2s ease;
}
.nav-link:hover { border-color: var(--line-strong); background: var(--panel-hover); color: var(--text); transform: translateX(2px); }
.nav-link.active { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent-strong); }
.nav-icon {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted-strong);
  font-family: 'Orbitron', sans-serif;
  font-size: .55rem;
  font-weight: 800;
  letter-spacing: -.08em;
}
.nav-link.active .nav-icon { border-color: var(--accent-border); background: var(--accent); color: var(--accent-ink); }
.sidebar-footer { margin-top: auto; padding: 18px 22px 22px; color: var(--muted); font-size: .75rem; }
.sidebar-footer strong { color: var(--text-soft); }

.main-shell { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px clamp(20px, 3vw, 48px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
}
.topbar-title { min-width: 0; }
.topbar-title .eyebrow { margin-bottom: 3px; }
.topbar-title h1 { margin: 0; font-size: 1rem; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sidebar-toggle { display: none; }
.theme-toggle, .user-chip {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--muted-strong);
  font-size: .78rem;
  font-weight: 700;
}
.theme-toggle:hover, .user-chip:hover { border-color: var(--accent-border); color: var(--accent-strong); }
.theme-toggle span:first-child { color: var(--accent); font-family: 'Orbitron', sans-serif; font-size: .65rem; }
.user-chip { background: transparent; }
.user-chip strong { color: var(--text); }

.page-content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 34px clamp(20px, 3vw, 48px) 64px; }
.page-header, .section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 22px;
}
.page-header > div:first-child, .section-header > div:first-child { min-width: 0; }
.page-header p, .section-header p { max-width: 720px; margin-bottom: 0; color: var(--muted); }
.eyebrow { margin-bottom: 7px; color: var(--accent-strong); font-size: .63rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.subtle { color: var(--muted); }
.code { color: var(--muted-strong); font-size: .72rem; letter-spacing: .04em; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.divider { height: 1px; margin: 22px 0; background: var(--line); }
.card {
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.card-compact { padding: 16px; }
.card:hover { border-color: var(--line-strong); }

.stat-card { position: relative; overflow: hidden; padding: 21px; }
.stat-card::after { position: absolute; right: -22px; bottom: -28px; width: 98px; height: 98px; border: 1px solid var(--accent-border); border-radius: 50%; content: ''; opacity: .45; }
.stat-label { color: var(--muted); font-family: 'Orbitron', sans-serif; font-size: .64rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.stat-value { margin-top: 12px; color: var(--text); font-size: clamp(1.5rem, 3vw, 2.25rem); font-weight: 700; letter-spacing: -.05em; line-height: 1; }
.stat-meta { margin-top: 12px; color: var(--muted); font-size: .65rem; letter-spacing: .05em; }
.metric-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.metric-line:last-child { border-bottom: 0; }
.metric-line span:first-child { color: var(--muted); }
.metric-line strong { color: var(--text); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.toolbar .actions, .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filter-panel { margin-bottom: 22px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel-soft); }
.filter-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.filter-heading strong { font-family: 'Orbitron', sans-serif; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.filter-hint { color: var(--muted); font-size: .78rem; }
.filter-panel form, .filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: end; }
.field { display: grid; gap: 7px; min-width: 0; }
.field label { color: var(--muted-strong); font-size: .78rem; font-weight: 700; }
.field small { color: var(--muted); font-size: .73rem; }
.input, .select, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  outline: 0;
  background: var(--bg-raised);
  color: var(--text);
  transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}
.field textarea { min-height: 118px; resize: vertical; }
.input::placeholder, .field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.input:hover, .select:hover, .field input:hover, .field select:hover, .field textarea:hover { border-color: var(--muted-strong); }
.input:focus, .select:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.checkbox { width: 17px; height: 17px; accent-color: var(--accent); }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 22px; }

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--panel-strong);
  color: var(--text-soft);
  font-size: .8rem;
  font-weight: 700;
  line-height: 1;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .2s ease, box-shadow .2s ease;
}
.btn:hover { border-color: var(--accent-border); background: var(--panel-hover); color: var(--text); transform: translateY(-1px); }
.btn-primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); box-shadow: 0 7px 18px rgba(245, 158, 11, .18); }
.btn-primary:hover { border-color: var(--accent-strong); background: var(--accent-strong); color: var(--accent-ink); }
.btn-secondary { border-color: var(--info); background: var(--info-soft); color: var(--info); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted-strong); }
.btn-danger { border-color: rgba(239, 68, 68, .45); background: var(--danger-soft); color: #f87171; }
[data-theme="light"] .btn-danger { color: var(--danger); }
.btn-small { min-height: 32px; padding: 6px 9px; font-size: .72rem; }

.flash, .notice { margin-bottom: 18px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text-soft); }
.flash-error { border-color: rgba(239, 68, 68, .45); background: var(--danger-soft); color: #fca5a5; }
.flash-success { border-color: rgba(34, 197, 94, .45); background: var(--success-soft); color: #86efac; }
.notice { border-color: var(--accent-border); background: var(--accent-soft); }
[data-theme="light"] .flash-error { color: var(--danger); }
[data-theme="light"] .flash-success { color: var(--success); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); }
.data-table { width: 100%; min-width: 720px; border-collapse: collapse; }
.data-table th { padding: 13px 15px; border-bottom: 1px solid var(--line-strong); background: var(--panel-soft); color: var(--muted); font-size: .62rem; font-weight: 700; letter-spacing: .1em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.data-table td { padding: 15px; border-bottom: 1px solid var(--line); color: var(--text-soft); vertical-align: middle; }
.data-table tbody tr { transition: background-color .18s ease; }
.data-table tbody tr:hover { background: var(--accent-soft); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table td strong { color: var(--text); }
.table-primary { color: var(--text); font-weight: 700; }
.table-secondary { display: block; margin-top: 3px; color: var(--muted); font-size: .76rem; }

.badge { display: inline-flex; min-height: 24px; align-items: center; gap: 6px; padding: 4px 8px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel-soft); color: var(--muted-strong); font-family: 'Orbitron', sans-serif; font-size: .58rem; font-weight: 700; letter-spacing: .06em; line-height: 1; text-transform: uppercase; white-space: nowrap; }
.badge::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ''; }
.badge-success { border-color: rgba(34, 197, 94, .35); background: var(--success-soft); color: var(--success); }
.badge-danger { border-color: rgba(239, 68, 68, .35); background: var(--danger-soft); color: var(--danger); }
.badge-warning { border-color: var(--accent-border); background: var(--warning-soft); color: var(--warning); }
.badge-info { border-color: rgba(56, 189, 248, .35); background: var(--info-soft); color: var(--info); }

.health-card { position: relative; display: flex; min-height: 116px; align-items: center; gap: 14px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel); box-shadow: var(--shadow-sm); }
.health-icon { display: grid; width: 42px; height: 42px; flex: 0 0 42px; place-items: center; border-radius: 12px; background: var(--accent-soft); color: var(--accent-strong); font-family: 'Orbitron', sans-serif; font-size: .63rem; font-weight: 800; }
.health-card strong { display: block; font-family: 'Orbitron', sans-serif; font-size: 1.22rem; }
.health-card span { display: block; margin-top: 3px; color: var(--muted); font-size: .75rem; }
.health-active .health-icon { background: var(--success-soft); color: var(--success); }
.health-paused .health-icon { background: var(--warning-soft); color: var(--warning); }
.health-owners .health-icon { background: var(--info-soft); color: var(--info); }
.rule-health { margin-bottom: 22px; }

.empty-state { display: grid; justify-items: center; gap: 10px; padding: 62px 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); background: var(--panel-soft); text-align: center; }
.empty-illustration { display: grid; width: 68px; height: 68px; place-items: center; border: 1px solid var(--accent-border); border-radius: 20px; background: var(--accent-soft); color: var(--accent-strong); font-family: 'Orbitron', sans-serif; font-size: .8rem; font-weight: 800; }
.empty-icon { color: var(--muted); font-size: 2rem; }
.empty-state h2 { margin-bottom: 0; }
.empty-state p { max-width: 500px; margin-bottom: 8px; color: var(--muted); }
.rule-empty { padding: 18px 0; color: var(--muted); text-align: center; }

.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; color: var(--muted); font-size: .78rem; }
.pagination-links { display: flex; flex-wrap: wrap; gap: 6px; }
.pagination-links a, .pagination-links span { display: grid; min-width: 34px; min-height: 34px; place-items: center; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--muted-strong); }
.pagination-links a:hover, .pagination-links .current { border-color: var(--accent-border); background: var(--accent-soft); color: var(--accent-strong); }

.login-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: min(100%, 460px); padding: clamp(24px, 5vw, 42px); }
.login-toolbar { display: flex; justify-content: flex-end; margin-bottom: 24px; }
.login-card .brand { margin-bottom: 28px; }
.login-card h1 { margin-top: 24px; }
.login-card .subtle { margin-bottom: 24px; }
.login-card .form-actions .btn { width: 100%; }

@media (max-width: 1180px) {
  :root { --sidebar-width: 240px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-panel form, .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .sidebar { width: 248px; transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow-md); }
  .sidebar.open { transform: translateX(0); }
  .main-shell { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .topbar { padding-inline: 20px; }
  .topbar-title { display: none; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .page-content { padding: 24px 16px 48px; }
  .page-header, .section-header, .split { display: grid; align-items: start; gap: 14px; }
  .page-header .actions, .section-header .actions { width: 100%; }
  .page-header .btn, .section-header .btn { flex: 1; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .filter-panel form, .filter-grid { grid-template-columns: 1fr; }
  .filter-panel { padding: 14px; }
  .card { padding: 17px; border-radius: var(--radius-md); }
  .toolbar { align-items: stretch; }
  .toolbar .actions, .toolbar .btn { width: 100%; }
  .toolbar .actions .btn { flex: 1; }
  .topbar { min-height: 68px; padding: 12px 16px; }
  .topbar-actions { margin-left: auto; }
  .theme-toggle { min-width: 40px; justify-content: center; padding: 7px; }
  .theme-toggle [data-theme-label] { display: none; }
  .user-chip { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pagination { align-items: stretch; flex-direction: column; }
  .pagination-links { width: 100%; }
  .pagination-links a, .pagination-links span { flex: 1; }
  .empty-state { padding: 42px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* Shell repair: align selectors with the actual shared layout markup. */
.main-content { min-height: 100vh; margin-left: var(--sidebar-width); }
.nav-list { display: grid; gap: 4px; }
.sidebar-kicker { margin-top: 18px; color: var(--muted); font-family: 'Orbitron', sans-serif; font-size: .58rem; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.nav-svg { width: 17px; height: 17px; display: block; }
.nav-icon:has(.nav-svg) { font-size: 0; }
.topbar-leading { display: flex; min-width: 0; align-items: center; gap: 14px; }
.topbar-user { display: inline-flex; min-width: 0; align-items: center; gap: 9px; padding-left: 8px; }
.topbar-user > span:last-child { display: grid; min-width: 0; gap: 1px; }
.topbar-user strong { overflow: hidden; color: var(--text); font-size: .79rem; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user small { color: var(--muted); font-size: .68rem; text-transform: capitalize; }
.avatar { display: grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; border: 1px solid var(--accent-border); border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-family: 'Orbitron', sans-serif; font-size: .73rem; font-weight: 800; }
.icon-button { display: inline-grid; width: 40px; height: 40px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--text-soft); }
.icon-button:hover { border-color: var(--accent-border); color: var(--accent-strong); }
.icon-button svg { width: 19px; height: 19px; }
.mobile-only { display: none; }
.status-dot { display: flex; align-items: center; gap: 8px; margin-bottom: 13px; color: var(--muted); font-size: .75rem; }
.status-dot span { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.muted-link { color: var(--muted); }
.page-footer { padding: 24px 0 0; color: var(--muted); font-size: .76rem; }
.page-footer span { padding: 0 5px; color: var(--accent); }
@media (max-width: 860px) {
  .main-content { margin-left: 0; }
  .mobile-only { display: inline-grid; }
  .sidebar.open { transform: translateX(0); }
}
@media (min-width: 861px) {
  .sidebar { transform: translateX(0); }
}
@media (max-width: 640px) {
  .topbar-user { max-width: 170px; }
  .topbar-user strong { max-width: 100px; }
}

/* Alert rule form: compact, balanced, and responsive. */
form.grid.grid-2 { align-items: start; gap: 20px; }
form.grid.grid-2 > .card { align-self: start; min-height: 0; }
form.grid.grid-2 > .card > h2 { margin-bottom: 6px; }
form.grid.grid-2 > .card > .subtle { margin-bottom: 20px; }
form.grid.grid-2 .field { min-width: 0; }
form.grid.grid-2 .form-actions { justify-content: flex-end; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
form.grid.grid-2 .form-actions .btn { min-width: 112px; }
form.grid.grid-2 .field:has(input[type="checkbox"]) { display: flex; align-items: flex-start; gap: 10px; margin-top: 18px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
form.grid.grid-2 .field:has(input[type="checkbox"]) label { color: var(--text-soft); line-height: 1.35; }
form.grid.grid-2 .checkbox { margin-top: 2px; }
form.grid.grid-2 .field small { line-height: 1.4; }
@media (max-width: 860px) {
  form.grid.grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  form.grid.grid-2 .form-actions { justify-content: stretch; }
  form.grid.grid-2 .form-actions .btn { flex: 1; }
}

/* Alert rule form: compact, balanced, and responsive. */
form.grid.grid-2 { align-items: start !important; gap: 20px; }
form.grid.grid-2 > .card { height: max-content !important; align-self: start !important; }
form.grid.grid-2 > .card { align-self: start; min-height: 0; }
form.grid.grid-2 > .card > h2 { margin-bottom: 6px; }
form.grid.grid-2 > .card > .subtle { margin-bottom: 20px; }
form.grid.grid-2 .field { min-width: 0; }
form.grid.grid-2 .form-actions { justify-content: flex-end; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
form.grid.grid-2 .form-actions .btn { min-width: 112px; }
form.grid.grid-2 .field:has(input[type="checkbox"]) { display: flex; align-items: flex-start; gap: 10px; margin-top: 18px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); }
form.grid.grid-2 .field:has(input[type="checkbox"]) label { color: var(--text-soft); line-height: 1.35; }
form.grid.grid-2 .checkbox { margin-top: 2px; }
form.grid.grid-2 .field small { line-height: 1.4; }
@media (max-width: 860px) {
  form.grid.grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  form.grid.grid-2 .form-actions { justify-content: stretch; }
  form.grid.grid-2 .form-actions .btn { flex: 1; }
}

/* Viewport safety: never let the alert form create a horizontal page scroll. */
.main-content, .page-content { min-width: 0; max-width: 100%; }
form.grid.grid-2 { width: 100%; max-width: 100%; min-width: 0; overflow: visible; }
form.grid.grid-2 > .card { width: 100%; min-width: 0; max-width: 100%; }
form.grid.grid-2 .field, form.grid.grid-2 .input, form.grid.grid-2 .select { min-width: 0; max-width: 100%; }
@media (max-width: 1280px) {
  form.grid.grid-2 { grid-template-columns: minmax(0, 1fr) !important; }
}
@media (max-width: 900px) {
  .page-content { padding-inline: 16px; }
  form.grid.grid-2 { gap: 14px; }
}

/* Alert-edit component polish: Tailwind-style utility composition over the existing PHP/CSS stack. */
.alert-edit-shell { --alert-accent: var(--accent); }
.alert-edit-shell .panel-title { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.alert-edit-shell .panel-icon { display: inline-grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; border: 1px solid var(--accent-border); border-radius: 10px; background: var(--accent-soft); color: var(--accent-strong); }
.alert-edit-shell .panel-icon .ui-icon { width: 18px; height: 18px; }
.alert-edit-shell .field-label { display: inline-flex; align-items: center; gap: 7px; }
.alert-edit-shell .field-icon { display: inline-grid; width: 20px; height: 20px; flex: 0 0 20px; place-items: center; border-radius: 6px; background: var(--panel-soft); color: var(--accent-strong); }
.alert-edit-shell .field-icon .ui-icon { width: 13px; height: 13px; }
.alert-edit-shell .ui-icon { display: block; width: 16px; height: 16px; }
.alert-edit-shell .btn > [aria-hidden="true"] { display: inline-grid; place-items: center; }
.alert-edit-shell .btn > [aria-hidden="true"] .ui-icon { width: 15px; height: 15px; }
.alert-edit-shell .toggle-card { display: flex; align-items: flex-start; gap: 10px; margin-top: 18px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(135deg, var(--panel-soft), var(--panel)); transition: border-color .2s ease, background-color .2s ease, box-shadow .2s ease; }
.alert-edit-shell .toggle-card:hover { border-color: var(--accent-border); box-shadow: 0 8px 20px rgba(2, 8, 23, .08); }
.alert-edit-shell .toggle-icon { display: inline-grid; width: 30px; height: 30px; flex: 0 0 30px; place-items: center; border-radius: 9px; background: var(--accent-soft); color: var(--accent-strong); }
.alert-edit-shell .toggle-icon .ui-icon { width: 16px; height: 16px; }
.alert-edit-shell .toggle-card .checkbox { margin-top: 7px; order: 2; }
.alert-edit-shell .toggle-card > span:last-child { flex: 1; order: 1; }
.alert-edit-shell .toggle-card .toggle-icon { order: 0; }
.alert-edit-shell .toggle-card strong { display: block; margin-bottom: 2px; }
.alert-edit-shell .form-actions { align-items: center; }
.alert-edit-shell .form-actions .btn-primary { min-width: 132px; }
@media (max-width: 640px) {
  .alert-edit-shell .panel-icon { width: 30px; height: 30px; flex-basis: 30px; }
  .alert-edit-shell .toggle-card { padding: 12px; }
}

/* Final safety rule for the alert-edit form: prevent horizontal crop at normal and narrow viewports. */
html, body { max-width: 100%; overflow-x: hidden; }
.main-content, .page-content { width: 100%; max-width: 100%; min-width: 0; overflow-x: hidden; }
form.alert-edit-shell { width: 100%; max-width: 100%; min-width: 0; grid-template-columns: minmax(0, 1fr) !important; overflow: visible; }
form.alert-edit-shell > .card { width: 100%; max-width: 100%; min-width: 0; }
form.alert-edit-shell > .card .grid.grid-2 { min-width: 0; }
form.alert-edit-shell .field, form.alert-edit-shell .input, form.alert-edit-shell .select { min-width: 0; max-width: 100%; }
@media (min-width: 1701px) {
  form.alert-edit-shell { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}
@media (max-width: 760px) {
  form.alert-edit-shell > .card .grid.grid-2 { grid-template-columns: minmax(0, 1fr) !important; }
}

/* Root-cause fix: main-content has a fixed sidebar offset, so its width must exclude that offset. */
.main-content { width: calc(100% - var(--sidebar-width)) !important; max-width: calc(100% - var(--sidebar-width)) !important; min-width: 0 !important; }
@media (max-width: 860px) {
  .main-content { width: 100% !important; max-width: 100% !important; margin-left: 0 !important; }
}

/* Compact alert-edit composition: two cards on desktop, one safe column on narrow screens. */
form.alert-edit-shell { width: 100%; max-width: 100%; min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; align-items: start !important; gap: 20px; }
form.alert-edit-shell > .card { width: 100%; min-width: 0; max-width: 100%; height: max-content !important; align-self: start !important; }
form.alert-edit-shell > .card .grid.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
form.alert-edit-shell .form-actions { margin-top: 20px; padding-top: 16px; }
form.alert-edit-shell .toggle-card { margin-top: 16px; }
@media (max-width: 1080px) {
  form.alert-edit-shell { grid-template-columns: minmax(0, 1fr) !important; }
}
@media (max-width: 720px) {
  form.alert-edit-shell > .card .grid.grid-2 { grid-template-columns: minmax(0, 1fr) !important; }
  form.alert-edit-shell .form-actions { flex-direction: column-reverse; align-items: stretch; }
  form.alert-edit-shell .form-actions .btn { width: 100%; }
}

/* Unified alert-edit component system: consistent card, field, toggle, and action geometry. */
form.alert-edit-shell { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; align-items: stretch !important; gap: 20px; }
form.alert-edit-shell > .card { display: flex; min-height: 360px; flex-direction: column; padding: 24px; border-radius: 16px; }
form.alert-edit-shell > .card > .subtle { min-height: 42px; margin-bottom: 20px; }
form.alert-edit-shell > .card > .field { margin-bottom: 14px; }
form.alert-edit-shell .field { gap: 6px; }
form.alert-edit-shell .field-label { min-height: 22px; }
form.alert-edit-shell .input,
form.alert-edit-shell .select,
form.alert-edit-shell input:not([type="checkbox"]),
form.alert-edit-shell select { height: 46px; min-height: 46px; }
form.alert-edit-shell .field small { min-height: 18px; line-height: 1.35; }
form.alert-edit-shell > .card > .grid.grid-2 { gap: 16px; }
form.alert-edit-shell .toggle-card { min-height: 72px; align-items: center; margin-top: 4px; padding: 12px 14px; }
form.alert-edit-shell .toggle-card .checkbox { margin-top: 0; }
form.alert-edit-shell .form-actions-global { grid-column: 1 / -1; display: flex; min-height: 56px; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 0; padding-top: 16px; border-top: 1px solid var(--line); }
form.alert-edit-shell .form-actions-global .btn { min-width: 118px; }
@media (max-width: 1080px) {
  form.alert-edit-shell { grid-template-columns: minmax(0, 1fr) !important; }
  form.alert-edit-shell > .card { min-height: 0; }
  form.alert-edit-shell .form-actions-global { grid-column: 1; }
}
@media (max-width: 720px) {
  form.alert-edit-shell > .card { padding: 18px; }
  form.alert-edit-shell > .card > .grid.grid-2 { grid-template-columns: minmax(0, 1fr) !important; }
  form.alert-edit-shell .form-actions-global { flex-direction: column-reverse; align-items: stretch; }
  form.alert-edit-shell .form-actions-global .btn { width: 100%; }
}

/* Final component normalization: equal-height alert panels with a shared footer. */
form.alert-edit-shell { align-items: stretch !important; }
form.alert-edit-shell > .card { height: 100% !important; min-height: 360px; align-self: stretch !important; }
form.alert-edit-shell > .card > .subtle { min-height: 42px; }
form.alert-edit-shell .form-actions-global { align-self: stretch; }
@media (max-width: 1080px) {
  form.alert-edit-shell > .card { height: auto !important; min-height: 0; }
}

/* Grid correction: let CSS Grid stretch both cards naturally in the same row. */
form.alert-edit-shell { grid-template-rows: auto auto; align-items: stretch !important; }
form.alert-edit-shell > .card { height: auto !important; align-self: stretch !important; }
form.alert-edit-shell > .card:first-child { min-height: 360px; }
form.alert-edit-shell > .card:nth-child(2) { min-height: 360px; }
@media (max-width: 1080px) {
  form.alert-edit-shell > .card { min-height: 0; }
}

/* Deterministic desktop composition: identical card heights at the validated desktop viewport. */
@media (min-width: 1081px) {
  form.alert-edit-shell > .card { height: 424px !important; min-height: 424px !important; max-height: 424px !important; overflow: hidden; }
}
@media (max-width: 1080px) {
  form.alert-edit-shell > .card { height: auto !important; min-height: 0 !important; max-height: none !important; overflow: visible; }
}

/* Threshold field alignment: helper text must not stretch the neighboring select. */
form.alert-edit-shell > .card .grid.grid-2 { align-items: start !important; }
form.alert-edit-shell > .card .grid.grid-2 > .field { align-self: start !important; min-height: 0 !important; }
form.alert-edit-shell > .card .grid.grid-2 > .field > .select,
form.alert-edit-shell > .card .grid.grid-2 > .field > .input,
form.alert-edit-shell > .card .grid.grid-2 > .field > input,
form.alert-edit-shell > .card .grid.grid-2 > .field > select { height: 46px !important; min-height: 46px !important; align-self: start; }
form.alert-edit-shell > .card .grid.grid-2 > .field > small { min-height: 0 !important; margin-top: 5px; }

/* Back navigation: make the text link visibly interactive. */
.page-content > .section-header > a.btn.btn-ghost {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.page-content > .section-header > a.btn.btn-ghost > span:first-child {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.page-content > .section-header > a.btn.btn-ghost .ui-icon { width: 14px; height: 14px; }
.page-content > .section-header > a.btn.btn-ghost:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: 0 8px 18px rgba(245, 158, 11, .14);
  transform: translateY(-1px);
}
.page-content > .section-header > a.btn.btn-ghost:active { transform: translateY(0); box-shadow: none; }
.page-content > .section-header > a.btn.btn-ghost:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
@media (max-width: 640px) {
  .page-content > .section-header > a.btn.btn-ghost { width: 100%; justify-content: center; }
}

/* Cancel action: visibly secondary, but unmistakably interactive. */
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
  font-size: .8rem;
  font-weight: 700;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease, transform .2s ease;
}
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost > span:first-child {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text-soft);
}
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost .ui-icon { width: 14px; height: 14px; }
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger-strong);
  box-shadow: 0 8px 18px rgba(239, 68, 68, .12);
  transform: translateY(-1px);
}
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost:hover > span:first-child { background: rgba(239, 68, 68, .1); color: var(--danger-strong); }
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost:active { transform: translateY(0); box-shadow: none; }
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost:focus-visible { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
@media (max-width: 720px) {
  form.alert-edit-shell .form-actions-global > a.btn.btn-ghost { width: 100%; }
}

/* Cancel icon refinement: remove the mismatched pale square and use a clean inline icon. */
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost > span:first-child {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: currentColor;
}
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost .ui-icon { width: 15px; height: 15px; }
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost:hover > span:first-child {
  background: rgba(239, 68, 68, .1);
  color: var(--danger-strong);
}
form.alert-edit-shell .form-actions-global > a.btn.btn-ghost:focus-visible > span:first-child { background: rgba(239, 68, 68, .1); }

/* Accessible alert-enable toggle. The native checkbox remains in the DOM and controls this visual switch. */
form.alert-edit-shell .toggle-card-switch { position: relative; display: flex; align-items: center; gap: 10px; }
form.alert-edit-shell .toggle-card-switch .toggle-input { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
form.alert-edit-shell .toggle-card-switch .toggle-copy { order: 1; flex: 1; min-width: 0; }
form.alert-edit-shell .toggle-card-switch .toggle-icon { order: 0; }
form.alert-edit-shell .toggle-card-switch .toggle-switch { order: 2; display: inline-flex; width: 48px; height: 28px; flex: 0 0 48px; align-items: center; padding: 3px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--line-strong); box-shadow: inset 0 1px 2px rgba(15, 23, 42, .14); transition: background-color .2s ease, border-color .2s ease, box-shadow .2s ease; }
form.alert-edit-shell .toggle-card-switch .toggle-thumb { display: block; width: 20px; height: 20px; border-radius: 999px; background: var(--panel); box-shadow: 0 2px 5px rgba(15, 23, 42, .2); transform: translateX(0); transition: transform .2s ease, background-color .2s ease; }
form.alert-edit-shell .toggle-card-switch .toggle-input:checked + .toggle-switch { border-color: var(--accent-strong); background: var(--accent); box-shadow: inset 0 1px 2px rgba(120, 53, 15, .16), 0 0 0 2px var(--accent-soft); }
form.alert-edit-shell .toggle-card-switch .toggle-input:checked + .toggle-switch .toggle-thumb { background: #fff; transform: translateX(20px); }
form.alert-edit-shell .toggle-card-switch .toggle-input:focus-visible + .toggle-switch { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
form.alert-edit-shell .toggle-card-switch:hover .toggle-switch { border-color: var(--accent); }
@media (max-width: 720px) {
  form.alert-edit-shell .toggle-card-switch { align-items: flex-start; }
  form.alert-edit-shell .toggle-card-switch .toggle-switch { margin-left: auto; }
}

/* Theme toggle icon polish: proper sun/moon SVGs instead of L/D marker blocks. */
.theme-toggle { gap: 9px; }
.theme-toggle [data-theme-icon] { display: inline-grid; width: 20px; height: 20px; flex: 0 0 20px; place-items: center; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); }
.theme-toggle [data-theme-icon] .ui-icon { display: block; width: 15px; height: 15px; }
.theme-toggle:hover [data-theme-icon] { background: var(--accent); color: #fff; }
.theme-toggle:focus-visible [data-theme-icon] { box-shadow: 0 0 0 3px var(--accent-soft); }
[data-theme="light"] .theme-toggle [data-theme-icon] { background: #e0f2fe; color: #0369a1; }
[data-theme="light"] .theme-toggle:hover [data-theme-icon] { background: #0284c7; color: #fff; }

/* History filter alignment: controlled columns and consistent field/action geometry. */
.history-filter { display: grid; grid-template-columns: minmax(220px, 1.25fr) minmax(140px, .8fr) repeat(2, minmax(170px, 1fr)) auto auto; align-items: end; gap: 16px; width: 100%; margin-bottom: 22px; }
.history-filter .field { min-width: 0; gap: 7px; }
.history-filter .field label { display: flex; min-height: 20px; align-items: center; }
.history-filter .field .input,
.history-filter .field .select,
.history-filter .field input,
.history-filter .field select { width: 100%; height: 52px; min-height: 52px; }
.history-filter > .btn,
.history-filter > a.btn { display: inline-flex; height: 52px; min-height: 52px; align-items: center; justify-content: center; align-self: end; white-space: nowrap; }
.history-filter > .btn { min-width: 128px; }
.history-filter > a.btn { min-width: 74px; border: 1px solid var(--line-strong); background: transparent; color: var(--text-soft); }
.history-filter > a.btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
@media (max-width: 1280px) {
  .history-filter { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .history-filter > .btn { grid-column: span 1; }
  .history-filter > a.btn { grid-column: span 1; }
}
@media (max-width: 860px) {
  .history-filter { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .history-filter > .btn,
  .history-filter > a.btn { width: 100%; grid-column: auto; }
}

/* User Management grid system: consistent cards, filters, bulk actions, and table geometry. */
.user-filter { display: grid; grid-template-columns: minmax(230px, 1.35fr) repeat(3, minmax(150px, 1fr)) auto auto; align-items: end; gap: 16px; width: 100%; margin-bottom: 20px !important; }
.user-filter .field { min-width: 0; gap: 7px; }
.user-filter .field label { display: flex; min-height: 20px; align-items: center; }
.user-filter .field input,
.user-filter .field select { width: 100%; height: 52px; min-height: 52px; }
.user-filter > .btn,
.user-filter > a.btn { display: inline-flex; height: 52px; min-height: 52px; align-items: center; justify-content: center; align-self: end; white-space: nowrap; }
.user-filter > .btn { min-width: 96px; }
.user-filter > a.btn { min-width: 72px; border: 1px solid var(--line-strong); background: transparent; color: var(--text-soft); }
.user-filter > a.btn:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.user-bulk-form { min-width: 0; }
.user-bulk-bar { min-height: 66px; margin-top: 0; padding: 14px 16px; }
.user-bulk-bar > .split { width: 100%; min-width: 0; align-items: center; gap: 16px; }
.user-bulk-bar .actions { justify-content: flex-end; }
.user-bulk-bar .actions .btn { min-width: 92px; min-height: 38px; }
.user-table-wrap { margin-top: 14px !important; }
.user-table-wrap .data-table { min-width: 860px; table-layout: fixed; }
.user-table-wrap .data-table th:first-child,
.user-table-wrap .data-table td:first-child { width: 52px; }
.user-table-wrap .data-table th:nth-child(2),
.user-table-wrap .data-table td:nth-child(2) { width: 30%; }
.user-table-wrap .data-table th:nth-child(3),
.user-table-wrap .data-table td:nth-child(3) { width: 18%; }
.user-table-wrap .data-table th:nth-child(4),
.user-table-wrap .data-table td:nth-child(4) { width: 14%; }
.user-table-wrap .data-table th:nth-child(5),
.user-table-wrap .data-table td:nth-child(5),
.user-table-wrap .data-table th:nth-child(6),
.user-table-wrap .data-table td:nth-child(6) { width: 14%; white-space: nowrap; }
.user-table-wrap .data-table th:last-child,
.user-table-wrap .data-table td:last-child { width: 150px; }
.user-table-wrap .data-table td:last-child { text-align: right; }
.user-table-wrap .data-table td:last-child .btn { margin-left: 6px; }
.user-table-wrap .table-primary,
.user-table-wrap .table-secondary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1280px) {
  .user-filter { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .user-filter > .btn, .user-filter > a.btn { grid-column: span 1; }
}
@media (max-width: 860px) {
  .user-filter { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .user-filter > .btn, .user-filter > a.btn { width: 100%; grid-column: auto; }
  .user-bulk-bar > .split { align-items: stretch; flex-direction: column; }
  .user-bulk-bar .actions { width: 100%; }
  .user-bulk-bar .actions .btn { flex: 1; }
  .user-table-wrap .data-table { min-width: 860px; }
}

/* Final User Management table grid: explicit percentages total 100% and prevent clipped date/action cells. */
.user-table-wrap .data-table { width: 100%; min-width: 1040px; table-layout: fixed; }
.user-table-wrap .data-table th:first-child,
.user-table-wrap .data-table td:first-child { width: 4%; }
.user-table-wrap .data-table th:nth-child(2),
.user-table-wrap .data-table td:nth-child(2) { width: 28%; }
.user-table-wrap .data-table th:nth-child(3),
.user-table-wrap .data-table td:nth-child(3) { width: 16%; }
.user-table-wrap .data-table th:nth-child(4),
.user-table-wrap .data-table td:nth-child(4) { width: 12%; }
.user-table-wrap .data-table th:nth-child(5),
.user-table-wrap .data-table td:nth-child(5) { width: 15%; }
.user-table-wrap .data-table th:nth-child(6),
.user-table-wrap .data-table td:nth-child(6) { width: 11%; }
.user-table-wrap .data-table th:last-child,
.user-table-wrap .data-table td:last-child { width: 14%; }
.user-table-wrap .data-table td:nth-child(5),
.user-table-wrap .data-table td:nth-child(6) { white-space: nowrap; font-size: .76rem; }
.user-table-wrap .data-table td:last-child { white-space: nowrap; text-align: right; }
.user-table-wrap .data-table td:last-child > a { display: inline-flex; align-items: center; vertical-align: middle; }
.user-table-wrap .data-table td:last-child > a + a { margin-left: 8px; }
@media (max-width: 1100px) {
  .user-table-wrap { overflow-x: auto; }
  .user-table-wrap .data-table { min-width: 1040px; }
}

/* User Management v18: give timestamp columns real width while preserving a balanced seven-column grid. */
.user-table-wrap .data-table { width: 100%; min-width: 1180px; table-layout: fixed; }
.user-table-wrap .data-table th:first-child,
.user-table-wrap .data-table td:first-child { width: 4%; }
.user-table-wrap .data-table th:nth-child(2),
.user-table-wrap .data-table td:nth-child(2) { width: 27%; }
.user-table-wrap .data-table th:nth-child(3),
.user-table-wrap .data-table td:nth-child(3) { width: 14%; }
.user-table-wrap .data-table th:nth-child(4),
.user-table-wrap .data-table td:nth-child(4) { width: 11%; }
.user-table-wrap .data-table th:nth-child(5),
.user-table-wrap .data-table td:nth-child(5) { width: 15%; }
.user-table-wrap .data-table th:nth-child(6),
.user-table-wrap .data-table td:nth-child(6) { width: 15%; }
.user-table-wrap .data-table th:last-child,
.user-table-wrap .data-table td:last-child { width: 14%; }
.user-table-wrap .data-table td:nth-child(5),
.user-table-wrap .data-table td:nth-child(6) { white-space: nowrap; font-family: var(--font-body); font-size: .78rem; }
.user-table-wrap .data-table td:nth-child(5) .table-secondary,
.user-table-wrap .data-table td:nth-child(6) .table-secondary { display: inline; overflow: visible; text-overflow: clip; white-space: nowrap; }
.user-table-wrap .data-table td:last-child { white-space: nowrap; text-align: right; }
.user-table-wrap .data-table td:last-child > a { display: inline-flex; align-items: center; vertical-align: middle; }
.user-table-wrap .data-table td:last-child > a + a { margin-left: 8px; }
@media (max-width: 1100px) {
  .user-table-wrap { overflow-x: auto; }
  .user-table-wrap .data-table { min-width: 1180px; }
}

/* User Management v19: the timestamp cells carry table-secondary on the td itself. */
.user-table-wrap .data-table td.table-secondary { overflow: visible; text-overflow: clip; white-space: nowrap; font-family: var(--font-body); font-size: .78rem; }
.user-table-wrap .data-table td.actions { overflow: visible; white-space: nowrap; text-align: right; }
.user-table-wrap .data-table td.actions > a { display: inline-flex; align-items: center; vertical-align: middle; }
.user-table-wrap .data-table td.actions > a + a { margin-left: 8px; }

/* User Management v20: keep row actions horizontal and remove desktop-only overflow. */
.user-table-wrap .data-table { min-width: 1140px; }
.user-table-wrap .data-table td.actions { display: flex !important; flex-direction: row !important; flex-wrap: nowrap !important; align-items: center; justify-content: flex-end; gap: 8px; min-height: 72px; }
.user-table-wrap .data-table td.actions > a,
.user-table-wrap .data-table td.actions > a + a { flex: 0 0 auto; width: auto; margin: 0 !important; }
@media (max-width: 1100px) {
  .user-table-wrap .data-table { min-width: 1140px; }
}

/* User Management row correction: keep the final column a real table cell. */
.user-table-wrap .data-table td.actions {
  display: table-cell !important;
  position: static;
  min-height: 0 !important;
  height: auto;
  vertical-align: middle;
  overflow: visible;
  white-space: nowrap;
  text-align: right;
}
.user-table-wrap .data-table td.actions > a {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  flex: none !important;
  width: auto !important;
  margin: 0 !important;
}
.user-table-wrap .data-table td.actions > a + a { margin-left: 8px !important; }
.user-table-wrap .data-table tbody tr { min-height: 0; }

/* User Management v22: explicit mapping for Last sign-in, Created, and actions. */
.user-table-wrap .data-table { width: 100%; min-width: 1140px; table-layout: fixed; }
.user-table-wrap .data-table th:first-child,
.user-table-wrap .data-table td:first-child { width: 4%; }
.user-table-wrap .data-table th:nth-child(2),
.user-table-wrap .data-table td:nth-child(2) { width: 27%; }
.user-table-wrap .data-table th:nth-child(3),
.user-table-wrap .data-table td:nth-child(3) { width: 14%; }
.user-table-wrap .data-table th:nth-child(4),
.user-table-wrap .data-table td:nth-child(4) { width: 11%; }
.user-table-wrap .data-table th:nth-child(5),
.user-table-wrap .data-table td:nth-child(5) { width: 15%; }
.user-table-wrap .data-table th:nth-child(6),
.user-table-wrap .data-table td:nth-child(6) { width: 15%; }
.user-table-wrap .data-table th:nth-child(7),
.user-table-wrap .data-table td:nth-child(7) { width: 14%; }
.user-table-wrap .data-table td.user-date {
  display: table-cell !important;
  position: static;
  height: auto;
  min-height: 0 !important;
  vertical-align: middle;
  overflow: visible;
  white-space: nowrap;
  font-family: var(--font-body);
  font-size: .78rem;
  text-align: left;
}
.user-table-wrap .data-table td.actions {
  display: table-cell !important;
  position: static;
  height: auto;
  min-height: 0 !important;
  vertical-align: middle;
  overflow: visible;
  white-space: nowrap;
  text-align: right;
}
.user-table-wrap .data-table td.actions > a,
.user-table-wrap .data-table td.actions > a + a {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  width: auto !important;
  margin: 0 !important;
}
.user-table-wrap .data-table td.actions > a + a { margin-left: 8px !important; }
@media (max-width: 1100px) {
  .user-table-wrap { overflow-x: auto; }
  .user-table-wrap .data-table { min-width: 1140px; }
}

/* Telegram Delivery UI polish and setup guide modal. */
.telegram-grid { align-items: stretch; gap: 22px; }
.telegram-grid > .card { min-height: 414px; display: flex; flex-direction: column; }
.telegram-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.telegram-card-heading > div { min-width: 0; }
.telegram-card-heading h2 { margin-bottom: 7px; }
.telegram-card-heading .subtle { margin-bottom: 0; max-width: 48ch; }
.telegram-guide-trigger { flex: 0 0 auto; min-height: 40px; padding: 9px 13px; border-color: var(--line-strong); background: var(--panel); color: var(--text); box-shadow: none; }
.telegram-guide-trigger:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); box-shadow: 0 8px 20px rgba(245, 158, 11, .12); }
.telegram-guide-trigger:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.telegram-guide-trigger-icon { display: inline-grid; width: 20px; height: 20px; place-items: center; color: var(--accent-strong); }
.telegram-guide-trigger-icon .ui-icon { width: 17px; height: 17px; }
.telegram-grid form { display: flex; flex: 1; flex-direction: column; gap: 17px; }
.telegram-grid form .field { gap: 8px; }
.telegram-grid form .field label { font-size: .76rem; font-weight: 700; letter-spacing: .03em; }
.telegram-grid form .input { height: 54px; min-height: 54px; border-color: var(--line-strong); background: var(--input-bg, var(--panel-soft)); }
.telegram-grid form .input:hover { border-color: var(--accent); }
.telegram-grid form .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.telegram-grid form > label.split { align-items: flex-start !important; gap: 12px; margin-top: 0; padding: 13px 14px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-soft); }
.telegram-grid form > label.split:hover { border-color: var(--line-strong); background: var(--panel); }
.telegram-grid form > label.split .checkbox { flex: 0 0 auto; margin-top: 3px; }
.telegram-grid form > label.split strong { display: block; margin-bottom: 4px; }
.telegram-grid form > label.split small { display: block; line-height: 1.45; }
.telegram-grid .form-actions { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
.telegram-grid .form-actions .btn { width: 100%; min-height: 46px; }
.telegram-grid > .card:nth-child(2) { padding-bottom: 24px; }
.telegram-grid > .card:nth-child(2) .stack { gap: 0; }
.telegram-security-note { display: flex; align-items: flex-start; gap: 10px; margin-top: 22px !important; line-height: 1.5; }
.telegram-security-note::before { content: '!'; display: inline-grid; flex: 0 0 22px; width: 22px; height: 22px; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-weight: 800; font-size: .78rem; }

body.modal-open { overflow: hidden; }
.telegram-guide-backdrop { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 24px; background: rgba(2, 6, 23, .72); backdrop-filter: blur(5px); }
.telegram-guide-backdrop[hidden] { display: none; }
.telegram-guide-dialog { width: min(720px, 100%); max-height: min(780px, calc(100vh - 48px)); display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line-strong); border-radius: var(--radius-lg); background: var(--panel); color: var(--text); box-shadow: 0 28px 80px rgba(2, 6, 23, .48); outline: none; }
.telegram-guide-dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 24px 26px 18px; border-bottom: 1px solid var(--line); }
.telegram-guide-dialog-header h2 { margin: 5px 0 8px; font-size: clamp(1.05rem, 2vw, 1.35rem); }
.telegram-guide-dialog-header p { max-width: 58ch; margin-bottom: 0; }
.telegram-guide-close { flex: 0 0 auto; width: 38px; height: 38px; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--muted); background: transparent; }
.telegram-guide-close:hover { border-color: var(--danger); color: var(--danger-strong); background: var(--danger-soft); }
.telegram-guide-close:focus-visible { border-color: var(--accent); color: var(--accent-strong); box-shadow: 0 0 0 3px var(--accent-soft); }
.telegram-guide-body { overflow: auto; padding: 22px 26px; }
.telegram-guide-steps { display: grid; gap: 15px; margin: 0; padding: 0; list-style: none; counter-reset: guide-step; }
.telegram-guide-steps li { position: relative; padding: 14px 16px 14px 52px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-soft); line-height: 1.52; }
.telegram-guide-steps li::before { content: counter(guide-step); counter-increment: guide-step; position: absolute; top: 14px; left: 16px; display: grid; width: 24px; height: 24px; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-family: 'Orbitron', sans-serif; font-size: .68rem; font-weight: 800; }
.telegram-guide-steps strong { color: var(--text); }
.telegram-guide-steps a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 3px; }
.telegram-guide-steps code, .telegram-guide-callout code { display: inline; padding: 2px 5px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); color: var(--accent-strong); font-size: .82em; overflow-wrap: anywhere; }
.telegram-guide-callout { margin-top: 18px; padding: 13px 15px; border: 1px solid var(--accent); border-radius: var(--radius-md); background: var(--accent-soft); line-height: 1.5; }
.telegram-guide-dialog-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 26px 22px; border-top: 1px solid var(--line); }
.telegram-guide-dialog-footer .btn { min-width: 112px; min-height: 42px; }
@media (max-width: 720px) {
  .telegram-grid > .card { min-height: 0; }
  .telegram-card-heading { flex-direction: column; gap: 14px; }
  .telegram-guide-trigger { width: 100%; justify-content: center; }
  .telegram-guide-backdrop { padding: 12px; }
  .telegram-guide-dialog { max-height: calc(100vh - 24px); }
  .telegram-guide-dialog-header, .telegram-guide-body { padding-left: 18px; padding-right: 18px; }
  .telegram-guide-dialog-footer { flex-direction: column-reverse; padding-left: 18px; padding-right: 18px; }
  .telegram-guide-dialog-footer .btn { width: 100%; }
}

/* Global boolean controls: retain native checkbox semantics but render settings as switches. */
label:has(> input[name="is_active"]),
label:has(> input[name="is_enabled"]) { align-items: flex-start !important; gap: 12px !important; }
label:has(> input[name="is_active"]) > input.checkbox,
label:has(> input[name="is_enabled"]) > input.checkbox,
label.card.card-compact:has(> input[name="role_ids[]"]) > input.checkbox {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 48px;
  height: 28px;
  min-width: 48px;
  min-height: 28px;
  flex: 0 0 48px;
  margin: 1px 0 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--line-strong) radial-gradient(circle at 14px 50%, var(--panel) 0 8px, transparent 8.5px);
  box-shadow: inset 0 1px 2px rgba(2, 8, 23, .24);
  cursor: pointer;
  transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
}
label:has(> input[name="is_active"]) > input.checkbox:checked,
label:has(> input[name="is_enabled"]) > input.checkbox:checked,
label.card.card-compact:has(> input[name="role_ids[]"]) > input.checkbox:checked {
  border-color: var(--accent-strong);
  background-color: var(--accent);
  background-image: radial-gradient(circle at 34px 50%, #fff 0 8px, transparent 8.5px);
  box-shadow: inset 0 1px 2px rgba(120, 53, 15, .18), 0 0 0 2px var(--accent-soft);
}
label:has(> input[name="is_active"]) > input.checkbox:focus-visible,
label:has(> input[name="is_enabled"]) > input.checkbox:focus-visible,
label.card.card-compact:has(> input[name="role_ids[]"]) > input.checkbox:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label:has(> input[name="is_active"]) > span:last-child,
label:has(> input[name="is_enabled"]) > span:last-child { min-width: 0; }
label.card.card-compact:has(> input[name="role_ids[]"]) {
  display: grid !important;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
  row-gap: 4px;
  min-height: 86px;
  padding: 16px 18px !important;
}
label.card.card-compact:has(> input[name="role_ids[]"]) > input.checkbox { grid-column: 1; grid-row: 1 / span 2; }
label.card.card-compact:has(> input[name="role_ids[]"]) > strong { grid-column: 2; grid-row: 1; }
label.card.card-compact:has(> input[name="role_ids[]"]) > br { display: none; }
label.card.card-compact:has(> input[name="role_ids[]"]) > small { grid-column: 2; grid-row: 2; }
@media (max-width: 720px) {
  label.card.card-compact:has(> input[name="role_ids[]"]) { min-height: 78px; }
}

/* Permission capabilities are boolean settings; render them as switches too. */
label:has(> input[name="permission_ids[]"]) {
  display: grid !important;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
  row-gap: 4px;
  min-height: 76px;
  padding: 15px 18px !important;
}
label:has(> input[name="permission_ids[]"]) > input.checkbox {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 48px;
  height: 28px;
  min-width: 48px;
  min-height: 28px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--line-strong) radial-gradient(circle at 14px 50%, var(--panel) 0 8px, transparent 8.5px);
  box-shadow: inset 0 1px 2px rgba(2, 8, 23, .24);
  cursor: pointer;
  transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
}
label:has(> input[name="permission_ids[]"]) > input.checkbox:checked {
  border-color: var(--accent-strong);
  background-color: var(--accent);
  background-image: radial-gradient(circle at 34px 50%, #fff 0 8px, transparent 8.5px);
  box-shadow: inset 0 1px 2px rgba(120, 53, 15, .18), 0 0 0 2px var(--accent-soft);
}
label:has(> input[name="permission_ids[]"]) > input.checkbox:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label:has(> input[name="permission_ids[]"]) > strong { grid-column: 2; grid-row: 1; }
label:has(> input[name="permission_ids[]"]) > br { display: none; }
label:has(> input[name="permission_ids[]"]) > small { grid-column: 2; grid-row: 2; }

/* Roles & Permissions: clear selection, edit context, and compact capability cards. */
.roles-layout { align-items: start; gap: 22px; }
.roles-layout > .card { min-width: 0; }
.role-card { position: relative; display: block; margin: 10px 0; border-color: var(--line); transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.role-card:hover { border-color: var(--accent); background: var(--panel); box-shadow: 0 10px 24px rgba(2, 8, 23, .18); transform: translateY(-1px); }
.role-card:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.role-card.is-selected { border-color: var(--accent); background: linear-gradient(135deg, var(--panel), var(--panel-soft)); box-shadow: inset 3px 0 0 var(--accent), 0 10px 25px rgba(2, 8, 23, .14); }
.role-card.is-selected::after { content: 'Editing'; position: absolute; top: 14px; right: 16px; padding: 4px 8px; border: 1px solid var(--accent-border); border-radius: 999px; color: var(--accent-strong); background: var(--accent-soft); font-family: 'Orbitron', sans-serif; font-size: .58rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.role-card.is-selected .split { padding-right: 74px; }
.role-editor-card { overflow: visible; }
.role-editor-card > .section-header { margin-bottom: 16px; }
.role-meta-panel { margin-bottom: 18px; }
.role-protected-note { margin: 0 0 18px; line-height: 1.45; }
.role-meta-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; margin-bottom: 18px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-soft); }
.role-meta-form .field { min-width: 0; }
.role-meta-form .role-meta-description { grid-column: 1 / -1; }
.role-meta-form textarea.input { min-height: 68px; resize: vertical; }
.role-meta-form .form-actions { grid-column: 1 / -1; justify-content: flex-end; margin-top: 2px; padding-top: 12px; border-top: 1px solid var(--line); }
.role-editor-card > form:not(.role-meta-form) { margin-top: 0; }
.permission-switch-card { margin: 9px 0 !important; }
@media (max-width: 900px) {
  .roles-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 620px) {
  .role-meta-form { grid-template-columns: minmax(0, 1fr); }
  .role-meta-form .role-meta-description, .role-meta-form .form-actions { grid-column: auto; }
  .role-card.is-selected::after { top: 12px; right: 12px; }
  .role-card.is-selected .split { padding-right: 66px; }
}

/* Create custom role: compact, aligned, and independent from the long permission editor. */
.roles-layout > .card:first-child { align-self: start; }
.create-role-form { display: grid; gap: 12px; margin-top: 16px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-soft); }
.create-role-form .field { display: grid; gap: 6px; min-width: 0; }
.create-role-form .field label { min-height: 18px; margin: 0; font-size: .74rem; font-weight: 700; letter-spacing: .03em; }
.create-role-form .input { width: 100%; height: 46px; min-height: 46px; padding: 10px 13px; }
.create-role-form textarea.input { height: 78px; min-height: 78px; resize: vertical; }
.create-role-form .btn { justify-self: start; min-height: 42px; padding: 10px 16px; }
.roles-layout > .card:first-child > hr.divider { margin: 22px 0 18px; }
.roles-layout > .card:first-child > h3 { margin-bottom: 0; }
@media (max-width: 900px) {
  .create-role-form { padding: 14px; }
}
@media (max-width: 620px) {
  .create-role-form .btn { width: 100%; }
}

/* Final create-role geometry: never stretch the left card to the permission editor height. */
.roles-layout { align-items: start !important; grid-auto-rows: max-content; }
.roles-layout > .card,
.roles-layout > .card:first-child { align-self: start !important; height: fit-content !important; min-height: 0 !important; }
.roles-layout > .card:first-child { overflow: visible; }

/* Telegram test notification action: visible, intentional, and responsive. */
.telegram-test-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.telegram-test-actions form { margin: 0; }
.telegram-test-actions .btn { min-height: 42px; }
.telegram-test-disabled { display: block; flex-basis: 100%; margin-top: -2px; line-height: 1.4; }
@media (max-width: 620px) {
  .telegram-test-actions { align-items: stretch; flex-direction: column; }
  .telegram-test-actions form, .telegram-test-actions .btn { width: 100%; }
}

/* Alert summary cards: semantic icons, consistent geometry, and readable hierarchy. */
.rule-health { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; gap: 20px; margin-bottom: 24px; }
.health-card { min-height: 142px; padding: 20px; gap: 16px; align-items: center; border-radius: var(--radius-lg); }
.health-card > .health-icon { display: grid; width: 50px; height: 50px; min-width: 50px; flex: 0 0 50px; margin: 0; place-items: center; border-radius: 15px; }
.health-card > .health-icon .ui-icon { display: block; width: 24px; height: 24px; margin: 0; }
.health-card > div { min-width: 0; display: grid; gap: 5px; align-content: center; }
.health-card strong { font-size: 1.55rem; line-height: 1.05; letter-spacing: -.02em; }
.health-card > div > span { display: block; margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.35; }
@media (max-width: 980px) {
  .rule-health { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .health-card { padding: 16px; gap: 12px; }
  .health-card > .health-icon { width: 44px; height: 44px; min-width: 44px; flex-basis: 44px; border-radius: 13px; }
  .health-card > .health-icon .ui-icon { width: 21px; height: 21px; }
}
@media (max-width: 720px) {
  .rule-health { grid-template-columns: 1fr; gap: 12px; }
  .health-card { min-height: 96px; }
}

/* Alerts filter panel: clear heading hierarchy, aligned controls, and intentional actions. */
.filter-panel { padding: 22px; }
.filter-panel .filter-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.filter-panel .filter-heading > div:first-child { min-width: 0; }
.filter-panel .filter-heading .eyebrow { margin-bottom: 8px; }
.filter-panel .filter-heading strong { display: block; margin-bottom: 5px; font-family: 'Orbitron', sans-serif; font-size: 1.05rem; line-height: 1.2; }
.filter-panel .filter-heading .subtle { margin: 0; }
.filter-panel .filter-hint { flex: 0 0 auto; margin-top: 2px; color: var(--muted-strong); font-size: .75rem; white-space: nowrap; }
.alerts-filter-form { display: grid !important; grid-template-columns: minmax(240px, 1.25fr) minmax(180px, .95fr) minmax(200px, 1fr) auto auto; align-items: end; gap: 16px; width: 100%; }
.alerts-filter-form .field { min-width: 0; gap: 7px; }
.alerts-filter-form .field label { min-height: 19px; display: flex; align-items: center; }
.alerts-filter-form .field .input,
.alerts-filter-form .field .select,
.alerts-filter-form > .btn { width: 100%; min-height: 52px; height: 52px; }
.alerts-filter-form > .btn { min-width: 132px; justify-content: center; align-self: end; }
.alerts-filter-form > .btn.btn-ghost { min-width: 82px; border-color: transparent; background: transparent; color: var(--muted-strong); }
.alerts-filter-form > .btn.btn-ghost:hover { border-color: var(--line-strong); background: var(--panel-soft); color: var(--text); }
@media (max-width: 1040px) {
  .alerts-filter-form { grid-template-columns: minmax(220px, 1.2fr) repeat(2, minmax(160px, 1fr)); }
  .alerts-filter-form > .btn { width: auto; }
  .alerts-filter-form > .btn.btn-primary { grid-column: 1 / 3; }
  .alerts-filter-form > .btn.btn-ghost { grid-column: 3; }
}
@media (max-width: 720px) {
  .filter-panel { padding: 16px; }
  .filter-panel .filter-heading { flex-direction: column; gap: 8px; margin-bottom: 16px; }
  .filter-panel .filter-hint { white-space: normal; }
  .alerts-filter-form { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .alerts-filter-form > .btn,
  .alerts-filter-form > .btn.btn-primary,
  .alerts-filter-form > .btn.btn-ghost { grid-column: auto; width: 100%; }
}

/* Alerts filter final action-grid correction. */
.filter-panel { height: max-content !important; min-height: 0 !important; }
.alerts-filter-form { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) minmax(250px, 1.1fr) !important; align-items: end !important; }
.alerts-filter-form .filter-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(86px, .42fr); gap: 10px; min-width: 0; align-self: end; }
.alerts-filter-form .filter-actions .btn { width: 100%; min-width: 0; height: 52px; min-height: 52px; justify-content: center; }
.alerts-filter-form .filter-actions .btn.btn-ghost { border-color: transparent; background: transparent; color: var(--muted-strong); }
.alerts-filter-form .filter-actions .btn.btn-ghost:hover { border-color: var(--line-strong); background: var(--panel-soft); color: var(--text); }
.filter-panel form.alerts-filter-form { margin: 0; }
@media (max-width: 1040px) {
.alerts-filter-form { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr) !important; }
.alerts-filter-form .filter-actions { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
.alerts-filter-form { grid-template-columns: minmax(0, 1fr) !important; }
.alerts-filter-form .filter-actions { grid-column: auto; grid-template-columns: minmax(0, 1fr); }
}

/* Alerts Reset: unmistakable secondary button. */
.alerts-filter-form .filter-actions .btn.btn-ghost { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; height: 52px; padding: 0 16px; border: 1px solid var(--line-strong) !important; border-radius: var(--radius-md); background: var(--panel-soft) !important; color: var(--text) !important; box-shadow: var(--shadow-sm); font-weight: 700; text-decoration: none; transition: border-color .18s ease, background-color .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease; }
.alerts-filter-form .filter-actions .btn.btn-ghost:hover { border-color: var(--accent) !important; background: var(--accent-soft) !important; color: var(--accent-strong) !important; box-shadow: 0 8px 18px rgba(245, 158, 11, .12); transform: translateY(-1px); }
.alerts-filter-form .filter-actions .btn.btn-ghost:active { transform: translateY(0); box-shadow: none; }
.alerts-filter-form .filter-actions .btn.btn-ghost:focus-visible { outline: none; border-color: var(--accent) !important; box-shadow: 0 0 0 3px var(--accent-soft); }

/* Shared footer: align to the content column and keep clear viewport spacing. */
.page-footer { display: flex; width: 100%; min-height: 58px; box-sizing: border-box; align-items: center; gap: 8px; margin: 30px 0 0; padding: 16px clamp(20px, 3vw, 48px) 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: .76rem; line-height: 1.45; }
.page-footer span { display: inline-block; padding: 0 5px; color: var(--accent); }
.main-shell > .page-footer { flex: 0 0 auto; }
@media (max-width: 860px) {
.page-footer { min-height: 54px; margin-top: 24px; padding: 14px 16px 20px; }
}
@media (max-width: 480px) {
.page-footer { align-items: flex-start; flex-wrap: wrap; margin-top: 20px; padding-top: 13px; font-size: .7rem; }
}


/* Audit Log: aligned filters, grouped actions, and readable table geometry */
.audit-filter-form { display: grid !important; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(140px, .7fr) minmax(140px, .7fr) minmax(240px, .95fr) !important; align-items: end; gap: 16px; width: 100%; }
.audit-filter-form .field { min-width: 0; gap: 7px; }
.audit-filter-form .field .input,
.audit-filter-form .field .select { width: 100%; min-height: 52px; height: 52px; }
.audit-filter-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(104px, .55fr); gap: 10px; min-width: 0; align-self: end; }
.audit-filter-actions .btn { width: 100%; min-height: 52px; height: 52px; justify-content: center; }
.audit-filter-actions .btn.btn-ghost { border: 1px solid var(--line-strong) !important; background: var(--panel-soft) !important; color: var(--text) !important; }
.audit-filter-actions .btn.btn-ghost:hover { border-color: var(--accent) !important; background: var(--accent-soft) !important; color: var(--accent-strong) !important; }
.audit-table-wrap { width: 100%; overflow-x: auto; border-radius: 18px; }
.audit-table-wrap .data-table { table-layout: fixed; width: 100%; min-width: 1100px; }
.audit-table-wrap .data-table th:nth-child(1), .audit-table-wrap .data-table td:nth-child(1) { width: 16%; }
.audit-table-wrap .data-table th:nth-child(2), .audit-table-wrap .data-table td:nth-child(2) { width: 24%; }
.audit-table-wrap .data-table th:nth-child(3), .audit-table-wrap .data-table td:nth-child(3) { width: 20%; }
.audit-table-wrap .data-table th:nth-child(4), .audit-table-wrap .data-table td:nth-child(4) { width: 17%; }
.audit-table-wrap .data-table th:nth-child(5), .audit-table-wrap .data-table td:nth-child(5) { width: 17%; }
.audit-table-wrap .data-table th:nth-child(6), .audit-table-wrap .data-table td:nth-child(6) { width: 6%; }
.audit-table-wrap .data-table td { vertical-align: middle; overflow-wrap: anywhere; }
.audit-table-wrap .data-table td:nth-child(1), .audit-table-wrap .data-table td:nth-child(6) { white-space: nowrap; overflow-wrap: normal; }
.audit-table-wrap .data-table td:nth-child(5) { line-height: 1.45; }
@media (max-width: 1180px) { .audit-filter-form { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; } .audit-filter-actions { grid-column: span 1; } }
@media (max-width: 760px) { .audit-filter-form { grid-template-columns: 1fr !important; gap: 12px; } .audit-filter-actions { grid-template-columns: 1fr 112px; } .audit-table-wrap { margin-inline: -1px; } }

/* Audit Log v36: prevent metadata column collapse */
.audit-table-wrap .data-table { min-width: 1260px; }
.audit-table-wrap .data-table th:nth-child(1), .audit-table-wrap .data-table td:nth-child(1) { width: 14%; }
.audit-table-wrap .data-table th:nth-child(2), .audit-table-wrap .data-table td:nth-child(2) { width: 22%; }
.audit-table-wrap .data-table th:nth-child(3), .audit-table-wrap .data-table td:nth-child(3) { width: 17%; }
.audit-table-wrap .data-table th:nth-child(4), .audit-table-wrap .data-table td:nth-child(4) { width: 13%; }
.audit-table-wrap .data-table th:nth-child(5), .audit-table-wrap .data-table td:nth-child(5) { width: 26%; min-width: 300px; }
.audit-table-wrap .data-table th:nth-child(6), .audit-table-wrap .data-table td:nth-child(6) { width: 8%; min-width: 92px; }
.audit-table-wrap .data-table td:nth-child(5) { white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; min-width: 300px; }
.audit-table-wrap .data-table td:nth-child(6) { white-space: nowrap; word-break: normal; overflow-wrap: normal; }
@media (max-width: 760px) { .audit-table-wrap .data-table { min-width: 1180px; } .audit-table-wrap .data-table th:nth-child(5), .audit-table-wrap .data-table td:nth-child(5) { min-width: 280px; } }

/* Audit Log v37: explicit colgroup layout and stable detail cells */
.audit-table-wrap { width: 100%; overflow-x: auto; }
.audit-data-table { table-layout: fixed !important; width: 100%; min-width: 1180px !important; }
.audit-data-table .audit-col-time { width: 15%; }
.audit-data-table .audit-col-actor { width: 22%; }
.audit-data-table .audit-col-action { width: 17%; }
.audit-data-table .audit-col-entity { width: 13%; }
.audit-data-table .audit-col-details { width: 25%; }
.audit-data-table .audit-col-ip { width: 8%; }
.audit-data-table tbody tr { height: auto !important; }
.audit-data-table td { vertical-align: middle; }
.audit-data-table .audit-details { min-width: 0 !important; }
.audit-data-table .audit-details code { display: block; min-width: 0; max-width: 100%; color: var(--muted-strong); font-family: var(--font-mono); font-size: .78rem; line-height: 1.45; white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; }
.audit-data-table .audit-ip { min-width: 0 !important; white-space: nowrap; word-break: normal; overflow-wrap: normal; }
@media (max-width: 760px) { .audit-data-table { min-width: 1100px !important; } .audit-data-table .audit-details code { font-size: .74rem; } }

/* Audit Log v38: keep semantic table cells as table cells */
.audit-data-table td.audit-time,
.audit-data-table td.audit-details,
.audit-data-table td.audit-ip { display: table-cell !important; }
.audit-data-table td.audit-time .table-secondary { display: block; margin-top: 0; white-space: nowrap; }
.audit-data-table td.audit-details { color: var(--muted-strong); vertical-align: top; }
.audit-data-table td.audit-details code { display: block; width: 100%; max-width: none; min-width: 0; padding: 0; color: inherit; font-family: var(--font-mono); font-size: .78rem; line-height: 1.45; letter-spacing: 0; white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; }
.audit-data-table td.audit-ip { vertical-align: top; }

/* Shared shell v39: sticky topbar and footer with independent content scroll */
.app-shell { min-height: 100vh; height: 100vh; overflow: hidden; }
.main-content { min-height: 0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.topbar { position: sticky; top: 0; z-index: 40; flex: 0 0 auto; background: var(--bg); box-shadow: 0 1px 0 var(--line); }
.page-content { flex: 1 1 auto; min-height: 0; overflow-y: auto !important; overflow-x: hidden; overscroll-behavior: contain; scrollbar-gutter: stable; }
.page-footer { position: sticky; bottom: 0; z-index: 35; flex: 0 0 auto; margin-top: 0; background: var(--bg); box-shadow: 0 -8px 20px color-mix(in srgb, var(--bg) 80%, transparent); }
@media (max-width: 860px) { .app-shell { height: 100dvh; } .main-content { height: 100dvh; } .topbar { z-index: 50; } .page-content { padding-bottom: 32px; } .page-footer { padding-bottom: max(20px, env(safe-area-inset-bottom)); } }
