/*
 * Realvia Service admin – compact design system on top of Bootstrap 5.3.
 * Tokens are defined as CSS variables; dark mode via [data-bs-theme="dark"].
 */

:root,
[data-bs-theme="light"] {
  --rv-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --rv-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --rv-bg: #f4f6f9;
  --rv-surface: #ffffff;
  --rv-surface-2: #f8fafc;
  --rv-border: #e3e7ee;
  --rv-border-strong: #cfd6e1;
  --rv-text: #0f172a;
  --rv-muted: #64748b;
  --rv-subtle: #94a3b8;

  --rv-primary: #2563eb;
  --rv-primary-hover: #1d4ed8;
  --rv-primary-soft: #eaf1ff;
  --rv-success: #16a34a;
  --rv-success-soft: #e8f7ee;
  --rv-warning: #d97706;
  --rv-warning-soft: #fdf3e2;
  --rv-danger: #dc2626;
  --rv-danger-soft: #fdecec;
  --rv-info: #0891b2;
  --rv-info-soft: #e5f6fa;

  --rv-sidebar-bg: #0f172a;
  --rv-sidebar-text: #cbd5e1;
  --rv-sidebar-muted: #64748b;
  --rv-sidebar-hover: rgba(255, 255, 255, .06);
  --rv-sidebar-active: rgba(59, 130, 246, .18);
  --rv-sidebar-active-text: #ffffff;

  --rv-radius: 8px;
  --rv-radius-lg: 12px;
  --rv-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --rv-shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
  --rv-sidebar-w: 232px;
  --rv-topbar-h: 52px;

  --bs-body-font-family: var(--rv-font);
  --bs-body-font-size: .875rem;
  --bs-body-line-height: 1.5;
  --bs-body-bg: var(--rv-bg);
  --bs-body-color: var(--rv-text);
  --bs-border-color: var(--rv-border);
  --bs-secondary-color: var(--rv-muted);
  --bs-primary: var(--rv-primary);
  --bs-primary-rgb: 37, 99, 235;
  --bs-link-color: var(--rv-primary);
  --bs-link-color-rgb: 37, 99, 235;
  --bs-link-hover-color: var(--rv-primary-hover);
  --bs-border-radius: var(--rv-radius);
  --bs-border-radius-sm: 6px;
  --bs-border-radius-lg: var(--rv-radius-lg);
  --bs-font-monospace: var(--rv-mono);
}

[data-bs-theme="dark"] {
  --rv-bg: #0b1120;
  --rv-surface: #111827;
  --rv-surface-2: #0f172a;
  --rv-border: #1f2a3c;
  --rv-border-strong: #2b3a52;
  --rv-text: #e5e9f0;
  --rv-muted: #94a3b8;
  --rv-subtle: #64748b;

  --rv-primary: #3b82f6;
  --rv-primary-hover: #60a5fa;
  --rv-primary-soft: rgba(59, 130, 246, .14);
  --rv-success: #22c55e;
  --rv-success-soft: rgba(34, 197, 94, .13);
  --rv-warning: #f59e0b;
  --rv-warning-soft: rgba(245, 158, 11, .13);
  --rv-danger: #f87171;
  --rv-danger-soft: rgba(248, 113, 113, .13);
  --rv-info: #22d3ee;
  --rv-info-soft: rgba(34, 211, 238, .12);

  --rv-sidebar-bg: #070b16;
  --rv-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --rv-shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);

  --bs-body-bg: var(--rv-bg);
  --bs-body-color: var(--rv-text);
  --bs-border-color: var(--rv-border);
  --bs-secondary-color: var(--rv-muted);
  --bs-primary-rgb: 59, 130, 246;
  --bs-link-color: var(--rv-primary);
  --bs-link-color-rgb: 59, 130, 246;
  --bs-link-hover-color: var(--rv-primary-hover);
  --bs-tertiary-bg: var(--rv-surface-2);
  color-scheme: dark;
}

/* ---------- Base ---------- */

html { font-size: 16px; }
body {
  background: var(--rv-bg);
  color: var(--rv-text);
  font-family: var(--rv-font);
  font-size: .875rem;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
h1, .h1 { font-size: 1.375rem; }
h2, .h2 { font-size: 1.125rem; }
h3, .h3 { font-size: 1rem; }
h4, .h4 { font-size: .95rem; }
h5, .h5 { font-size: .9rem; }
h6, .h6 { font-size: .8125rem; }
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { font-weight: 600; letter-spacing: -.01em; color: var(--rv-text); }
a { text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
.btn:hover, .nav-link:hover, .list-group-item-action:hover, .dropdown-item:hover, .page-link:hover { text-decoration: none; }
code, kbd, pre, .font-monospace { font-family: var(--rv-mono); font-size: .8em; }
code { color: var(--rv-primary); background: var(--rv-primary-soft); padding: .1em .35em; border-radius: 4px; }
pre code { background: none; padding: 0; color: inherit; }
pre { background: var(--rv-surface-2); border: 1px solid var(--rv-border); border-radius: var(--rv-radius); padding: .75rem; font-size: .75rem; }
.text-muted, .text-secondary { color: var(--rv-muted) !important; }
.small, small { font-size: .8125rem; }
.xsmall { font-size: .75rem; }
hr { border-color: var(--rv-border); opacity: 1; }
::selection { background: rgba(37, 99, 235, .2); }

/* ---------- App shell ---------- */

.rv-app { min-height: 100vh; }

.rv-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rv-sidebar-w);
  background: var(--rv-sidebar-bg);
  color: var(--rv-sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .2s ease, width .2s ease;
}
.rv-sidebar__brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  height: var(--rv-topbar-h);
  padding: 0 1rem;
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  letter-spacing: -.01em;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  flex-shrink: 0;
}
.rv-sidebar__brand:hover { color: #fff; text-decoration: none; }
.rv-sidebar__logo {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff; font-size: .9rem;
  flex-shrink: 0;
}
.rv-sidebar__brand small { display: block; font-weight: 400; font-size: .6875rem; color: var(--rv-sidebar-muted); }
.rv-sidebar__nav { flex: 1; overflow-y: auto; padding: .5rem .5rem 1rem; scrollbar-width: thin; scrollbar-color: #1e293b transparent; }
.rv-nav-group { margin-top: .75rem; }
.rv-nav-group__title {
  padding: 0 .65rem .3rem;
  font-size: .6563rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--rv-sidebar-muted);
}
.rv-nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .4rem .65rem;
  border-radius: 6px;
  color: var(--rv-sidebar-text);
  font-size: .8125rem;
  line-height: 1.35;
  white-space: nowrap;
}
.rv-nav-link i { font-size: 1rem; width: 1.1rem; text-align: center; opacity: .8; flex-shrink: 0; }
.rv-nav-link:hover { background: var(--rv-sidebar-hover); color: #fff; text-decoration: none; }
.rv-nav-link.active { background: var(--rv-sidebar-active); color: var(--rv-sidebar-active-text); font-weight: 500; }
.rv-nav-link.active i { opacity: 1; color: #60a5fa; }
.rv-sidebar__foot { padding: .6rem; border-top: 1px solid rgba(255, 255, 255, .06); font-size: .75rem; color: var(--rv-sidebar-muted); }

.rv-main { margin-left: var(--rv-sidebar-w); min-width: 0; transition: margin-left .2s ease; }

.rv-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  height: var(--rv-topbar-h);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--rv-surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--rv-border);
}
.rv-topbar__title { font-weight: 600; font-size: .9375rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rv-topbar__crumbs { font-size: .8125rem; color: var(--rv-muted); display: flex; align-items: center; gap: .35rem; min-width: 0; }
.rv-topbar__crumbs a { color: var(--rv-muted); text-decoration: none; }
.rv-topbar__crumbs a:hover { color: var(--rv-text); text-decoration: underline; }
.rv-topbar__crumbs .sep { color: var(--rv-subtle); }
.rv-topbar__actions { margin-left: auto; display: flex; align-items: center; gap: .35rem; }

.rv-content { padding: 1.25rem; max-width: 1600px; }
.rv-content--narrow { max-width: 1100px; }

/* Legacy pages wrap themselves in .container / mt-5 – flatten that inside the shell */
.rv-content > .container,
.rv-content > .container-fluid { max-width: none; padding-left: 0; padding-right: 0; margin-top: 0 !important; }

.rv-sidebar-toggle { display: none; }

body.rv-collapsed { --rv-sidebar-w: 64px; }
body.rv-collapsed .rv-sidebar__brand span,
body.rv-collapsed .rv-nav-link span,
body.rv-collapsed .rv-nav-group__title,
body.rv-collapsed .rv-sidebar__foot span { display: none; }
body.rv-collapsed .rv-nav-link { justify-content: center; padding: .5rem; }
body.rv-collapsed .rv-nav-group { margin-top: .4rem; border-top: 1px solid rgba(255, 255, 255, .05); padding-top: .4rem; }
body.rv-collapsed .rv-sidebar__brand { justify-content: center; padding: 0; }

@media (max-width: 991.98px) {
  .rv-sidebar { transform: translateX(-100%); box-shadow: var(--rv-shadow-lg); --rv-sidebar-w: 260px; width: 260px; }
  body.rv-sidebar-open .rv-sidebar { transform: none; }
  body.rv-sidebar-open .rv-backdrop { display: block; }
  .rv-main { margin-left: 0 !important; }
  .rv-sidebar-toggle { display: inline-flex; }
  .rv-collapse-btn { display: none !important; }
  .rv-content { padding: 1rem; }
  .rv-topbar { padding: 0 1rem; }
}
.rv-backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1035; }

/* ---------- Page header ---------- */

.rv-page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: 1rem;
}
.rv-page-head h1 { margin: 0; font-size: 1.25rem; }
.rv-page-head p { margin: .2rem 0 0; color: var(--rv-muted); font-size: .8125rem; }
.rv-page-head__actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.rv-page-head__actions .form-control, .rv-page-head__actions .form-select { width: auto; }
.rv-page-head__actions form { display: contents; }
.rv-back { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 6px; color: var(--rv-muted); border: 1px solid var(--rv-border); background: var(--rv-surface); margin-right: .5rem; vertical-align: middle; }
.rv-back:hover { color: var(--rv-text); background: var(--rv-surface-2); text-decoration: none; }

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

.card,
.rv-card {
  --bs-card-bg: var(--rv-surface);
  --bs-card-border-color: var(--rv-border);
  --bs-card-cap-bg: transparent;
  --bs-card-spacer-y: .875rem;
  --bs-card-spacer-x: 1rem;
  --bs-card-cap-padding-y: .65rem;
  --bs-card-border-radius: var(--rv-radius-lg);
  --bs-card-inner-border-radius: calc(var(--rv-radius-lg) - 1px);
  background: var(--rv-surface);
  border: 1px solid var(--rv-border);
  border-radius: var(--rv-radius-lg);
  box-shadow: var(--rv-shadow);
}
.rv-card { display: block; }
.rv-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--rv-border);
  min-height: 44px;
}
.rv-card__head h2, .rv-card__head h3, .rv-card__title { margin: 0; font-size: .875rem; font-weight: 600; }
.rv-card__head p { margin: 0; font-size: .75rem; color: var(--rv-muted); }
.rv-card__body { padding: .875rem 1rem; }
.rv-card__body--flush { padding: 0; }
.rv-card__foot { padding: .6rem 1rem; border-top: 1px solid var(--rv-border); background: var(--rv-surface-2); border-radius: 0 0 var(--rv-radius-lg) var(--rv-radius-lg); }
.card-header { font-weight: 600; font-size: .875rem; border-bottom-color: var(--rv-border); }

/* Legacy look-alikes that some pages still use */
.border.rounded.bg-white,
.rounded.bg-white.shadow-sm { background: var(--rv-surface) !important; border-color: var(--rv-border) !important; border-radius: var(--rv-radius-lg) !important; box-shadow: var(--rv-shadow) !important; }
.bg-white { background-color: var(--rv-surface) !important; }
.bg-light { background-color: var(--rv-surface-2) !important; }
[data-bs-theme="dark"] .text-black, [data-bs-theme="dark"] .text-dark { color: var(--rv-text) !important; }

/* ---------- Stats ---------- */

.rv-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.rv-stat {
  background: var(--rv-surface);
  border: 1px solid var(--rv-border);
  border-radius: var(--rv-radius-lg);
  padding: .7rem .9rem;
  box-shadow: var(--rv-shadow);
}
.rv-stat__label { font-size: .7188rem; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; color: var(--rv-muted); }
.rv-stat__value { font-size: 1.375rem; font-weight: 600; letter-spacing: -.02em; line-height: 1.25; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.rv-stat__hint { font-size: .75rem; color: var(--rv-muted); }
.rv-stat--danger .rv-stat__value { color: var(--rv-danger); }
.rv-stat--success .rv-stat__value { color: var(--rv-success); }
.rv-stat--warning .rv-stat__value { color: var(--rv-warning); }

/* ---------- Toolbar ---------- */

.rv-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.rv-toolbar .form-control, .rv-toolbar .form-select { width: auto; min-width: 160px; }
.rv-toolbar__spacer { flex: 1; }
.rv-search { position: relative; }
.rv-search > i { position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); color: var(--rv-subtle); pointer-events: none; font-size: .85rem; }
.rv-search > .form-control { padding-left: 1.9rem; }

/* ---------- Buttons ---------- */

.btn {
  --bs-btn-padding-y: .3125rem;
  --bs-btn-padding-x: .75rem;
  --bs-btn-font-size: .8125rem;
  --bs-btn-font-weight: 500;
  --bs-btn-border-radius: 6px;
  --bs-btn-focus-box-shadow: 0 0 0 3px rgba(37, 99, 235, .25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  white-space: nowrap;
  line-height: 1.4;
}
.btn-sm { --bs-btn-padding-y: .1875rem; --bs-btn-padding-x: .5rem; --bs-btn-font-size: .75rem; --bs-btn-border-radius: 5px; }
.btn-lg { --bs-btn-padding-y: .5rem; --bs-btn-padding-x: 1rem; --bs-btn-font-size: .9rem; }
.btn-primary { --bs-btn-bg: var(--rv-primary); --bs-btn-border-color: var(--rv-primary); --bs-btn-hover-bg: var(--rv-primary-hover); --bs-btn-hover-border-color: var(--rv-primary-hover); --bs-btn-active-bg: var(--rv-primary-hover); --bs-btn-active-border-color: var(--rv-primary-hover); --bs-btn-disabled-bg: var(--rv-primary); --bs-btn-disabled-border-color: var(--rv-primary); }
.btn-light, .btn-outline-secondary, .btn-secondary {
  --bs-btn-color: var(--rv-text);
  --bs-btn-bg: var(--rv-surface);
  --bs-btn-border-color: var(--rv-border-strong);
  --bs-btn-hover-color: var(--rv-text);
  --bs-btn-hover-bg: var(--rv-surface-2);
  --bs-btn-hover-border-color: var(--rv-border-strong);
  --bs-btn-active-color: var(--rv-text);
  --bs-btn-active-bg: var(--rv-border);
  --bs-btn-active-border-color: var(--rv-border-strong);
  box-shadow: 0 1px 1px rgba(15, 23, 42, .04);
}
.btn-ghost { --bs-btn-color: var(--rv-muted); --bs-btn-bg: transparent; --bs-btn-border-color: transparent; --bs-btn-hover-color: var(--rv-text); --bs-btn-hover-bg: var(--rv-surface-2); --bs-btn-active-bg: var(--rv-border); }
.btn-soft-primary { --bs-btn-color: var(--rv-primary); --bs-btn-bg: var(--rv-primary-soft); --bs-btn-border-color: transparent; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: var(--rv-primary); --bs-btn-active-bg: var(--rv-primary-hover); --bs-btn-active-color: #fff; }
.btn-soft-danger, .btn-outline-danger { --bs-btn-color: var(--rv-danger); --bs-btn-bg: var(--rv-danger-soft); --bs-btn-border-color: transparent; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: var(--rv-danger); --bs-btn-hover-border-color: var(--rv-danger); --bs-btn-active-bg: var(--rv-danger); --bs-btn-active-color: #fff; }
.btn-soft-success { --bs-btn-color: var(--rv-success); --bs-btn-bg: var(--rv-success-soft); --bs-btn-border-color: transparent; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: var(--rv-success); --bs-btn-active-bg: var(--rv-success); --bs-btn-active-color: #fff; }
.btn-soft-warning { --bs-btn-color: var(--rv-warning); --bs-btn-bg: var(--rv-warning-soft); --bs-btn-border-color: transparent; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: var(--rv-warning); --bs-btn-active-bg: var(--rv-warning); --bs-btn-active-color: #fff; }
.btn-outline-primary { --bs-btn-color: var(--rv-primary); --bs-btn-border-color: color-mix(in srgb, var(--rv-primary) 45%, transparent); --bs-btn-hover-bg: var(--rv-primary); --bs-btn-hover-border-color: var(--rv-primary); --bs-btn-active-bg: var(--rv-primary-hover); }
.btn-icon { --bs-btn-padding-x: 0; width: 30px; height: 30px; }
.btn-icon.btn-sm { width: 26px; height: 26px; }
.btn-group-tight { display: inline-flex; gap: .25rem; align-items: center; }
.btn-group-tight form { margin: 0; display: inline-flex; }

/* ---------- Forms ---------- */

.form-control, .form-select {
  font-size: .8125rem;
  padding: .375rem .65rem;
  min-height: 32px;
  border-radius: 6px;
  border: 1px solid var(--rv-border-strong);
  background-color: var(--rv-surface);
  color: var(--rv-text);
  box-shadow: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-select { padding-right: 2rem; background-position: right .55rem center; }
.form-control-sm, .form-select-sm { min-height: 28px; padding: .2rem .5rem; font-size: .75rem; }
.form-control:focus, .form-select:focus { border-color: var(--rv-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .18); background-color: var(--rv-surface); color: var(--rv-text); }
.form-control::placeholder { color: var(--rv-subtle); }
textarea.form-control { min-height: 72px; }
.form-label { font-size: .75rem; font-weight: 500; color: var(--rv-muted); margin-bottom: .25rem; }
.form-text { font-size: .75rem; color: var(--rv-muted); }
.form-check-input { border-color: var(--rv-border-strong); }
.form-check-input:checked { background-color: var(--rv-primary); border-color: var(--rv-primary); }
.form-check-label { font-size: .8125rem; }
.input-group-text { font-size: .8125rem; background: var(--rv-surface-2); border-color: var(--rv-border-strong); color: var(--rv-muted); }
.rv-form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem 1rem; }
.rv-form-grid .span-2 { grid-column: span 2; }
.rv-form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 575.98px) { .rv-form-grid .span-2 { grid-column: 1 / -1; } }
.rv-form-actions { display: flex; gap: .5rem; justify-content: flex-end; padding-top: .75rem; margin-top: .75rem; border-top: 1px solid var(--rv-border); }

/* ---------- Tables ---------- */

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--rv-text);
  --bs-table-border-color: var(--rv-border);
  --bs-table-striped-bg: color-mix(in srgb, var(--rv-surface-2) 70%, transparent);
  --bs-table-striped-color: var(--rv-text);
  --bs-table-hover-bg: var(--rv-primary-soft);
  --bs-table-hover-color: var(--rv-text);
  font-size: .8125rem;
  margin-bottom: 0;
}
.table > :not(caption) > * > * { padding: .45rem .75rem; border-bottom-color: var(--rv-border); }
.table-sm > :not(caption) > * > * { padding: .3rem .6rem; }
.table > thead > tr > th,
.table thead.table-dark th,
.table thead.table-light th {
  --bs-table-bg: var(--rv-surface-2);
  --bs-table-color: var(--rv-muted);
  background: var(--rv-surface-2);
  color: var(--rv-muted);
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--rv-border) !important;
  border-top: 0;
  vertical-align: middle;
}
.table-bordered > :not(caption) > * > * { border-width: 0 0 1px 0; }
.table-bordered > :not(caption) > * { border-width: 0; }
.table > tbody > tr:last-child > * { border-bottom: 0; }
.table td { vertical-align: middle; }
.table .table-dark { --bs-table-bg: var(--rv-surface-2); --bs-table-color: var(--rv-muted); }
.table-responsive { border-radius: inherit; }
.rv-table-wrap { background: var(--rv-surface); border: 1px solid var(--rv-border); border-radius: var(--rv-radius-lg); box-shadow: var(--rv-shadow); overflow: hidden; }
.rv-table-wrap > .table-responsive { margin: 0; }
.rv-table-sticky thead th { position: sticky; top: 0; z-index: 2; }
.rv-table-scroll { max-height: 70vh; overflow: auto; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table .num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table tr.is-off td { color: var(--rv-muted); }
.table-success { --bs-table-bg: var(--rv-success-soft); --bs-table-color: var(--rv-text); }
.table-danger { --bs-table-bg: var(--rv-danger-soft); --bs-table-color: var(--rv-text); }
.table-warning { --bs-table-bg: var(--rv-warning-soft); --bs-table-color: var(--rv-text); }
.table-info { --bs-table-bg: var(--rv-info-soft); --bs-table-color: var(--rv-text); }
.sort-link { color: inherit; display: inline-flex; align-items: center; gap: .25rem; }
.sort-link:hover { color: var(--rv-text); text-decoration: none; }

/* ---------- Badges / pills ---------- */

.badge { font-weight: 500; font-size: .6875rem; padding: .25em .55em; border-radius: 5px; letter-spacing: .01em; }
.rv-badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .6875rem; font-weight: 500; padding: .15rem .5rem; border-radius: 999px; background: var(--rv-surface-2); color: var(--rv-muted); border: 1px solid var(--rv-border); white-space: nowrap; line-height: 1.5; }
.rv-badge--primary { background: var(--rv-primary-soft); color: var(--rv-primary); border-color: transparent; }
.rv-badge--success { background: var(--rv-success-soft); color: var(--rv-success); border-color: transparent; }
.rv-badge--warning { background: var(--rv-warning-soft); color: var(--rv-warning); border-color: transparent; }
.rv-badge--danger { background: var(--rv-danger-soft); color: var(--rv-danger); border-color: transparent; }
.rv-badge--info { background: var(--rv-info-soft); color: var(--rv-info); border-color: transparent; }
.rv-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; flex-shrink: 0; }
.bg-primary { background-color: var(--rv-primary) !important; }
.bg-success { background-color: var(--rv-success) !important; }
.bg-danger { background-color: var(--rv-danger) !important; }
.bg-warning { background-color: var(--rv-warning) !important; }
.bg-info { background-color: var(--rv-info) !important; }
.bg-secondary { background-color: var(--rv-subtle) !important; }
.text-primary { color: var(--rv-primary) !important; }
.text-success { color: var(--rv-success) !important; }
.text-danger { color: var(--rv-danger) !important; }
.text-warning { color: var(--rv-warning) !important; }

/* ---------- Alerts ---------- */

.alert { font-size: .8125rem; padding: .6rem .85rem; border-radius: var(--rv-radius); border: 1px solid transparent; }
.alert-success { background: var(--rv-success-soft); color: var(--rv-success); border-color: color-mix(in srgb, var(--rv-success) 25%, transparent); }
.alert-danger { background: var(--rv-danger-soft); color: var(--rv-danger); border-color: color-mix(in srgb, var(--rv-danger) 25%, transparent); }
.alert-warning { background: var(--rv-warning-soft); color: var(--rv-warning); border-color: color-mix(in srgb, var(--rv-warning) 25%, transparent); }
.alert-info, .alert-primary { background: var(--rv-info-soft); color: var(--rv-info); border-color: color-mix(in srgb, var(--rv-info) 25%, transparent); }
.alert-secondary, .alert-light { background: var(--rv-surface-2); color: var(--rv-muted); border-color: var(--rv-border); }

/* ---------- Lists, nav, pagination ---------- */

.list-group { --bs-list-group-bg: var(--rv-surface); --bs-list-group-border-color: var(--rv-border); --bs-list-group-color: var(--rv-text); --bs-list-group-action-hover-bg: var(--rv-surface-2); --bs-list-group-action-hover-color: var(--rv-text); --bs-list-group-item-padding-y: .5rem; --bs-list-group-item-padding-x: .85rem; font-size: .8125rem; }
.nav-tabs { --bs-nav-tabs-border-color: var(--rv-border); --bs-nav-tabs-link-active-bg: transparent; --bs-nav-tabs-link-active-border-color: transparent; gap: .25rem; }
.nav-tabs .nav-link { border: 0; border-bottom: 2px solid transparent; color: var(--rv-muted); font-size: .8125rem; font-weight: 500; padding: .5rem .75rem; }
.nav-tabs .nav-link.active { color: var(--rv-primary); border-bottom-color: var(--rv-primary); background: transparent; }
.nav-pills { --bs-nav-pills-link-active-bg: var(--rv-primary-soft); --bs-nav-pills-link-active-color: var(--rv-primary); }
.nav-pills .nav-link { font-size: .8125rem; padding: .3rem .7rem; color: var(--rv-muted); }

.pagination { --bs-pagination-padding-x: .6rem; --bs-pagination-padding-y: .25rem; --bs-pagination-font-size: .8125rem; --bs-pagination-bg: var(--rv-surface); --bs-pagination-border-color: var(--rv-border); --bs-pagination-color: var(--rv-text); --bs-pagination-hover-bg: var(--rv-surface-2); --bs-pagination-hover-color: var(--rv-text); --bs-pagination-hover-border-color: var(--rv-border); --bs-pagination-active-bg: var(--rv-primary); --bs-pagination-active-border-color: var(--rv-primary); --bs-pagination-disabled-bg: var(--rv-surface); --bs-pagination-disabled-color: var(--rv-muted); --bs-pagination-disabled-border-color: var(--rv-border); --bs-pagination-border-radius: 6px; flex-wrap: wrap; gap: .2rem; margin-bottom: 0; }
.pagination .page-link { border-radius: 6px !important; min-width: 30px; text-align: center; }
.rv-pager { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; padding: .6rem 1rem; border-top: 1px solid var(--rv-border); font-size: .8125rem; color: var(--rv-muted); }

.breadcrumb { font-size: .8125rem; --bs-breadcrumb-divider-color: var(--rv-subtle); --bs-breadcrumb-item-active-color: var(--rv-muted); }

.dropdown-menu { --bs-dropdown-font-size: .8125rem; --bs-dropdown-bg: var(--rv-surface); --bs-dropdown-border-color: var(--rv-border); --bs-dropdown-link-hover-bg: var(--rv-surface-2); --bs-dropdown-link-active-bg: var(--rv-primary); box-shadow: var(--rv-shadow-lg); border-radius: var(--rv-radius); padding: .3rem; }
.dropdown-item { border-radius: 5px; padding: .35rem .6rem; }
.modal-content { background: var(--rv-surface); border-color: var(--rv-border); border-radius: var(--rv-radius-lg); }
.modal-header, .modal-footer { border-color: var(--rv-border); padding: .75rem 1rem; }
.modal-title { font-size: .95rem; }
.tooltip { --bs-tooltip-font-size: .75rem; }
.accordion { --bs-accordion-bg: var(--rv-surface); --bs-accordion-border-color: var(--rv-border); --bs-accordion-btn-padding-y: .6rem; --bs-accordion-btn-padding-x: .9rem; --bs-accordion-body-padding-y: .75rem; --bs-accordion-body-padding-x: .9rem; --bs-accordion-active-bg: var(--rv-primary-soft); --bs-accordion-active-color: var(--rv-primary); --bs-accordion-btn-focus-box-shadow: none; font-size: .8125rem; }
.accordion-button { font-size: .8125rem; font-weight: 500; }

/* ---------- Misc components ---------- */

.rv-empty { text-align: center; padding: 2.25rem 1rem; color: var(--rv-muted); }
.rv-empty i { font-size: 1.75rem; display: block; margin-bottom: .4rem; color: var(--rv-subtle); }
.rv-kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; font-size: .8125rem; margin: 0; }
.rv-kv dt { color: var(--rv-muted); font-weight: 500; }
.rv-kv dd { margin: 0; min-width: 0; word-break: break-word; }
.rv-mono { font-family: var(--rv-mono); font-size: .75rem; }
.rv-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; display: inline-block; vertical-align: bottom; }
.rv-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.rv-grid { display: grid; gap: 1rem; }
.rv-grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.rv-grid-3 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.rv-section-title { font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--rv-muted); margin: 1.25rem 0 .5rem; }
.rv-section-title a { color: inherit; text-decoration: none; }
.rv-section-title a:hover { color: var(--rv-text); }
.rv-divider { height: 1px; background: var(--rv-border); margin: .75rem 0; }
.rv-scroll { max-height: 360px; overflow: auto; }

/* Dashboard tiles */
.rv-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .65rem; }
.rv-tile {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem .85rem;
  background: var(--rv-surface);
  border: 1px solid var(--rv-border);
  border-radius: var(--rv-radius-lg);
  color: var(--rv-text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
  box-shadow: var(--rv-shadow);
}
.rv-tile:hover { border-color: color-mix(in srgb, var(--rv-primary) 45%, var(--rv-border)); box-shadow: var(--rv-shadow-lg); text-decoration: none; color: var(--rv-text); transform: translateY(-1px); }
.rv-tile__icon { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-size: 1.05rem; background: var(--rv-primary-soft); color: var(--rv-primary); flex-shrink: 0; }
.rv-tile__name { font-weight: 600; font-size: .8125rem; line-height: 1.3; }
.rv-tile__desc { font-size: .75rem; color: var(--rv-muted); line-height: 1.35; }
.rv-tile--green .rv-tile__icon { background: var(--rv-success-soft); color: var(--rv-success); }
.rv-tile--amber .rv-tile__icon { background: var(--rv-warning-soft); color: var(--rv-warning); }
.rv-tile--red .rv-tile__icon { background: var(--rv-danger-soft); color: var(--rv-danger); }
.rv-tile--cyan .rv-tile__icon { background: var(--rv-info-soft); color: var(--rv-info); }

/* Login */
.rv-auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(1200px 600px at 10% -10%, rgba(59, 130, 246, .18), transparent 60%), radial-gradient(900px 500px at 110% 110%, rgba(99, 102, 241, .16), transparent 60%), var(--rv-bg); }
.rv-auth__card { width: 100%; max-width: 380px; }
.rv-auth__brand { display: flex; align-items: center; gap: .6rem; justify-content: center; margin-bottom: 1.25rem; font-weight: 600; font-size: 1rem; }
.rv-auth__brand .rv-sidebar__logo { width: 34px; height: 34px; font-size: 1.05rem; }

/* Third-party widgets: selectize, summernote */
.selectize-control { font-size: .8125rem; }
.selectize-control .selectize-input, .selectize-input.focus { border-color: var(--rv-border-strong); border-radius: 6px; min-height: 32px; padding: .3rem .5rem; box-shadow: none; background: var(--rv-surface); color: var(--rv-text); }
.selectize-input.focus { border-color: var(--rv-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .18); }
.selectize-control.multi .selectize-input > div { background: var(--rv-primary-soft); color: var(--rv-primary); border-radius: 4px; padding: 1px 6px; font-size: .75rem; border: 0; }
.selectize-control.multi .selectize-input > div.active { background: var(--rv-primary); color: #fff; }
.selectize-dropdown { background: var(--rv-surface); color: var(--rv-text); border-color: var(--rv-border); border-radius: 0 0 6px 6px; font-size: .8125rem; }
.selectize-dropdown .active { background: var(--rv-primary-soft); color: var(--rv-text); }
.selectize-input input { color: var(--rv-text) !important; }
.note-editor.note-frame { border-color: var(--rv-border-strong) !important; border-radius: 6px; background: var(--rv-surface); }
.note-editor .note-toolbar { background: var(--rv-surface-2) !important; border-bottom: 1px solid var(--rv-border) !important; padding: .3rem .4rem !important; }
.note-editor .note-editing-area .note-editable { background: var(--rv-surface); color: var(--rv-text); }
.note-btn { font-size: .75rem !important; padding: .2rem .45rem !important; background: var(--rv-surface) !important; border-color: var(--rv-border-strong) !important; color: var(--rv-text) !important; }
.note-statusbar { background: var(--rv-surface-2) !important; }

/* Leaflet / charts in dark mode */
[data-bs-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
[data-bs-theme="dark"] .leaflet-popup-content-wrapper, [data-bs-theme="dark"] .leaflet-popup-tip { background: var(--rv-surface); color: var(--rv-text); }

/* Utilities */
.gap-xs { gap: .25rem !important; }
.mw-0 { min-width: 0; }
.w-1 { width: 1%; }
.cursor-pointer { cursor: pointer; }

.progress { --bs-progress-bg: var(--rv-surface-2); --bs-progress-bar-bg: var(--rv-primary); border-radius: 999px; }

/* ---------- Fixer / Info functions / Info Realvia / Tests ---------- */
/* KPI tile used as a link (e.g. jump to a section) */
a.rv-stat { display: block; color: var(--rv-text); transition: border-color .15s, box-shadow .15s; }
a.rv-stat:hover { border-color: color-mix(in srgb, var(--rv-primary) 45%, var(--rv-border)); box-shadow: var(--rv-shadow-lg); text-decoration: none; color: var(--rv-text); }
/* Main (growing) part of a wrapping flex header, e.g. title + description in .rv-card__head.flex-wrap */
.rv-flex-main { flex: 1 1 16rem; min-width: 0; }
/* In-page anchor target below the sticky topbar */
.rv-anchor { scroll-margin-top: calc(var(--rv-topbar-h) + .75rem); }
/* Grouped rows inside a flush card body: .rv-group > .rv-subhead + .list-group */
.rv-group + .rv-group { border-top: 1px solid var(--rv-border); }
.rv-subhead { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .35rem 1rem; min-height: 38px; background: var(--rv-surface-2); border-bottom: 1px solid var(--rv-border); font-size: .8125rem; }
.rv-subhead form { margin: 0; }
.rv-scroll .rv-subhead { position: sticky; top: 0; z-index: 1; }
.rv-list-dense { --bs-list-group-item-padding-y: .3rem; --bs-list-group-item-padding-x: 1rem; --bs-list-group-border-radius: 0; font-size: .75rem; }
/* "Show N more" disclosure */
details.rv-more > summary { padding: .3rem 1rem; font-size: .75rem; color: var(--rv-primary); cursor: pointer; list-style: none; border-top: 1px solid var(--rv-border); user-select: none; }
details.rv-more > summary::-webkit-details-marker { display: none; }
details.rv-more > summary .bi { display: inline-block; transition: transform .15s; }
details.rv-more[open] > summary .bi { transform: rotate(180deg); }
details.rv-more[open] > summary .rv-more__closed,
details.rv-more:not([open]) > summary .rv-more__opened { display: none; }
/* Toggle chips: <input class="btn-check"> + <label class="btn btn-light"> */
.rv-check-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.rv-check-chips .btn { --bs-btn-padding-y: .125rem; --bs-btn-padding-x: .55rem; --bs-btn-font-size: .75rem; border-radius: 999px; box-shadow: none; }
.rv-check-chips .btn-check:checked + .btn { background: var(--rv-primary-soft); color: var(--rv-primary); border-color: color-mix(in srgb, var(--rv-primary) 45%, transparent); }
/* Feature matrix: sticky header + first column, vertical column labels */
.rv-matrix { border-collapse: separate; border-spacing: 0; }
.rv-matrix > :not(caption) > tr > :first-child { position: sticky; left: 0; z-index: 1; background-color: var(--rv-surface); border-right: 1px solid var(--rv-border); }
.rv-matrix > thead > tr > :first-child { z-index: 3; background-color: var(--rv-surface-2); vertical-align: bottom; }
.rv-matrix > tfoot > tr > * { position: sticky; bottom: 0; z-index: 2; background-color: var(--rv-surface-2); border-top: 1px solid var(--rv-border); border-bottom: 0; font-weight: 600; font-size: .75rem; }
.rv-matrix > tfoot > tr > :first-child { z-index: 3; }
.rv-matrix > thead > tr > th.rv-vth { vertical-align: bottom; text-align: center; padding: .5rem .15rem; text-transform: none; letter-spacing: 0; font-weight: 500; cursor: default; }
.rv-matrix > thead > tr > th.rv-vth.is-active { color: var(--rv-primary); }
.rv-vth > span { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; max-height: 150px; overflow: hidden; text-overflow: ellipsis; }
.rv-matrix .rv-cell { text-align: center; padding: .25rem .15rem; min-width: 28px; }
.rv-yes { color: var(--rv-success); }
.rv-no { color: var(--rv-danger); opacity: .4; }

/* ---------- RS importer / Locations ---------- */
/* Count bubble inside a badge, e.g. queue size per import URL */
.rv-badge__count { display: inline-flex; align-items: center; justify-content: center; min-width: 1.15rem; padding: 0 .3rem; border-radius: 999px; background: var(--rv-surface); color: var(--rv-text); font-size: .625rem; font-weight: 600; line-height: 1.5; font-variant-numeric: tabular-nums; }
/* Autocomplete dropdown under an input (parent must be position: relative) */
.rv-suggest { position: absolute; top: 100%; left: 0; right: 0; min-width: 280px; z-index: 1050; margin-top: .25rem; max-height: 340px; overflow-y: auto; box-shadow: var(--rv-shadow-lg); border-radius: var(--rv-radius); }
.rv-suggest .list-group-item-action { cursor: pointer; }

/* ---------- Monitor / Realsoft / Reminder logs / AI fill requests ---------- */
/* Collapsible value in a dense table: <details class="rv-disclose"><summary>…</summary><pre>…</pre></details> */
details.rv-disclose > summary { display: inline-flex; align-items: center; gap: .3rem; max-width: 100%; cursor: pointer; list-style: none; font-size: .75rem; color: var(--rv-primary); user-select: none; white-space: nowrap; }
details.rv-disclose > summary::-webkit-details-marker { display: none; }
details.rv-disclose > summary::before { content: "\f285"; font-family: "bootstrap-icons"; font-size: .625rem; flex-shrink: 0; transition: transform .15s; }
details.rv-disclose[open] > summary::before { transform: rotate(90deg); }
.rv-disclose__preview { display: inline-block; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; color: var(--rv-muted); }
details.rv-disclose > pre,
.rv-disclose__body { margin: .35rem 0 0; min-width: 340px; max-width: 640px; max-height: 320px; overflow: auto; }
details.rv-disclose > pre { white-space: pre-wrap; word-break: break-word; }
.rv-disclose__body { background: var(--rv-surface-2); border: 1px solid var(--rv-border); border-radius: var(--rv-radius); padding: .6rem .75rem; font-size: .8125rem; white-space: normal; }
.rv-disclose__body > :last-child { margin-bottom: 0; }
.rv-disclose__body img { max-width: 100%; height: auto; }
.rv-disclose + .rv-disclose { margin-top: .2rem; }
/* Top-aligned rows for tables whose cells expand */
.table.rv-valign-top > tbody > tr > td { vertical-align: top; }
.rv-prewrap { white-space: pre-wrap; word-break: break-word; }

/* ---------- Statistics / Data / Map ---------- */
/* Sortable header: <th data-sort aria-sort><button class="rv-sort">Label<i class="bi bi-arrow-down-up"></i></button></th>; also <a class="rv-sort is-active"> for server-side sorting */
.rv-sort { display: inline-flex; align-items: center; gap: .25rem; padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; white-space: nowrap; cursor: pointer; }
.rv-sort > i { font-size: .625rem; opacity: .35; transition: opacity .15s; }
.rv-sort:hover { color: var(--rv-text); text-decoration: none; }
.rv-sort:hover > i { opacity: .8; }
th[aria-sort="ascending"] > .rv-sort, th[aria-sort="descending"] > .rv-sort, .rv-sort.is-active { color: var(--rv-primary); }
th[aria-sort="ascending"] > .rv-sort > i, th[aria-sort="descending"] > .rv-sort > i, .rv-sort.is-active > i { opacity: 1; }
/* Sticky totals row inside .rv-table-scroll */
.rv-table-sticky-foot tfoot > tr > * { position: sticky; bottom: 0; z-index: 2; background: var(--rv-surface-2); box-shadow: inset 0 1px 0 var(--rv-border); border-bottom: 0; font-weight: 600; }
/* Column group label row above a sticky header row (scrolls away, the row below stays) */
.rv-table-sticky thead > tr.rv-th-group > th { position: static; text-align: center; padding-top: .35rem; padding-bottom: .15rem; border-bottom: 0 !important; }
/* Vertical separator between column groups */
.table > :not(caption) > tr > .rv-col-sep { box-shadow: inset 1px 0 0 var(--rv-border), inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg))); }
.rv-table-sticky-foot tfoot > tr > .rv-col-sep { box-shadow: inset 1px 0 0 var(--rv-border), inset 0 1px 0 var(--rv-border); }
/* Group heading row inside tbody */
.table > tbody > tr.rv-group-row > * { background-color: var(--rv-surface-2); font-weight: 600; font-size: .75rem; }
/* Popover with a long plain-text list (newline separated) */
.rv-popover-list { --bs-popover-max-width: 320px; --bs-popover-font-size: .75rem; --bs-popover-bg: var(--rv-surface); --bs-popover-border-color: var(--rv-border); --bs-popover-header-bg: var(--rv-surface-2); --bs-popover-header-font-size: .75rem; --bs-popover-header-padding-y: .4rem; --bs-popover-header-padding-x: .75rem; --bs-popover-body-padding-y: .5rem; --bs-popover-body-padding-x: .75rem; --bs-popover-body-color: var(--rv-text); }
.rv-popover-list .popover-body { white-space: pre-line; max-height: 280px; overflow-y: auto; }
/* Keyboard-highlighted autocomplete item */
.rv-suggest .list-group-item.is-active { background: var(--rv-primary-soft); color: var(--rv-text); }
/* Map page: full-height map with a side column (overview, legend, errors) */
.rv-map-layout { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
.rv-map-card { overflow: hidden; }
.rv-map-stack { position: relative; isolation: isolate; height: calc(100vh - var(--rv-topbar-h) - 130px); min-height: 420px; }
.rv-map-pane { position: absolute; inset: 0; visibility: hidden; }
.rv-map-pane.is-active { visibility: visible; }
.rv-map-side { display: grid; gap: 1rem; position: sticky; top: calc(var(--rv-topbar-h) + 1rem); }
@media (max-width: 1199.98px) {
  .rv-map-layout { grid-template-columns: minmax(0, 1fr); }
  .rv-map-side { position: static; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); align-items: start; }
}
@media (max-width: 991.98px) { .rv-map-stack { height: 62vh; min-height: 340px; } }
.rv-legend { display: grid; gap: .3rem; font-size: .75rem; }
.rv-legend__item { display: flex; align-items: center; gap: .5rem; }
.rv-legend__swatch { width: 22px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.rv-legend__dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
[data-bs-theme="dark"] .leaflet-container { background: var(--rv-surface-2); }
[data-bs-theme="dark"] .leaflet-bar { border-color: var(--rv-border); }
[data-bs-theme="dark"] .leaflet-bar a { background-color: var(--rv-surface); color: var(--rv-text); border-bottom-color: var(--rv-border); }
[data-bs-theme="dark"] .leaflet-container .leaflet-control-attribution { background: color-mix(in srgb, var(--rv-surface) 85%, transparent); color: var(--rv-muted); }
