/* Cranium AI: the single shared theme for every module. */
:root, [data-theme="ai"] {
  color-scheme: dark;
  --chart-grid:     rgba(0, 200, 255, .1);
  --bg-page:        #04040f;
  --bg-card:        rgba(12, 14, 40, 0.82);
  --bg-input:       rgba(15, 18, 50, 0.9);
  --bg-table-head:  rgba(0, 200, 255, 0.07);
  --bg-modal:       #0a0d28;
  --text-primary:   #ccd8ff;
  --text-muted:     #7088bb;
  --text-nav:       #00e5ff;
  --text-nav-hover: #ff00e5;
  --text-nav-brand: #00e5ff;
  --nav-bg:         rgba(2, 3, 18, 0.97);
  --border-color:   rgba(0, 200, 255, 0.18);
  --card-shadow:    0 0 18px rgba(0, 180, 255, 0.12);
  --input-border:   rgba(0, 200, 255, 0.3);
  --footer-border:  rgba(0, 200, 255, 0.12);
  --footer-color:   #4a6a99;
  --progress-bg:    rgba(0, 200, 255, 0.1);
  --toggle-active:  rgba(0, 200, 255, 0.2);
  --toggle-text:    #00e5ff;
  --bs-body-bg:     #04040f;
  --bs-body-color:  #ccd8ff;
  --bs-tooltip-color: #ccd8ff;
  --bs-tooltip-bg:    #0c1040;
  --bs-emphasis-color: #ccd8ff;
  --bs-link-color:  #7ec8e3;
  --bs-link-hover-color: #00e5ff;
}

/* ── Base overrides ───────────────────────────────────────── */
body {
  background: var(--bg-page) !important;
  color: var(--text-primary) !important;
  transition: background .25s, color .2s;
}
.card {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: var(--card-shadow) !important;
  color: var(--text-primary) !important;
}
.text-muted { color: var(--text-muted) !important; }
.table {
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}
.table > thead { background: var(--bg-table-head) !important; }
.table td, .table th { border-color: var(--border-color) !important; }
.table-hover > tbody > tr:hover > * { background: color-mix(in srgb, var(--bg-card) 80%, var(--text-primary) 5%); }
.form-control, .form-select {
  background: var(--bg-input) !important;
  border-color: var(--input-border) !important;
  color: var(--text-primary) !important;
}
.form-control:focus, .form-select:focus {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
}

[data-theme="ai"] .input-group-text {
  background: rgba(0, 200, 255, 0.10) !important;
  border-color: var(--input-border) !important;
  color: #00e5ff !important;
}
.form-text { color: var(--text-muted) !important; }
/* Bootstrap's file button and breadcrumbs are light-theme grays; match the theme. */
.form-control::file-selector-button {
  background: rgba(0, 200, 255, 0.10) !important;
  color: #00e5ff !important;
  border-color: var(--input-border) !important;
}
.form-control:hover:not(:disabled)::file-selector-button { background: rgba(0, 200, 255, 0.18) !important; }
.breadcrumb {
  --bs-breadcrumb-divider-color: var(--text-muted);
  --bs-breadcrumb-item-active-color: var(--text-primary);
}
.modal-content {
  background: var(--bg-modal) !important;
  border-color: var(--border-color) !important;
  color: var(--text-primary) !important;
}
.modal-header, .modal-footer { border-color: var(--border-color) !important; }
/* modal-xl is only used by the bill form; give its line table more room. */
@media (min-width: 1200px) {
  .modal-xl { --bs-modal-width: min(1400px, 94vw); }
}
/* Theme-aware accent header: tints toward the accent while keeping the
   modal's normal (readable) text colour in every theme. */
.modal-accent-primary { background: color-mix(in srgb, var(--bg-modal) 82%, #0d6efd 18%) !important; }
.modal-accent-success { background: color-mix(in srgb, var(--bg-modal) 82%, #198754 18%) !important; }
.progress { background: var(--progress-bg) !important; }
.alert-success { background: color-mix(in srgb, var(--bg-card) 70%, #198754 30%); border-color: #198754; color: var(--text-primary); }
.alert-danger  { background: color-mix(in srgb, var(--bg-card) 70%, #dc3545 30%); border-color: #dc3545; color: var(--text-primary); }
.alert-info    { background: color-mix(in srgb, var(--bg-card) 70%, #0dcaf0 30%); border-color: #0dcaf0; color: var(--text-primary); }

/* ── Toasts ───────────────────────────────────────────────
   Flash messages render as prominent toasts centered at bottom. */
.toast-container.flash-toasts {
  z-index: 1100;
  max-width: min(560px, 92vw);
  pointer-events: none;   /* empty container must not block clicks */
}
.toast-container.flash-toasts .toast {
  pointer-events: auto;
  min-width: 360px;
  font-size: 1rem;
  font-weight: 500;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
  color: var(--text-primary);
  background: var(--bg-card);
}
.toast-container.flash-toasts .toast .toast-body {
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.toast-container.flash-toasts .toast .toast-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  line-height: 1;
}
.toast-container.flash-toasts .toast.toast-success {
  background: color-mix(in srgb, var(--bg-card) 55%, #198754 45%);
  border-color: #198754;
}
.toast-container.flash-toasts .toast.toast-success .toast-icon { color: #25c97c; }
.toast-container.flash-toasts .toast.toast-danger {
  background: color-mix(in srgb, var(--bg-card) 55%, #dc3545 45%);
  border-color: #dc3545;
}
.toast-container.flash-toasts .toast.toast-danger .toast-icon { color: #ff5b6c; }
.toast-container.flash-toasts .toast.toast-info {
  background: color-mix(in srgb, var(--bg-card) 55%, #0dcaf0 45%);
  border-color: #0dcaf0;
}
.toast-container.flash-toasts .toast.toast-info .toast-icon { color: #29d6f8; }
.toast-container.flash-toasts .toast.toast-warning {
  background: color-mix(in srgb, var(--bg-card) 55%, #ffc107 45%);
  border-color: #ffc107;
}
.toast-container.flash-toasts .toast.toast-warning .toast-icon { color: #ffd93b; }

[data-theme="ai"]   .toast-container.flash-toasts .toast {
  box-shadow: 0 0 24px rgba(0,200,255,.35), 0 8px 32px rgba(0,0,0,.6);
  backdrop-filter: blur(10px);
}
[data-theme="ai"] .toast-container.flash-toasts .toast.toast-success { box-shadow: 0 0 24px rgba(0,255,120,.4), 0 8px 32px rgba(0,0,0,.6); }
[data-theme="ai"] .toast-container.flash-toasts .toast.toast-danger  { box-shadow: 0 0 24px rgba(255,60,90,.45),  0 8px 32px rgba(0,0,0,.6); }
[data-theme="ai"] .toast-container.flash-toasts .toast.toast-warning { box-shadow: 0 0 24px rgba(255,200,0,.4),   0 8px 32px rgba(0,0,0,.6); }
@keyframes flashToastIn {
  from { opacity: 0; transform: translateY(20px) scale(.95); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}
.toast-container.flash-toasts .toast.show { animation: flashToastIn .25s ease-out; }
.form-check-input { background-color: var(--bg-input); border-color: var(--input-border); }

/* ── Navbar ───────────────────────────────────────────────── */
.navbar { background: var(--nav-bg) !important; border-bottom: 1px solid var(--border-color); box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.navbar-brand, .navbar .nav-link { color: var(--text-nav) !important; }
.navbar-brand { color: var(--text-nav-brand) !important; font-weight: 700; letter-spacing: .3px; }
.navbar .nav-link:hover { color: var(--text-nav-hover) !important; }
.navbar .nav-link.active { color: var(--text-nav-hover) !important; font-weight: 600; }

/* Navbar dropdowns (Admin / Account) — themed to match cards, not Bootstrap white */
.navbar .dropdown-menu {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  border-radius: 10px;
  padding: .35rem;
}
.navbar .dropdown-item {
  color: var(--text-primary);
  border-radius: 7px;
  padding: .45rem .7rem;
}
.navbar .dropdown-item:hover, .navbar .dropdown-item:focus {
  background: color-mix(in srgb, var(--bg-modal) 80%, var(--text-primary) 12%);
  color: var(--text-primary);
}
.navbar .dropdown-item.active {
  background: var(--toggle-active);
  color: var(--text-nav-hover);
}
.navbar .dropdown-header { color: var(--text-muted); }
.navbar .dropdown-divider { border-top-color: var(--border-color); }

/* ── Mobile bottom tab bar ────────────────────────────────── */
.mobile-tabbar { display: none; }
@media (max-width: 991.98px) {
  :root { --tabbar-h: 56px; --safe-bottom: env(safe-area-inset-bottom, 0px); }
  /* Leave room for the fixed tab bar + iPhone home indicator */
  .has-mobile-tabs .app-content { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px); }
  /* Primary modules live in the bottom tab bar on mobile; the collapsed
     top menu keeps Admin / Account only. */
  .navbar .nav-primary { display: none !important; }
  .mobile-tabbar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 1030;
    justify-content: space-around;
    align-items: stretch;
    padding: 6px 4px calc(6px + var(--safe-bottom));
    background: color-mix(in srgb, var(--nav-bg) 92%, transparent);
    border-top: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  [data-theme="ai"] .mobile-tabbar { box-shadow: 0 -8px 24px rgba(0,100,255,.18); }
  /* Toast position — lift above the bottom tab bar */
  .has-mobile-tabs .toast-container.flash-toasts {
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px) !important;
  }
  .toast-container.flash-toasts .toast { min-width: 0; width: 100%; }
  .mobile-tabbar .tab-item {
    flex: 1 1 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 10px; font-weight: 500; line-height: 1.1;
    padding: 4px 2px; min-height: 44px; border-radius: 10px;
    transition: color .15s, background .15s, transform .1s;
  }
  .mobile-tabbar .tab-item i { font-size: 22px; line-height: 1; margin-bottom: 1px; }
  .mobile-tabbar .tab-item:active { transform: scale(.94); }
  .mobile-tabbar .tab-item.active {
    color: var(--text-nav-hover);
    background: color-mix(in srgb, currentColor 13%, transparent);
  }
  .mobile-tabbar .tab-item.active i { transform: scale(1.08); }
  .mobile-tabbar .tab-item.active span { font-weight: 700; }

  /* Bigger hit areas for checkboxes, switches and bare link buttons */
  .form-check-input { width: 1.3em; height: 1.3em; }
  .form-switch .form-check-input { width: 2.4em; }
  .btn-link.p-0 { padding: .375rem .5rem !important; }
  .table a:not(.btn) { display: inline-block; padding: .3rem 0; }
  [data-theme="ai"] .mobile-tabbar .tab-item.active {
    color: #00e5ff;
    text-shadow: 0 0 8px rgba(0,229,255,.6);
  }
}

/* ── Page header ─────────────────────────────────────────── */
.page-header { border-bottom: 2px solid var(--border-color); margin-bottom: 1.5rem; padding-bottom: .75rem; flex-wrap: wrap; gap: .5rem; }

/* ── Balance colours ─────────────────────────────────────── */
.balance-owed   { color: #dc3545; font-weight: 600; }
.balance-credit { color: #198754; font-weight: 600; }
.balance-zero   { color: #6c757d; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 575.98px) {
  .container { padding-left: .75rem; padding-right: .75rem; }
  .page-header h3 { font-size: 1.15rem; }
  .table { font-size: .85rem; }
  .btn-sm { min-height: 36px; }
  .table .btn-sm { padding: .25rem .45rem; }
}

/* ── AI theme extras ─────────────────────────────────────── */
[data-theme="ai"] body {
  background:
    radial-gradient(ellipse at 15% 40%, rgba(40, 0, 120, 0.35) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(0, 60, 120, 0.35) 0%, transparent 55%),
    radial-gradient(ellipse at 55% 85%, rgba(80, 0, 100, 0.25) 0%, transparent 50%),
    #04040f !important;
  background-attachment: fixed !important;
}
[data-theme="ai"] body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,200,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,200,255,.04) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
  z-index: 0;
}
/* Keep the grid behind content without overriding fixed mobile navigation. */
[data-theme="ai"] .container { position: relative; }
[data-theme="ai"] .card {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0,200,255,.18) !important;
}
body.modal-open .card,
body.modal-open [style*="backdrop-filter"] {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
[data-theme="ai"] h1,[data-theme="ai"] h2,[data-theme="ai"] h3,
[data-theme="ai"] h4,[data-theme="ai"] h5,[data-theme="ai"] h6 {
  background: linear-gradient(90deg, #00e5ff, #c060ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
[data-theme="ai"] .navbar-brand {
  background: linear-gradient(90deg, #00e5ff, #c060ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
}
[data-theme="ai"] .badge.bg-secondary {
  background: rgba(0,200,255,.15) !important;
  border: 1px solid rgba(0,200,255,.35);
  color: #00e5ff !important;
}
[data-theme="ai"] .badge.bg-success {
  background: rgba(0,255,120,.12) !important;
  border: 1px solid rgba(0,255,120,.4);
  color: #00ff99 !important;
}
[data-theme="ai"] .badge.bg-danger {
  background: rgba(255,0,80,.15) !important;
  border: 1px solid rgba(255,0,80,.4);
  color: #ff4477 !important;
}
[data-theme="ai"] .btn-primary {
  background: linear-gradient(135deg, #0070cc, #9000cc) !important;
  border: 1px solid rgba(0,200,255,.4) !important;
  box-shadow: 0 0 12px rgba(0,120,255,.3);
}
[data-theme="ai"] .btn-primary:hover {
  box-shadow: 0 0 20px rgba(0,180,255,.5) !important;
}
[data-theme="ai"] .btn-outline-secondary {
  border-color: rgba(0,200,255,.35) !important;
  color: #00e5ff !important;
}
[data-theme="ai"] .btn-outline-secondary:hover {
  background: rgba(0,200,255,.12) !important;
}
[data-theme="ai"] .btn-outline-primary {
  border-color: rgba(0,200,255,.4) !important;
  color: #00e5ff !important;
}
[data-theme="ai"] .btn-outline-primary:hover {
  background: rgba(0,200,255,.12) !important;
}
[data-theme="ai"] .btn-outline-danger {
  border-color: rgba(255,0,80,.5) !important;
  color: #ff4477 !important;
}
[data-theme="ai"] .btn-success {
  background: linear-gradient(135deg, #00994d, #007755) !important;
  border: 1px solid rgba(0,255,120,.4) !important;
  box-shadow: 0 0 12px rgba(0,200,80,.2);
  color: #fff !important;
}
[data-theme="ai"] .btn-success:hover {
  box-shadow: 0 0 20px rgba(0,255,120,.35) !important;
}
[data-theme="ai"] .btn-outline-success {
  border-color: rgba(0,255,120,.5) !important;
  color: #00ff99 !important;
}
[data-theme="ai"] .btn-outline-success:hover {
  background: rgba(0,255,120,.12) !important;
}
[data-theme="ai"] .badge.bg-primary {
  background: rgba(0,150,255,.2) !important;
  border: 1px solid rgba(0,200,255,.4);
  color: #00e5ff !important;
}
[data-theme="ai"] .badge.bg-info {
  background: rgba(0,200,255,.12) !important;
  border: 1px solid rgba(0,200,255,.35);
  color: #66d9ff !important;
}
[data-theme="ai"] .badge.bg-warning {
  background: rgba(255,180,0,.14) !important;
  border: 1px solid rgba(255,180,0,.4);
  color: #ffcc55 !important;
}
[data-theme="ai"]   .list-group-item {
  background-color: var(--bg-card) !important;
  border-color: var(--border-color) !important;
  color: var(--text-primary) !important;
}
[data-theme="ai"] .progress-bar {
  background: linear-gradient(90deg, #00c8ff, #9000ff) !important;
}
[data-theme="ai"] .progress-bar.bg-success {
  background: linear-gradient(90deg, #00ff99, #00c8ff) !important;
}
[data-theme="ai"] .progress-bar.bg-danger {
  background: linear-gradient(90deg, #ff0055, #ff6600) !important;
}
[data-theme="ai"] .text-success { color: #00ff99 !important; }
[data-theme="ai"] .text-danger  { color: #ff4477 !important; }
[data-theme="ai"] .text-warning { color: #ffaa00 !important; }
[data-theme="ai"] .text-primary { color: #00e5ff !important; }
[data-theme="ai"] .balance-owed   { color: #ff4477 !important; }
[data-theme="ai"] .balance-credit { color: #00ff99 !important; }
[data-theme="ai"] .navbar {
  border-bottom: 1px solid rgba(0,200,255,.2) !important;
  box-shadow: 0 0 20px rgba(0,100,255,.15);
}

[data-theme="ai"] .btn-outline-secondary.active {
  background: rgba(0,200,255,.22) !important;
  border-color: #00e5ff !important;
  color: #fff !important;
}
[data-theme="ai"] .balance-zero { color: var(--text-muted) !important; }

/* List items use the same surface as their containing cards. */
.list-group-item { background-color: var(--bg-card); }

/* AI overrides for Bootstrap components. */
[data-theme="ai"]   .btn-close { filter: invert(1) brightness(1.8); }

[data-theme="ai"]   .table-secondary > *,
[data-theme="ai"]   .table-secondary    { --bs-table-bg: rgba(0,200,255,.04) !important; color: var(--text-muted) !important; }

[data-theme="ai"]   .table-light > *,
[data-theme="ai"]   .table-light        { --bs-table-bg: rgba(0,200,255,.07) !important; --bs-table-color: #ccd8ff !important; color: var(--text-primary) !important; }

/* Bootstrap paints hover/striped rows with an inset shadow, independently
   of their background. Override those states as well as the base surface. */
[data-theme="ai"] .table-secondary,
[data-theme="ai"] .table-secondary > *,
[data-theme="ai"] .table-light,
[data-theme="ai"] .table-light > * {
  --bs-table-striped-bg: rgba(0,200,255,.06);
  --bs-table-striped-color: var(--text-primary);
  --bs-table-hover-bg: rgba(0,200,255,.10);
  --bs-table-hover-color: var(--text-primary);
  --bs-table-active-bg: rgba(0,200,255,.14);
  --bs-table-active-color: var(--text-primary);
}
[data-theme="ai"] .table-secondary:hover > * {
  color: var(--text-primary) !important;
}

/* Success rows (including current addresses) must keep the dark surface and
   readable text in every Bootstrap table interaction state. */
[data-theme="ai"] .table-success,
[data-theme="ai"] .table-success > * {
  --bs-table-bg: rgba(0,255,153,.07);
  --bs-table-color: var(--text-primary);
  --bs-table-border-color: var(--border-color);
  --bs-table-striped-bg: rgba(0,255,153,.10);
  --bs-table-striped-color: var(--text-primary);
  --bs-table-hover-bg: rgba(0,255,153,.12);
  --bs-table-hover-color: var(--text-primary);
  --bs-table-active-bg: rgba(0,255,153,.16);
  --bs-table-active-color: var(--text-primary);
  color: var(--text-primary);
}

[data-theme="ai"]   select option { background: #0a0d28; color: #ccd8ff; }

[data-theme="ai"]   .form-control::placeholder { color: rgba(112,136,187,.7); }

[data-theme="ai"]   label,
[data-theme="ai"]   .form-label,
[data-theme="ai"]   .form-check-label { color: var(--text-primary) !important; }

[data-theme="ai"] .modal-title {
  background: none !important;
  -webkit-text-fill-color: #ccd8ff !important;
  color: #ccd8ff !important;
}

[data-theme="ai"] .card h5,
[data-theme="ai"] .card h6 {
  background: none !important;
  -webkit-text-fill-color: #a0c4ff !important;
  color: #a0c4ff !important;
}

[data-theme="ai"] .alert { color: var(--text-primary) !important; }

[data-theme="ai"] .form-check-input:checked {
  background-color: rgba(0,200,255,.5) !important;
  border-color: #00e5ff !important;
}

[data-theme="ai"] .navbar-toggler { border-color: rgba(0,200,255,.3) !important; }

[data-theme="ai"] .tooltip-inner {
  background: rgba(10, 14, 52, 0.97) !important;
  color: #ccd8ff !important;
  border: 1px solid rgba(0,200,255,.25);
}
[data-theme="ai"] .tooltip .tooltip-arrow::before { border-top-color: rgba(10,14,52,.97) !important; }
[data-theme="ai"] .bs-tooltip-bottom .tooltip-arrow::before { border-top-color: transparent !important; border-bottom-color: rgba(10,14,52,.97) !important; }

[data-theme="ai"]   a:not(.btn):not(.nav-link):not(.navbar-brand):not(.badge) { color: #7ec8e3; }
[data-theme="ai"]   a:not(.btn):not(.nav-link):not(.navbar-brand):not(.badge):hover { color: #00e5ff; }

/* ── Cranium modules ─────────────────────────────────────────
   <body> carries --module-accent: the current module's color, or
   Cranium purple on the home page, shown as an accent strip. */

.navbar.has-module, .navbar.is-home { border-bottom: 3px solid var(--module-accent) !important; }
[data-theme="ai"]   .navbar .nav-primary .nav-link.active { box-shadow: inset 0 -3px 0 var(--module-accent); }

.navbar .nav-primary .nav-link { padding-left: .7rem !important; padding-right: .7rem !important; }
.cranium-mark { flex: none; }
.module-pill {
  display: inline-flex; align-items: center; gap: .45rem; min-width: 0;
  max-width: 13rem; padding: .28rem .8rem; border-radius: 999px;
  font-size: .9rem; font-weight: 600; line-height: 1.3;
  color: var(--text-nav);
  background: color-mix(in srgb, var(--module-accent) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--module-accent) 65%, transparent);
}
.module-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.module-pill:hover { color: var(--text-nav-hover); }

.module-pill-static { cursor: default; }
.module-pill-static:hover { color: var(--text-nav); }
.navbar .module-switcher .dropdown-item.active {
  background: color-mix(in srgb, var(--module-accent) 20%, var(--bg-modal));
  color: var(--text-primary); font-weight: 600;
}
.module-dot {
  display: inline-block; width: .55rem; height: .55rem; border-radius: 50%;
  background: var(--dot); margin-right: .55rem; vertical-align: .05rem;
}
@media (max-width: 575.98px) {
  .navbar.has-module .navbar-brand span { display: none; }   /* the mark alone, to fit the pill */
  .module-pill { max-width: 11rem; }
}
.mobile-tabbar .tab-item .cranium-mark { margin-bottom: 1px; }

/* Home page: greeting, module tiles, and an "Elsewhere" row of links */
.home-hero { margin: .5rem 0 1.75rem; }
.home-greeting {
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.3rem); font-weight: 700;
  letter-spacing: -.02em; margin: 0 0 .2rem;
}
.home-date { color: var(--text-muted); font-size: .95rem; min-height: 1.4em; }
.home-section {
  font-size: .78rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-muted); margin: 2.25rem 0 .85rem;
}
/* At most three columns, so the tiles line up in even rows. */
.home-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(max(16.5rem, calc((100% - 2rem) / 3)), 1fr)); }
.home-links { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(max(15rem, calc((100% - 1.5rem) / 3)), 1fr)); }

.module-tile {
  position: relative; overflow: hidden; isolation: isolate;
  display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; height: 100%;
  text-decoration: none; color: var(--text-primary) !important;
  border: 1px solid color-mix(in srgb, var(--tile-accent) 22%, transparent) !important;
  border-radius: 1.1rem !important;
  background:
    radial-gradient(120% 90% at 100% 0%, color-mix(in srgb, var(--tile-accent) 16%, transparent), transparent 60%),
    var(--bg-card) !important;
  box-shadow: none !important;
  touch-action: manipulation;
  transition: border-color .18s ease, box-shadow .18s ease;
  animation: tile-in .45s cubic-bezier(.2, .7, .2, 1) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
/* Pointer-following spotlight (position set by the home page script). */
.module-tile::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(18rem circle at var(--mx, 50%) var(--my, 0%),
              color-mix(in srgb, var(--tile-accent) 18%, transparent), transparent 70%);
  opacity: 0; transition: opacity .2s;
}
.module-tile:focus-visible::before { opacity: 1; }
.module-tile:focus-visible, .module-tile:active {
  border-color: color-mix(in srgb, var(--tile-accent) 55%, transparent) !important;
  box-shadow: 0 12px 32px -12px color-mix(in srgb, var(--tile-accent) 55%, transparent) !important;
}
.module-tile:focus-visible { outline: 2px solid var(--tile-accent); outline-offset: 2px; }

.module-tile .tile-icon {
  width: 3rem; height: 3rem; border-radius: .9rem; flex: none; margin-bottom: .6rem;
  display: grid; place-items: center; font-size: 1.4rem;
  color: color-mix(in srgb, var(--tile-accent) 70%, #fff);
  background: color-mix(in srgb, var(--tile-accent) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tile-accent) 35%, transparent),
              inset 0 1px 0 rgba(255, 255, 255, .08);
}
/* Tiles for apps with their own icon show it as is. */
.module-tile .tile-image { padding: 0; object-fit: cover; background: none; box-shadow: none; }
.module-tile .tile-name { font-size: 1.12rem; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
.module-tile .tile-desc { color: var(--text-muted); font-size: .92rem; line-height: 1.45; }
.module-tile .tile-arrow {
  position: absolute; top: 1rem; right: 1rem; font-size: 1rem;
  pointer-events: none;
  color: color-mix(in srgb, var(--tile-accent) 70%, #fff);
  opacity: 0; transform: translate(-4px, 4px); transition: opacity .18s, transform .18s;
}
.module-tile:focus-visible .tile-arrow { opacity: 1; transform: none; }

/* Link tiles: compact chips, icon + name + address. */
.module-tile.link-tile {
  flex-direction: row; align-items: center; gap: .8rem; padding: .7rem .9rem;
  border-radius: .95rem !important;
}
.module-tile.link-tile .tile-icon { width: 2.5rem; height: 2.5rem; border-radius: .7rem; margin: 0; }
.module-tile.link-tile .link-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.module-tile.link-tile .tile-name { font-size: .98rem; }
.module-tile .tile-host {
  color: var(--text-muted); font-size: .8rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.module-tile .tile-arrow-inline { color: var(--text-muted); font-size: .85rem; transition: color .18s; }
.module-tile.link-tile:focus-visible .tile-arrow-inline { color: var(--text-primary); }

/* Touch browsers can synthesize hover on the first tap. Keep it off touch layouts. */
@media (hover: hover) and (pointer: fine) {
  .module-tile:hover {
    border-color: color-mix(in srgb, var(--tile-accent) 55%, transparent) !important;
    box-shadow: 0 12px 32px -12px color-mix(in srgb, var(--tile-accent) 55%, transparent) !important;
  }
  .module-tile:hover::before { opacity: 1; }
  .module-tile:hover .tile-arrow { opacity: 1; transform: none; }
  .module-tile.link-tile:hover .tile-arrow-inline { color: var(--text-primary); }
}

@keyframes tile-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .module-tile { animation: none; transition: none; }
  .module-tile::before, .module-tile .tile-arrow, .module-tile .tile-arrow-inline { transition: none; }
}
/* Phones: two compact tiles per row, no descriptions. */
@media (max-width: 575.98px) {
  .home-hero { margin-bottom: 1.25rem; }
  .home-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
  .home-grid .module-tile { padding: .95rem !important; }
  .home-grid .tile-desc, .home-grid .tile-arrow { display: none; }
  .home-grid .tile-icon { width: 2.6rem; height: 2.6rem; font-size: 1.2rem; margin-bottom: .45rem; }
  .home-grid .tile-name { font-size: 1rem; }
  .home-links { grid-template-columns: 1fr; }
}

.captured-body {
  white-space: pre-wrap; word-break: break-word;
  color: var(--text-primary); font-size: .85rem;
}

/* Badges nested in a heading must not inherit the AI theme's transparent
   gradient text fill, or their label becomes invisible (e.g. the
   relationship pill on the household detail page). */
[data-theme="ai"] h1 .badge, [data-theme="ai"] h2 .badge, [data-theme="ai"] h3 .badge,
[data-theme="ai"] h4 .badge, [data-theme="ai"] h5 .badge, [data-theme="ai"] h6 .badge {
  -webkit-text-fill-color: #fff;
  color: #fff;
}

/* btn-check selected pills: keep readable contrast in dark/AI themes
       (theme rules forced the outline text color even when filled — pill became
       same color as its text). */
    [data-theme="ai"]   .btn-check:checked + .btn-outline-success {
      background-color: #198754 !important;
      border-color: #198754 !important;
      color: #fff !important;
    }
[data-theme="ai"]   .btn-check:checked + .btn-outline-danger {
      background-color: #dc3545 !important;
      border-color: #dc3545 !important;
      color: #fff !important;
    }
[data-theme="ai"]   .btn-check:checked + .btn-outline-secondary {
      background-color: #6c757d !important;
      border-color: #6c757d !important;
      color: #fff !important;
    }
[data-theme="ai"]   .btn-check:checked + .btn-outline-primary {
      background-color: #0d6efd !important;
      border-color: #0d6efd !important;
      color: #fff !important;
    }
[data-theme="ai"]   .btn-check:checked + .btn-outline-warning {
      background-color: #ffc107 !important;
      border-color: #ffc107 !important;
      color: #000 !important;
    }
/* -- Outline buttons: missing variants, hover, and selected state -------
       The [data-theme="ai"] rules above pin `color` with !important, but
       Bootstrap's .active and :hover only swap the *background*. That left
       neon text on a solid brand fill -- the Households filter pills measured
       1.3:1. The .btn-check:checked rules covered radio pills but not the
       class-toggled .active ones used by the filter bars.

       Every variant now gets one treatment: translucent neon fill, neon text,
       brighter border. All six measure above 6:1 on the page background. */
    /* warning and info had no theme rule at all,
    so they kept Bootstrap's
       solid fill and read as a different design language next to the rest. */
    [data-theme="ai"] .btn-outline-warning {
      border-color: rgba(255,190,0,.45) !important;
      color: #ffc83d !important;
    }
[data-theme="ai"] .btn-outline-info {
      border-color: rgba(0,229,255,.4) !important;
      color: #00e5ff !important;
    }
/* Hover: keep the fill translucent so the pinned text colour stays legible. */
    [data-theme="ai"] .btn-outline-danger:hover { background: rgba(255,60,110,.12) !important; }
[data-theme="ai"] .btn-outline-warning:hover { background: rgba(255,190,0,.12) !important; }
[data-theme="ai"] .btn-outline-info:hover { background: rgba(0,229,255,.12) !important; }
/* Selected state, for both class-toggled (.active) and radio (btn-check) pills. */
    [data-theme="ai"] .btn-outline-success.active,
    [data-theme="ai"] .btn-outline-success.active:hover {
      background: rgba(0,255,153,.20) !important;
      border-color: rgba(0,255,153,.65) !important;
      color: #00ff99 !important;
      box-shadow: 0 0 10px rgba(0,255,153,.15);
    }
[data-theme="ai"] .btn-outline-secondary.active,
    [data-theme="ai"] .btn-outline-secondary.active:hover {
      background: rgba(150,170,205,.22) !important;
      border-color: rgba(150,170,205,.5) !important;
      color: #cfdaf0 !important;
    }
[data-theme="ai"] .btn-outline-primary.active,
    [data-theme="ai"] .btn-outline-primary.active:hover {
      background: rgba(0,150,255,.24) !important;
      border-color: rgba(0,150,255,.6) !important;
      color: #6cc4ff !important;
      box-shadow: 0 0 10px rgba(0,150,255,.15);
    }
[data-theme="ai"] .btn-outline-info.active,
    [data-theme="ai"] .btn-outline-info.active:hover {
      background: rgba(0,229,255,.20) !important;
      border-color: rgba(0,229,255,.6) !important;
      color: #00e5ff !important;
      box-shadow: 0 0 10px rgba(0,229,255,.15);
    }
[data-theme="ai"] .btn-outline-warning.active,
    [data-theme="ai"] .btn-outline-warning.active:hover {
      background: rgba(255,190,0,.20) !important;
      border-color: rgba(255,190,0,.6) !important;
      color: #ffc83d !important;
      box-shadow: 0 0 10px rgba(255,190,0,.15);
    }
[data-theme="ai"] .btn-outline-danger.active,
    [data-theme="ai"] .btn-outline-danger.active:hover {
      background: rgba(255,60,110,.20) !important;
      border-color: rgba(255,60,110,.6) !important;
      color: #ff6b90 !important;
      box-shadow: 0 0 10px rgba(255,60,110,.15);
    }
/* Count badges inside those pills: bg-warning and bg-info were the only
       two left as solid Bootstrap fills with .text-dark, so they jumped out
       against the translucent neon badges beside them. */
    [data-theme="ai"] .badge.bg-warning,
    [data-theme="ai"] .badge.bg-warning.text-dark {
      background: rgba(255,190,0,.16) !important;
      border: 1px solid rgba(255,190,0,.45);
      color: #ffc83d !important;
    }
[data-theme="ai"] .badge.bg-info,
    [data-theme="ai"] .badge.bg-info.text-dark {
      background: rgba(0,229,255,.15) !important;
      border: 1px solid rgba(0,229,255,.4);
      color: #00e5ff !important;

}

/* ── Shared component polish ───────────────────────────────────────────
   Previously scoped to the household detail page; promoted so every
   page shares one label, card-header and table-header treatment. */

  /* Card headers: quiet, tracked, with a real divider. */
  .card > .card-header {
    padding: .7rem 1.15rem;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--text-muted) !important;
    background: rgba(0, 200, 255, .045);
    border-bottom: 1px solid var(--border-color);
  }
  .card > .card-body { padding: 1.15rem; }
  .card > .card-body.p-0 { padding: 0 !important; }

  /* Labels should recede so the values they name read first.
     Modals included, or their fields would not match the cards behind them. */
  [data-theme="ai"] .card .form-label,
  [data-theme="ai"] .modal .form-label {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted) !important;
    margin-bottom: .3rem;
  }

  /* View-only mode renders a <dl>; match the edit form's label treatment. */
  .card dl dt {
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted) !important;
    margin-bottom: .15rem;
  }
  .card dl dd { margin-bottom: .95rem; }
  .card dl dd:last-child { margin-bottom: 0; }

  /* One consistent gap between form groups. */
  .card form .mb-3, .modal-body .mb-3 { margin-bottom: 1rem !important; }

  /* Neon focus ring in place of Bootstrap's blue. */
  [data-theme="ai"] .form-control:focus,
  [data-theme="ai"] .form-select:focus {
    border-color: rgba(0, 229, 255, .55) !important;
    box-shadow: 0 0 0 .19rem rgba(0, 229, 255, .12) !important;
  }

  /* Tables: room to breathe, and action buttons that are not fused together. */
  .card .table > thead th {
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted) !important;
    padding: .6rem .9rem;
  }
  .card .table > tbody td { padding: .7rem .9rem; vertical-align: middle; }

/* Shared page rhythm; module identity lives in its accent and icon. */
.page-header { display: flex; align-items: center; justify-content: space-between; }
.page-header h1, .page-header h2, .page-header h3 {
  font-size: 1.5rem; font-weight: 600; letter-spacing: -.015em;
}
.card { border-radius: .85rem; }
.card-header .btn, .card-header .badge { text-transform: none; letter-spacing: normal; }
.navbar .nav-link { white-space: nowrap; }
.navbar > .container { flex-wrap: nowrap; gap: .5rem; }
.navbar .navbar-brand { margin-right: .25rem; min-height: 44px; }
.navbar .module-switcher { min-width: 0; }
.navbar .module-switcher .dropdown-menu { max-height: min(70vh, 28rem); overflow-y: auto; }
.navbar .module-pill { min-height: 44px; }
.navbar .navbar-toggler {
  width: 44px; height: 44px; flex: none; padding: 0;
  color: var(--text-primary); font-size: 1.6rem;
}
.account-menu > button { background: transparent; border: 0; padding: .6rem .75rem; min-height: 44px; }
.account-menu .dropdown-menu { width: 240px; padding: .375rem; }
.navigation-drawer {
  --bs-offcanvas-width: min(360px, 100vw);
  background: var(--bg-modal); color: var(--text-primary);
  border-left: 1px solid var(--border-color);
}
.navigation-drawer .offcanvas-header {
  padding-top: calc(1rem + var(--safe-top)); border-bottom: 1px solid var(--border-color);
}
.navigation-drawer .offcanvas-body { padding: .75rem 1rem calc(1rem + var(--safe-bottom)); }
.navigation-drawer .btn-close { padding: .75rem; }
.navigation-heading {
  color: var(--text-muted); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; margin: .6rem .75rem .35rem;
}
.navigation-drawer section + section, .account-menu section + section {
  border-top: 1px solid var(--border-color); margin-top: .75rem; padding-top: .5rem;
}
.navigation-link {
  display: flex; align-items: center; gap: .75rem; min-height: 48px;
  padding: .65rem .75rem; border-radius: .6rem; text-decoration: none;
}
[data-theme="ai"] a.navigation-link, .navigation-modules summary { color: var(--text-primary); }
.navigation-link:hover, .navigation-link:focus-visible { background: rgba(0, 200, 255, .08); }
[data-theme="ai"] a.navigation-link.active {
  color: var(--text-nav); background: rgba(0, 200, 255, .1);
  box-shadow: inset 3px 0 var(--module-accent); font-weight: 600;
}
.navigation-link > i { flex: none; width: 1.2rem; text-align: center; }
.navigation-identity { margin: .5rem .75rem; color: var(--text-muted); font-size: .85rem; overflow-wrap: anywhere; }
.navigation-identity strong { color: var(--text-primary); font-weight: 500; }
/* Desktop dropdowns use tighter spacing than the touch-friendly drawer. */
.account-menu .navigation-link { min-height: 36px; padding: .375rem .625rem; gap: .625rem; }
.account-menu .navigation-heading { margin: .375rem .625rem .25rem; }
.account-menu section + section { margin-top: .375rem; padding-top: .375rem; }
.account-menu .navigation-identity { margin: .375rem .625rem; }
.navigation-modules summary { cursor: pointer; list-style: none; }
.navigation-modules summary::-webkit-details-marker { display: none; }
.navigation-modules[open] summary .bi-chevron-down { transform: rotate(180deg); }
.navigation-modules > a { margin-left: 1rem; }
.mobile-tabbar .tab-item { font-size: 11px; }
.mobile-tabbar .tab-item.active { box-shadow: inset 0 2px var(--module-accent); }
.page-header .badge { letter-spacing: normal; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem; }
.form-actions .form-action-delete { margin-right: auto; }
.form-actions .btn { min-height: 40px; }
.modal-footer > .form-actions { flex: 1; }
.modal-content > form[data-edit-form] { display: flex; flex-direction: column; min-height: 0; }
.empty-state { padding: 1.75rem 1rem; text-align: center; }
.empty-state-icon { display: block; font-size: 1.8rem; color: var(--text-muted); margin-bottom: .65rem; }
.empty-state-title { font-weight: 600; margin-bottom: .35rem; }
.empty-state-description { max-width: 32rem; margin: 0 auto 1rem; color: var(--text-muted); font-size: .9rem; }
.invalid-feedback { color: #ff6b90; }
.form-control.is-invalid, .form-select.is-invalid { border-color: #ff6b90 !important; }
.form-control.is-invalid:focus, .form-select.is-invalid:focus { box-shadow: 0 0 0 .2rem rgba(255,60,110,.15) !important; }
@media (max-width: 575.98px) {
  .form-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.8fr); }
  .form-actions > .form-action-delete { grid-column: 1 / -1; justify-self: start; margin-bottom: .5rem; }
}
:root { --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px); }
@media (max-width: 768px) {
  body { padding-bottom: 0 !important; }
  .navbar { padding-top: calc(.5rem + var(--safe-top)); }
  .form-control, .form-select { font-size: 16px; min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .page-header h1, .page-header h2, .page-header h3 { font-size: 1.2rem; }
  .card .table > thead th, .card .table > tbody td { padding: .6rem .45rem; }
}
@media (display-mode: standalone) { body { overscroll-behavior-y: contain; } }

/* Keep keyboard focus distinct from the theme's persistent button glows.
   Hidden radio inputs need the ring on their visible segmented label. */
[data-theme="ai"] :focus-visible,
[data-theme="ai"] .btn-check:focus-visible + .btn {
  outline: 2px solid var(--text-nav) !important;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  [data-theme="ai"] *,
  [data-theme="ai"] *::before,
  [data-theme="ai"] *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
