/* -------------------------------------------------------------------------
   Rindify · Design tokens
   Light is the default; dark applies via [data-bs-theme="dark"] on <html>,
   set before first paint by the inline script in base.html.
   Tokens also feed Bootstrap 5.3's own variables so utilities follow the theme.
   ---------------------------------------------------------------------- */

:root,
[data-bs-theme="light"] {
  --r-bg: #F6F8F5;
  --r-side: #EEF6F1;
  --r-surface: #FFFFFF;
  --r-surface-2: #EFF4F0;
  --r-border: #E3E9E4;
  --r-text: #13231C;
  --r-muted: #5B6B63;

  --r-primary: #0B7D54;
  --r-primary-hover: #096A47;
  --r-primary-contrast: #FFFFFF;
  --r-primary-soft: #D5F5E6;
  --r-primary-ink: #0B6445;
  --r-focus: #0F9D68;
  --r-track: #A8EACF;

  --r-mint: #3FCB93;
  --r-coral: #E0664A;
  --r-coral-soft: #FDE8E3;
  --r-coral-ink: #B8391F;
  --r-sun-soft: #FFF3CF;
  --r-sun-ink: #7A5000;
  --r-lav: #8B7CF6;
  --r-lav-soft: #EEEBFE;
  --r-lav-ink: #4B3BC0;
  --r-sky-soft: #E4F0FD;
  --r-sky-ink: #1B5FA8;

  --r-logo-bg: #0B7D54;
  --r-logo-fg: #FFFFFF;
  --r-logo-leaf: #A8EACF;

  --r-shadow-sm: 0 1px 2px rgba(11, 61, 43, 0.05);
  --r-shadow-md: 0 12px 32px rgba(11, 61, 43, 0.10);
  --r-backdrop: rgba(19, 35, 28, 0.45);

  --r-radius-sm: 14px;
  --r-radius: 20px;
  --r-radius-lg: 24px;
  --r-font-display: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
  --r-font-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;

  --bs-body-bg: var(--r-bg);
  --bs-body-color: var(--r-text);
  --bs-body-font-family: var(--r-font-body);
  --bs-emphasis-color: var(--r-text);
  --bs-secondary-color: var(--r-muted);
  --bs-secondary-bg: var(--r-surface-2);
  --bs-tertiary-bg: var(--r-surface-2);
  --bs-border-color: var(--r-border);
  --bs-border-radius: var(--r-radius-sm);
  --bs-link-color: var(--r-primary);
  --bs-link-color-rgb: 11, 125, 84;
  --bs-link-hover-color: var(--r-primary-hover);
  --bs-link-hover-color-rgb: 9, 106, 71;
  --bs-primary: #0B7D54;
  --bs-primary-rgb: 11, 125, 84;
  --bs-success-rgb: 11, 100, 69;
  --bs-danger-rgb: 184, 57, 31;
  --bs-focus-ring-color: rgba(15, 157, 104, 0.25);
  color-scheme: light;
}

[data-bs-theme="dark"] {
  --r-bg: #0D1512;
  --r-side: #101B17;
  --r-surface: #14201B;
  --r-surface-2: #1B2A24;
  --r-border: #253630;
  --r-text: #E8F1EC;
  --r-muted: #9DB0A6;

  --r-primary: #3FCB93;
  --r-primary-hover: #5ED8A7;
  --r-primary-contrast: #062B1C;
  --r-primary-soft: #133A2B;
  --r-primary-ink: #7BE3B6;
  --r-focus: #3FCB93;
  --r-track: #0B6445;

  --r-mint: #3FCB93;
  --r-coral: #F08A74;
  --r-coral-soft: #3A1D17;
  --r-coral-ink: #FF9A85;
  --r-sun-soft: #33290F;
  --r-sun-ink: #FFD66B;
  --r-lav: #B3A8FF;
  --r-lav-soft: #25214A;
  --r-lav-ink: #B3A8FF;
  --r-sky-soft: #152A40;
  --r-sky-ink: #8CC4FF;

  --r-logo-bg: #3FCB93;
  --r-logo-fg: #062B1C;
  --r-logo-leaf: #0B6445;

  --r-shadow-sm: none;
  --r-shadow-md: 0 12px 32px rgba(0, 0, 0, 0.35);
  --r-backdrop: rgba(0, 0, 0, 0.6);

  --bs-body-bg: var(--r-bg);
  --bs-body-color: var(--r-text);
  --bs-emphasis-color: var(--r-text);
  --bs-secondary-color: var(--r-muted);
  --bs-secondary-bg: var(--r-surface-2);
  --bs-tertiary-bg: var(--r-surface-2);
  --bs-border-color: var(--r-border);
  --bs-link-color: var(--r-primary);
  --bs-link-color-rgb: 63, 203, 147;
  --bs-link-hover-color: var(--r-primary-hover);
  --bs-link-hover-color-rgb: 94, 216, 167;
  --bs-primary: #3FCB93;
  --bs-primary-rgb: 63, 203, 147;
  --bs-success-rgb: 123, 227, 182;
  --bs-danger-rgb: 255, 154, 133;
  --bs-focus-ring-color: rgba(63, 203, 147, 0.3);
  color-scheme: dark;
}

html, body {
  background-color: var(--r-bg);
  color: var(--r-text);
  font-family: var(--r-font-body);
}

body { -webkit-font-smoothing: antialiased; }

h1, h2, h3, .h1, .h2, .h3, .h4, .h5, .display-font {
  font-family: var(--r-font-display);
  letter-spacing: -0.02em;
}

.text-muted { color: var(--r-muted) !important; }
.num, .kpi-value, .table td.text-end, .pl-band span:last-child { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------------------
   Brand mark
   ---------------------------------------------------------------------- */

.brand-mark { flex-shrink: 0; display: block; }
.brand-mark .bm-bg { fill: var(--r-logo-bg); }
.brand-mark .bm-fg { fill: var(--r-logo-fg); }
.brand-mark .bm-stem { stroke: var(--r-logo-fg); }
.brand-mark .bm-leaf { fill: var(--r-logo-leaf); }

.brand-wordmark {
  font-family: var(--r-font-display);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--r-text);
}

/* -------------------------------------------------------------------------
   Layout shell
   ---------------------------------------------------------------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: 252px;
  background: var(--r-side);
  border-right: 1px solid var(--r-border);
  color: var(--r-text);
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.app-sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0.5rem;
  text-decoration: none;
}
.app-sidebar .brand .brand-wordmark { font-size: 1.6rem; }

.org-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--r-border);
  border-radius: 16px;
  background: var(--r-surface);
  color: var(--r-text);
  text-decoration: none;
}
.org-card:hover { color: var(--r-text); border-color: var(--r-track); }
.org-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--r-sun-soft);
  color: var(--r-sun-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
  text-transform: uppercase;
}
.org-card-name { font-weight: 700; font-size: 0.9rem; line-height: 1.2; }
.org-card-role { font-size: 0.75rem; color: var(--r-muted); }

.app-sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.app-sidebar nav .nav-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--r-muted);
  margin: 1.1rem 0 0.35rem;
  padding: 0 0.85rem;
}

.app-sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--r-radius-sm);
  color: var(--r-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.app-sidebar nav a .bi { font-size: 1.1rem; }

.app-sidebar nav a:hover {
  background: var(--r-surface);
  color: var(--r-text);
}

.app-sidebar nav a.is-active {
  background: var(--r-primary-soft);
  color: var(--r-primary-ink);
  font-weight: 700;
}

.app-sidebar .sidebar-footer {
  margin-top: auto;
  padding: 0 0.5rem;
  font-size: 0.8rem;
  color: var(--r-muted);
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-topbar {
  background: color-mix(in srgb, var(--r-bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  padding: 0.85rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-icon-btn,
.app-topbar .dropdown > .btn {
  height: 44px;
  min-width: 44px;
  border-radius: 999px;
  border: 1px solid var(--r-border);
  background: var(--r-surface);
  color: var(--r-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0 0.85rem;
  font-weight: 600;
}
.topbar-icon-btn:hover,
.app-topbar .dropdown > .btn:hover { background: var(--r-surface-2); color: var(--r-text); }
.topbar-icon-btn { padding: 0; width: 44px; }
.topbar-icon-btn .bi { font-size: 1.1rem; }

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--r-lav-soft);
  color: var(--r-lav-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.app-content {
  padding: 1.25rem 2rem 2.5rem;
  flex: 1;
}

.app-content h1 {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.25rem;
}

.app-content .lead {
  color: var(--r-muted);
  font-size: 1.05rem;
  margin-bottom: 1.5rem;
}

/* -------------------------------------------------------------------------
   Cards & KPI
   ---------------------------------------------------------------------- */

.card {
  --bs-card-bg: var(--r-surface);
  --bs-card-border-color: var(--r-border);
  --bs-card-border-radius: var(--r-radius-lg);
  --bs-card-inner-border-radius: calc(var(--r-radius-lg) - 1px);
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-lg);
  box-shadow: var(--r-shadow-sm);
  color: var(--r-text);
}

.card .card-body { padding: 1.35rem 1.5rem; }

.card-title-sm {
  font-family: var(--r-font-display);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  margin: 0;
}

.kpi-card {
  border: 0;
  box-shadow: none;
  background: var(--r-surface-2);
  transition: transform 0.15s ease;
  height: 100%;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-card .card-body { display: flex; flex-direction: column; gap: 0.75rem; padding: 1.25rem; }
.kpi-card .kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.kpi-card .kpi-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--kpi-ink, var(--r-muted));
}
.kpi-card .kpi-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--r-surface);
  color: var(--kpi-ink, var(--r-muted));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}
.kpi-card .kpi-value {
  font-family: var(--r-font-display);
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--r-text);
  line-height: 1.1;
}
.kpi-card .kpi-note { font-size: 0.82rem; font-weight: 600; color: var(--kpi-ink, var(--r-muted)); }
.kpi-card .kpi-value { white-space: nowrap; }
@media (max-width: 575.98px) {
  .kpi-card .card-body { padding: 1rem; gap: 0.5rem; }
  .kpi-card .kpi-value { font-size: 1.35rem; }
  .kpi-card .kpi-icon { width: 30px; height: 30px; border-radius: 10px; font-size: 0.9rem; }
}

.kpi-income { background: var(--r-primary-soft); --kpi-ink: var(--r-primary-ink); }
.kpi-expense { background: var(--r-coral-soft); --kpi-ink: var(--r-coral-ink); }
.kpi-profit { background: var(--r-sky-soft); --kpi-ink: var(--r-sky-ink); }
.kpi-margin { background: var(--r-lav-soft); --kpi-ink: var(--r-lav-ink); }

/* Budget meters on the summary page */
.meter-row + .meter-row { margin-top: 0.9rem; }
.meter-head { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.9rem; margin-bottom: 0.35rem; }
.meter-head .meter-pct { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--r-primary-ink); }
.meter-row.is-warning .meter-pct { color: var(--r-sun-ink); }
.meter-row.is-over .meter-pct { color: var(--r-coral-ink); }
.meter {
  height: 10px;
  border-radius: 999px;
  background: var(--r-surface-2);
  overflow: hidden;
}
.meter > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--r-primary);
}
.meter-row.is-warning .meter > span { background: #E3A500; }
.meter-row.is-over .meter > span { background: var(--r-coral); }

.callout {
  border-radius: 16px;
  padding: 0.75rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
}
.callout-warning { background: var(--r-sun-soft); color: var(--r-sun-ink); }

/* Recent movements list */
.move-list { list-style: none; margin: 0; padding: 0.25rem; }
.move-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 0.85rem;
  border-radius: 16px;
  color: var(--r-text);
  text-decoration: none;
}
.move-item:hover { background: var(--r-surface-2); color: var(--r-text); }
.move-sign {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
}
.move-sign.is-income { background: var(--r-primary-soft); color: var(--r-primary-ink); }
.move-sign.is-expense { background: var(--r-coral-soft); color: var(--r-coral-ink); }
.move-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.move-concept { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.move-meta { font-size: 0.82rem; color: var(--r-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.move-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.move-amount.is-income { color: var(--r-primary-ink); }
.move-amount.is-expense { color: var(--r-coral-ink); }

/* -------------------------------------------------------------------------
   P&L bands
   ---------------------------------------------------------------------- */

.pl-band {
  padding: 0.9rem 1.1rem;
  border-radius: var(--r-radius);
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.pl-band span:last-child { font-family: var(--r-font-display); font-size: 1.15rem; }

.pl-band-income { background: var(--r-primary-soft); color: var(--r-primary-ink); }
.pl-band-expense { background: var(--r-coral-soft); color: var(--r-coral-ink); }
.pl-band-profit { background: var(--r-sky-soft); color: var(--r-sky-ink); }

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

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--r-text);
  --bs-table-border-color: var(--r-border);
  --bs-table-hover-bg: var(--r-surface-2);
  --bs-table-striped-bg: var(--r-surface-2);
}

.table-card .table { margin-bottom: 0; }
.table-card .table thead th {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--r-muted);
  border-bottom-width: 1px;
  padding-top: 0.9rem;
  padding-bottom: 0.7rem;
}
.table-card .table > :not(caption) > * > * { padding-left: 0.75rem; padding-right: 0.75rem; }
.table-card .table > :not(caption) > * > :first-child { padding-left: 1.1rem; }
.table-card .table > :not(caption) > * > :last-child { padding-right: 1.1rem; }
.table-card .table tbody tr:last-child td { border-bottom: 0; }
.table-card .table tbody td { vertical-align: middle; }
/* Amounts and row actions never break across lines. */
.table td.text-end, .table th.text-end { white-space: nowrap; }
.table-card .table-responsive { border-radius: inherit; }

@media (max-width: 767.98px) {
  .table-card .table { font-size: 0.875rem; }
  .table-card .table > :not(caption) > * > * {
    padding: 0.55rem 0.65rem;
    white-space: nowrap;
  }
  .table-card .card-body { padding: 1rem; }

  /* Edge shadows hint that the table scrolls sideways; they fade out at each end. */
  .table-card .table-responsive {
    -webkit-overflow-scrolling: touch;
    background:
      linear-gradient(to right, var(--r-surface) 30%, transparent) left center / 32px 100% no-repeat local,
      linear-gradient(to left, var(--r-surface) 30%, transparent) right center / 32px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(11, 61, 43, 0.16), transparent) left center / 12px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(11, 61, 43, 0.16), transparent) right center / 12px 100% no-repeat scroll;
  }
}

/* -------------------------------------------------------------------------
   Forms & buttons
   ---------------------------------------------------------------------- */

.form-section {
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius-lg);
  padding: 1.5rem;
  box-shadow: var(--r-shadow-sm);
}

label.form-label, .form-label { font-weight: 600; font-size: 0.9rem; }

.form-control, .form-select {
  border-radius: var(--r-radius-sm);
  border: 1.5px solid var(--r-border);
  background-color: var(--r-surface);
  color: var(--r-text);
  min-height: 46px;
}
.form-control-sm, .form-select-sm { min-height: 38px; border-radius: 12px; }
.form-control::placeholder { color: var(--r-muted); opacity: 0.8; }
.form-control:focus, .form-select:focus {
  border-color: var(--r-focus);
  background-color: var(--r-surface);
  color: var(--r-text);
  box-shadow: 0 0 0 4px var(--bs-focus-ring-color);
}
.form-check-input:checked { background-color: var(--r-primary); border-color: var(--r-primary); }
.form-text { color: var(--r-muted); }

.btn {
  --bs-btn-border-radius: 999px;
  --bs-btn-font-weight: 700;
  border-radius: 999px;
  font-weight: 700;
  padding-left: 1.1rem;
  padding-right: 1.1rem;
}
.btn:not(.btn-sm):not(.btn-link) { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; }
.btn-sm { --bs-btn-border-radius: 12px; border-radius: 12px; padding-left: 0.6rem; padding-right: 0.6rem; }

.btn-primary {
  --bs-btn-bg: var(--r-primary);
  --bs-btn-border-color: var(--r-primary);
  --bs-btn-color: var(--r-primary-contrast);
  --bs-btn-hover-bg: var(--r-primary-hover);
  --bs-btn-hover-border-color: var(--r-primary-hover);
  --bs-btn-hover-color: var(--r-primary-contrast);
  --bs-btn-active-bg: var(--r-primary-hover);
  --bs-btn-active-border-color: var(--r-primary-hover);
  --bs-btn-active-color: var(--r-primary-contrast);
  --bs-btn-disabled-bg: var(--r-primary);
  --bs-btn-disabled-border-color: var(--r-primary);
  --bs-btn-disabled-color: var(--r-primary-contrast);
}

.btn-outline-primary {
  --bs-btn-color: var(--r-primary-ink);
  --bs-btn-bg: var(--r-primary-soft);
  --bs-btn-border-color: var(--r-primary-soft);
  --bs-btn-hover-color: var(--r-primary-ink);
  --bs-btn-hover-bg: color-mix(in srgb, var(--r-primary-soft) 80%, var(--r-primary));
  --bs-btn-hover-border-color: transparent;
  --bs-btn-active-color: var(--r-primary-ink);
  --bs-btn-active-bg: color-mix(in srgb, var(--r-primary-soft) 70%, var(--r-primary));
  --bs-btn-active-border-color: transparent;
}

.btn-light {
  --bs-btn-color: var(--r-text);
  --bs-btn-bg: var(--r-surface-2);
  --bs-btn-border-color: var(--r-surface-2);
  --bs-btn-hover-color: var(--r-text);
  --bs-btn-hover-bg: var(--r-border);
  --bs-btn-hover-border-color: var(--r-border);
  --bs-btn-active-bg: var(--r-border);
  --bs-btn-active-border-color: var(--r-border);
  --bs-btn-active-color: var(--r-text);
}
.btn-light.text-danger { color: var(--r-coral-ink) !important; }

.btn-outline-danger {
  --bs-btn-color: var(--r-coral-ink);
  --bs-btn-border-color: var(--r-coral-soft);
  --bs-btn-bg: var(--r-coral-soft);
  --bs-btn-hover-color: var(--r-primary-contrast);
  --bs-btn-hover-bg: var(--r-coral-ink);
  --bs-btn-hover-border-color: var(--r-coral-ink);
}

.btn-link { --bs-btn-color: var(--r-primary); --bs-btn-hover-color: var(--r-primary-hover); text-decoration: none; }

.btn:focus-visible, a:focus-visible, button:focus-visible {
  outline: 3px solid var(--r-focus);
  outline-offset: 2px;
  box-shadow: none;
}

/* -------------------------------------------------------------------------
   Badges, alerts, dropdowns, tabs, pagination
   ---------------------------------------------------------------------- */

.badge { border-radius: 999px; padding: 0.4em 0.75em; font-weight: 700; }
.badge-soft-income { background-color: var(--r-primary-soft); color: var(--r-primary-ink); }
.badge-soft-expense { background-color: var(--r-coral-soft); color: var(--r-coral-ink); }
.text-bg-success { background-color: var(--r-primary-soft) !important; color: var(--r-primary-ink) !important; }
.text-bg-secondary { background-color: var(--r-surface-2) !important; color: var(--r-muted) !important; }
.text-bg-light { background-color: var(--r-lav-soft) !important; color: var(--r-lav-ink) !important; }

.alert {
  border: 0;
  border-radius: var(--r-radius);
  font-weight: 500;
}
.alert-success { background: var(--r-primary-soft); color: var(--r-primary-ink); }
.alert-danger, .alert-error { background: var(--r-coral-soft); color: var(--r-coral-ink); }
.alert-warning { background: var(--r-sun-soft); color: var(--r-sun-ink); }
.alert-info { background: var(--r-sky-soft); color: var(--r-sky-ink); }
[data-bs-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

.dropdown-menu {
  --bs-dropdown-bg: var(--r-surface);
  --bs-dropdown-border-color: var(--r-border);
  --bs-dropdown-link-color: var(--r-text);
  --bs-dropdown-link-hover-bg: var(--r-surface-2);
  --bs-dropdown-link-hover-color: var(--r-text);
  --bs-dropdown-link-active-bg: var(--r-primary-soft);
  --bs-dropdown-link-active-color: var(--r-primary-ink);
  --bs-dropdown-divider-bg: var(--r-border);
  border-radius: 18px;
  padding: 0.4rem;
  box-shadow: var(--r-shadow-md);
}
.dropdown-item { border-radius: 12px; padding: 0.55rem 0.75rem; font-weight: 500; }

.nav-tabs {
  --bs-nav-tabs-border-color: transparent;
  gap: 0.35rem;
  border: 0;
}
.nav-tabs .nav-link {
  border: 0;
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  font-weight: 600;
  color: var(--r-muted);
  background: var(--r-surface-2);
}
.nav-tabs .nav-link:hover { color: var(--r-text); }
.nav-tabs .nav-link.active {
  background: var(--r-primary-soft);
  color: var(--r-primary-ink);
}
.nav-pills .nav-link { border-radius: 999px; color: var(--r-muted); font-weight: 600; }
.nav-pills .nav-link.active { background: var(--r-primary-soft); color: var(--r-primary-ink); }

.pagination {
  --bs-pagination-color: var(--r-text);
  --bs-pagination-bg: var(--r-surface);
  --bs-pagination-border-color: var(--r-border);
  --bs-pagination-hover-color: var(--r-text);
  --bs-pagination-hover-bg: var(--r-surface-2);
  --bs-pagination-hover-border-color: var(--r-border);
  --bs-pagination-active-bg: var(--r-primary);
  --bs-pagination-active-border-color: var(--r-primary);
  --bs-pagination-active-color: var(--r-primary-contrast);
  --bs-pagination-disabled-bg: var(--r-surface-2);
  --bs-pagination-disabled-color: var(--r-muted);
  --bs-pagination-disabled-border-color: var(--r-border);
  --bs-pagination-border-radius: 999px;
  gap: 0.35rem;
}
.page-link { border-radius: 999px !important; min-width: 40px; text-align: center; }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--r-muted);
}

.org-switcher { min-width: 240px; }
.min-w-0 { min-width: 0; }

/* -------------------------------------------------------------------------
   Mobile navigation (hamburger + off-canvas sidebar)
   ---------------------------------------------------------------------- */

.sidebar-toggle,
.sidebar-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--r-radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-toggle {
  width: 44px;
  height: 44px;
  font-size: 1.5rem;
  color: var(--r-text);
  background: var(--r-surface-2);
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--r-border); }

.sidebar-close {
  margin-left: auto;
  width: 40px;
  height: 40px;
  font-size: 1rem;
  color: var(--r-muted);
  background: transparent;
}
.sidebar-close:hover { background: var(--r-surface); color: var(--r-text); }

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}
.topbar-brand .brand-wordmark { font-size: 1.4rem; }

.app-sidebar-backdrop { display: none; }

@media (max-width: 767.98px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(290px, 86vw);
    height: 100dvh;
    z-index: 1050;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
    box-shadow: var(--r-shadow-md);
    border-right: 0;
  }

  .app-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: var(--r-backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .app-sidebar {
    transform: none;
    visibility: visible;
    transition: transform 0.25s ease;
  }
  body.sidebar-open .app-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .app-sidebar .brand { white-space: nowrap; }
  .app-topbar {
    padding: 0.65rem 1rem;
    background: var(--r-surface);
    border-bottom: 1px solid var(--r-border);
    backdrop-filter: none;
  }
  .org-switcher { min-width: 0; }
  .app-content { padding: 1.1rem 1rem 6rem; }
  .app-content h1 { font-size: 1.85rem; }
}

@media (max-width: 359.98px) {
  .topbar-brand .brand-wordmark { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .app-sidebar-backdrop { transition: none !important; }
}

/* Floating "new" button on mobile */
.fab {
  position: fixed;
  right: 1rem;
  bottom: 1.25rem;
  z-index: 90;
  box-shadow: 0 10px 24px rgba(11, 125, 84, 0.3);
  min-height: 56px !important;
  padding-left: 1.35rem !important;
  padding-right: 1.4rem !important;
  font-size: 1rem;
}

/* -------------------------------------------------------------------------
   Collapsible filter panel
   ---------------------------------------------------------------------- */

.filter-panel {
  background: var(--r-surface);
  border: 1px solid var(--r-border);
  border-radius: var(--r-radius);
  box-shadow: var(--r-shadow-sm);
}

.filter-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-right: 1rem;
}

.filter-panel-toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: var(--r-radius);
  background: transparent;
  color: var(--r-text);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}
.filter-panel-toggle .bi-funnel { color: var(--r-muted); }
.filter-panel-toggle:focus-visible {
  outline: 3px solid var(--r-focus);
  outline-offset: -3px;
}

.filter-count {
  min-width: 1.35rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: var(--r-primary-soft);
  color: var(--r-primary-ink);
  font-size: 0.75rem;
  text-align: center;
}

.filter-chevron {
  margin-left: auto;
  color: var(--r-muted);
}
.filter-panel.is-collapsed .filter-chevron { transform: rotate(-90deg); }
.filter-panel.is-ready .filter-chevron { transition: transform 0.2s ease; }

.filter-clear {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--r-muted);
  text-decoration: none;
  white-space: nowrap;
}
.filter-clear:hover { color: var(--r-primary); }

/* Grid-rows trick animates height without measuring the content.
   Transitions only start once JS marks the panel ready, so the initial state never animates. */
.filter-panel-body {
  display: grid;
  grid-template-rows: 1fr;
}
.filter-panel.is-ready .filter-panel-body {
  transition: grid-template-rows 0.2s ease, visibility 0s;
}
.filter-panel-inner {
  min-height: 0;
  overflow: hidden;
  padding: 0 1rem 1rem;
}
.filter-panel.is-collapsed .filter-panel-body {
  grid-template-rows: 0fr;
  visibility: hidden;
}
.filter-panel.is-ready.is-collapsed .filter-panel-body {
  transition: grid-template-rows 0.2s ease, visibility 0s linear 0.2s;
}
.filter-panel.is-collapsed .filter-panel-inner { padding-bottom: 0; }

/* Before JS runs, mobile starts collapsed so the panel doesn't flash open. */
@media (max-width: 767.98px) {
  .filter-panel:not(.is-expanded) .filter-panel-body {
    grid-template-rows: 0fr;
    visibility: hidden;
  }
  .filter-panel:not(.is-expanded) .filter-panel-inner { padding-bottom: 0; }
  .filter-panel:not(.is-expanded) .filter-chevron { transform: rotate(-90deg); }
}

@media (prefers-reduced-motion: reduce) {
  .filter-panel-body,
  .filter-chevron { transition: none !important; }
}

/* -------------------------------------------------------------------------
   Auth pages (login, signup, password flows)
   ---------------------------------------------------------------------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.auth-aside {
  background: var(--r-primary-soft);
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2rem;
}
.auth-aside h2 {
  font-size: clamp(2.25rem, 4vw, 3.5rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1;
  color: var(--r-text);
  margin: 0;
}
.auth-aside p { color: var(--r-primary-ink); font-size: 1.1rem; max-width: 30rem; margin: 0; }
.auth-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.25rem;
}
.auth-card { width: 100%; max-width: 440px; }
.auth-card h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 0.35rem; }
.auth-card .auth-sub { color: var(--r-muted); margin-bottom: 1.5rem; }
.auth-links { font-size: 0.92rem; color: var(--r-muted); text-align: center; margin-top: 1.25rem; }
.auth-mobile-brand { display: none; }

@media (max-width: 899.98px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .auth-mobile-brand { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1.75rem; text-decoration: none; }
  .auth-mobile-brand .brand-wordmark { font-size: 1.6rem; }
}

.theme-float {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 50;
}

.auth-points li { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; color: var(--r-primary-ink); }
.auth-points .bi { color: var(--r-primary); font-size: 1.1rem; }
.auth-card .form-section { padding: 1.5rem; }

/* Forms rendered with {{ form.as_p }} (password flows) get the same field styling. */
.form-section p { margin-bottom: 1rem; }
.form-section p > label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem; }
.form-section input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not(.form-control),
.form-section select:not(.form-select) {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 0.5rem 0.9rem;
  border: 1.5px solid var(--r-border);
  border-radius: var(--r-radius-sm);
  background: var(--r-surface);
  color: var(--r-text);
  font: inherit;
}
.form-section input:not([type="checkbox"]):not([type="radio"]):focus,
.form-section select:focus {
  outline: none;
  border-color: var(--r-focus);
  box-shadow: 0 0 0 4px var(--bs-focus-ring-color);
}
.form-section .helptext, .form-section p + ul, .form-section .helptext ul { font-size: 0.82rem; color: var(--r-muted); }
.form-section ul.errorlist { list-style: none; padding: 0; margin: 0 0 0.35rem; color: var(--r-coral-ink); font-size: 0.85rem; font-weight: 600; }
