:root {
  /* Fresh & Clean Light Theme */
  --bg-base: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --bg-input: #ffffff;
  --bg-inset: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #2563eb;
  --border-subtle: #f1f5f9;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;

  --color-success: #059669;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-info: #0284c7;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 16px 32px -4px rgba(15, 23, 42, 0.12), 0 4px 6px -2px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 1.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: #eff6ff;
  color: #2563eb;
  border: 1px solid #bfdbfe;
  margin-left: 0.4rem;
}

.header-status-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.service-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.8rem;
  border-radius: 20px;
  font-size: 0.825rem;
  background: var(--bg-inset);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-success);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}
.status-dot.active {
  background-color: var(--color-success);
  box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.4);
  animation: pulseDot 2.8s infinite cubic-bezier(0.4, 0, 0.6, 1);
}
.status-dot.error {
  background-color: var(--color-danger);
}

@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.4); }
  70% { box-shadow: 0 0 0 5px rgba(5, 150, 105, 0); }
  100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-size: 0.925rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.15s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.15s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.1s ease;
  text-decoration: none;
  line-height: 1.3;
  user-select: none;
}
.btn:active {
  transform: scale(0.97);
}
.btn svg {
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
  box-shadow: 0 1px 2px 0 rgba(37, 99, 235, 0.2);
}
.btn-primary:hover {
  background: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
  box-shadow: 0 4px 8px -1px rgba(37, 99, 235, 0.25);
}

.btn-secondary {
  background: var(--bg-surface);
  border: 1px solid #cbd5e1;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: #94a3b8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.btn-secondary.active {
  background: #eff6ff;
  border-color: #2563eb;
  color: #2563eb;
  font-weight: 600;
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.825rem;
  border-radius: var(--radius-sm);
}

.btn-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--color-danger);
}
.btn-danger:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: var(--color-danger-hover);
  box-shadow: 0 2px 6px rgba(220, 38, 38, 0.12);
}

/* Main Container */
.container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.75rem 1.5rem;
  flex: 1;
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 1.75rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.nav-tabs::-webkit-scrollbar {
  display: none;
}

.tab-link {
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  transition: color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  user-select: none;
}
.tab-link:hover {
  color: var(--accent-primary);
}
.tab-link.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.tab-content {
  animation: tabFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.35rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1),
              box-shadow 0.18s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.18s ease;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.stat-info .stat-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}
.stat-info .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.stat-icon-wrapper {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-inset);
  border: 1px solid var(--border-color);
  transition: transform 0.18s ease;
}
.stat-card:hover .stat-icon-wrapper {
  transform: scale(1.05);
}
.stat-icon-all { color: #64748b; }
.stat-icon-emby { color: #0284c7; background: #f0f9ff; border-color: #bae6fd; }
.stat-icon-generic { color: #4338ca; background: #eef2ff; border-color: #c7d2fe; }
.stat-icon-proxy { color: #059669; background: #ecfdf5; border-color: #a7f3d0; }

/* Card Components */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

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

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Responsive Table */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.885rem;
}

.rules-table, .ua-table {
  width: 100%;
}

/* Frozen / Sticky Sequence Column */
.col-sticky-seq {
  position: sticky;
  left: 0;
  width: 42px;
  min-width: 42px;
  max-width: 42px;
  text-align: center;
  border-right: 1px solid var(--border-color);
  user-select: none;
}
th.col-sticky-seq {
  z-index: 3;
  background: var(--bg-inset);
}
td.col-sticky-seq {
  z-index: 2;
  background: var(--bg-surface);
}
tr:hover td.col-sticky-seq {
  background: var(--bg-surface-hover);
}
.seq-num {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Compact Table Toolbar */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.toolbar-actions .form-control {
  width: 210px;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

th {
  background: var(--bg-inset);
  padding: 0.55rem 0.65rem;
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
  line-height: 1.35;
}

td .btn-sm {
  padding: 0.22rem 0.45rem;
  font-size: 0.78rem;
  gap: 3px;
}

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

tr {
  transition: background-color 0.12s ease;
}

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

/* Page switch transition animation */
@keyframes tableRowFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.table-fade-enter tr {
  animation: tableRowFadeIn 0.16s ease-out both;
}

.table-fade-enter tr:nth-child(1) { animation-delay: 0ms; }
.table-fade-enter tr:nth-child(2) { animation-delay: 18ms; }
.table-fade-enter tr:nth-child(3) { animation-delay: 36ms; }
.table-fade-enter tr:nth-child(4) { animation-delay: 54ms; }
.table-fade-enter tr:nth-child(5) { animation-delay: 72ms; }
.table-fade-enter tr:nth-child(6) { animation-delay: 90ms; }
.table-fade-enter tr:nth-child(7) { animation-delay: 108ms; }
.table-fade-enter tr:nth-child(8) { animation-delay: 126ms; }
.table-fade-enter tr:nth-child(9) { animation-delay: 144ms; }
.table-fade-enter tr:nth-child(10) { animation-delay: 162ms; }

@media (prefers-reduced-motion: reduce) {
  .table-fade-enter tr {
    animation: none !important;
  }
}

/* Domain & Upstream Compact Cell Layout */
.domain-cell, .upstream-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.domain-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #1d4ed8;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.88rem;
  text-decoration: none;
  max-width: 100%;
  transition: color 0.12s ease;
}
.domain-link:hover {
  color: #2563eb;
  text-decoration: underline;
}

.domain-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
  display: inline-block;
  vertical-align: middle;
}

.external-link-icon {
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.domain-link:hover .external-link-icon {
  opacity: 1;
  transform: translate(1px, -1px);
}

.cell-sub-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.rule-name-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.72rem;
  font-weight: 500;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  line-height: 1.25;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upstream-code {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius-sm);
  background: var(--bg-inset);
  border: 1px solid var(--border-color);
  color: #0369a1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
  display: inline-block;
  line-height: 1.35;
  vertical-align: middle;
}

.upstream-proxy-label {
  color: var(--text-muted);
  font-size: 0.84rem;
  white-space: nowrap;
}

.rule-badges-inline {
  display: inline-flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

/* Pagination Controls */
.pagination-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.pagination-info {
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.pagination-info b {
  color: var(--text-primary);
  font-weight: 600;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 0.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  line-height: 1;
}
.page-btn:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  border-color: #94a3b8;
}
.page-btn:active:not(:disabled) {
  transform: scale(0.95);
}
.page-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}
.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.18rem 0.48rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  line-height: 1.25;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.badge:hover {
  transform: scale(1.02);
}

.badge-generic {
  background: #eef2ff;
  color: #4338ca;
  border: 1px solid #c7d2fe;
}

.badge-emby {
  background: #f0f9ff;
  color: #0284c7;
  border: 1px solid #bae6fd;
}

.badge-proxy {
  background: #ecfdf5;
  color: #059669;
  border: 1px solid #a7f3d0;
}

.badge-insecure {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}

.badge-cert {
  background: #f5f3ff;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
}

/* Clean Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: background-color 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 22px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
input:checked + .slider {
  background-color: var(--accent-primary);
}
input:checked + .slider:before {
  transform: translateX(20px);
}

/* Form Controls */
.form-group {
  margin-bottom: 1.15rem;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-md);
  background: var(--bg-input);
  border: 1px solid #cbd5e1;
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  outline: none;
}
.form-control:hover {
  border-color: #94a3b8;
}
.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-help {
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

textarea.form-control {
  resize: vertical;
}

/* Compound Domain Input Group (Subdomain + Dynamic Width Zone Trigger + Custom Dropdown + Refresh) */
.domain-compound-wrapper {
  position: relative;
  width: 100%;
}

.domain-compound-input {
  display: flex;
  align-items: center;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.domain-compound-input:hover {
  border-color: #94a3b8;
}

.domain-compound-input:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.domain-sub-input {
  flex: 1 1 auto;
  min-width: 60px;
  padding: 0.55rem 0.75rem;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
}

.domain-zone-dropdown-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.domain-zone-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  height: 30px;
  padding: 0 0.5rem 0 0.4rem;
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  user-select: none;
  width: auto;
}

.domain-zone-trigger:hover {
  background: rgba(148, 163, 184, 0.18);
  border-color: rgba(148, 163, 184, 0.35);
}

.domain-zone-trigger.active {
  background: rgba(37, 99, 235, 0.08);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.domain-dot {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 1rem;
}

.domain-zone-text {
  color: inherit;
  font-size: 0.875rem;
}

.domain-zone-arrow {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  margin-left: 0.15rem;
}

.domain-zone-trigger.active .domain-zone-arrow {
  transform: rotate(180deg);
  color: var(--accent-primary);
}

/* Custom Dropdown Menu */
.domain-zone-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  max-width: 280px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.18), 0 8px 10px -6px rgba(15, 23, 42, 0.1);
  z-index: 100;
  padding: 0.35rem;
  backdrop-filter: blur(12px);
}

.domain-zone-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.domain-zone-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
  user-select: none;
}

.domain-zone-item:hover {
  background: var(--bg-surface-hover, rgba(148, 163, 184, 0.12));
}

.domain-zone-item.selected {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent-primary);
  font-weight: 600;
}

.domain-zone-divider {
  height: 1px;
  background: var(--border-color);
  margin: 0.25rem 0;
}

.domain-zone-custom-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.domain-zone-custom-item:hover {
  background: var(--bg-surface-hover, rgba(148, 163, 184, 0.12));
  color: var(--accent-primary);
}

.btn-domain-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin: 0 0.25rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background-color 0.15s ease;
  flex: 0 0 auto;
}

.btn-domain-action:hover {
  color: var(--accent-primary);
  background: rgba(37, 99, 235, 0.08);
}

.btn-domain-action.loading svg {
  animation: domain-spin 0.8s linear infinite;
}

@keyframes domain-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.domain-mode-toggle {
  font-size: 0.775rem;
  color: var(--accent-primary);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}

.domain-mode-toggle:hover {
  text-decoration: underline;
}

.domain-preview-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--color-info);
  background: rgba(2, 132, 199, 0.08);
  border: 1px solid rgba(2, 132, 199, 0.25);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  margin-top: 0.35rem;
  width: fit-content;
}

/* Modal Dialog - NO SCROLLBAR */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  scrollbar-width: none; /* Firefox: Hide scrollbar */
  -ms-overflow-style: none; /* IE and Edge: Hide scrollbar */
  box-shadow: var(--shadow-lg);
  transform: translateY(12px) scale(0.98);
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.18s ease;
}
.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.modal-content::-webkit-scrollbar {
  display: none; /* Chrome, Safari, WebKit: Hide scrollbar */
  width: 0;
  height: 0;
}

.modal-header {
  padding: 1.15rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background: var(--bg-inset);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* Rule Type Selector Cards */
.type-selector-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.type-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.75rem;
  text-align: center;
  cursor: pointer;
  background: var(--bg-inset);
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.15s ease,
              background-color 0.15s ease,
              box-shadow 0.15s ease;
}
.type-card:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}
.type-card:active {
  transform: scale(0.98);
}
.type-card.selected {
  border-color: var(--accent-primary);
  background: #eff6ff;
  box-shadow: 0 0 0 1px var(--accent-primary), 0 2px 4px rgba(37, 99, 235, 0.08);
}

.type-card-icon {
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: color 0.15s ease, transform 0.15s ease;
}
.type-card:hover .type-card-icon {
  transform: scale(1.06);
}
.type-card.selected .type-card-icon {
  color: var(--accent-primary);
}

.type-card-title {
  font-size: 0.925rem;
  font-weight: 700;
  color: var(--text-primary);
}

.type-card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  line-height: 1.35;
}

/* Tag Chips */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-inset);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  min-height: 52px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 18px;
  font-size: 0.825rem;
  font-family: monospace;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  animation: chipIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}
.chip:hover {
  border-color: #94a3b8;
  transform: translateY(-1px);
}
.chip-remove {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  transition: color 0.12s ease, transform 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chip-remove:hover {
  color: var(--color-danger);
  transform: scale(1.25);
}

@keyframes chipIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.toast {
  min-width: 280px;
  padding: 0.75rem 1.15rem;
  border-radius: var(--radius-md);
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 10px 25px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -2px rgba(15, 23, 42, 0.05);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast-success { border-left: 4px solid var(--color-success); }
.toast-error { border-left: 4px solid var(--color-danger); }
.toast-info { border-left: 4px solid var(--accent-primary); }

@keyframes slideIn {
  from { transform: translateY(12px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* Grid Layouts */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* Code Preview */
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875rem;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  color: #0f172a;
  border: 1px solid #e2e8f0;
}

/* Responsive Rules for Mobile */
@media (max-width: 768px) {
  header {
    padding: 0.75rem 1rem;
  }
  .container {
    padding: 1rem;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
  .grid-2 {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .card-header > div:last-child {
    width: 100%;
    display: flex;
    justify-content: flex-start;
  }
  .header-status-group {
    width: 100%;
    justify-content: space-between;
  }
  #search-rules {
    width: 100% !important;
  }
  .modal-overlay {
    padding: 0.5rem;
  }
  .modal-content {
    max-height: 94vh;
  }
}

@media (max-width: 580px) {
  .type-selector-grid {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }
  .type-card {
    display: flex;
    align-items: center;
    text-align: left;
    gap: 0.85rem;
    padding: 0.75rem 1rem;
  }
  .type-card-icon {
    margin-bottom: 0;
    flex-shrink: 0;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .form-control {
    font-size: 16px;
  }
}

/* Accessibility: Reduce Motion */
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
