:root {
  color-scheme: light;
  --ps-bg: #f4f6fb;
  --ps-surface: #ffffff;
  --ps-surface-2: #fafbff;
  --ps-surface-3: #f1f3fb;
  --ps-input-bg: #fcfcff;
  --ps-border: #e6e9f2;
  --ps-border-strong: #d5d9e8;
  --ps-text: #1f2540;
  --ps-muted: #6b7280;
  --ps-primary: #4f46e5;
  --ps-primary-600: #4338ca;
  --ps-primary-050: #eef2ff;
  --ps-primary-rgb: 79, 70, 229;
  --ps-accent: #06b6d4;
  --ps-success: #059669;
  --ps-danger: #dc2626;
  --ps-warning: #f59e0b;
  --ps-radius: 14px;
  --ps-radius-sm: 10px;
  --ps-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --ps-shadow-lg: 0 12px 40px rgba(31, 37, 64, .12);
  --ps-bg-gradient:
    radial-gradient(1200px 600px at 100% -10%, #e8ecff 0%, rgba(232, 236, 255, 0) 55%),
    radial-gradient(1000px 500px at -10% 0%, #dff7fb 0%, rgba(223, 247, 251, 0) 45%),
    var(--ps-bg);
  --ps-code-bg: #0f172a;
  --ps-code-text: #e2e8f0;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ps-bg: #333c50;
  --ps-surface: #3c4660;
  --ps-surface-2: #45506e;
  --ps-surface-3: #505c7d;
  --ps-input-bg: #38425c;
  --ps-border: #566284;
  --ps-border-strong: #6b78a0;
  --ps-text: #f3f6fc;
  --ps-muted: #c2ccdf;
  --ps-primary: #949df9;
  --ps-primary-600: #aeb6fb;
  --ps-primary-050: rgba(148, 157, 249, .18);
  --ps-primary-rgb: 148, 157, 249;
  --ps-accent: #38d6ee;
  --ps-success: #4ade80;
  --ps-danger: #f87171;
  --ps-warning: #fbbf24;
  --ps-shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 10px 30px rgba(0, 0, 0, .22);
  --ps-shadow-lg: 0 16px 48px rgba(0, 0, 0, .32);
  --ps-bg-gradient:
    radial-gradient(1200px 600px at 100% -10%, rgba(148, 157, 249, .14) 0%, rgba(148, 157, 249, 0) 55%),
    radial-gradient(1000px 500px at -10% 0%, rgba(56, 214, 238, .1) 0%, rgba(56, 214, 238, 0) 45%),
    var(--ps-bg);
  --ps-code-bg: #202a40;
  --ps-code-text: #e2e8ff;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 15px;
  position: relative;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ps-text);
  background: var(--ps-bg-gradient);
  -webkit-font-smoothing: antialiased;
  --bs-body-bg: var(--ps-bg);
  --bs-body-color: var(--ps-text);
  --bs-border-color: var(--ps-border);
  --bs-secondary-color: var(--ps-muted);
  --bs-emphasis-color: var(--ps-text);
}

/* ---------- DataTables theming ---------- */
.dataTables_wrapper,
.dt-container {
  color: var(--ps-text);
}

.dataTables_wrapper input[type="search"],
.dataTables_filter input,
.dt-search input,
.dt-input,
input.form-control.dataTables_filter,
.dataTables_wrapper .form-control {
  background: var(--ps-input-bg);
  color: var(--ps-text);
  border: 1px solid var(--ps-border);
  border-radius: var(--ps-radius-sm);
}

.dataTables_wrapper input::placeholder,
.dt-search input::placeholder {
  color: var(--ps-muted);
}

.dataTables_info,
.dataTables_length,
.dt-info,
.dt-length,
.dataTables_paginate {
  color: var(--ps-muted);
}

.dataTables_wrapper .dataTables_paginate .paginate_button,
.dt-paging .dt-paging-button {
  color: var(--ps-text) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dt-paging .dt-paging-button.current {
  background: var(--ps-primary-050) !important;
  border-color: var(--ps-border) !important;
  color: var(--ps-primary-600) !important;
}

main {
  flex: 1 0 auto;
}

h1, h2, h3, h4, h5 {
  font-weight: 700;
  letter-spacing: -0.01em;
}

a {
  color: var(--ps-primary);
  text-decoration: none;
}

a:hover {
  color: var(--ps-primary-600);
  text-decoration: underline;
}

/* Bootstrap text utilities must follow the theme so content stays readable on
   dark surfaces. */
.text-muted,
.text-body-secondary {
  color: var(--ps-muted) !important;
}

.text-body,
.text-dark {
  color: var(--ps-text) !important;
}

.text-primary {
  color: var(--ps-primary) !important;
}

/* Background utilities must follow the theme so light-surface panels (toolbars,
   filter bars) don't render as bright white blocks in dark mode. */
.bg-light {
  background-color: var(--ps-surface-2) !important;
  color: var(--ps-text) !important;
}

.bg-white {
  background-color: var(--ps-surface) !important;
  color: var(--ps-text) !important;
}

.bg-body,
.bg-body-tertiary,
.bg-body-secondary {
  background-color: var(--ps-surface) !important;
  color: var(--ps-text) !important;
}

.border,
.border-top,
.border-bottom,
.border-start,
.border-end {
  border-color: var(--ps-border) !important;
}

/* Bootstrap pagination should follow the theme. */
.page-link {
  background: var(--ps-surface);
  border-color: var(--ps-border);
  color: var(--ps-text);
}

.page-link:hover {
  background: var(--ps-primary-050);
  border-color: var(--ps-border);
  color: var(--ps-primary-600);
}

.page-item.active .page-link {
  background: var(--ps-primary);
  border-color: var(--ps-primary);
  color: #fff;
}

.page-item.disabled .page-link {
  background: var(--ps-surface);
  border-color: var(--ps-border);
  color: var(--ps-muted);
}

body,
p,
li,
span,
label,
dd,
dt,
small,
th,
td {
  color: inherit;
}

.hero p,
.ps-card p,
.card p {
  color: var(--ps-muted);
}

.hero h1,
.hero h2,
.hero h3,
h1, h2, h3, h4, h5, h6,
strong {
  color: var(--ps-text);
}

code,
.code,
kbd {
  background: var(--ps-primary-050);
  color: var(--ps-primary-600);
  padding: .1rem .35rem;
  border-radius: 6px;
  font-size: .85em;
}

/* ---------- Navbar ---------- */
.navbar {
  background: color-mix(in srgb, var(--ps-surface) 80%, transparent) !important;
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--ps-border) !important;
  box-shadow: none !important;
  padding-top: .6rem;
  padding-bottom: .6rem;
}

.navbar .navbar-brand {
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ps-text);
  display: inline-flex;
  align-items: center;
  gap: .55rem;
}

.navbar .navbar-brand .brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--ps-primary), var(--ps-accent));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
  box-shadow: var(--ps-shadow);
}

.navbar .nav-link {
  color: var(--ps-muted) !important;
  font-weight: 500;
  border-radius: 8px;
  padding: .45rem .8rem !important;
  transition: background-color .15s ease, color .15s ease;
}

.navbar .nav-link:hover {
  color: var(--ps-text) !important;
  background: var(--ps-primary-050);
  text-decoration: none;
}

.navbar .nav-item > span.nav-link {
  color: var(--ps-text) !important;
  font-weight: 600;
}

/* ---------- Cards ---------- */
.card,
.ps-card {
  background: var(--ps-surface);
  border: 1px solid var(--ps-border);
  border-radius: var(--ps-radius);
  box-shadow: var(--ps-shadow);
}

.ps-card {
  padding: 1.75rem;
}

/* ---------- Rule editor ---------- */
/* The rule editor is a wide two-pane workspace; let it use more horizontal space
   than the default content column so the editor and summary don't feel cramped.
   The settings page uses the same comfortable capped width for consistency. */
.app-main:has(.rule-editor),
.app-main:has(.settings-page),
.app-main:has(.gateway-editor) {
  max-width: 1440px;
}

.rule-editor .ps-card {
  padding: 1.35rem 1.5rem;
}

/* Segmented matching-mode toggle: two large, clickable option cards where the
   active mode is clearly highlighted. Replaces the greyed-out disabled panels. */
.match-mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .75rem;
}

.match-mode-option {
  display: flex;
  align-items: flex-start;
  text-align: left;
  gap: .25rem;
  padding: .9rem 1rem;
  border: 1px solid var(--ps-border);
  border-radius: var(--ps-radius-sm);
  background: var(--ps-surface);
  color: inherit;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.match-mode-option > .bi {
  font-size: 1.15rem;
  line-height: 1.4;
  color: var(--ps-primary);
}

.match-mode-option:hover {
  border-color: var(--ps-primary);
}

.match-mode-option.active {
  border-color: var(--ps-primary);
  background: color-mix(in srgb, var(--ps-primary) 8%, var(--ps-surface));
  box-shadow: 0 0 0 1px var(--ps-primary) inset;
}

@media (max-width: 575.98px) {
  .match-mode-toggle {
    grid-template-columns: 1fr;
  }
}

/* Sticky summary card: follows the user while scrolling on wide screens and
   never grows taller than the viewport. Falls back to static flow when the
   two columns collapse into a single stacked column on smaller screens. */
.rule-summary-card {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

/* Sticky action bar keeps Save/Cancel pinned to the bottom of the viewport so
   the buttons are never hidden behind the page footer. */
.rule-action-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin-top: 1rem;
  padding: .85rem 0;
  background: linear-gradient(to top, var(--ps-surface) 70%, rgba(255, 255, 255, 0));
  border-top: 1px solid var(--ps-border);
}

@media (max-width: 991.98px) {
  .rule-summary-card {
    position: static;
    max-height: none;
  }
}

/* ---------- Buttons ---------- */
.btn {
  border-radius: var(--ps-radius-sm);
  font-weight: 600;
  padding: .4rem .85rem;
  line-height: 1.35;
  transition: transform .05s ease, box-shadow .15s ease, background-color .15s ease, border-color .15s ease, color .15s ease;
}

.btn-sm {
  padding: .3rem .6rem;
  font-size: .82rem;
}

/* Keep small selects/inputs and small buttons on the same height so inline
   toolbars (e.g. the JSON editor actions) align cleanly. */
.form-select-sm,
.form-control-sm {
  padding: .3rem 1.8rem .3rem .6rem;
  font-size: .82rem;
  border-radius: var(--ps-radius-sm);
}

.form-control-sm {
  padding-right: .6rem;
}

.d-inline-flex.align-items-center .btn-sm,
.d-inline-flex.align-items-center .form-select-sm {
  min-height: calc(1.5em + .6rem + 2px);
  line-height: 1.5;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--ps-primary), var(--ps-primary-600));
  border: none;
  color: #fff;
  box-shadow: 0 6px 16px rgba(var(--ps-primary-rgb), .28);
}

.btn-primary:hover,
.btn-primary:focus {
  background: linear-gradient(135deg, var(--ps-primary-600), var(--ps-primary-600));
  color: #fff;
}

.btn-outline-primary {
  color: var(--ps-primary);
  border: 1px solid color-mix(in srgb, var(--ps-primary) 45%, var(--ps-border));
  background: var(--ps-surface-2);
}

.test-play-generate-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .55rem 1.1rem;
  font-size: .95rem;
  font-weight: 600;
}

.btn-outline-primary:hover {
  background: var(--ps-primary-050);
  color: var(--ps-primary-600);
  border-color: var(--ps-primary);
}

.btn-secondary,
.btn-outline-secondary {
  background: var(--ps-surface-3);
  border: 1px solid var(--ps-border-strong);
  color: var(--ps-text);
}

.btn-secondary:hover,
.btn-outline-secondary:hover {
  background: color-mix(in srgb, var(--ps-surface-3) 85%, var(--ps-text));
  border-color: var(--ps-border-strong);
  color: var(--ps-text);
}

.btn-outline-danger {
  color: var(--ps-danger);
  border: 1px solid color-mix(in srgb, var(--ps-danger) 45%, var(--ps-border));
  background: var(--ps-surface-2);
}

.btn-outline-danger:hover {
  background: color-mix(in srgb, var(--ps-danger) 14%, var(--ps-surface));
  border-color: var(--ps-danger);
  color: var(--ps-danger);
}

/* Disabled buttons should read as clearly inactive, not as empty ghost fills. */
.btn:disabled,
.btn.disabled {
  background: var(--ps-surface-2);
  border-color: var(--ps-border);
  color: var(--ps-muted);
  opacity: .65;
  box-shadow: none;
}

.btn-link.nav-link {
  border: none;
  background: none;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus,
.form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 .2rem rgba(var(--ps-primary-rgb), .25);
}

/* ---------- Forms ---------- */
.form-label {
  font-weight: 600;
  font-size: .9rem;
  color: var(--ps-text);
  margin-bottom: .35rem;
}

.form-control,
.form-select {
  border-radius: var(--ps-radius-sm);
  border: 1px solid var(--ps-border);
  padding: .6rem .85rem;
  background: var(--ps-input-bg);
  color: var(--ps-text);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--ps-primary);
  background: var(--ps-surface);
  color: var(--ps-text);
}

.form-control::placeholder {
  color: var(--ps-muted);
}

/* ---------- Checkboxes & switches ---------- */
.form-check-input {
  background-color: var(--ps-input-bg);
  border: 1px solid var(--ps-border-strong);
}

.form-check-input:checked {
  background-color: var(--ps-primary);
  border-color: var(--ps-primary);
}

.form-check-input:focus {
  border-color: var(--ps-primary);
  box-shadow: 0 0 0 .2rem rgba(var(--ps-primary-rgb), .25);
}

/* Switch thumb color via Bootstrap's own variable so the knob renders correctly
   in both states and both themes (Bootstrap draws the circle SVG itself). */
.form-switch .form-check-input {
  --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23c2ccdf'/%3e%3c/svg%3e");
}

.form-switch .form-check-input:focus {
  --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23c2ccdf'/%3e%3c/svg%3e");
}

.form-switch .form-check-input:checked {
  --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23ffffff'/%3e%3c/svg%3e");
}

.form-check-label {
  color: var(--ps-text);
}

/* ---------- Tables ---------- */
.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--ps-text);
  border-collapse: separate;
  border-spacing: 0;
  color: var(--ps-text);
  margin-bottom: 0;
}

.table thead th {
  text-transform: uppercase;
  font-size: .72rem;
  letter-spacing: .06em;
  color: var(--ps-muted);
  background: var(--ps-surface-2);
  border-bottom: 1px solid var(--ps-border);
  padding: .8rem 1rem;
  position: sticky;
  top: 0;
  z-index: 2;
}

.table tbody td {
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--ps-border);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

.table tbody tr {
  transition: background-color .12s ease;
}

.table tbody tr:hover > * {
  background: var(--ps-primary-050);
}

.table tbody tr:last-child > td {
  border-bottom: none;
}

.table.table-striped > tbody > tr:nth-of-type(odd) > * {
  --bs-table-accent-bg: var(--ps-surface-2);
  background: var(--ps-surface-2);
}

.table.table-striped > tbody > tr:hover > * {
  background: var(--ps-primary-050);
}

/* Sortable header affordance: adds a subtle sort glyph and pointer cue. */
.table thead th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.table thead th.sortable::after {
  content: "\F282";
  font-family: "bootstrap-icons";
  font-size: .8em;
  margin-left: .35rem;
  opacity: .35;
  vertical-align: -1px;
}

.table thead th.sortable:hover::after {
  opacity: .7;
}

.table thead th.sortable.sort-asc::after {
  content: "\F235";
  opacity: 1;
  color: var(--ps-primary);
}

.table thead th.sortable.sort-desc::after {
  content: "\F229";
  opacity: 1;
  color: var(--ps-primary);
}

/* Rounded card wrapper for grids: gives any table a clean, elevated container
   with clipped corners and a sticky-header-friendly scroll region. */
.ps-grid-card {
  background: var(--ps-surface);
  border: 1px solid var(--ps-border);
  border-radius: var(--ps-radius);
  box-shadow: var(--ps-shadow);
  overflow: hidden;
}

.ps-grid-card .table-responsive,
.ps-grid-card .ps-grid-scroll {
  max-height: none;
  border-radius: inherit;
}

.ps-grid-card .table {
  width: 100%;
}

/* Empty-state helper for grids and lists. */
.ps-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--ps-muted);
}

.ps-empty-state .bi {
  font-size: 2rem;
  color: var(--ps-border-strong);
}

/* ---------- Badges ---------- */
.badge {
  font-weight: 600;
  border-radius: 999px;
  padding: .4em .75em;
}

.badge.bg-secondary {
  background: var(--ps-surface-3) !important;
  color: var(--ps-text) !important;
}

.badge.bg-danger {
  background: #fee2e2 !important;
  color: var(--ps-danger) !important;
}

/* ---------- Alerts ---------- */
.alert {
  border-radius: var(--ps-radius-sm);
  border: 1px solid transparent;
}

.alert-success {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}

.alert-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.alert-info {
  background: var(--ps-primary-050);
  border-color: color-mix(in srgb, var(--ps-primary) 35%, var(--ps-border));
  color: var(--ps-text);
}

html[data-theme="dark"] .alert-success {
  background: rgba(52, 211, 153, .12);
  border-color: rgba(52, 211, 153, .4);
  color: #a7f3d0;
}

html[data-theme="dark"] .alert-danger {
  background: rgba(248, 113, 113, .12);
  border-color: rgba(248, 113, 113, .4);
  color: #fecaca;
}

/* ---------- Auth card ---------- */
.auth-shell {
  min-height: calc(100vh - 200px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--ps-surface);
  border: 1px solid var(--ps-border);
  border-radius: 18px;
  box-shadow: var(--ps-shadow-lg);
  padding: 2.25rem;
}

.brand-mark-lg {
  width: 48px;
  height: 48px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--ps-primary), var(--ps-accent));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.35rem;
  margin-bottom: 1rem;
  box-shadow: var(--ps-shadow);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--ps-muted);
  font-size: .85rem;
  margin: 1.25rem 0;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--ps-border);
}

/* ---------- Dropdowns ---------- */
.dropdown-menu {
  background: var(--ps-surface);
  border: 1px solid var(--ps-border);
  border-radius: var(--ps-radius-sm);
  box-shadow: var(--ps-shadow-lg);
  padding: .35rem;
}

.dropdown-item {
  border-radius: 8px;
  color: var(--ps-text);
  padding: .5rem .7rem;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--ps-primary-050);
  color: var(--ps-primary-600);
}

.dropdown-divider {
  border-top-color: var(--ps-border);
}

/* ---------- Hero ---------- */
.hero {
  background: var(--ps-surface);
  border: 1px solid var(--ps-border);
  border-radius: 20px;
  box-shadow: var(--ps-shadow);
  padding: 3rem;
  overflow: hidden;
  position: relative;
}

.hero::after {
  content: "";
  position: absolute;
  right: -80px;
  top: -80px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(79, 70, 229, .18), rgba(6, 182, 212, .05));
}

.hero .eyebrow {
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: .78rem;
  font-weight: 700;
  color: var(--ps-primary);
}

.feature-card {
  height: 100%;
}

.feature-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: var(--ps-primary-050);
  color: var(--ps-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  margin-bottom: .85rem;
}

/* ---------- Rules table density & Name column ---------- */
#rulesTable > tbody > tr > td,
#rulesTable > thead > tr > th {
  padding-top: .5rem;
  padding-bottom: .5rem;
  vertical-align: middle;
}

/* Keep rule names on as few lines as possible: wrap on spaces, never split words. */
#rulesTable .rule-name-cell {
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  line-height: 1.3;
}

/* ---------- Footer ---------- */
.footer {
  flex-shrink: 0;
  border-top: 1px solid var(--ps-border);
  background: color-mix(in srgb, var(--ps-surface) 60%, transparent);
  color: var(--ps-muted);
  padding: 1.1rem 0;
  font-size: .9rem;
}

.footer a {
  color: var(--ps-muted);
}

.footer a:hover {
  color: var(--ps-text);
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* ---------- App shell with right-side sidebar ---------- */
.app-shell {
  display: flex;
  flex-direction: row; /* sidebar on the left */
  align-items: stretch;
  min-height: 100vh;
  width: 100%;
}

.app-sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: color-mix(in srgb, var(--ps-surface) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-right: 1px solid var(--ps-border);
  padding: .85rem .85rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.app-sidebar-brand .navbar-brand {
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ps-text);
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  margin: 0;
}

.app-sidebar-close,
.app-menu-toggle,
.app-theme-toggle {
  border: 1px solid var(--ps-border);
  background: var(--ps-surface);
  color: var(--ps-text);
}

.app-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  padding: .25rem .5rem;
  border-radius: var(--ps-radius-sm);
  font-size: .875rem;
  line-height: 1.5;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}

.app-theme-toggle:hover {
  background: var(--ps-primary-050);
  color: var(--ps-primary-600);
  border-color: var(--ps-primary);
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: .65rem;
}

.app-nav-group {
  display: flex;
  flex-direction: column;
  gap: .05rem;
}

.app-nav-heading {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ps-muted);
  padding: 0 .6rem .2rem;
}

.app-nav-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .4rem .7rem;
  border-radius: var(--ps-radius-sm);
  color: var(--ps-muted);
  font-weight: 500;
  font-size: .92rem;
  transition: background-color .15s ease, color .15s ease;
}

.app-nav-link:hover {
  color: var(--ps-text);
  background: var(--ps-primary-050);
  text-decoration: none;
}

.app-nav-link.active {
  color: var(--ps-primary-600);
  background: var(--ps-primary-050);
  font-weight: 600;
}

.app-nav-link i {
  font-size: 1.05rem;
  width: 1.25rem;
  text-align: center;
}

.app-content {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .8rem 1.5rem;
  background: color-mix(in srgb, var(--ps-surface) 80%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--ps-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-user-menu {
  color: var(--ps-text);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
}

.app-user-menu:hover {
  color: var(--ps-primary-600);
  text-decoration: none;
}

.app-notifications {
  position: relative;
}

.app-notification-bell {
  color: var(--ps-text);
  border: none;
  line-height: 1;
}

.app-notification-bell:hover {
  color: var(--ps-primary-600);
}

.app-notification-flyout {
  width: 360px;
  max-width: calc(100vw - 2rem);
}

.app-notification-list {
  max-height: calc(5 * 5.5rem);
  overflow-y: auto;
}

.app-notification-item {
  min-height: 5.5rem;
}

.app-notification-item .app-notification-message {
  word-break: break-word;
}

.app-main {
  flex: 1 0 auto;
  padding: 1.5rem;
  width: 100%;
  min-width: 0;
}

.app-content .footer {
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

.app-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 1040;
}

.app-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 1050;
    box-shadow: var(--ps-shadow-lg);
  }

  .app-sidebar.is-open {
    transform: translateX(0);
  }
}

/* ---------- Log viewer ---------- */
.log-table-card {
  overflow: hidden;
}

.log-list {
  display: flex;
  flex-direction: column;
}

.log-row {
  display: grid;
  grid-template-columns: 110px 74px 1fr;
  gap: .75rem;
  align-items: start;
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--ps-border);
  border-left: 3px solid transparent;
}

.log-row:last-child {
  border-bottom: none;
}

.log-row:nth-child(even) {
  background: var(--ps-surface-2);
}

.log-row--warning {
  border-left-color: #f59e0b;
  background: rgba(245, 158, 11, .06);
}

.log-row--error {
  border-left-color: var(--ps-danger);
  background: rgba(220, 38, 38, .06);
}

.log-row--fatal {
  border-left-color: #111827;
  background: rgba(17, 24, 39, .07);
}

.log-time {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.log-time-time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: .85rem;
  color: var(--ps-text);
}

.log-time-date {
  font-variant-numeric: tabular-nums;
  font-size: .72rem;
  color: var(--ps-muted);
}

.log-level .badge {
  font-size: .68rem;
  letter-spacing: .03em;
}

.log-body {
  min-width: 0;
  word-break: break-word;
}

.log-source {
  display: inline-block;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .72rem;
  color: var(--ps-muted);
  background: var(--ps-primary-050);
  border-radius: 6px;
  padding: .05rem .4rem;
  margin-right: .45rem;
  vertical-align: middle;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-message {
  color: var(--ps-text);
  font-size: .9rem;
}

.log-details-toggle {
  font-size: .78rem;
  text-decoration: none;
}

.log-details {
  margin-top: .4rem;
  padding: .6rem .75rem;
  background: var(--ps-code-bg);
  color: var(--ps-code-text);
  border-radius: var(--ps-radius-sm);
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .78rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

@media (max-width: 575.98px) {
  .log-row {
    grid-template-columns: 1fr;
    gap: .25rem;
  }

  .log-time {
    flex-direction: row;
    gap: .4rem;
  }
}

/* Gateway chips: a distinct, accessible color per gateway so they are easy to
   distinguish at a glance in the rules list. */
.gateway-chip {
  color: #fff;
  font-weight: 600;
  letter-spacing: .01em;
}

.gateway-chip-cybersource {
  background-color: #1a73e8; /* blue */
}

.gateway-chip-mpgs {
  background-color: #7b2ff7; /* purple */
}

.gateway-chip-adyen {
  background-color: #0abf53; /* green */
}

.gateway-chip-default {
  background-color: #6c757d; /* neutral grey */
}

/* ---------------------------------------------------------------------------
   JSON editor with syntax highlighting.
   A transparent-text <textarea> sits on top of a highlighted <pre> layer that
   mirrors its content and scroll position, so users still edit a real textarea
   but see coloured JSON tokens underneath.
   --------------------------------------------------------------------------- */
.json-editor {
  position: relative;
}

.json-editor .json-editor-highlight,
.json-editor textarea.json-editor-input {
  /* Both layers must share identical box metrics so glyphs line up exactly. */
  margin: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--ps-border-strong);
  border-radius: 0.375rem;
  font-family: var(--bs-font-monospace, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 0.875rem;
  line-height: 1.5;
  letter-spacing: normal;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}

.json-editor .json-editor-highlight {
  position: absolute;
  inset: 0;
  overflow: auto;
  pointer-events: none;
  background: var(--ps-input-bg);
  color: var(--ps-text);
  z-index: 0;
}

.json-editor textarea.json-editor-input {
  position: relative;
  z-index: 1;
  width: 100%;
  background: transparent;
  color: transparent;
  caret-color: var(--ps-text);
  resize: vertical;
}

.json-editor textarea.json-editor-input::selection {
  color: transparent;
  background: rgba(var(--ps-primary-rgb), 0.25);
}

/* Token colours */
.json-editor .json-key { color: #0b6bcb; }
.json-editor .json-string { color: #158a3c; }
.json-editor .json-number { color: #b2532a; }
.json-editor .json-boolean { color: #8250df; font-weight: 600; }
.json-editor .json-null { color: #8250df; font-weight: 600; }
.json-editor .json-punctuation { color: var(--ps-muted); }
.json-editor .json-token { color: #b2532a; font-weight: 600; } /* {{request.x}} template tokens */
/* ---------------------------------------------------------------------------
   Read-only payload viewer (request log details): highlighted JSON + copy buttons.
   Reuses the rule-editor token colours.
   --------------------------------------------------------------------------- */
pre.payload-pre,
.copyable > pre {
  background: var(--ps-input-bg, #f8f9fc);
  color: var(--ps-text);
  border: 1px solid var(--ps-border-strong) !important;
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-family: var(--bs-font-monospace, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 0.875rem;
  line-height: 1.5;
  max-height: 32rem;
  overflow: auto;
  tab-size: 2;
}

/* Reserve space above the <pre> for the floating Copy button so it doesn't
   overlap the first line of headers/content inside the box. */
.copyable-toolbar .copy-btn { opacity: 0.85; }
.copyable-toolbar .copy-btn:hover { opacity: 1; }

/* Headings paired with an inline Copy button (e.g. "Headers") keep the button
   aligned on the same line rather than stacked above the box. */
.payload-heading-row .copy-btn {
  opacity: 0.85;
}
.payload-heading-row .copy-btn:hover {
  opacity: 1;
}

/* Request/response Headers blocks (Request Log details): capped height with its own
   scrollbar so long header lists don't stretch the Request/Response cards out of
   alignment with each other. Long individual header lines scroll horizontally too.
   A fixed min-height (matching max-height) keeps the two side-by-side boxes the same
   height even when one side has few/no headers (e.g. "(no headers)"), so the Pretty/Raw
   toggle and body below stay aligned between the Request and Response columns. */
pre.payload-pre.headers-pre {
  min-height: 10rem;
  max-height: 10rem;
  white-space: pre;
  overflow-x: auto;
}

pre.json-view .json-key { color: #0b6bcb; }
pre.json-view .json-string { color: #158a3c; }
pre.json-view .json-number { color: #b2532a; }
pre.json-view .json-boolean,
pre.json-view .json-null { color: #8250df; font-weight: 600; }
pre.json-view .json-punctuation { color: var(--ps-muted); }
