/* ---------- Base (macOS-inspired) ---------- */
:root {
  --brand: #0a3d62;
  --brand-2: #1e6091;
  --accent: #f39c12;

  /* Soft, layered backgrounds */
  --bg: #f5f6fa;
  --bg-2: #eef0f6;
  --surface: #ffffffd9;          /* translucent white */
  --surface-solid: #ffffff;

  --text: #1b2330;
  --muted: #6b7280;

  --danger-bg: #ffe9e9;
  --danger-fg: #b91c1c;
  --warn-bg:  #fff4d6;
  --warn-fg:  #92580c;
  --ok-bg:    #e2f6ea;
  --ok-fg:    #166534;

  --border:        rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);
  --hairline:      rgba(15, 23, 42, 0.06);

  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;

  /* Layered, soft shadows in macOS style */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow:    0 6px 18px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.05);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
               "Segoe UI Variable", "Segoe UI", "Helvetica Neue",
               Tahoma, sans-serif;
  background:
    radial-gradient(1200px 600px at 0% -10%, rgba(30, 96, 145, 0.05) 0, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(243, 156, 18, 0.04) 0, transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* ~10% smaller base for a more professional, dense look. */
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: -0.005em;
}
h1 { font-size: 1.6rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
.section-title { font-size: 1.15rem; }
.stat .value { font-size: 1.3rem; }
.report-table th { font-size: 0.68rem; }
.report-table td, .nested-table td { font-size: 0.82rem; }
.btn { font-size: 0.82rem; }
.btn-sm { font-size: 0.74rem; }
.pill, .badge { font-size: 0.7rem; }
.form-label { font-size: 0.8rem; }
.app-bar { padding: 0.55rem 1rem; }
.app-nav a { font-size: 0.82rem; }

/* ---------- App bar ---------- */
.app-bar {
  background: linear-gradient(180deg,
              rgba(10, 61, 98, 0.96) 0%,
              rgba(30, 96, 145, 0.94) 100%);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  color: #fff;
  padding: 0.7rem 1.15rem;
  position: sticky;
  top: 0;
  z-index: 1020;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 4px 18px rgba(10, 61, 98, 0.18);
}

.app-bar .navbar-brand {
  color: #fff !important;
  text-decoration: none;
  font-size: 1.05rem;
}

/* Modern nav pills — replace the plain underlined links */
.app-nav { gap: 0.35rem; }
.app-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: rgba(255,255,255,0.92) !important;
  text-decoration: none !important;
  padding: 0.42rem 0.95rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.04);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  line-height: 1;
  white-space: nowrap;
}
.app-nav a:hover,
.app-nav a:focus {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.28);
  color: #ffffff !important;
}
.app-nav a:active { transform: translateY(1px); }
.app-nav a.active {
  background: #ffffff;
  color: var(--brand) !important;
  border-color: #ffffff;
}
.app-nav a .ico {
  font-size: 0.95rem;
  line-height: 1;
}

/* Right-side action buttons (Password / Logout) — keep them readable
   on hover (Bootstrap's btn-outline-light flips bg to white which would
   otherwise hide the white text). */
.app-bar .btn-outline-light {
  border-radius: 999px;
  font-weight: 600;
  padding: 0.4rem 0.95rem;
  font-size: 0.88rem;
}
.app-bar .btn-outline-light:hover,
.app-bar .btn-outline-light:focus,
.app-bar .btn-outline-light:active,
.app-bar .btn-outline-light.active,
.app-bar .btn-outline-light.show,
.app-bar .btn-outline-light[aria-expanded="true"] {
  background-color: #ffffff !important;
  color: var(--brand) !important;
  border-color: #ffffff !important;
}
.app-bar .btn-outline-light:hover .user-avatar,
.app-bar .btn-outline-light.show .user-avatar,
.app-bar .btn-outline-light[aria-expanded="true"] .user-avatar {
  background: rgba(10, 61, 98, 0.12);
  color: var(--brand);
  border-color: rgba(10, 61, 98, 0.22);
}

/* ---------- User menu (top-right) ---------- */
.user-toggle {
  display: inline-flex !important;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.85rem 0.3rem 0.4rem !important;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.1px;
}
.user-toggle::after {
  margin-left: 0.2rem;
  opacity: 0.85;
}
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  color: #ffffff;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}
.user-name {
  font-size: 0.88rem;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu { min-width: 260px; max-width: 320px; }
.user-menu .user-meta {
  padding: 0.7rem 0.9rem 0.45rem;
}
.user-menu .user-display-name {
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
}
.user-menu .user-code {
  margin-top: 0.1rem;
  font-size: 0.74rem;
}
.dropdown-item-logout {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  font-weight: 600;
  color: var(--danger-fg);
}
.dropdown-item-logout:hover,
.dropdown-item-logout:focus {
  background: linear-gradient(180deg, #d63b3b 0%, var(--danger-fg) 100%) !important;
  color: #ffffff !important;
}

/* Hide the nav pills (which carry icons) on phones — the bottom bar covers it */
@media (max-width: 768px) {
  .app-nav { display: none !important; }
}

.brand-mark {
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* ---------- Cards / surfaces ---------- */
.card-surface {
  background: var(--surface);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.2rem 1.25rem;
}

.section-title {
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.01em;
  margin-bottom: 0.55rem;
}

.muted { color: var(--muted); }

/* ---------- Tables ---------- */
.report-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}
.report-table th,
.report-table td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}
.report-table thead th {
  text-align: left;
  background: linear-gradient(180deg, #f3f6fc 0%, #ebeff8 100%);
  color: var(--brand);
  font-weight: 600;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.report-table thead th:first-child { border-top-left-radius: var(--radius-md); }
.report-table thead th:last-child  { border-top-right-radius: var(--radius-md); }
.report-table tbody tr { transition: background 0.12s ease; }
.report-table tbody tr:hover { background: #f6f8ff; }
.report-table tbody tr:last-child td { border-bottom: none; }

.overdue-row { background: var(--danger-bg) !important; }
.overdue-row td { color: var(--danger-fg); font-weight: 600; }

.pill {
  display: inline-block;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.1px;
  border: 1px solid transparent;
}
.pill.ok     { background: var(--ok-bg);     color: var(--ok-fg);     border-color: rgba(22, 101, 52, 0.15); }
.pill.warn   { background: var(--warn-bg);   color: var(--warn-fg);   border-color: rgba(146, 88, 12, 0.18); }
.pill.danger { background: var(--danger-bg); color: var(--danger-fg); border-color: rgba(185, 28, 28, 0.18); }
.pill.info   { background: #e6f0fb;          color: var(--brand);     border-color: rgba(10, 61, 98, 0.15); }

/* ---------- Drill-down table ---------- */
.drill-table tbody .party-row {
  cursor: pointer;
  user-select: none;
}
.drill-table tbody .party-row td:first-child {
  width: 32px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}
.drill-table .chev {
  display: inline-block;
  font-size: 1.05rem;
  line-height: 1;
  transition: transform 0.18s ease;
  color: var(--muted);
}
/* Bootstrap toggles the .collapsed class off when the target is open */
.drill-table tr.party-row:not(.collapsed) .chev {
  transform: rotate(90deg);
  color: var(--brand);
}
.drill-table tr.party-row:not(.collapsed) {
  background: #eef3fb;
}
.drill-table tr.party-row.overdue-row:not(.collapsed) {
  background: #ffdede;
}
.drill-table tr.party-detail > td { padding: 0; border-bottom: 1px solid var(--hairline); }
.drill-table .nested {
  padding: 0.6rem 0.85rem 0.9rem 2.6rem;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.025) 0, rgba(15, 23, 42, 0.00) 14px),
    #fbfcfe;
  border-top: 1px solid var(--hairline);
}
.nested-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #ffffff;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
}
.nested-table th,
.nested-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
  font-size: 0.88rem;
}
.nested-table thead th {
  background: #f7f9fd;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  text-align: left;
}
.nested-table tbody tr:last-child td { border-bottom: none; }

/* ---------- Buttons (macOS-style) ---------- */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  letter-spacing: -0.005em;
  transition: background 0.12s ease, transform 0.05s ease, box-shadow 0.15s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:active { transform: translateY(0.5px); }

.btn-brand {
  background: linear-gradient(180deg, var(--brand-2) 0%, var(--brand) 100%);
  border: 1px solid rgba(10, 61, 98, 0.6);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.18) inset, var(--shadow-sm);
}
.btn-brand:hover {
  background: linear-gradient(180deg, #2773ad 0%, var(--brand-2) 100%);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.22) inset, var(--shadow);
}
.btn-outline-secondary,
.btn-outline-primary,
.btn-outline-danger {
  background: rgba(255,255,255,0.7);
  border-color: var(--border-strong);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}
.btn-outline-secondary { color: var(--text); }
.btn-outline-secondary:hover {
  background: #ffffff;
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}
.btn-outline-primary:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* ---------- Bottom nav (mobile app feel) ---------- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 22px rgba(15, 23, 42, 0.07);
  z-index: 1030;
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 0.55rem 0.25rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
}
.bottom-nav a.active,
.bottom-nav a:hover {
  color: var(--brand);
}
.bottom-nav a .icon {
  display: block;
  font-size: 1.2rem;
  line-height: 1;
}

/* ---------- Stats blocks ---------- */
.stat {
  background: var(--surface);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1.05rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.stat:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}
.stat .label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  font-weight: 600;
}
.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.02em;
}
.stat.danger .value { color: var(--danger-fg); }
.stat.warn   .value { color: var(--warn-fg); }
.stat.ok     .value { color: var(--ok-fg); }
.stat .sublabel {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 0.15rem;
}
.stat.danger .sublabel { color: var(--danger-fg); opacity: 0.85; }
.stat.warn   .sublabel { color: var(--warn-fg); opacity: 0.9; }
.stat.ok     .sublabel { color: var(--ok-fg); opacity: 0.85; }

/* ---------- Layout helpers ---------- */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1rem 1rem 6rem 1rem;
}

@media (max-width: 768px) {
  body { font-size: 14px; }
  .bottom-nav { display: flex; }
  .desktop-only { display: none !important; }
  .page { padding-bottom: 6rem; }
  .report-table th, .report-table td { padding: 0.45rem 0.5rem; font-size: 0.85rem; }
}

@media (min-width: 769px) {
  .mobile-only { display: none !important; }
}

/* ---------- Login page ---------- */
.login-body {
  margin: 0;
  background: #eef2f9;
}
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}

/* Left: brand panel (desktop only) */
.login-brand {
  position: relative;
  color: #fff;
  padding: 3rem 3rem;
  display: flex;
  align-items: center;
  background:
    radial-gradient(circle at 18% 18%, rgba(255,255,255,0.10) 0, transparent 55%),
    radial-gradient(circle at 82% 78%, rgba(243, 156, 18, 0.22) 0, transparent 55%),
    linear-gradient(135deg, #0a3d62 0%, #1e6091 60%, #3c8dbc 100%);
  overflow: hidden;
}
.login-brand::before,
.login-brand::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.45;
  z-index: 0;
}
.login-brand::before {
  width: 320px; height: 320px;
  top: -90px; right: -80px;
  background: rgba(243, 156, 18, 0.45);
}
.login-brand::after {
  width: 260px; height: 260px;
  bottom: -90px; left: -80px;
  background: rgba(255, 255, 255, 0.22);
}
.login-brand-inner {
  position: relative;
  z-index: 1;
  max-width: 440px;
}
.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px; height: 56px;
  border-radius: 16px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.30);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.6px;
  color: #fff;
  margin-bottom: 1.1rem;
  backdrop-filter: blur(6px);
}
.brand-badge.sm {
  width: 42px; height: 42px;
  font-size: 0.85rem;
  border-radius: 12px;
  margin-bottom: 0;
}
.login-brand h1 {
  font-size: clamp(1.8rem, 3.2vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.4px;
  line-height: 1.15;
  margin-bottom: 0.6rem;
}
.login-brand .tag {
  font-size: 1.02rem;
  opacity: 0.92;
  margin-bottom: 1.4rem;
  max-width: 30rem;
}
.login-brand .bullets {
  list-style: none;
  padding: 0;
  margin: 0 0 1.6rem 0;
}
.login-brand .bullets li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
  opacity: 0.95;
}
.login-brand .bullets .dot {
  width: 8px; height: 8px;
  background: #f5d062;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(243, 156, 18, 0.22);
  flex-shrink: 0;
}
.login-brand .brand-foot {
  font-size: 0.78rem;
  opacity: 0.7;
  margin-top: 2rem;
}

/* Right: form panel */
.login-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.25rem;
  background: #eef2f9;
}
.login-card {
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(20, 30, 60, 0.10);
  padding: 2rem 1.8rem;
  width: 100%;
  max-width: 420px;
  border: 1px solid #e3e8f2;
}
.login-card .mobile-brand {
  display: none;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 1.1rem;
}
.login-card .m-brand-name {
  font-weight: 700;
  color: var(--brand);
  font-size: 1.05rem;
  line-height: 1.1;
}
.login-card .m-brand-sub {
  color: var(--muted);
  font-size: 0.82rem;
}
.login-card .welcome {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 0.2rem;
}
.login-card .sub {
  color: var(--muted);
  margin-bottom: 1.4rem;
  font-size: 0.93rem;
}
.login-card .field {
  margin-bottom: 1rem;
}
.login-card .form-label {
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.login-card .input-wrap {
  position: relative;
}
.login-card .input-wrap .iicon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  opacity: 0.55;
  pointer-events: none;
}
.login-card .input-wrap .form-control {
  padding-left: 2.2rem;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #d9dee7;
  background: #f9fbff;
}
.login-card .input-wrap .form-control:focus {
  background: #ffffff;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 0.18rem rgba(30, 96, 145, 0.18);
}
.login-card .btn-signin {
  width: 100%;
  height: 46px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-top: 0.4rem;
  transition: transform 0.05s ease, box-shadow 0.15s ease;
  box-shadow: 0 8px 22px rgba(10, 61, 98, 0.25);
}
.login-card .btn-signin:hover {
  box-shadow: 0 10px 26px rgba(10, 61, 98, 0.32);
}
.login-card .btn-signin:active {
  transform: translateY(1px);
}
.login-card .login-foot {
  margin-top: 1.2rem;
  padding-top: 0.9rem;
  border-top: 1px dashed #e3e8f2;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.login-card .captcha-field {
  background: #fff8e6;
  border: 1px solid #f4d883;
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  margin-bottom: 1rem;
}
.login-card .captcha-question {
  font-weight: 700;
  color: #5b4400;
  margin-bottom: 0.4rem;
}

/* Mobile: stack, hide brand panel, show inline mobile-brand instead */
@media (max-width: 900px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-pane {
    background:
      radial-gradient(circle at 10% 0%, rgba(10, 61, 98, 0.08) 0, transparent 50%),
      #eef2f9;
    padding: 1.5rem 1rem;
    min-height: 100vh;
  }
  .login-card .mobile-brand { display: flex; }
}

/* ---------- Forms ---------- */
.form-label { font-weight: 600; color: var(--text); font-size: 0.86rem; }
.form-control,
.form-select {
  border-radius: var(--radius-sm);
  border-color: var(--border-strong);
  background: rgba(255,255,255,0.85);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.12s ease, box-shadow 0.15s ease, background 0.12s ease;
}
.form-control:focus,
.form-select:focus {
  border-color: var(--brand-2);
  background: #ffffff;
  box-shadow: 0 0 0 0.2rem rgba(30, 96, 145, 0.18);
}

/* Alerts — restrained, with hairline border */
.alert {
  border-radius: var(--radius-md);
  border-width: 1px;
  box-shadow: var(--shadow-sm);
}

/* Refined badges (aging buckets) */
.badge {
  border-radius: 999px;
  padding: 0.32em 0.7em;
  font-weight: 600;
  letter-spacing: 0.2px;
  font-size: 0.72rem;
}

/* ---------- Sortable headers / search toolbar / paginator ---------- */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 0.7rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--hairline);
}

/* Bootstrap input-group (search field + button) sized & polished */
.search-group {
  max-width: 460px;
  width: 100%;
}
.search-group .input-group-text {
  background: linear-gradient(180deg, #f3f6fc 0%, #ebeff8 100%);
  border-color: var(--border-strong);
  color: var(--muted);
}
.search-group .form-control {
  border-color: var(--border-strong);
  background: #ffffff;
  font-size: 0.82rem;
}
.search-group .form-control::placeholder { color: var(--muted); }
.search-group .form-control:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 0.18rem rgba(30, 96, 145, 0.18);
  z-index: 3;
}
.search-group .btn-brand { font-size: 0.8rem; }

/* Sortable column headers — render as real headers, NOT hyperlinks.
   The whole th cell gets the hover tint so users see it's interactive. */
.report-table thead th:has(.sort-link) {
  cursor: pointer;
  padding: 0;          /* the inner <a> provides padding */
  transition: background 0.12s ease;
}
.report-table thead th:has(.sort-link):hover {
  background: linear-gradient(180deg, #e7eef9 0%, #dde6f4 100%);
}
.report-table thead th .sort-link,
.report-table thead th a.sort-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  color: var(--brand) !important;
  text-decoration: none !important;
  font: inherit;
  font-weight: 600;
  letter-spacing: inherit;
  text-transform: inherit;
  white-space: nowrap;
  padding: 0.7rem 0.85rem;
  border-bottom: 2px solid transparent;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
/* Right-aligned numeric columns should keep the label right-aligned too */
.report-table thead th.text-end .sort-link {
  justify-content: flex-end;
}
.report-table thead th .sort-link .arrow {
  font-size: 0.62rem;
  opacity: 0.3;
  transition: opacity 0.12s ease, color 0.12s ease;
  width: 0.85em;
  display: inline-block;
  text-align: center;
  line-height: 1;
}
.report-table thead th .sort-link.is-active {
  color: var(--brand) !important;
  border-bottom-color: var(--brand);
}
.report-table thead th .sort-link.is-active .arrow {
  opacity: 1;
  color: var(--accent);
}

.paginator {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--hairline);
}
.paginator-btns {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}
.page-pill {
  background: #eef3fb;
  color: var(--brand);
  font-weight: 600;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.74rem;
}

/* ---------- Payment status picker (radio cards) ---------- */
.payment-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.5rem;
}
.payment-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.payment-option:hover {
  border-color: var(--brand-2);
  background: #f6f9fe;
}
.payment-option input { margin: 0; }
.payment-option:has(input:checked) {
  background: linear-gradient(180deg, #e9f0fa 0%, #dde8f5 100%);
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand) inset;
}

/* Inline action cluster inside invoice rows */
.inv-actions { white-space: nowrap; }
.inv-actions .btn { padding: 0.18rem 0.55rem; font-size: 0.72rem; }
.inv-actions .btn + .btn { margin-left: 0.18rem; }

/* ---------- Bulk-upload progress ---------- */
.progress-wrap { padding-top: 0.3rem; }
.progress-track {
  position: relative;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: #eef2f9;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(135deg, var(--brand-2) 0%, var(--brand) 100%);
  position: relative;
  overflow: hidden;
  transition: width 0.35s ease;
  box-shadow: 0 1px 0 rgba(255,255,255,0.18) inset;
}
/* Animated stripes while moving */
.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(
    45deg,
    rgba(255,255,255,0.18) 25%, transparent 25%,
    transparent 50%, rgba(255,255,255,0.18) 50%,
    rgba(255,255,255,0.18) 75%, transparent 75%, transparent
  );
  background-size: 24px 24px;
  animation: progress-stripes 1.1s linear infinite;
}
.progress-fill.done {
  background: linear-gradient(135deg, #2e9a5e 0%, var(--ok-fg) 100%);
}
.progress-fill.done::after { animation: none; opacity: 0.3; }
@keyframes progress-stripes {
  from { background-position: 0 0; }
  to   { background-position: 24px 0; }
}

.mini-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  text-align: left;
}
.mini-stat .lbl {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
}
.mini-stat .val {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.02em;
}
.mini-stat.ok     .val { color: var(--ok-fg); }
.mini-stat.warn   .val { color: var(--warn-fg); }
.mini-stat.danger .val { color: var(--danger-fg); }

/* ---------- Danger zone (factory reset) ---------- */
.danger-zone {
  border: 1px solid rgba(185, 28, 28, 0.22);
  background: linear-gradient(180deg, #fff8f7 0%, #ffeaea 100%);
}
.danger-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 1rem;
}
.danger-banner .danger-icon {
  font-size: 1.8rem;
  line-height: 1;
  color: var(--danger-fg);
  flex-shrink: 0;
  margin-top: 0.1rem;
}
.reset-impact {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
  margin-bottom: 1rem;
}
.reset-impact .impact-title {
  font-weight: 600;
  color: var(--brand);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}
.reset-impact .impact-list {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.9rem;
}
.reset-impact .impact-list li { margin-bottom: 0.18rem; }
.reset-impact .impact-keep {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
  font-size: 0.86rem;
  color: var(--ok-fg);
}
.captcha-tough {
  background: #fff8e6;
  border: 1px solid #f4d883;
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
}
.captcha-tough .captcha-question {
  font-weight: 700;
  font-size: 1.05rem;
  color: #5b4400;
  margin-bottom: 0.45rem;
  letter-spacing: 0.3px;
}
.reset-done-tick {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2e9a5e 0%, var(--ok-fg) 100%);
  color: #ffffff;
  font-size: 1.6rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 14px rgba(22, 101, 52, 0.3);
}

/* ---------- Error pages (404/500/403/400) ---------- */
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 12% 18%, rgba(255,255,255,0.10) 0, transparent 55%),
    radial-gradient(700px 500px at 88% 82%, rgba(243, 156, 18, 0.18) 0, transparent 55%),
    linear-gradient(135deg, #0a3d62 0%, #1e6091 60%, #3c8dbc 100%);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
               "Segoe UI Variable", "Segoe UI", sans-serif;
}
.error-card {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-radius: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
  padding: 2.2rem 2.4rem;
  text-align: center;
  max-width: 520px;
  width: 100%;
}
.error-card .error-code {
  font-size: clamp(3.5rem, 9vw, 5rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 0.4rem;
}
.error-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--brand);
}
.error-card p {
  color: var(--muted);
  margin-bottom: 1rem;
}
.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
}

/* ---------- Dropdown menus (macOS-style) ---------- */
.dropdown-menu {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem;
  min-width: 240px;
  font-size: 0.9rem;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: background 0.1s ease, color 0.1s ease;
}
.dropdown-item:hover,
.dropdown-item:focus {
  background: linear-gradient(180deg, #2773ad 0%, var(--brand) 100%);
  color: #fff;
}
.dropdown-item.disabled,
.dropdown-item:disabled {
  color: var(--muted);
  background: transparent !important;
  cursor: not-allowed;
  opacity: 0.6;
}
.dropdown-item .dd-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  flex-shrink: 0;
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.9;
}
.dropdown-divider {
  margin: 0.35rem 0.25rem;
  border-top: 1px solid var(--hairline);
}
.btn.dropdown-toggle::after {
  margin-left: 0.5rem;
  vertical-align: 0.15em;
}

/* ---------- Region picker (checkbox grid + select-all) ---------- */
.region-picker {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.region-counter {
  font-weight: 600;
  color: var(--brand);
  background: #eef3fb;
  border: 1px solid var(--border);
  padding: 0.12rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
}
.region-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
  background: linear-gradient(180deg, #f3f6fc 0%, #ebeff8 100%);
  border-bottom: 1px solid var(--border);
}
.region-select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--brand);
  user-select: none;
  margin: 0;
}
.region-select-all input { margin: 0; cursor: pointer; }
.region-search {
  flex: 0 0 220px;
  max-width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.32rem 0.85rem;
  font-size: 0.85rem;
  background: #fff;
  outline: none;
  transition: border-color .12s ease, box-shadow .15s ease;
}
.region-search:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 0.15rem rgba(30, 96, 145, 0.18);
}

.region-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
  padding: 0.7rem;
  max-height: 360px;
  overflow-y: auto;
  background: #fbfcfe;
}
.region-card {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  cursor: pointer;
  margin: 0;
  transition: background 0.12s ease, border-color 0.12s ease,
              transform 0.05s ease, box-shadow 0.15s ease, color 0.12s ease;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
  font-size: 0.9rem;
  line-height: 1.2;
  user-select: none;
}
.region-card:hover {
  background: #f3f7ff;
  border-color: var(--brand-2);
}
.region-card:active { transform: translateY(0.5px); }
.region-card input { margin: 0; flex-shrink: 0; cursor: pointer; }
.region-card.is-selected,
.region-card:has(input:checked) {
  background: linear-gradient(180deg, #e9f0fa 0%, #dde8f5 100%);
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--brand) inset, var(--shadow-sm);
}
.region-card-label { line-height: 1.25; }

/* Hide the default <ul> wrapper Django emits */
.region-grid ul { all: unset; display: contents; }
.region-grid li { all: unset; display: contents; }

/* ---------- Expand/collapse hint ---------- */
.expand-link {
  text-decoration: none;
  color: var(--brand);
  font-weight: 600;
}
.expand-link:hover { text-decoration: underline; }
