/* RXG Admin — Dark Theme */

:root {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-elevated: #242836;
  --bg-hover: #2d3244;
  --border: #333849;
  --text: #e1e4ed;
  --text-muted: #8b90a0;
  --text-dim: #5c6070;
  --accent: #4f8ff7;
  --accent-hover: #6ba1ff;
  --accent-dim: rgba(79, 143, 247, 0.15);
  --success: #34d399;
  --danger: #f87171;
  --danger-hover: #fca5a5;
  --warning: #fbbf24;
  --radius: 8px;
  --radius-sm: 4px;
  --sidebar-width: 240px;
  --rail-width: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

#app {
  display: flex;
  min-height: 100vh;
  justify-content: center;
  align-items: center;
}

#app.app-shell {
  justify-content: flex-start;
  align-items: stretch;
}

/* --- Sidebar --- */

#sidebar {
  width: var(--rail-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow: hidden;
  transition: width 0.2s ease;
}

#sidebar.expanded,
#sidebar.pinned {
  width: var(--sidebar-width);
}

#sidebar.expanded:not(.pinned) {
  box-shadow: 6px 0 24px rgba(0, 0, 0, 0.4);
  z-index: 20;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* --- Nav Icons & Labels --- */

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-label {
  opacity: 0;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 60ms ease;
  pointer-events: none;
  flex-shrink: 1;
  min-width: 0;
}

#sidebar.expanded .nav-label,
#sidebar.pinned .nav-label {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 120ms ease 250ms;
}

/* --- Sidebar Header --- */

.sidebar-header {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  max-width: 14px;
  flex-shrink: 0;
  transition: max-width 0.2s ease;
}

#sidebar.expanded .sidebar-logo,
#sidebar.pinned .sidebar-logo {
  max-width: 200px;
}

.logo-ver {
  font-weight: 400;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 2px;
}

.sidebar-pin-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  width: 0;
  height: 0;
  padding: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  pointer-events: none;
  visibility: hidden;
}

#sidebar.expanded .sidebar-pin-toggle,
#sidebar.pinned .sidebar-pin-toggle {
  display: flex;
  visibility: visible;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  pointer-events: auto;
}

.sidebar-pin-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar-pin-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.sidebar-pin-toggle svg {
  width: 14px;
  height: 14px;
}

/* --- Sidebar Filter --- */

.sidebar-filter {
  padding: 0 18px;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.sidebar-filter-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s;
}

.sidebar-filter-icon:hover {
  color: var(--text-muted);
}

.sidebar-filter-icon svg {
  width: 16px;
  height: 16px;
}

.sidebar-filter-input-wrap {
  position: relative;
  width: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 60ms ease;
}

#sidebar.expanded .sidebar-filter-input-wrap,
#sidebar.pinned .sidebar-filter-input-wrap {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 120ms ease 250ms;
}

.sidebar-filter input {
  width: 100%;
  padding: 6px 26px 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
}

.sidebar-filter-clear {
  display: none;
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}

.sidebar-filter-clear:hover {
  color: var(--text);
}

.sidebar-filter input:focus {
  outline: none;
  border-color: var(--accent);
}

.sidebar-filter input::placeholder {
  color: var(--text-dim);
}

/* --- Nav Items --- */

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  height: 34px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  position: relative;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-dashboard {
  font-weight: 600;
}

/* --- Nav Groups --- */

.nav-group-label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  height: 34px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: color 0.15s;
}

.nav-group-label:hover {
  color: var(--text-muted);
}

.nav-group-label.group-active .nav-icon {
  color: var(--accent);
}

.nav-group-label.group-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-group-chevron {
  font-size: 10px;
  margin-left: auto;
  transition: transform 0.2s ease;
  line-height: 1;
}

.nav-group-items.collapsed {
  display: none;
}

#sidebar:not(.expanded):not(.pinned) .nav-group-items {
  display: none;
}

.nav-item.nav-sub {
  padding-left: 50px;
  height: 30px;
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 18px;
  opacity: 0.5;
}

/* --- Navigation History --- */

.nav-history-section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 4px;
}

#sidebar:not(.expanded):not(.pinned) .nav-history-section {
  display: none;
}

.nav-history-label {
  padding: 12px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
}

.nav-history-item {
  font-size: 12px !important;
  padding: 5px 16px !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* --- Main Content --- */

#content {
  margin-left: var(--rail-width);
  flex: 1;
  padding: 32px;
  transition: margin-left 0.2s ease;
}

#sidebar.pinned ~ #content {
  margin-left: var(--sidebar-width);
}

.loading {
  color: var(--text-muted);
  padding: 48px;
  text-align: center;
}

/* --- Page Header --- */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 600;
}

.breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

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

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-success {
  background: #388e3c;
  color: #fff;
}

.btn-success:hover {
  background: #43a047;
}

.btn-warning {
  background: transparent;
  color: #ffa726;
  border-color: #ffa726;
}

.btn-warning:hover {
  background: rgba(255, 167, 38, 0.1);
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

.btn-outline:hover {
  background: var(--accent-dim);
}

.ct-test-result {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
}

.ct-test-result table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.ct-test-result th,
.ct-test-result td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

.ct-test-result th {
  color: var(--text-muted);
}

.ct-rendered-preview {
  margin-top: 8px;
}

.ct-rendered-preview summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
}

.ct-rendered-preview pre {
  margin-top: 4px;
  padding: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-x: auto;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

/* --- Dashboard Cards --- */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card-group {
  margin-bottom: 32px;
}

.card-group h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
  display: block;
}

.card:hover {
  border-color: var(--accent);
  background: var(--bg-elevated);
}

.card h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.card .count {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.card .label {
  font-size: 12px;
  color: var(--text-muted);
}

/* --- Table --- */

.table-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

th:last-child,
td:last-child {
  position: sticky;
  right: 0;
  background: var(--bg-surface);
  z-index: 1;
  box-shadow: -2px 0 4px rgba(0,0,0,0.15);
}

th:last-child {
  background: var(--bg-elevated);
}

tr:hover td:last-child {
  background: var(--bg-hover);
}

tr:hover td {
  background: var(--bg-hover);
}

td a {
  color: var(--accent);
  text-decoration: none;
}

td a:hover {
  text-decoration: underline;
}

/* --- Actions Dropdown --- */

.actions-dropdown {
  position: relative;
  display: inline-block;
  margin-left: 4px;
}

.actions-dropdown-toggle {
  min-width: 28px;
  padding: 4px 6px;
  font-size: 16px;
  line-height: 1;
}

.actions-dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  min-width: 160px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 200;
}

.actions-dropdown-menu.open {
  display: block;
}

.actions-dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  text-align: left;
  font-size: 13px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}

.actions-dropdown-item:last-child {
  border-bottom: none;
}

.actions-dropdown-item:hover {
  background: var(--bg-hover);
}

.actions-dropdown-item.btn-danger {
  color: #e87e7e;
}

.actions-dropdown-item.btn-warning {
  color: #e8c87e;
}

.actions-dropdown-item.btn-primary {
  color: var(--accent);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.pagination-buttons {
  display: flex;
  gap: 8px;
}

/* --- Detail View --- */

.detail-grid {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.detail-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-elevated);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.detail-value {
  padding: 10px 16px;
  font-size: 13px;
  word-break: break-all;
  font-family: var(--font-mono);
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.edge-section {
  margin-top: 24px;
}

.edge-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.scoped-scaffold-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.scoped-scaffold-header h3 {
  margin-bottom: 0;
}

.scoped-actions {
  white-space: nowrap;
  text-align: right;
}

.scoped-actions .btn {
  margin-left: 4px;
}

.scoped-scaffold-form {
  margin-top: 12px;
}

/* --- Forms --- */

.form-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 640px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group label .required {
  color: var(--danger);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
  font-family: var(--font-mono);
}

.form-group input[type="checkbox"] {
  width: auto;
}

.field-hint {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-group input:disabled,
.form-group select:disabled,
.form-group textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-surface);
  border-style: dashed;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 24px;
}

/* --- Inline Form (Active Scaffold style) --- */

.inline-form-panel {
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.inline-form-header {
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
}

.inline-form-body {
  padding: 16px;
}

.inline-form-body .form-actions {
  margin-top: 16px;
}

.inline-form-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0 16px;
}

.inline-form-row td {
  padding: 0 !important;
  border-bottom: 2px solid var(--accent);
}

.inline-form-row .inline-form-panel {
  border: none;
  border-radius: 0;
  margin: 0;
}

/* --- Toast --- */

#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  animation: slideIn 0.2s ease;
  max-width: 400px;
}

.toast-success {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.toast-error {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* --- Empty State --- */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state p {
  margin-bottom: 16px;
}

/* --- Auth Pages --- */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.auth-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 24px;
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 1px;
}

.auth-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.auth-error {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}

.auth-card .form-group {
  margin-bottom: 16px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}

/* --- Sidebar Footer --- */

.sidebar-footer {
  flex-shrink: 0;
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  min-height: 48px;
}

.sidebar-footer .user-avatar {
  color: var(--text-muted);
}

.sidebar-footer .user-avatar svg {
  width: 18px;
  height: 18px;
}

.sidebar-user {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
}

.sidebar-footer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.sidebar-footer-actions .icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 3px;
  display: flex;
  align-items: center;
  position: relative;
}

.sidebar-footer-actions .icon-btn:hover {
  color: var(--text);
}

.sidebar-footer-actions .icon-btn svg {
  width: 16px;
  height: 16px;
}

.bell-dot::after {
  content: '';
  position: absolute;
  top: 1px;
  right: 1px;
  width: 6px;
  height: 6px;
  background: var(--warning);
  border-radius: 50%;
  display: none;
}

.bell-dot.has-badge::after {
  display: block;
}

.sidebar-logout {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  padding: 3px 0;
}

.sidebar-logout:hover {
  color: var(--text);
}

/* --- Form Sections --- */

.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 16px;
}

.form-section legend {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 6px;
}

/* --- M2M Picker --- */

.m2m-section {
  margin-top: 24px;
}

.m2m-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.m2m-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.m2m-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 13px;
}

.m2m-chip a {
  color: var(--text);
  text-decoration: none;
}

.m2m-chip a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.m2m-chip-remove {
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 15px;
  padding: 0 2px;
  line-height: 1;
}

.m2m-chip-remove:hover {
  color: var(--danger);
}

.m2m-search-container {
  position: relative;
  max-width: 400px;
}

.m2m-search-input {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
}

.m2m-search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.m2m-search-input::placeholder {
  color: var(--text-dim);
}

.m2m-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 100;
  margin-top: 2px;
}

.m2m-dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.m2m-dropdown-item:last-child {
  border-bottom: none;
}

.m2m-dropdown-item:hover,
.m2m-dropdown-item.active {
  background: var(--bg-hover);
  color: var(--accent);
}

.m2m-dropdown-empty {
  padding: 8px 12px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
}

/* --- Toast History --- */

.toast-history-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.toast-history-btn:hover {
  background: var(--bg-hover);
}

.toast-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 15px;
  height: 15px;
  line-height: 15px;
  text-align: center;
  border-radius: 8px;
  padding: 0 3px;
}

.toast-history {
  position: fixed;
  bottom: 52px;
  left: 8px;
  width: 224px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
}

.toast-history-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.toast-history-item:last-child {
  border-bottom: none;
}

.toast-history-success .toast-history-msg { color: var(--success); }
.toast-history-error .toast-history-msg { color: var(--danger); }

.toast-history-msg {
  flex: 1;
  word-break: break-word;
}

.toast-history-time {
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

.toast-history-empty {
  padding: 16px 12px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  font-style: italic;
}

/* --- Health Notice Banners --- */

#health-notices {
  z-index: 100;
  margin: 0 -24px 16px -24px;
}

.health-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  font-size: 14px;
  border-bottom: 1px solid rgba(0,0,0,0.2);
}

.health-notice-content {
  flex: 1;
}

.health-notice-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.health-notice-content strong {
  display: block;
}

.health-notice-time {
  font-size: 11px;
  opacity: 0.6;
  white-space: nowrap;
}

.health-notice-detail {
  margin: 4px 0 0;
  font-size: 12px;
  opacity: 0.85;
}

.health-notice-actions {
  display: flex;
  gap: 8px;
  margin-left: 16px;
  flex-shrink: 0;
}

.health-notice-notice {
  background: #1e3a5f;
  color: #7eb8e8;
}

.health-notice-warning {
  background: #5f4b1e;
  color: #e8c87e;
}

.health-notice-critical {
  background: #5f1e1e;
  color: #e87e7e;
}

.health-notice-fatal {
  background: #7f1e1e;
  color: #ff9e9e;
  font-weight: bold;
}

/* Edge preview in list tables */
.edge-preview-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85em;
}
.edge-preview-link:hover { text-decoration: underline; }

.edge-inline-row td {
  background: var(--bg-surface);
  padding: 8px 12px;
}
.edge-inline-table {
  width: 100%;
  font-size: 0.9em;
  border-collapse: collapse;
}
.edge-inline-table th {
  text-transform: capitalize;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.edge-inline-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-light, #2a2d37);
}

/* --- Composite Views --- */

.view-section {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.view-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  cursor: pointer;
  user-select: none;
}
.view-section-header:hover {
  background: var(--bg-hover);
}
.view-section-title {
  font-weight: 600;
  flex: 1;
}
.view-section-header .btn {
  margin-left: auto;
}
.view-section-body {
  padding: 12px 16px;
}
.view-section-body.collapsed {
  display: none;
}
.view-section-body table {
  width: 100%;
}
.view-section-body .pagination {
  margin-top: 8px;
  font-size: 0.85em;
  color: var(--text-muted);
}
.view-section-body .empty-state {
  padding: 16px 0;
  text-align: center;
  color: var(--text-muted);
}

/* --- Search --- */
.list-search { position: relative; margin-bottom: 16px; }
.list-search input {
  width: 100%; padding: 10px 36px 10px 14px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 14px; font-family: var(--font);
}
.list-search input:focus { outline: none; border-color: var(--accent); }
.list-search input::placeholder { color: var(--text-dim); }
.search-clear {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1; display: none;
}
.search-clear.visible { display: block; }
.search-clear:hover { color: var(--text); }

/* --- Sortable Headers --- */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th.sorted { color: var(--accent); }

/* --- Section Search --- */
.section-search {
  width: 100%; padding: 6px 10px; margin-bottom: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 13px; font-family: var(--font);
}
.section-search:focus { outline: none; border-color: var(--accent); }

/* Metrics Graphs */
.graph-wrapper { margin-top: 12px; }
.graph-controls { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.graph-title { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.graph-chart { width: 100%; min-height: 180px; }
.graph-refresh-label { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.btn-sm { padding: 2px 10px; font-size: 12px; }

/* Policy Lookup */
.lookup-page { max-width: 900px; }
.lookup-form { display: flex; gap: 8px; margin-bottom: 20px; }
.lookup-form .input { flex: 1; }
.lookup-context, .lookup-effective, .lookup-layers { margin-bottom: 16px; }
.lookup-effective .detail-table th:first-child { width: 160px; }
.source-col { color: var(--text-muted); font-size: 12px; }
.badge-bypassed { background: #2d4a1e; color: #7ecf5a; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; margin-left: 8px; }
.nav-lookup { border-bottom: 1px solid var(--border); margin-bottom: 4px; padding-bottom: 8px; }
.lookup-diagram { margin-bottom: 16px; overflow-x: auto; }
.cascade-diagram { display: block; margin: 0 auto; }
.cd-tier-label { font-size: 10px; font-weight: 700; fill: var(--text-muted); letter-spacing: 1px; }
.cd-group-node { fill: var(--card-bg); stroke: var(--border); stroke-width: 1.5; }
.cd-group-text { font-size: 13px; font-weight: 600; fill: var(--text); }
.cd-policy-subtext { font-size: 10px; fill: var(--text-muted); }
.cd-line-winner { stroke: var(--accent); stroke-width: 2; }
.cd-line-overridden { stroke: var(--border); stroke-width: 1; stroke-dasharray: 4 3; }
.cd-line-cleared { stroke: #b04050; stroke-width: 1.5; stroke-dasharray: 6 3; }
.cd-dot-winner { fill: var(--accent); }
.cd-dot-overridden { fill: var(--border); }
.cd-dot-cleared { fill: #b04050; }
.cd-slot-winner { font-size: 13px; font-weight: 600; fill: var(--accent); }
.cd-slot-overridden { font-size: 12px; fill: var(--text-muted); }
.cd-slot-cleared { font-size: 12px; fill: #b04050; font-style: italic; }
.cd-slot-detail { font-size: 10px; fill: var(--text-muted); }
.cd-slot-bypassed { font-size: 10px; fill: #7ecf5a; font-weight: 600; }
.cd-winner-star { font-size: 14px; fill: var(--accent); }
.cd-separator { stroke: var(--border); stroke-width: 0.5; stroke-dasharray: 2 4; }
.cascade-diagram a:hover .cd-group-node { stroke: var(--accent); }
.cascade-diagram a:hover .cd-slot-winner,
.cascade-diagram a:hover .cd-slot-overridden { fill: var(--accent); text-decoration: underline; }

/* Topology diagram */
.topology-diagram { display: block; margin: 0 auto; }
.topology-legend { display: block; }
.topo-node { fill: var(--card-bg); stroke: var(--border); stroke-width: 1.5; cursor: pointer; }
.topo-node:hover { stroke: var(--accent); stroke-width: 2; }
.topo-node-offline { fill: var(--card-bg); stroke: #b04050; stroke-width: 1.5; stroke-dasharray: 4 2; }
.topo-node-label { font-size: 13px; font-weight: 600; fill: var(--text); }
.topo-node-sublabel { font-size: 10px; fill: var(--text-muted); }
.topo-edge { stroke: var(--accent); stroke-width: 2; }
.topo-edge-stale { stroke: #b04050; stroke-width: 1.5; stroke-dasharray: 6 3; }
.topo-port-label { font-size: 10px; fill: var(--text-muted); }
.topo-speed-label { font-size: 10px; fill: var(--accent); font-weight: 600; }
.topo-dot-online { fill: #4a9; }
.topo-dot-offline { fill: #b04050; }
.topo-group-header { font-size: 14px; font-weight: 600; fill: var(--text); }
.topo-legend-text { font-size: 11px; fill: var(--text-muted); }
.topology-diagram a:hover .topo-node { stroke: var(--accent); stroke-width: 2; }
.topology-diagram a:hover .topo-node-label { fill: var(--accent); }

/* uPlot dark theme overrides */
.uplot { font-family: var(--font); }
.u-legend { font-size: 12px; }
.u-legend th { color: var(--text-muted); font-weight: normal; }
.u-legend td { color: var(--text); }
.u-select { background: var(--accent-dim); }
.u-axis .u-label { fill: var(--text-muted) !important; color: var(--text-muted) !important; }
.u-values .u-value { fill: var(--text-muted) !important; color: var(--text-muted) !important; }

/* --- Manual Viewer --- */
.manual-page { max-width: 1200px; }

.manual-toc { display: flex; flex-direction: column; gap: 2px; margin-top: 16px; }
.manual-toc-item {
  display: flex; align-items: baseline; gap: 12px;
  padding: 12px 16px; border-radius: 6px;
  color: var(--text); text-decoration: none;
  transition: background 0.15s;
}
.manual-toc-item:hover { background: var(--row-hover); }
.manual-toc-order { color: var(--text-muted); font-weight: 600; min-width: 28px; }
.manual-toc-title { font-size: 15px; }

.manual-layout { display: flex; gap: 32px; margin-top: 8px; }
.manual-sidebar {
  flex: 0 0 220px; position: sticky; top: 16px; align-self: flex-start;
  display: flex; flex-direction: column; gap: 2px;
  max-height: calc(100vh - 32px); overflow-y: auto;
}
.manual-sidebar-back {
  display: block; padding: 8px 12px; margin-bottom: 8px;
  color: var(--accent); text-decoration: none; font-size: 13px;
}
.manual-sidebar-back:hover { text-decoration: underline; }
.manual-sidebar-item {
  display: block; padding: 6px 12px; border-radius: 4px;
  color: var(--text-muted); text-decoration: none; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.manual-sidebar-item:hover { color: var(--text); background: var(--row-hover); }
.manual-sidebar-item.active { color: var(--accent); font-weight: 600; }

.manual-content {
  flex: 1; min-width: 0; line-height: 1.7; font-size: 15px;
}
.manual-content h1 { font-size: 24px; margin: 0 0 24px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.manual-content h2 { font-size: 20px; margin: 32px 0 12px; }
.manual-content h3 { font-size: 16px; margin: 24px 0 8px; }
.manual-content p { margin: 0 0 12px; }
.manual-content table { border-collapse: collapse; margin: 12px 0 20px; width: 100%; }
.manual-content th, .manual-content td {
  border: 1px solid var(--border); padding: 8px 12px; text-align: left;
}
.manual-content th { background: var(--surface); font-weight: 600; font-size: 13px; }
.manual-content td { font-size: 14px; }
.manual-content code {
  background: var(--surface); padding: 2px 6px; border-radius: 3px;
  font-size: 13px; font-family: var(--font-mono, monospace);
}
.manual-content pre {
  background: var(--surface); padding: 16px; border-radius: 6px;
  overflow-x: auto; margin: 12px 0 20px; border: 1px solid var(--border);
}
.manual-content pre code { background: none; padding: 0; font-size: 13px; }
.manual-content ul, .manual-content ol { margin: 0 0 12px; padding-left: 24px; }
.manual-content li { margin-bottom: 4px; }
.manual-content blockquote {
  border-left: 3px solid var(--accent); margin: 12px 0; padding: 8px 16px;
  color: var(--text-muted); background: var(--surface); border-radius: 0 4px 4px 0;
}
.manual-content a { color: var(--accent); }

.manual-nav {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border);
}
.manual-nav .btn { text-decoration: none; }

@media (max-width: 900px) {
  .manual-layout { flex-direction: column; }
  .manual-sidebar { flex: none; position: static; max-height: none; flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .manual-sidebar-item { white-space: normal; }
}

/* --- Cluster Health Panel --- */

.cluster-health-panel { margin-bottom: 24px; }

.cluster-health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 12px;
}

.cluster-health-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
}

.cluster-health-info {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.cluster-health-identity {
  display: flex; align-items: center; gap: 8px;
}
.cluster-health-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}
.cluster-health-mode {
  font-size: 10px; font-weight: 600; font-family: var(--font-mono);
  color: var(--text-muted); background: var(--bg-hover);
  padding: 1px 6px; border-radius: 3px; letter-spacing: 0.5px;
}
.cluster-health-meta {
  display: flex; align-items: center; gap: 12px;
  font-size: 12px; color: var(--text-muted);
}
.cluster-health-status { font-weight: 600; }

.cluster-health-age {
  font-size: 12px; color: var(--text-muted); margin-bottom: 8px;
}
.cluster-health-age-label { color: var(--text-dim); }
.cluster-health-age-value { font-family: var(--font-mono); font-weight: 600; }

.cluster-health-ecg {
  width: 100%; height: 64px; border-radius: var(--radius-sm);
  display: block;
}
