/* App-specific stylesheets for Load Balancer Dashboard (AdminLTE 4 theme) */

:root {
  /* Spacing */
  --space-0-5: 0.125rem;
  --space-1: 0.25rem;
  --space-1-5: 0.375rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-xs: 0.25rem;
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Semantic colors */
  --accent-base: #4f46e5;
  --accent-hover: #4338ca;
  --accent-subtle: #eef2ff;
  --accent-solid: #4f46e5;
  --border-dim: var(--bs-border-color, #e2e8f0);
  --border-focus: #818cf8;
  --bg-surface: var(--bs-body-bg, #ffffff);
  --bg-subtle: var(--bs-tertiary-bg, #f8fafc);
  --bg-muted: var(--bs-secondary-bg, #f1f5f9);
  --text-main: var(--bs-body-color, #0f172a);
  --text-muted: var(--bs-secondary-color, #64748b);

  /* Bootstrap 5.3 Primary & Link Theming (APIN-113) */
  --bs-primary: #4f46e5;
  --bs-primary-rgb: 79, 70, 229;
  --bs-link-color: #4f46e5;
  --bs-link-color-rgb: 79, 70, 229;
  --bs-link-hover-color: #4338ca;
  --bs-link-hover-color-rgb: 67, 56, 202;
  --bs-code-color: #b91c1c;

  --danger-base: #dc2626;
  --danger-subtle: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;

  --warning-base: #d97706;
  --warning-subtle: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;

  --notice-line: #bfdbfe;
  --notice-bg: #eff6ff;
  --notice-text: #1e40af;
}

:root[data-theme="dark"], [data-bs-theme="dark"] {
  --accent-base: #4f46e5;
  --accent-hover: #4338ca;
  --accent-subtle: rgba(99, 102, 241, 0.15);
  --accent-solid: #4f46e5;
  --border-dim: var(--bs-border-color, #334155);
  --border-focus: #818cf8;
  --bg-surface: var(--bs-body-bg, #111827);
  --bg-subtle: var(--bs-tertiary-bg, #1e293b);
  --bg-muted: var(--bs-secondary-bg, #1e293b);
  --text-main: var(--bs-body-color, #f8fafc);
  --text-muted: var(--bs-secondary-color, #cbd5e1);
  --bs-secondary-color: #cbd5e1;
  --bs-secondary-color-rgb: 203, 213, 225;

  /* Bootstrap 5.3 Primary & Link Theming Dark Mode (APIN-113) */
  --bs-primary: #a5b4fc;
  --bs-primary-rgb: 165, 180, 252;
  --bs-link-color: #a5b4fc;
  --bs-link-color-rgb: 165, 180, 252;
  --bs-link-hover-color: #c7d2fe;
  --bs-link-hover-color-rgb: 199, 210, 254;
  --bs-code-color: #fca5a5;
  --bs-focus-ring-color: rgba(165, 180, 252, 0.25);

  --danger-subtle: rgba(220, 38, 38, 0.15);
  --danger-border: rgba(239, 68, 68, 0.4);
  --danger-text: #fca5a5;

  --warning-subtle: rgba(217, 119, 6, 0.15);
  --warning-border: rgba(245, 158, 11, 0.4);
  --warning-text: #fcd34d;

  --notice-line: #1e3a8a;
  --notice-bg: rgba(30, 58, 138, 0.25);
  --notice-text: #93c5fd;
}

/* APIN-104 touch target compliance & theme toggle (verified in core/tests.py) */
.public-header .theme-toggle {
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 0.5rem;
  color: var(--bs-secondary-color, #64748b);
  background: transparent;
  border: 1px solid var(--bs-border-color, #e2e8f0);
}
.theme-toggle { display: grid; width: 2.25rem; height: 2.25rem; place-items: center; border-radius: 0.5rem; color: #94a3b8; background: transparent; border: 1px solid rgba(255, 255, 255, 0.15); cursor: pointer; transition: 150ms ease; }
.theme-toggle:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.theme-toggle i, .theme-icon { font-size: 1.1rem; line-height: 1; }

/* Public shell styling for login page */
.public-shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--bs-body-bg, #f8fafc); }
.public-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; border-bottom: 1px solid var(--bs-border-color, #e2e8f0); background: var(--bs-body-bg, #fff); }
.public-content { flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.public-footer { padding: 1rem; text-align: center; font-size: 0.8125rem; color: var(--bs-secondary-color, #64748b); border-top: 1px solid var(--bs-border-color, #e2e8f0); background: var(--bs-body-bg, #fff); }
.public-card { width: 100%; max-width: 28rem; background: var(--bs-body-bg, #fff); border: 1px solid var(--bs-border-color, #e2e8f0); border-radius: 0.75rem; padding: 2rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08); }

/* Brand styling */
.brand { display: flex; align-items: center; gap: 0.75rem; color: inherit; text-decoration: none; }
.brand-mark { display: grid; width: 2.25rem; height: 2.25rem; min-width: 2.25rem; flex: 0 0 2.25rem; place-items: center; border-radius: 0.5rem; color: #fff; background: linear-gradient(135deg, #6366f1, #4f46e5); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.04em; }

/* Environment badges (verified in core/tests.py) */
.environment-badge { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.35rem 0.65rem; border: 1px solid #3f3f46; border-radius: 9999px; color: #d4d4d8; background: #27272a; font-size: 0.75rem; font-weight: 600; }
.environment-badge span { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 0.2rem rgba(34, 197, 94, 0.2); }
.environment-badge.environment-badge-production { border-color: #be123c; color: #ffe4e6; background: rgba(190, 18, 60, 0.25); }
.environment-badge.environment-badge-production span { background: #f43f5e; box-shadow: 0 0 0 0.2rem rgba(244, 63, 94, 0.3); }

/* App Header & Sidebar Brand alignment (APIN-113) */
.app-header,
.sidebar-brand {
  height: 3.5rem !important;
  min-height: 3.5rem !important;
  max-height: 3.5rem !important;
  box-sizing: border-box;
}

.app-header {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  display: flex !important;
  align-items: center !important;
}

.app-header .container-fluid {
  height: 100%;
  display: flex;
  align-items: center;
}

.sidebar-brand {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  padding: 0 1rem !important;
  border-bottom: 1px solid var(--bs-border-color-translucent, var(--bs-border-color)) !important;
}

.sidebar-brand .brand-link {
  height: 100%;
  width: 100%;
  display: flex !important;
  align-items: center !important;
  gap: 0.75rem !important;
  text-decoration: none;
  margin: 0;
  padding: 0;
}

.sidebar-brand .brand-text,
.public-header .brand-text {
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  line-height: 1.15 !important;
  margin-left: 0 !important;
}

.sidebar-brand .brand-text strong,
.public-header .brand-text strong {
  font-size: 0.95rem !important;
  font-weight: 700 !important;
  line-height: 1.15 !important;
  margin: 0 !important;
}

.sidebar-brand .brand-text small,
.public-header .brand-text small {
  font-size: 0.72rem !important;
  line-height: 1.1 !important;
  margin-top: 2px !important;
}

/* Sidebar navigation item styling (verified in core/test_navigation.py) */
.app-sidebar {
  min-height: 100vh;
  height: 100%;
  --bs-secondary-color: #cbd5e1;
  --bs-secondary-color-rgb: 203, 213, 225;
}
.sidebar-wrapper { min-height: 0; height: 100%; }
.app-sidebar .sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; }
.app-sidebar .nav-header { padding: 0.75rem 1rem 0.25rem; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: #cbd5e1; }
.app-sidebar a.nav-item, .app-sidebar span.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem;
  border-radius: 0.375rem;
  color: #cbd5e1;
  font-weight: 500;
  font-size: 0.875rem;
  text-decoration: none;
  transition: background 150ms ease, color 150ms ease;
}
.app-sidebar a.nav-item .nav-text,
.app-sidebar a.nav-item .nav-icon {
  color: #cbd5e1;
}
.app-sidebar a.nav-item:hover { color: #fff; background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.app-sidebar a.nav-item:hover .nav-text,
.app-sidebar a.nav-item:hover .nav-icon {
  color: #fff;
}
.app-sidebar a.nav-item.is-active {
  color: #fff;
  background-color: #4f46e5;
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.25);
}
.app-sidebar a.nav-item.is-active:hover {
  background-color: #4338ca;
}
.app-sidebar a.nav-item.is-active .nav-text,
.app-sidebar a.nav-item.is-active .nav-icon {
  color: #ffffff;
}
.app-sidebar .nav-icon { display: grid; width: 1.5rem; height: 1.5rem; place-items: center; font-size: 0.9rem; flex-shrink: 0; }
.app-sidebar .nav-badge { margin-left: auto; font-size: 0.75rem; padding: 0.2em 0.55em; border-radius: 9999px; background: #f59e0b; color: #000; font-weight: 700; }
.app-sidebar .sidebar-user { padding: 0.75rem 1rem; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.app-header .avatar { background-color: #4f46e5; color: #ffffff; }
.app-sidebar .avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #ffffff; background: #4338ca; font-weight: 700; width: 34px; height: 34px; font-size: 0.85rem; }
.app-sidebar .user-copy { min-width: 0; }
.app-sidebar .user-copy strong, .app-sidebar .user-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-sidebar .user-copy strong { font-size: 0.8rem; color: #f8fafc; }
.app-sidebar .user-copy small { color: #cbd5e1; font-size: 0.75rem; }
.app-sidebar .sidebar-tenant-chip { font-size: 0.75rem; color: #38bdf8; text-decoration: none; }
.app-sidebar .sidebar-tenant-chip:hover { text-decoration: underline; }
.app-sidebar .sidebar-brand .brand-text small,
.app-sidebar .sidebar-user-text small,
.app-sidebar .sidebar-user-text .text-secondary,
.app-sidebar .text-secondary {
  color: #cbd5e1;
}
.app-sidebar .icon-button { background: transparent; border: 1px solid rgba(255, 255, 255, 0.2); color: #cbd5e1; border-radius: 0.375rem; padding: 0.25rem 0.5rem; cursor: pointer; }
.app-sidebar .icon-button:hover { background: rgba(239, 68, 68, 0.2); color: #ef4444; border-color: #ef4444; }

/* Sidebar Collapsed State Rules (APIN-113) */
.sidebar-collapse .app-sidebar .sidebar-env-badge,
.sidebar-collapse .app-sidebar .brand-text,
.sidebar-collapse .app-sidebar .nav-text,
.sidebar-collapse .app-sidebar .nav-label,
.sidebar-collapse .app-sidebar .nav-badge,
.sidebar-collapse .app-sidebar .sidebar-user-text,
.sidebar-collapse .app-sidebar .sidebar-user-logout {
  display: none !important;
}

.sidebar-collapse .app-sidebar .sidebar-brand {
  padding: 0 !important;
  text-align: center;
  justify-content: center !important;
}

.sidebar-collapse .app-sidebar .brand-link {
  justify-content: center !important;
  padding: 0 !important;
  gap: 0 !important;
}

.sidebar-collapse .app-sidebar .nav-link,
.sidebar-collapse .app-sidebar .nav-item {
  justify-content: center;
  padding: 0.65rem 0 !important;
}

.sidebar-collapse .app-sidebar .sidebar-user {
  justify-content: center;
  padding: 0.75rem 0 !important;
  display: flex !important;
}
.sidebar-collapse .app-sidebar .sidebar-user > .d-flex {
  justify-content: center;
  width: 100%;
}

.user-menu .dropdown-menu {
  min-width: 240px;
  margin-top: 0.5rem !important;
  margin-right: 0.5rem !important;
}

/* Status pills and semantic tags (verified in configuration tests) */
.status-pill { display: inline-flex; align-items: center; padding: 0.2rem 0.6rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; border: 1px solid transparent; }
.status-pill.status-draft { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.status-pill.status-submitted { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.status-pill.status-approved { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.status-pill.status-rejected { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.status-pill.status-production { background: #fff1f2; color: #be123c; border-color: #fecdd3; }
.status-pill.status-verified { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.status-pill.status-active { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }

.badge-tag { display: inline-block; padding: 0.15rem 0.45rem; border-radius: 0.25rem; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em; }
.badge-tag.badge-production { background: #be123c; color: #fff; }

/* Sub-nav tabs (verified in core/test_navigation.py) */
.sub-nav { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--bs-border-color, #dee2e6); }
.sub-nav-item { display: inline-flex; align-items: center; padding: 0.4rem 0.85rem; border-radius: 0.375rem; font-size: 0.85rem; font-weight: 550; color: var(--bs-secondary-color, #64748b); text-decoration: none; border: 1px solid transparent; background: transparent; transition: 150ms ease; }
.sub-nav-item:hover { color: var(--bs-body-color, #0f172a); background: var(--bs-tertiary-bg, #f1f5f9); text-decoration: none; }
.sub-nav-item.is-active { color: #fff !important; background: var(--accent-base) !important; border-color: var(--accent-base) !important; }

/* Empty state and event details (verified in tests) */
.empty-state { padding: 2rem; text-align: center; color: var(--bs-secondary-color, #64748b); font-size: 0.9rem; }
.form-fieldset { border: none; padding: 0; margin: 0 0 1rem 0; }
.form-legend { display: block; margin-bottom: 0.5rem; font-weight: 600; font-size: 0.85rem; }
.event-details { padding: 0.75rem 1rem; border-radius: 0.375rem; background: var(--bs-tertiary-bg, #f8fafc); border: 1px solid var(--bs-border-color, #dee2e6); margin-top: 0.5rem; font-size: 0.85rem; }

/* Button and action-bar aliases */
.button-primary, a.button-primary, button.button-primary, .button-link.button-primary { display: inline-flex; align-items: center; justify-content: center; padding: 0.375rem 0.85rem; font-size: 0.875rem; font-weight: 600; border-radius: 0.375rem; color: #fff !important; background-color: var(--accent-base); border: 1px solid var(--accent-base); text-decoration: none; cursor: pointer; }
.button-primary:hover, a.button-primary:hover, button.button-primary:hover, .button-link.button-primary:hover { background-color: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.button-primary:active, a.button-primary:active, button.button-primary:active, .button-link.button-primary:active { background-color: #3730a3; border-color: #3730a3; }

.button-secondary, a.button-secondary, button.button-secondary, .button-link.button-secondary { display: inline-flex; align-items: center; justify-content: center; padding: 0.375rem 0.85rem; font-size: 0.875rem; font-weight: 600; border-radius: 0.375rem; color: var(--bs-body-color, #212529) !important; background-color: var(--bs-body-bg, #fff) !important; border: 1px solid var(--bs-border-color, #dee2e6) !important; text-decoration: none; cursor: pointer; }
.button-secondary:hover, a.button-secondary:hover, button.button-secondary:hover, .button-link.button-secondary:hover { background-color: var(--bs-tertiary-bg, #f8f9fa) !important; border-color: #c6c7c8 !important; text-decoration: none !important; }

/* Primary Button Theming (APIN-113) */
.btn-primary {
  --bs-btn-color: #ffffff;
  --bs-btn-bg: #4f46e5;
  --bs-btn-border-color: #4f46e5;
  --bs-btn-hover-color: #ffffff;
  --bs-btn-hover-bg: #4338ca;
  --bs-btn-hover-border-color: #4338ca;
  --bs-btn-focus-shadow-rgb: 79, 70, 229;
  --bs-btn-active-color: #ffffff;
  --bs-btn-active-bg: #3730a3;
  --bs-btn-active-border-color: #3730a3;
  --bs-btn-disabled-color: #ffffff;
  --bs-btn-disabled-bg: #4f46e5;
  --bs-btn-disabled-border-color: #4f46e5;
}
[data-bs-theme="dark"] .btn-primary {
  --bs-btn-color: #ffffff;
  --bs-btn-bg: #4f46e5;
  --bs-btn-border-color: #4f46e5;
  --bs-btn-hover-color: #ffffff;
  --bs-btn-hover-bg: #4338ca;
  --bs-btn-hover-border-color: #4338ca;
  --bs-btn-focus-shadow-rgb: 79, 70, 229;
  --bs-btn-active-color: #ffffff;
  --bs-btn-active-bg: #3730a3;
  --bs-btn-active-border-color: #3730a3;
  --bs-btn-disabled-color: #ffffff;
  --bs-btn-disabled-bg: #4f46e5;
  --bs-btn-disabled-border-color: #4f46e5;
}

/* Outline Primary Button Theming (APIN-113 E5) */
.btn-outline-primary {
  --bs-btn-color: #4f46e5;
  --bs-btn-border-color: #4f46e5;
  --bs-btn-hover-color: #ffffff;
  --bs-btn-hover-bg: #4f46e5;
  --bs-btn-hover-border-color: #4f46e5;
  --bs-btn-focus-shadow-rgb: 79, 70, 229;
  --bs-btn-active-color: #ffffff;
  --bs-btn-active-bg: #4338ca;
  --bs-btn-active-border-color: #4338ca;
}
[data-bs-theme="dark"] .btn-outline-primary {
  --bs-btn-color: #a5b4fc;
  --bs-btn-border-color: #a5b4fc;
  --bs-btn-hover-color: #ffffff;
  --bs-btn-hover-bg: #4f46e5;
  --bs-btn-hover-border-color: #4f46e5;
  --bs-btn-focus-shadow-rgb: 165, 180, 252;
  --bs-btn-active-color: #ffffff;
  --bs-btn-active-bg: #3730a3;
  --bs-btn-active-border-color: #3730a3;
}

/* Outline Secondary Button Contrast in Light & Dark Mode (APIN-113) */
.btn-outline-secondary {
  --bs-btn-color: #475569;
  --bs-btn-border-color: #64748b;
  --bs-btn-hover-color: #ffffff;
  --bs-btn-hover-bg: #475569;
  --bs-btn-hover-border-color: #475569;
  --bs-btn-focus-shadow-rgb: 100, 116, 139;
  --bs-btn-active-color: #ffffff;
  --bs-btn-active-bg: #334155;
  --bs-btn-active-border-color: #334155;
}
[data-bs-theme="dark"] .btn-outline-secondary {
  --bs-btn-color: #cbd5e1;
  --bs-btn-border-color: #94a3b8;
  --bs-btn-hover-color: #ffffff;
  --bs-btn-hover-bg: #475569;
  --bs-btn-hover-border-color: #cbd5e1;
  --bs-btn-focus-shadow-rgb: 148, 163, 184;
  --bs-btn-active-color: #ffffff;
  --bs-btn-active-bg: #334155;
  --bs-btn-active-border-color: #cbd5e1;
}

/* Form controls & checks indigo theming (APIN-113 E5) */
.form-check-input:checked {
  background-color: #4f46e5;
  border-color: #4f46e5;
}
.form-check-input:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.25);
}
.form-control:focus, .form-select:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.25);
}
[data-bs-theme="dark"] .form-check-input:checked {
  background-color: #4f46e5;
  border-color: #6366f1;
}
[data-bs-theme="dark"] .form-check-input:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.25);
}

/* Links Theming & Contrast (APIN-113) */
.app-main a:not(.btn):not(.button-primary):not(.button-secondary):not(.button-danger):not(.sub-nav-item):not(.badge):not(.nav-link):not(.dropdown-item),
.public-shell a:not(.btn):not(.button-primary):not(.button-secondary):not(.button-danger):not(.badge):not(.brand) {
  color: var(--bs-link-color, #4f46e5);
}
.app-main a:not(.btn):not(.button-primary):not(.button-secondary):not(.button-danger):not(.sub-nav-item):not(.badge):not(.nav-link):not(.dropdown-item):hover,
.public-shell a:not(.btn):not(.button-primary):not(.button-secondary):not(.button-danger):not(.badge):not(.brand):hover {
  color: var(--bs-link-hover-color, #4338ca);
}
[data-bs-theme="dark"] .app-main a:not(.btn):not(.button-primary):not(.button-secondary):not(.button-danger):not(.sub-nav-item):not(.badge):not(.nav-link):not(.dropdown-item) {
  color: #a5b4fc;
}
[data-bs-theme="dark"] .app-main a:not(.btn):not(.button-primary):not(.button-secondary):not(.button-danger):not(.sub-nav-item):not(.badge):not(.nav-link):not(.dropdown-item):hover {
  color: #c7d2fe;
}

/* Accessibility & Contrast Utilities (APIN-113) */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  background: #4f46e5;
  color: #ffffff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  z-index: 10000;
  font-weight: 600;
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 1rem;
  background: #4f46e5;
  color: #ffffff;
}

code {
  color: var(--bs-code-color, #b91c1c);
}
[data-bs-theme="dark"] code {
  color: var(--bs-code-color, #fca5a5);
}

[data-bs-theme="dark"] .bg-primary {
  background-color: #4f46e5;
  color: #ffffff;
}

[data-bs-theme="dark"] .sub-nav-item {
  color: #cbd5e1;
}
[data-bs-theme="dark"] .sub-nav-item:hover {
  color: #ffffff;
  background: var(--bs-tertiary-bg, #1e293b);
}

[data-bs-theme="dark"] .back-link {
  color: #a5b4fc;
}

.button-sm { padding: 0.25rem 0.5rem; font-size: 0.8125rem; }
.action-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 1rem 0; }
form[action*="delete"] button, form[action*="disable"] button, form[action*="revoke"] button, form[action*="retire"] button, form[action*="cleanup"] button, form[action*="rollback"] button { color: #b91c1c; border-color: #fecaca; background-color: #fef2f2; }
form[action*="delete"] button:hover, form[action*="disable"] button:hover, form[action*="revoke"] button:hover, form[action*="retire"] button:hover, form[action*="cleanup"] button:hover, form[action*="rollback"] button:hover { background-color: #fee2e2; border-color: #ef4444; }

/* Dashboard layout grid and metric cards */
.dashboard-header { margin-bottom: 1.5rem; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.metric-card { background: var(--bs-body-bg, #fff); border: 1px solid var(--bs-border-color, #dee2e6); border-radius: 0.5rem; padding: 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.metric-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.metric-desc { margin-top: 0.5rem; font-size: 0.8125rem; color: var(--bs-secondary-color, #6c757d); margin-bottom: 0; }
.quick-actions-card { margin-top: 1.5rem; padding: 1.5rem; background: var(--bs-body-bg, #fff); border: 1px solid var(--bs-border-color, #dee2e6); border-radius: 0.5rem; }
.quick-actions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-top: 1rem; }
.quick-action-item { display: flex; align-items: flex-start; gap: 0.75rem; padding: 1rem; border: 1px solid var(--bs-border-color, #dee2e6); border-radius: 0.5rem; text-decoration: none; color: inherit; transition: 150ms ease; }
.quick-action-item:hover { border-color: var(--bs-primary, #4f46e5); background: var(--bs-tertiary-bg, #f8f9fa); text-decoration: none; }
.action-icon { font-size: 1.25rem; display: grid; width: 2.25rem; height: 2.25rem; place-items: center; background: #eef2ff; color: #4338ca; border-radius: 0.375rem; flex-shrink: 0; }
:root[data-theme="dark"] .action-icon, [data-bs-theme="dark"] .action-icon, body.dark-mode .action-icon { background: rgba(99, 102, 241, 0.2); color: #c7d2fe; }
.action-text strong { display: block; font-size: 0.95rem; }
.action-text small { color: var(--bs-secondary-color, #6c757d); font-size: 0.8125rem; }

/* Data tables */
.table-container { overflow-x: auto; margin: 1rem 0; border: 1px solid var(--bs-border-color, #dee2e6); border-radius: 0.5rem; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; margin-bottom: 0; }
.data-table th, .data-table td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--bs-border-color, #dee2e6); text-align: left; }
.data-table th { background: var(--bs-tertiary-bg, #f8f9fa); font-weight: 600; color: var(--bs-secondary-color, #6c757d); }
.data-table tr:hover { background: rgba(0, 0, 0, 0.02); }
.table-title-link { color: inherit; text-decoration: none; }
.table-title-link:hover { color: var(--bs-link-hover-color, #4338ca); text-decoration: underline; }
.table-subtitle { display: block; font-size: 0.75rem; color: var(--bs-secondary-color, #6c757d); }
.table-cell-mono { font-family: monospace; font-size: 0.8125rem; }
.table-col-actions { text-align: right; }

/* Bootstrap table headers with theme-aware background & secondary text */
.table > thead {
  --bs-table-bg: var(--bs-tertiary-bg);
  --bs-table-color: var(--bs-secondary-color);
  background-color: var(--bs-tertiary-bg);
}
.table > thead > tr > th {
  background-color: var(--bs-tertiary-bg);
  color: var(--bs-secondary-color);
  font-weight: 600;
  border-bottom: 1px solid var(--bs-border-color-translucent, var(--bs-border-color));
}

/* Topbar indicators */
.topbar-status { display: inline-flex; align-items: center; font-size: 0.75rem; font-weight: 600; padding: 0.25rem 0.6rem; border-radius: 9999px; background: rgba(34, 197, 94, 0.1); color: #166534; border: 1px solid rgba(34, 197, 94, 0.25); }
.topbar-status.topbar-status-production { background: rgba(239, 68, 68, 0.1); color: #991b1b; border-color: rgba(239, 68, 68, 0.25); }
:root[data-theme="dark"] .topbar-status,
[data-bs-theme="dark"] .topbar-status,
body.dark-mode .topbar-status {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.3);
}
:root[data-theme="dark"] .topbar-status.topbar-status-production,
[data-bs-theme="dark"] .topbar-status.topbar-status-production,
body.dark-mode .topbar-status.topbar-status-production {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(252, 165, 165, 0.3);
}

/* Staging journal & diff viewer */
.diff-viewer { background: #1e1e2e; color: #cdd6f4; border-radius: 0.5rem; padding: 1rem; font-family: monospace; font-size: 0.82rem; overflow-x: auto; }
.diff-addition { color: #a6e3a1; }
.diff-deletion { color: #f38ba8; }

/* --- SAFETY & PRODUCTION ACTIONS --- */
.notice { padding: 0.85rem 1rem; border-left: 4px solid var(--accent-base); border-radius: var(--radius-sm); color: var(--notice-text); background: var(--notice-bg); margin: 1rem 0; }
.notice-production { border-left-color: #be123c !important; border-left: 4px solid #be123c !important; background: #fff1f2 !important; color: #881337 !important; }
:root[data-theme="dark"] .notice-production, [data-bs-theme="dark"] .notice-production { background: rgba(190, 18, 60, 0.15) !important; color: #fecdd3 !important; border-left-color: #f43f5e !important; }

.danger-zone { margin-top: 1.25rem; padding: 1rem; border: 1px dashed var(--danger-border); border-radius: var(--radius-md); background: var(--danger-subtle); display: flex; flex-wrap: wrap; gap: 0.75rem; }
.danger-zone form { margin: 0; }
:root[data-theme="dark"] .danger-zone, [data-bs-theme="dark"] .danger-zone { background: rgba(220, 38, 38, 0.15); border-color: rgba(239, 68, 68, 0.4); color: #fecdd3; }

.button-danger { display: inline-flex; align-items: center; justify-content: center; min-height: 2.4rem; padding: 0.5rem 1rem; border: 1px solid var(--danger-border); border-radius: var(--radius-md); color: var(--danger-text) !important; background: var(--danger-subtle) !important; font-weight: 650; text-decoration: none; cursor: pointer; transition: 150ms ease; }
.button-danger:hover { background: #fee2e2 !important; border-color: var(--danger-base) !important; text-decoration: none !important; }
:root[data-theme="dark"] .button-danger, [data-bs-theme="dark"] .button-danger { background: rgba(220, 38, 38, 0.2) !important; color: #fca5a5 !important; border-color: #ef4444 !important; }
:root[data-theme="dark"] .button-danger:hover, [data-bs-theme="dark"] .button-danger:hover { background: rgba(220, 38, 38, 0.35) !important; color: #fecaca !important; }

.button-production,
:root[data-theme="dark"] .button-production, [data-bs-theme="dark"] .button-production { background: #be123c !important; color: #ffffff !important; border-color: #9f1239 !important; font-weight: 600; }
.button-production:hover,
:root[data-theme="dark"] .button-production:hover, [data-bs-theme="dark"] .button-production:hover { background: #9f1239 !important; color: #ffffff !important; }
.button-production:active,
:root[data-theme="dark"] .button-production:active, [data-bs-theme="dark"] .button-production:active { background: #881337 !important; border-color: #881337 !important; color: #ffffff !important; }
.button-production:disabled, .button-production[disabled],
.button-production:disabled:active, .button-production[disabled]:active,
:root[data-theme="dark"] .button-production:disabled, [data-bs-theme="dark"] .button-production[disabled],
:root[data-theme="dark"] .button-production:disabled:active, [data-bs-theme="dark"] .button-production[disabled]:active { opacity: 0.55 !important; cursor: not-allowed !important; background: var(--bg-muted) !important; color: var(--text-muted) !important; border-color: var(--border-dim) !important; }

/* Popover styling (APIN-113) */
.popover-body { white-space: pre-line; word-break: break-word; }

.button-emergency-stop { color: var(--danger-text, #dc2626); border-color: var(--danger-border, #f87171); font-weight: 600; }
:root[data-theme="dark"] .button-emergency-stop, [data-bs-theme="dark"] .button-emergency-stop { color: #f87171; border-color: #ef4444; }

.capability-error-banner { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0.5rem; background: var(--danger-subtle, #fef2f2); border: 1px solid var(--danger-border, #f87171); border-radius: var(--radius-xs); margin-bottom: 0.25rem; }
:root[data-theme="dark"] .capability-error-banner, [data-bs-theme="dark"] .capability-error-banner { background: rgba(220, 38, 38, 0.15); border-color: rgba(239, 68, 68, 0.4); }

.production-executor-panel { border-left: 4px solid #be123c !important; }
.staging-executor-panel { border-left: 4px solid var(--accent-base) !important; }

.production-confirm-disclosure summary::-webkit-details-marker,
.staging-confirm-disclosure summary::-webkit-details-marker { display: none; }
.production-confirm-disclosure summary,
.staging-confirm-disclosure summary { list-style: none; cursor: pointer; }

.production-confirm-box, .staging-confirm-box { margin-top: 0.75rem; padding: 0.75rem; border: 1px solid var(--border-dim); border-radius: var(--radius-sm); background: var(--bg-surface); max-width: 480px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }

.production-node-status, .staging-node-status { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px dashed var(--border-dim); display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.production-node-summary { display: flex; flex-direction: column; gap: 0.25rem; margin: 0.5rem 0 0; padding: 0; list-style: none; font-size: 0.8125rem; line-height: 1.4; }

/* --- RESPONSIVE VIEWS --- */
.npm-desktop-view { display: block; }
.npm-mobile-view { display: none; }
@media (max-width: 768px) {
  .npm-desktop-view { display: none !important; }
  .npm-mobile-view { display: flex !important; }
}

/* --- NAVIGATION & WORKFLOW COMPONENTS --- */
.breadcrumb-current { color: var(--text-main); font-weight: 600; }
.breadcrumb-separator { color: var(--text-muted); margin: 0 0.25rem; }
.breadcrumb .breadcrumb-item + .breadcrumb-current::before,
.breadcrumb .breadcrumb-item + span:not(.breadcrumb-item):not(.breadcrumb-separator)::before {
  content: "/";
  padding: 0 0.5rem;
  color: var(--bs-secondary-color, #6c757d);
}
.nav-label { margin: 1.1rem 0.7rem 0.35rem; font-size: 0.65rem; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase; color: var(--text-muted); }
.nav-toggle { display: none; }
.menu-button { display: grid; width: 2rem; height: 2rem; place-items: center; padding: 0; border: 0; border-radius: 0.45rem; background: transparent; cursor: pointer; }
.drawer-controls { display: flex; gap: 0.5rem; }

.kv-card { background: var(--bg-surface); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 1.25rem; margin-bottom: 1rem; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.kv-item { display: flex; flex-direction: column; gap: 0.25rem; }
.kv-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kv-value { font-size: 0.9375rem; color: var(--text-main); word-break: break-word; }
.kv-list { display: grid; gap: 0.75rem; }

.detail-header { margin-bottom: 1.5rem; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.detail-subtitle { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.25rem; }
.detail-badges { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 1rem; }

.form-card { background: var(--bg-surface); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 1.5rem; margin-bottom: 1.5rem; }
.change-card { background: var(--bg-surface); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 1.25rem; margin-bottom: 1rem; }
.node-card { background: var(--bg-surface); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 1rem; margin-bottom: 1rem; }
.node-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.node-card-name { font-weight: 600; font-size: 1rem; }

.operation-card { background: var(--bg-surface); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 1rem; margin-bottom: 1rem; }
.operation-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.operation-diff { margin-top: 1rem; }

.workflow-guidance-card { background: var(--bg-subtle); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 1.25rem; margin-bottom: 1.5rem; }
.workflow-steps { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 0.75rem; }
.workflow-step { display: flex; align-items: flex-start; gap: 0.75rem; }
.step-num { display: grid; width: 1.5rem; height: 1.5rem; place-items: center; border-radius: 50%; background: var(--accent-base); color: #fff; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; }

.form-group { margin-bottom: 1rem; }
.form-row { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.helptext { display: block; font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }
.errorlist { list-style: none; padding: 0.5rem 0.75rem; margin: 0.25rem 0 0.5rem; border-radius: var(--radius-sm); background: var(--danger-subtle); border: 1px solid var(--danger-border); color: var(--danger-text); font-size: 0.8125rem; }
.errorlist li { margin-bottom: 0.25rem; }

.inline-form, .inline-action-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0; max-width: 100%; }

/* Responsive form controls to prevent horizontal overflow (D2) */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-sm);
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  background-color: var(--bg-surface);
  color: var(--text-main);
}
input:not([type="checkbox"]):not([type="radio"]):focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.25);
}
form input:not([type="checkbox"]):not([type="radio"]), form select, form textarea {
  max-width: 100%;
  box-sizing: border-box;
}
.form-card input:not([type="checkbox"]):not([type="radio"]), .form-card select, .form-card textarea {
  width: 100%;
}
.inline-form input:not([type="checkbox"]):not([type="radio"]),
.inline-form select {
  max-width: 100%;
  flex: 1 1 180px;
}

/* Section cards padding (I1) */
section.card { padding: 1.25rem; }
section.card:has(.card-body) { padding: 0; }

.payload-container { display: grid; gap: 1rem; margin: 1rem 0; }
.payload-box { background: var(--bg-surface); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 1rem; }
.payload-section { margin-bottom: 1rem; }
.payload-tag { display: inline-block; padding: 0.2rem 0.5rem; font-size: 0.75rem; border-radius: var(--radius-xs); background: var(--bg-subtle); border: 1px solid var(--border-dim); }

.code-block { font-family: monospace; font-size: 0.8125rem; padding: 0.75rem; background: var(--bg-subtle); border: 1px solid var(--border-dim); border-radius: var(--radius-sm); overflow-x: auto; }
.diff-row-changed { background-color: rgba(234, 179, 8, 0.15); }
.event-details-json { font-size: 0.8125rem; max-height: 240px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; }

.button-lg { min-height: 3rem; padding: 0.75rem 1.4rem; font-size: 1rem; border-radius: var(--radius-md); }
.back-link { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--text-muted); text-decoration: none; font-size: 0.875rem; margin-bottom: 1rem; }
.back-link:hover { color: var(--accent-base); text-decoration: underline; }

.badge-kind { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.badge-mono { font-family: monospace; font-size: 0.8125rem; }

.status-inactive { color: var(--text-muted); background: var(--bg-subtle); }
.status-pending { color: var(--warning-text); background: var(--warning-subtle); border-color: var(--warning-border); }

.status-summary-item { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; padding: 2px 0; }
.status-summary-node { min-width: 0; overflow-wrap: anywhere; }

.reconcile-action-box, .reconcile-waiting-box { padding: 1rem; border-radius: var(--radius-md); border: 1px solid var(--border-dim); background: var(--bg-subtle); margin: 1rem 0; }
.refresh-banner { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; background: var(--bg-subtle); border: 1px solid var(--border-dim); border-radius: var(--radius-md); margin-bottom: 1rem; }
.refresh-spinner { display: inline-block; animation: spin 2s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

.search-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 1.25rem 0; max-width: 100%; }
.tab-container { margin: 1rem 0; }
.tab-btn { padding: 0.5rem 1rem; border: 1px solid var(--border-dim); background: var(--bg-subtle); border-radius: var(--radius-sm); cursor: pointer; }
.tab-btn.is-active { background: var(--accent-base); color: #fff; border-color: var(--accent-base); }

.table-cell-meta { font-size: 0.8125rem; color: var(--text-muted); }
.table-cell-title { font-weight: 600; }
.table-windows { width: 100%; }

.admin-tenant-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 1rem; background: var(--bg-subtle); border: 1px solid var(--border-dim); border-radius: var(--radius-md); margin-bottom: 1rem; max-width: 100%; }
.tenant-action-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; max-width: 100%; }
.tenant-action-group { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; max-width: 100%; }
.tenant-selector { min-width: 200px; max-width: 100%; }
.toolbar-label { font-size: 0.875rem; font-weight: 600; color: var(--text-muted); }

.toast-dismiss { cursor: pointer; border: none; background: none; }
.toast-icon { font-size: 1.25rem; }
.empty-icon { font-size: 2.25rem; margin-bottom: 0.5rem; line-height: 1; }
.public-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0; }

.is-disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }
.metric-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 600; }
.copy-btn { cursor: pointer; }
.alert-box { padding: 0.75rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border-dim); background: var(--bg-subtle); margin-bottom: 1rem; }
