/* =============================================================================
   Family Finance — FamFin design system v3
   Premium dark navy + teal/cyan glow • glassmorphism cards • collapsible sidebar
   Mobile-first, mirrors the iPhone reference design.
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;600;700&display=swap');

:root {
  /* Surfaces — deeper midnight navy */
  --bg:           #060c1f;
  --bg-2:         #0a1230;
  --bg-elev:      #0d1838;
  --bg-card:      rgba(15, 26, 56, 0.78);
  --bg-card-solid:#0f1a38;
  --bg-card-2:    #122046;
  --bg-input:     #0a1432;
  --bg-overlay:   rgba(2, 6, 18, 0.78);

  /* Lines + glow */
  --line:         rgba(99, 154, 220, 0.10);
  --line-strong:  rgba(99, 154, 220, 0.22);
  --line-bright:  rgba(34, 211, 238, 0.45);

  /* Text */
  --text:         #e6eaf5;
  --text-strong:  #f5f8ff;
  --text-muted:   #93a1c4;
  --text-soft:    #6478a3;
  --text-on-accent: #001a26;

  /* Accent — teal/cyan neon */
  --accent:       #22d3ee;       /* cyan-400 */
  --accent-hi:    #67e8f9;       /* cyan-300 */
  --accent-strong:#06b6d4;       /* cyan-500 */
  --accent-deep:  #0891b2;       /* cyan-600 */
  --accent-soft:  rgba(34, 211, 238, 0.14);
  --accent-glow:  rgba(34, 211, 238, 0.42);

  /* Semantic */
  --success:      #34d399;
  --success-soft: rgba(52, 211, 153, 0.16);
  --warn:         #fbbf24;
  --warn-soft:    rgba(251, 191, 36, 0.14);
  --danger:       #f87171;
  --danger-soft:  rgba(248, 113, 113, 0.16);
  --info:         #60a5fa;
  --violet:       #a78bfa;
  --violet-soft:  rgba(167, 139, 250, 0.16);

  /* Per-currency tints */
  --c-usd:        #34d399;
  --c-usd-soft:   rgba(52, 211, 153, 0.14);
  --c-kes:        #38bdf8;
  --c-kes-soft:   rgba(56, 189, 248, 0.14);
  --c-etb:        #fbbf24;
  --c-etb-soft:   rgba(251, 191, 36, 0.14);

  --p-samic:      #67e8f9;
  --p-aziti:      #c4b5fd;

  /* Shape */
  --radius:       14px;
  --radius-sm:    10px;
  --radius-lg:    20px;
  --radius-xl:    26px;
  --radius-pill:  999px;
  --space:        16px;
  --space-sm:     8px;
  --space-lg:     24px;

  /* Shadows */
  --shadow-card:  0 10px 40px -16px rgba(2, 8, 24, 0.7),
                  0 0 0 1px var(--line);
  --shadow-pop:   0 22px 60px -20px rgba(0, 0, 0, 0.85);
  --shadow-glow:  0 0 0 1px rgba(34,211,238,0.4),
                  0 8px 28px -10px var(--accent-glow);
  --shadow-inset: inset 0 1px 0 rgba(255,255,255,0.05);

  /* Type */
  --font-sans:    "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  /* Layout */
  --sidebar-w:    248px;
  --sidebar-w-collapsed: 76px;
  --topbar-h:     54px;
  --bottomnav-h:  68px;

  /* Motion (v7) — one standard everywhere instead of ad-hoc transitions */
  --ease:         cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast:       140ms var(--ease);
  --t-med:        220ms var(--ease);

  /* Focus ring (v7) */
  --focus-ring:   0 0 0 2px var(--bg), 0 0 0 4px rgba(34, 211, 238, 0.55);
}

/* -----------------------------------------------------------------------------
   v7 premium polish — motion, focus, form states, skeletons
   ----------------------------------------------------------------------------- */

/* Visible keyboard-focus everywhere, without the fuzzy default outline. */
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

/* Interactive elements share one motion standard. */
.btn, .chip, .kpi-tab, .kpi-card, .card, .due-row, .upcoming-row,
.sidebar a, .bottomnav-tab, .more-tile, .modal-card, .toast {
  transition: background-color var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), box-shadow var(--t-med), transform var(--t-fast),
              opacity var(--t-med);
}
.btn:active { transform: translateY(1px) scale(0.99); }
.kpi-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-card), 0 0 24px -14px var(--accent-glow); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Form validation states — pair with .field-error text under the control. */
.is-error, input.is-error, select.is-error, textarea.is-error {
  border-color: rgba(248, 113, 113, 0.65) !important;
  box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.35);
}
.field-error { color: var(--danger); font-size: 0.78rem; margin-top: 4px; }
.is-success, input.is-success { border-color: rgba(52, 211, 153, 0.55) !important; }

/* Skeleton loaders — drop .skeleton on any placeholder block. */
.skeleton {
  position: relative; overflow: hidden;
  background: rgba(99, 154, 220, 0.08);
  border-radius: var(--radius-sm);
  min-height: 14px;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  animation: ff-shimmer 1.4s infinite;
}
@keyframes ff-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* Responsive table wrapper — horizontal scroll with edge fade on small screens.
   Wrap any wide <table class="table"> in <div class="table-wrap">…</div>. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.table-wrap .table { min-width: 640px; }
@media (max-width: 767px) {
  .table-wrap {
    margin-inline: -4px; padding-inline: 4px;
    mask-image: linear-gradient(90deg, #000 0%, #000 calc(100% - 18px), transparent 100%);
    -webkit-mask-image: linear-gradient(90deg, #000 0%, #000 calc(100% - 18px), transparent 100%);
  }
}

/* Notification dot — fade in/out instead of popping. */
#notifDot { transition: opacity var(--t-med), transform var(--t-med); }
#notifDot[hidden] { display: block !important; opacity: 0; transform: scale(0.5); pointer-events: none; }

/* KPI flip affordance — small corner glyph signalling the value flips on tap. */
.kpi-card [data-kpi-flip] { position: relative; }
.kpi-card [data-kpi-flip][style*="pointer"]::after {
  content: "⇄"; position: absolute; top: 2px; right: 0;
  font-size: 0.62em; color: var(--text-soft); opacity: 0.85;
}

/* -----------------------------------------------------------------------------
   Reset
   ----------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(34, 211, 238, 0.08) 0%, transparent 55%),
    radial-gradient(80% 60% at 100% 0%, rgba(56, 189, 248, 0.06) 0%, transparent 55%),
    radial-gradient(100% 80% at 50% 100%, rgba(167, 139, 250, 0.05) 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--accent-hi); }
::selection { background: var(--accent-soft); color: var(--text-strong); }

h1, h2, h3, h4 {
  color: var(--text-strong);
  font-weight: 700;
  letter-spacing: -0.018em;
  line-height: 1.2;
}
h1 { font-size: 1.85rem; letter-spacing: -0.024em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0rem; font-weight: 600; }
h4 { font-size: 0.92rem; font-weight: 600; }

/* Brand-gradient text */
.h-brand {
  background: linear-gradient(135deg, var(--accent-hi) 0%, var(--accent) 50%, #0ea5e9 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.welcome-line {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

/* Dashboard header — welcome + title + month picker */
.dash-header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 18px;
}
.dash-header-left { min-width: 0; flex: 1 1 280px; }
.dash-header-right {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.dash-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 6px;
  letter-spacing: 0.01em;
}
.month-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(15, 26, 56, 0.7);
  border: 1px solid rgba(99, 154, 220, 0.18);
  backdrop-filter: blur(8px);
  font-size: 0.85rem;
}
.month-picker-icon { opacity: 0.85; }
.month-picker select {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.88rem;
  padding: 2px 4px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%2393a1c4' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 4px center;
  padding-right: 20px;
}
.month-picker select:focus {
  outline: 1px solid rgba(34, 211, 238, 0.5);
  outline-offset: 2px;
  border-radius: 6px;
}
.month-picker select option { background: #0f1a38; color: var(--text); }

/* Dashboard hero illustration */
.dash-hero {
  position: relative;
  flex: 0 0 auto;
  width: clamp(220px, 30vw, 320px);
  height: 140px;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.6),
              0 0 0 1px rgba(34, 211, 238, 0.18);
  isolation: isolate;
}
.dash-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(115deg, rgba(6, 12, 31, 0.55) 0%, rgba(6, 12, 31, 0) 50%, rgba(6, 12, 31, 0.55) 100%),
    radial-gradient(80% 80% at 30% 20%, rgba(34, 211, 238, 0.18), transparent 70%);
  pointer-events: none;
}
.dash-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
@media (max-width: 1023px) {
  .dash-hero { display: none; }
}

/* Personalize cards in Settings */
.personalize-card {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
  align-items: center;
  padding: 14px;
  background: rgba(13, 24, 56, 0.5);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.personalize-preview {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-card-2, #0f1a38);
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
}
.personalize-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.personalize-preview.is-family {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  width: 92px;
  height: 92px;
  margin: 0 auto;
}
.personalize-preview.is-family img { border-radius: 50%; }
.personalize-meta input[type="file"] {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 100%;
}
@media (max-width: 600px) {
  .personalize-card { grid-template-columns: 1fr; }
  .personalize-preview.is-family { margin: 0; }
}

.num, .money, .amount, .card-value, .ccy-amount, .table-money {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* =============================================================================
   App shell
   ============================================================================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0));
}

.app-content {
  padding: 18px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}
@media (min-width: 1024px) { .app-content { padding: 28px 32px; } }

/* =============================================================================
   Top bar
   ============================================================================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  /* Honor the iPhone notch / Dynamic Island so the topbar content isn't
     hidden under the front camera. env(safe-area-inset-top) is 0 on
     desktops and ~44px on a notched phone in landscape orientation. */
  padding: max(7px, env(safe-area-inset-top)) 16px 7px;
  padding-left:  max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: rgba(6, 12, 31, 0.78);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  /* Topbar grows to fit the safe-area inset rather than sticking to a
     fixed height that would clip into the notch. */
  min-height: var(--topbar-h);
}
.topbar-brand {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.topbar-meta .who {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.topbar-toggle {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--text-muted);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  /* Hidden on desktop; shown via the @media (max-width:767px) block. */
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s;
}
@media (max-width: 767px) {
  .topbar-toggle { display: inline-flex; }
}

/* Transactions filter — mobile presents only a period dropdown plus a
   "Filters" toggle by default; desktop shows the full layout inline. */
.tx-filter-mobile-primary { display: none; }
@media (max-width: 767px) {
  .tx-filter-mobile-primary {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
  }
  .tx-filter-mobile-primary .tx-filter-period { flex: 1; }
  .tx-filter-secondary { display: none; }
  .tx-filter.is-mobile-open .tx-filter-secondary { display: block; }
  /* On mobile, the duplicate period select inside the secondary row is
     redundant since we already show one in the primary row. Hide its
     wrapper-row's period select if it ever stays in. The primary one
     submits via onchange, so re-running with a different range works. */
}
.topbar-toggle:hover { color: var(--accent-hi); border-color: var(--accent); }

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.topbar-right { gap: 8px; flex-wrap: nowrap; }

.topbar-brand-icon { font-size: 1.1rem; }
.topbar-brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-iconbtn {
  position: relative;
  background: rgba(15, 26, 56, 0.7);
  border: 1px solid rgba(99, 154, 220, 0.18);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}
.topbar-iconbtn:hover {
  color: var(--accent-hi);
  border-color: rgba(34, 211, 238, 0.45);
  background: rgba(15, 26, 56, 0.95);
}
.topbar-bell-dot {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: var(--danger, #f87171);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(15, 26, 56, 0.95), 0 0 8px rgba(248, 113, 113, 0.7);
}

.topbar-profile-wrap { position: relative; }
.topbar-profile {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 3px;
  background: rgba(15, 26, 56, 0.7);
  border: 1px solid rgba(99, 154, 220, 0.18);
  border-radius: 100px;
  max-width: 200px;
  overflow: hidden;
  /* Now a button — explicitly reset the user-agent button styles so it keeps
     looking like the original pill. */
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.topbar-profile:hover { background: rgba(15, 26, 56, 0.92); border-color: rgba(34, 211, 238, 0.35); }
.topbar-profile:focus-visible { outline: 2px solid rgba(34, 211, 238, 0.5); outline-offset: 2px; }
.topbar-profile[aria-expanded="true"] { border-color: rgba(34, 211, 238, 0.5); }
.topbar-profile-caret {
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-left: 2px;
  transition: transform 0.15s;
}
.topbar-profile[aria-expanded="true"] .topbar-profile-caret { transform: rotate(180deg); }

.topbar-profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: rgba(8, 17, 41, 0.96);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid rgba(99, 154, 220, 0.22);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45), 0 0 0 1px rgba(34,211,238,0.08);
  padding: 6px;
  z-index: 80;
  animation: famfin-menu-pop 0.16s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.topbar-profile-menu[hidden] { display: none; }
@keyframes famfin-menu-pop {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
.topbar-profile-menu-header {
  padding: 8px 12px 10px;
  border-bottom: 1px solid rgba(99, 154, 220, 0.14);
  margin-bottom: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.topbar-profile-menu-header strong { font-size: 0.86rem; color: var(--text-strong); }
.topbar-profile-menu-header .muted { font-size: 0.74rem; }
.topbar-profile-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-strong);
  font-size: 0.86rem;
  text-decoration: none;
  cursor: pointer;
}
.topbar-profile-menu-item:hover { background: rgba(34, 211, 238, 0.10); }
.topbar-profile-menu-item.is-danger:hover { background: rgba(248, 113, 113, 0.12); color: #fda4af; }
.topbar-profile-img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1.5px solid rgba(34, 211, 238, 0.45);
  background: var(--bg-card-2, #0f1a38);
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.topbar-profile { padding: 3px 12px 3px 4px; }
.topbar-profile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.topbar-profile-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-profile-meta { font-size: 0.7rem; color: var(--text-muted); }
.topbar-lock { padding: 7px 10px !important; }

/* =============================================================================
   Search modal
   ============================================================================= */
.search-modal-content {
  max-width: 640px;
  padding: 16px;
}
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 26, 56, 0.6);
  border: 1px solid rgba(34, 211, 238, 0.25);
  border-radius: 14px;
  padding: 8px 10px;
  margin-bottom: 14px;
}
.search-bar input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-strong);
  font-size: 1rem;
  outline: none;
  font-family: inherit;
}
.search-bar input::placeholder { color: var(--text-muted); }
.search-bar-icon { color: var(--accent-hi); display: inline-flex; }

.search-results { max-height: 60vh; overflow-y: auto; padding-right: 2px; }
.search-hint, .search-loading, .search-empty {
  padding: 18px 4px;
  color: var(--text-muted);
  font-size: 0.88rem;
  text-align: center;
}
.search-group { margin-bottom: 14px; }
.search-group:last-child { margin-bottom: 0; }
.search-group-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.07em;
  margin-bottom: 6px;
  padding: 0 4px;
  font-weight: 600;
}
.search-item {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid transparent;
  transition: all 0.12s;
}
.search-item:hover {
  background: rgba(34, 211, 238, 0.08);
  border-color: rgba(34, 211, 238, 0.2);
}
.search-item-title { font-size: 0.92rem; font-weight: 500; color: var(--text-strong); margin-bottom: 2px; }
.search-item-sub { font-size: 0.78rem; color: var(--text-muted); }

/* =============================================================================
   Notification panel
   ============================================================================= */
.notif-panel {
  position: fixed;
  top: calc(var(--topbar-h, 64px) + 6px);
  right: 16px;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - var(--topbar-h, 64px) - 24px);
  background: linear-gradient(180deg, rgba(15, 26, 56, 0.98) 0%, rgba(13, 24, 56, 0.98) 100%);
  border: 1px solid rgba(99, 154, 220, 0.25);
  border-radius: 16px;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(34, 211, 238, 0.08);
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.notif-panel[hidden] { display: none; }
.notif-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.notif-panel-title { font-weight: 600; font-size: 0.95rem; color: var(--text-strong); }
.notif-body { padding: 8px 8px 4px; overflow-y: auto; flex: 1; }
.notif-loading, .notif-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.notif-group { margin-bottom: 10px; }
.notif-group-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 8px 4px;
}
.notif-group.is-danger .notif-group-title { color: var(--danger, #f87171); }
.notif-group.is-accent .notif-group-title { color: var(--accent-hi); }
.notif-group.is-success .notif-group-title { color: var(--success, #34d399); }

.notif-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s;
}
.notif-item:hover { background: rgba(34, 211, 238, 0.06); }
.notif-item-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(34, 211, 238, 0.1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notif-item-sub { font-size: 0.74rem; color: var(--text-muted); margin-top: 1px; }
.notif-item-amount {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-strong);
  flex-shrink: 0;
}
.notif-foot {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.15);
}

/* Status pills used on Accounts table */
.chip-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  text-transform: uppercase;
}
.chip-pill.is-active   { color: var(--success, #34d399); background: rgba(52, 211, 153, 0.10); border-color: rgba(52, 211, 153, 0.35); }
.chip-pill.is-archived { color: var(--text-muted);      background: rgba(99, 154, 220, 0.07); border-color: rgba(99, 154, 220, 0.18); }
tr.is-archived td      { opacity: 0.55; }
.chip-pill.is-late     { color: var(--danger, #f87171); background: rgba(248, 113, 113, 0.10); border-color: rgba(248, 113, 113, 0.35); }

/* Entity image upload row (used in property/asset/plan forms) */
.entity-image-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  background: rgba(15, 26, 56, 0.45);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 4px;
}
.entity-thumb {
  width: 84px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--bg-card-2, #0f1a38);
  border: 1px solid rgba(99, 154, 220, 0.2);
  flex-shrink: 0;
}
.entity-image-controls { flex: 1; min-width: 0; }
.entity-image-controls input[type="file"] { font-size: 0.78rem; color: var(--text-muted); }

/* Dashboard bottom-row widget grid */
.widget-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 900px) {
  .widget-row { grid-template-columns: repeat(3, 1fr); }
}

/* Properties list (dashboard widget) */
.prop-list { display: flex; flex-direction: column; gap: 10px; }
.prop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  background: rgba(15, 26, 56, 0.45);
  border: 1px solid var(--line);
  transition: background 0.12s, border-color 0.12s;
}
.prop-item:hover { background: rgba(34, 211, 238, 0.06); border-color: rgba(34, 211, 238, 0.25); }
.prop-thumb {
  width: 64px; height: 44px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
  border: 1px solid rgba(99, 154, 220, 0.2);
  background: var(--bg-card-2, #0f1a38);
}
.prop-meta { flex: 1; min-width: 0; }
.prop-name { font-size: 0.92rem; font-weight: 600; color: var(--text-strong); }
.prop-sub  { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; font-family: var(--font-mono); }

/* Goals / Future plans list */
.goal-list { display: flex; flex-direction: column; gap: 12px; }
.goal-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  background: rgba(15, 26, 56, 0.45);
  border: 1px solid var(--line);
}
.goal-item:hover { background: rgba(34, 211, 238, 0.06); border-color: rgba(34, 211, 238, 0.25); }
.goal-thumb {
  width: 56px; height: 56px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
  border: 1px solid rgba(99, 154, 220, 0.2);
  background: var(--bg-card-2, #0f1a38);
}
.goal-meta { min-width: 0; }
.goal-name {
  font-size: 0.92rem; font-weight: 600; color: var(--text-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.goal-sub  { font-size: 0.74rem; color: var(--text-muted); margin: 3px 0 6px; font-family: var(--font-mono); }
.goal-pct {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-hi);
  font-size: 0.86rem;
}

/* Assets summary + list */
.asset-summary {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.asset-summary-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.asset-summary .goal-progress-bar { margin: 8px 0; }
.asset-list { display: flex; flex-direction: column; gap: 8px; }
.asset-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  background: rgba(15, 26, 56, 0.35);
  border: 1px solid transparent;
}
.asset-item:hover { background: rgba(34, 211, 238, 0.05); border-color: rgba(34, 211, 238, 0.2); }
.asset-thumb {
  width: 44px; height: 32px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  border: 1px solid rgba(99, 154, 220, 0.18);
  background: var(--bg-card-2, #0f1a38);
}
.asset-meta { min-width: 0; }
.asset-name { font-size: 0.86rem; font-weight: 600; color: var(--text-strong); }
.asset-sub  { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* =============================================================================
   Sidebar — collapsible
   ============================================================================= */
.sidebar {
  display: none;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, rgba(13, 24, 56, 0.85) 0%, rgba(6, 12, 31, 0.85) 100%);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-right: 1px solid var(--line);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 14px 24px;
  transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
.sidebar.is-collapsed { width: var(--sidebar-w-collapsed); padding: 18px 10px 24px; }

@media (min-width: 1024px) {
  .sidebar { display: block; }
}

/* Brand block */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.sidebar-brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(34,211,238,0.18) 0%, rgba(8,145,178,0.12) 100%);
  box-shadow:
    0 0 0 1px rgba(34, 211, 238, 0.45),
    0 8px 24px -8px var(--accent-glow);
  display: grid;
  place-items: center;
  color: var(--accent-hi);
}
.sidebar-brand-mark svg { width: 22px; height: 22px; }
.sidebar-brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sidebar-brand-name {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.022em;
  line-height: 1;
  color: var(--text-strong);
}
.sidebar-brand-name b {
  background: linear-gradient(135deg, var(--accent-hi), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-weight: 800;
}
.sidebar-brand-tag {
  font-size: 0.7rem;
  color: var(--text-soft);
  letter-spacing: 0.02em;
  font-weight: 500;
}
.sidebar.is-collapsed .sidebar-brand-text { display: none; }
.sidebar.is-collapsed .sidebar-brand { justify-content: center; padding: 4px 0 18px; }

/* Sidebar banner — family photo, full sidebar width, banner-shaped */
.sidebar-banner {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 12px;
  width: 100%;
  height: 130px;
  border-radius: 14px;
  margin-bottom: 14px;
  background-image: linear-gradient(135deg, rgba(34,211,238,0.18) 0%, rgba(8,145,178,0.12) 100%);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--line);
  overflow: hidden;
}
.sidebar-banner.has-photo { box-shadow: 0 8px 24px -10px rgba(0,0,0,0.45); }
.sidebar-banner-mark {
  position: absolute;
  top: 10px;
  left: 12px;
  width: 32px; height: 32px;
  border-radius: 10px;
  background: rgba(34,211,238,0.18);
  display: grid; place-items: center;
  color: var(--accent-hi);
}
.sidebar-banner-mark svg { width: 18px; height: 18px; }
.sidebar-banner-text {
  position: relative;
  text-shadow: 0 1px 8px rgba(0,0,0,0.6);
  line-height: 1.1;
}
.sidebar-banner-name {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: -0.022em;
  color: var(--text-strong);
}
.sidebar-banner-name b {
  background: linear-gradient(135deg, var(--accent-hi), var(--accent));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-weight: 800;
}
.sidebar-banner-tag {
  font-size: 0.72rem;
  color: var(--text-soft);
  font-weight: 500;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar.is-collapsed .sidebar-banner { height: 56px; padding: 8px; }
.sidebar.is-collapsed .sidebar-banner-text { display: none; }
.sidebar.is-collapsed .sidebar-banner-mark { position: static; width: 32px; height: 32px; }

.sidebar-identity {
  margin-top: auto;
  padding: 10px 8px 4px;
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--line);
}
.sidebar.is-collapsed .sidebar-identity { display: none; }

/* Toggle button (sits at very top of sidebar) */
.sidebar-collapse-btn {
  position: absolute;
  top: 22px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 0.78rem;
  z-index: 5;
  transition: all 0.15s;
}
.sidebar-collapse-btn:hover { color: var(--accent-hi); border-color: var(--accent); }
.sidebar.is-collapsed .sidebar-collapse-btn { right: 50%; transform: translateX(50%); top: 8px; }

/* Sections */
.sidebar-section {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-soft);
  padding: 16px 12px 6px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar.is-collapsed .sidebar-section {
  font-size: 0; padding: 14px 0 4px;
  border-top: 1px solid var(--line);
  margin: 8px 6px 0;
  height: 0;
}

/* Links */
.sidebar-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 500;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: rgba(34, 211, 238, 0.06); color: var(--text-strong); }
.sidebar-link.is-active {
  background: linear-gradient(90deg, rgba(34,211,238,0.18) 0%, rgba(34,211,238,0.05) 100%);
  color: var(--accent-hi);
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar-link .ico {
  font-size: 1.08rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar.is-collapsed .sidebar-link {
  justify-content: center;
  padding: 12px 0;
}
/* Visually hide the label when collapsed but KEEP it in the accessibility tree,
   so screen readers still announce each nav link (the :hover tooltip is sighted-only). */
.sidebar.is-collapsed .sidebar-link .lbl {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.sidebar.is-collapsed .sidebar-link[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-elev);
  color: var(--text-strong);
  border: 1px solid var(--line-strong);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  box-shadow: var(--shadow-pop);
}

/* Sidebar promo card */
.sidebar-promo {
  margin-top: 18px;
  padding: 16px 14px;
  background: linear-gradient(180deg, rgba(34,211,238,0.10) 0%, rgba(99,102,241,0.05) 100%);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}
.sidebar-promo .close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 0.9rem;
}
.sidebar-promo h4 {
  color: var(--text-strong);
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 2px;
}
.sidebar-promo p { font-size: 0.74rem; color: var(--text-muted); margin: 0; }
.sidebar.is-collapsed .sidebar-promo { display: none; }

/* Sidebar profile block (bottom) */
.sidebar-profile {
  position: relative;
  margin-top: 18px;
  margin-bottom: 4px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(34,211,238,0.08) 0%, rgba(13,24,56,0.4) 100%);
  border: 1px solid rgba(99, 154, 220, 0.15);
}
.sidebar-profile-img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(34, 211, 238, 0.4);
  background: var(--bg-card-2, #0f1a38);
}
.sidebar-profile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.sidebar-profile-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-profile-meta { font-size: 0.7rem; color: var(--text-muted); margin-top: 1px; }

.sidebar.is-collapsed .sidebar-profile {
  justify-content: center;
  padding: 8px 0;
  background: transparent;
  border: none;
}
.sidebar.is-collapsed .sidebar-profile-text { display: none; }
.sidebar.is-collapsed .sidebar-profile[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-elev);
  color: var(--text-strong);
  border: 1px solid var(--line-strong);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  box-shadow: var(--shadow-pop);
}

/* Currency view pills (sidebar bottom) */
.sidebar-ccy {
  margin-top: 16px;
  padding: 0 8px;
}
.sidebar-ccy-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-soft);
  margin-bottom: 8px;
  font-weight: 700;
}
.sidebar-ccy-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.sidebar-ccy-row .chip {
  flex: 1;
  min-width: 42px;
  padding: 6px 8px;
  font-size: 0.7rem;
  text-align: center;
}
.sidebar.is-collapsed .sidebar-ccy { display: none; }

/* =============================================================================
   Mobile bottom nav
   ============================================================================= */
.bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(6, 12, 31, 0.92);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 80;
}
.bottomnav-link {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--text-soft);
  font-size: 0.66rem;
  font-weight: 500;
  height: var(--bottomnav-h);
  text-decoration: none;
  transition: color 0.15s;
}
.bottomnav-link.is-active { color: var(--accent); }
.bottomnav-link:hover { color: var(--text); }
.bottomnav-link .ico { font-size: 1.25rem; }
.bottomnav-link.is-add {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: var(--text-on-accent);
  border-radius: 999px;
  width: 56px; height: 56px;
  margin: 6px auto;
  font-size: 1.6rem; font-weight: 700;
  box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.18), 0 12px 32px -8px var(--accent-glow);
}
.bottomnav-link.is-add .ico { font-size: 1.6rem; }
.bottomnav-link.is-add .lbl { display: none; }
@media (min-width: 1024px) {
  .bottomnav { display: none; }
  .app-main { padding-bottom: 0; }
}

/* New 4-tab bottom nav (FamFin v4). The center column is reserved for the FAB. */
.bottomnav-v2 {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  background: rgba(6, 12, 31, 0.94);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border-top: 1px solid rgba(99, 154, 220, 0.18);
  padding: 0 0 env(safe-area-inset-bottom, 0);
  z-index: 80;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0));
}
.bottomnav-v2 .bottomnav-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.66rem;
  font-weight: 600;
  height: var(--bottomnav-h);
  text-decoration: none;
  background: transparent;
  border: none;
  cursor: pointer;
  letter-spacing: 0.01em;
  min-width: 0;
  padding: 0 4px;
}
.bottomnav-v2 .bottomnav-tab:hover { color: var(--text-strong); }
.bottomnav-v2 .bottomnav-tab.is-active { color: var(--accent-hi); }
.bottomnav-v2 .bottomnav-tab .ico { font-size: 1.25rem; line-height: 1; }
.bottomnav-v2 .bottomnav-tab .lbl {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.bottomnav-spacer { display: block; }

@media (min-width: 1024px) {
  .bottomnav-v2 { display: none; }
}

/* Fullscreen "More" sheet */
.more-sheet {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, rgba(6, 12, 31, 0.98), rgba(15, 26, 56, 0.98));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 90;
  display: flex;
  flex-direction: column;
  padding: 16px 16px calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0) + 24px);
  overflow-y: auto;
}
.more-sheet[hidden] { display: none; }
.more-sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.more-sheet-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-strong);
  background: linear-gradient(135deg, var(--accent-hi) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.more-sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.more-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 12px;
  background: rgba(15, 26, 56, 0.5);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-decoration: none;
  color: var(--text-strong);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  transition: background 0.12s, border-color 0.12s;
}
.more-tile:hover {
  background: rgba(34, 211, 238, 0.06);
  border-color: rgba(34, 211, 238, 0.3);
}
.more-tile .ico { font-size: 1.6rem; line-height: 1; }
.more-tile .lbl { line-height: 1.2; }

@media (min-width: 1024px) {
  .more-sheet { display: none; }
}

/* =============================================================================
   Cards
   ============================================================================= */
.card {
  background:
    linear-gradient(180deg, rgba(34, 211, 238, 0.04) 0%, transparent 40%),
    var(--bg-card);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--line-strong); }

.card-row {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
}
.card-row.kpi-row {
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
}
@media (min-width: 1280px) {
  .card-row.kpi-row { grid-template-columns: repeat(6, 1fr); }
}
.card-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  margin-bottom: 8px;
}
.card-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: -0.022em;
  line-height: 1.05;
}
.card-sub {
  font-size: 0.78rem;
  color: var(--text-soft);
  margin-top: 8px;
  font-family: var(--font-mono);
}
.card-trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.card-trend.up { color: var(--success); }
.card-trend.down { color: var(--danger); }

.card.is-income .card-value { color: var(--success); }
.card.is-expense .card-value { color: var(--danger); }
.card.is-loan .card-value { color: var(--warn); }
.card.is-balance .card-value { color: var(--accent); }
.card.is-savings .card-value { color: var(--accent-hi); }

/* =============================================================================
 * KPI strip — horizontal-scroll row of all KPI tiles. Lives above .grid-stack
 * so every KPI is reachable in one swipe regardless of viewport width. Uses
 * scroll-snap so each card lands cleanly when the user releases. Right-edge
 * fade gradient hints there's more content offscreen.
 * ============================================================================= */
.kpi-strip {
  display: flex;
  flex-wrap: nowrap;
  gap: 12px;
  padding: 4px 4px 14px;
  margin-bottom: 8px;
  overflow-x: auto;
  overflow-y: visible;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  /* Subtle fade on the right edge so the user notices it's scrollable.
   * Mask is drawn from a transparent right-edge over an opaque main area. */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
  mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent 100%);
}
.kpi-strip::-webkit-scrollbar { height: 6px; }
.kpi-strip::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); border-radius: 999px; }
.kpi-strip > .kpi-card,
.kpi-strip > .tile-carousel {
  flex: 0 0 220px;
  min-width: 220px;
  max-width: 280px;
  scroll-snap-align: start;
}
@media (max-width: 640px) {
  .kpi-strip > .kpi-card,
  .kpi-strip > .tile-carousel { flex-basis: 78vw; min-width: 78vw; max-width: 78vw; }
}

/* KPI card — compact variant matching the reference. Icon top-left, label, value, sub. */
.kpi-card {
  position: relative;
  padding: 11px 14px 12px;
  background:
    linear-gradient(180deg, rgba(34, 211, 238, 0.04) 0%, transparent 40%),
    var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.kpi-card .card-label { margin-bottom: 0; font-size: 0.62rem; line-height: 1.1; }
.kpi-card .card-value { font-size: clamp(1rem, 4.6vw, 1.2rem); line-height: 1.05; }
.kpi-card .card-sub   { font-size: 0.68rem; margin-top: 1px; }
.kpi-card .kpi-delta {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.68rem; font-weight: 600; margin-top: 1px;
}
.kpi-card .kpi-delta.up   { color: var(--success); }
.kpi-card .kpi-delta.down { color: var(--danger); }
.kpi-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  box-shadow: var(--shadow-inset);
}
.kpi-icon svg { width: 14px; height: 14px; }
.kpi-icon.is-income   { background: var(--success-soft); color: var(--success); border: 1px solid rgba(52,211,153,0.2); }
.kpi-icon.is-expense  { background: var(--danger-soft);  color: var(--danger);  border: 1px solid rgba(248,113,133,0.2); }
.kpi-icon.is-savings  { background: var(--accent-soft);  color: var(--accent);  border: 1px solid var(--line-bright); }
.kpi-icon.is-loan     { background: var(--violet-soft);  color: var(--violet);  border: 1px solid rgba(167,139,250,0.2); }
.kpi-icon.is-rental   { background: var(--warn-soft);    color: var(--warn);    border: 1px solid rgba(251,191,36,0.2); }
.kpi-icon.is-balance  { background: var(--accent-soft);  color: var(--accent-hi); border: 1px solid var(--line-bright); }

.card.is-currency-usd { border-top: 2px solid var(--c-usd); }
.card.is-currency-kes { border-top: 2px solid var(--c-kes); }
.card.is-currency-etb { border-top: 2px solid var(--c-etb); }

/* =============================================================================
   Forms
   ============================================================================= */
.form-group { margin-bottom: 16px; }
.form-group > label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.input, .select, .textarea,
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="search"],
input[type="url"], input[type="tel"], input[type="file"],
select, textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="number"], input[type="date"] { font-family: var(--font-mono); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-soft); }

.form-grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.form-grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { background: var(--bg-card); border-color: var(--line-bright); color: var(--text-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: var(--text-on-accent);
  border-color: var(--accent-deep);
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(34,211,238,0.4), 0 8px 24px -8px var(--accent-glow);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hi) 0%, var(--accent) 100%);
  color: var(--text-on-accent);
}
.btn-ghost { background: transparent; border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-hi); }
.btn-block { width: 100%; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(248, 113, 133, 0.1); }
.btn-sm { padding: 7px 12px; font-size: 0.82rem; border-radius: 9px; }
.btn-lg { padding: 14px 24px; font-size: 1rem; border-radius: 14px; }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.05rem;
  cursor: pointer;
  padding: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.btn-icon:hover { background: var(--bg-card-2); color: var(--text-strong); }

/* =============================================================================
   Auth shell
   ============================================================================= */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}
.auth-shell::before {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(60% 40% at 30% 20%, rgba(34,211,238,0.10), transparent 70%),
    radial-gradient(40% 35% at 80% 70%, rgba(167,139,250,0.05), transparent 75%);
  pointer-events: none;
  z-index: -1;
}
.auth-card {
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(13, 24, 56, 0.6) 100%);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  padding: 40px 34px 30px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-card), 0 0 0 8px rgba(34,211,238,0.05);
}
.auth-icon { font-size: 2.5rem; margin-bottom: 12px; }
.auth-card h1 { font-size: 1.7rem; margin-bottom: 6px; }
.auth-sub { color: var(--text-muted); font-size: 0.92rem; margin-bottom: 24px; line-height: 1.5; }
.auth-card form { text-align: left; }

/* =============================================================================
   Flash
   ============================================================================= */
.flash {
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 0.92rem;
  border: 1px solid;
}
.flash.is-error    { background: var(--danger-soft); border-color: rgba(248,113,133,0.4); color: var(--danger); }
.flash.is-success  { background: var(--success-soft); border-color: rgba(52,211,153,0.4); color: var(--success); }
.flash.is-warning  { background: var(--warn-soft); border-color: rgba(251,191,36,0.4); color: var(--warn); }
.flash.is-info     { background: var(--accent-soft); border-color: var(--line-bright); color: var(--accent-hi); }

/* =============================================================================
   FAB
   ============================================================================= */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--bottomnav-h) + 22px + env(safe-area-inset-bottom, 0));
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: var(--text-on-accent);
  border: none;
  font-size: 1.7rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow:
    0 0 0 4px rgba(34, 211, 238, 0.18),
    0 16px 36px -10px var(--accent-glow);
  z-index: 90;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab:hover { transform: scale(1.05); }
@media (min-width: 1024px) { .fab { bottom: 32px; } }

/* =============================================================================
   Charts
   ============================================================================= */
.chart-card { padding: 22px; }
.chart-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.chart-container { position: relative; height: 280px; }
.empty-chart {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-soft);
  font-style: italic;
  font-size: 0.85rem;
}

/* =============================================================================
   Tables
   ============================================================================= */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 12px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.table tr:hover td { background: rgba(34, 211, 238, 0.03); }

/* =============================================================================
   Filter chips
   ============================================================================= */
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.settings-tabs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.settings-tabs .chip { font-family: inherit; }
.settings-tabs .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Transactions filter — single tidy row */
.tx-filter-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.tx-filter-search { margin: 0; flex: 1; min-width: 220px; }
.tx-filter-search input { width: 100%; }
.tx-filter-period {
  width: auto;
  min-width: 130px;
  padding: 8px 12px;
  font-size: 0.85rem;
}
.tx-filter-ccy { display: inline-flex; gap: 4px; }
.tx-filter-ccy .chip { padding: 6px 10px; font-size: 0.78rem; min-width: 38px; justify-content: center; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: var(--bg-card-2);
  color: var(--text-muted);
  border: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--line-bright); }
.chip.is-active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: var(--text-on-accent);
  border-color: var(--accent-deep);
  font-weight: 700;
  box-shadow: 0 4px 14px -6px var(--accent-glow);
}
.chip-meta { color: var(--text-soft); font-size: 0.78rem; margin-left: 6px; }

/* =============================================================================
   Currency badges + person tags
   ============================================================================= */
.ccy {
  display: inline-block;
  font-size: 0.66rem;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
  text-transform: uppercase;
}
.ccy-USD { background: var(--c-usd-soft); color: var(--c-usd); }
.ccy-KES { background: var(--c-kes-soft); color: var(--c-kes); }
.ccy-ETB { background: var(--c-etb-soft); color: var(--c-etb); }

.who-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.74rem; font-weight: 500;
  color: var(--text);
}
.who-tag::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-soft);
}
.who-tag.who-samic::before { background: var(--p-samic); box-shadow: 0 0 8px rgba(103, 232, 249, 0.6); }
.who-tag.who-aziti::before { background: var(--p-aziti); box-shadow: 0 0 8px rgba(196, 181, 253, 0.5); }

/* =============================================================================
   Type-toggle pills
   ============================================================================= */
.type-toggle {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
@media (min-width: 480px) { .type-toggle { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 640px) { .type-toggle { grid-template-columns: repeat(6, 1fr); } }

.type-btn {
  padding: 10px 8px;
  background: var(--bg-input);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.78rem; font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.type-btn:hover { border-color: var(--line-strong); color: var(--text); }
.type-btn.is-active[data-type="expense"]       { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.type-btn.is-active[data-type="income"]        { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.type-btn.is-active[data-type="savings"]       { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hi); }
.type-btn.is-active[data-type="rental_income"] { background: var(--violet-soft); border-color: var(--violet); color: var(--violet); }
.type-btn.is-active[data-type="loan_payment"]  { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.type-btn.is-active[data-type="transfer"]      { background: rgba(125,211,252,0.14); border-color: var(--accent-hi); color: var(--accent-hi); }

/* =============================================================================
   Modal
   ============================================================================= */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal.is-active { display: flex; }
.modal-content {
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(13, 24, 56, 0.7) 100%);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  padding: 26px 24px;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-pop);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.modal-head h2 { font-size: 1.15rem; }
.modal-content.is-wide { max-width: 820px; }

/* =============================================================================
   KPI tile currency tabs
   ============================================================================= */
.kpi-tabs {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  /* Each tile is h=2 in GridStack with overflow:hidden on the cell, so a
   * wrapped second tab row used to be clipped. Horizontal scroll keeps the
   * tab strip on a single line and lets the user scroll within it. */
}
.kpi-tabs::-webkit-scrollbar { height: 4px; }
.kpi-tabs::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.18); border-radius: 999px; }
.kpi-tab { flex-shrink: 0; }
.kpi-tab {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  border: 1px solid var(--line-soft, rgba(255, 255, 255, 0.06));
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.18s ease;
}
.kpi-tab:hover { background: rgba(255, 255, 255, 0.08); color: var(--text-strong, #f1f5f9); }
.kpi-tab.is-active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(99, 102, 241, 0.18));
  border-color: rgba(56, 189, 248, 0.5);
  color: var(--text-strong, #f1f5f9);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.15);
}

/* =============================================================================
   v6.4 — reusable tile interaction primitives
   ============================================================================= */
/* Pill row uses existing .chip / .chip.is-active. Wrapper just needs flow control. */
.tile-pill-group { display: inline-flex; gap: 4px; flex-wrap: wrap; }

/* Scrollable tile body with a CSS-only bottom-fade gradient. */
.tile-scroll {
  position: relative;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.tile-scroll::after {
  content: "";
  position: sticky;
  display: block;
  bottom: 0; left: 0; right: 0;
  height: 32px;
  margin-top: -32px;
  background: linear-gradient(180deg, transparent, var(--bg-card, #0f1a38));
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.tile-scroll.is-at-end::after { opacity: 0; }

/* Carousel: only one item visible, ‹ ●●● › controls below. */
.tile-carousel { position: relative; }
.tile-carousel-track { position: relative; min-height: 1px; }
.tile-carousel-item { display: none; animation: tile-carousel-fade 220ms ease; }
.tile-carousel-item.is-active { display: block; }
@keyframes tile-carousel-fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tile-carousel-controls {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; margin-top: 10px;
}
.tile-carousel-arrow {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border: 1px solid var(--line-soft, rgba(255, 255, 255, 0.08));
  border-radius: 999px;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1; cursor: pointer;
  transition: all 0.18s ease;
}
.tile-carousel-arrow:hover {
  background: rgba(56, 189, 248, 0.18);
  color: var(--text-strong, #f1f5f9);
  border-color: rgba(56, 189, 248, 0.45);
}
.tile-carousel-dots { display: inline-flex; gap: 6px; align-items: center; }
.tile-carousel-dot {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  width: 7px; height: 7px;
  border-radius: 999px;
  padding: 0; cursor: pointer;
  transition: all 0.18s ease;
}
.tile-carousel-dot.is-active {
  background: var(--accent-cyan, #22d3ee);
  transform: scale(1.25);
}

/* Sparkline overlay — sits in the bottom-right of a .kpi-card, fades in on hover. */
.tile-sparkline {
  position: absolute;
  inset: auto 8px 8px auto;
  width: 110px;
  height: 44px;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.kpi-card { position: relative; }
.kpi-card:hover .tile-sparkline,
.kpi-card.is-sparkline-on .tile-sparkline { opacity: 0.8; }

/* Click-to-flip on KPI big number — make it look interactive. */
[data-kpi-amount][data-kpi-modes] {
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease;
}
[data-kpi-amount][data-kpi-modes]:hover { opacity: 0.85; }

/* Privacy mode — eye-button icon swap + body-class blur for sensitive surfaces.
   Applied on .num, .card-value, KPI amount, money displays. Hover reveals
   selectively (helpful for the user, hostile to a shoulder-surfer at distance). */
.topbar-iconbtn .icon-eye-on,
.topbar-iconbtn .icon-eye-off { display: none; }
.topbar-iconbtn:not(.is-active) .icon-eye-on  { display: inline-block; }
.topbar-iconbtn.is-active       .icon-eye-off { display: inline-block; color: var(--accent-cyan, #22d3ee); }
.topbar-iconbtn.is-active { background: rgba(34, 211, 238, 0.10); }

body.is-privacy-on .num,
body.is-privacy-on .card-value,
body.is-privacy-on [data-kpi-amount],
body.is-privacy-on .upcoming-amount,
body.is-privacy-on .loan-overview-amount,
body.is-privacy-on .ccy-amount,
body.is-privacy-on .account-preview-balance strong,
body.is-privacy-on td.num,
body.is-privacy-on .strong.num {
  filter: blur(7px);
  transition: filter 0.18s ease;
  user-select: none;
}
body.is-privacy-on .num:hover,
body.is-privacy-on .card-value:hover,
body.is-privacy-on [data-kpi-amount]:hover,
body.is-privacy-on .upcoming-amount:hover,
body.is-privacy-on td.num:hover,
body.is-privacy-on .strong.num:hover { filter: none; }
/* Sparkline canvases get hidden completely — they trace the same shape. */
body.is-privacy-on .tile-sparkline { display: none; }
/* Charts (canvas) get a stronger blur so the bar heights aren't readable. */
body.is-privacy-on .chart-container canvas { filter: blur(8px); transition: filter 0.18s ease; }
body.is-privacy-on .chart-container:hover canvas { filter: none; }

/* Small chip used by Rental KPI for occupancy. Sits inline with the sub line so
 * the rental tile fits in the same h=2 GridStack cell as every other KPI tile —
 * a margin-top'd chip on its own row used to overflow the cell and get clipped
 * by .grid-stack-item-content's overflow:hidden. */
.kpi-card .occupancy-chip {
  display: inline-block;
  margin: 0 0 0 4px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.15);
  color: var(--success, #34d399);
  border: 1px solid rgba(52, 211, 153, 0.35);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  vertical-align: baseline;
}

@media (max-width: 640px) {
  .tile-sparkline { width: 80px; height: 32px; }
  .tile-pill-group .chip { font-size: 0.66rem !important; padding: 2px 8px; }
  .tile-carousel-arrow { width: 32px; height: 32px; } /* easier to tap */
}

/* =============================================================================
   Account picker preview panel
   ============================================================================= */
.account-picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 1fr);
  gap: 12px;
  align-items: stretch;
  grid-column: 1 / -1;
}
@media (max-width: 640px) {
  .account-picker-row { grid-template-columns: 1fr; }
}
.account-preview {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg, 14px);
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(56, 189, 248, 0.06) 100%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
  font-size: 0.85rem;
  position: relative;
  overflow: hidden;
}
.account-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.45), rgba(56, 189, 248, 0.35));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
  opacity: 0.5;
}
.account-preview.is-filled::before { opacity: 1; }
.account-preview-empty {
  color: var(--text-muted);
  font-style: italic;
  align-self: center;
  margin: auto;
}
.account-preview-name { font-weight: 600; font-size: 0.95rem; }
.account-preview-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.account-preview-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-soft, rgba(255,255,255,0.08));
  font-size: 0.72rem;
  color: var(--text-muted);
}
.account-preview-chip.is-ccy {
  background: rgba(56, 189, 248, 0.15);
  color: var(--text-strong, #e2e8f0);
  border-color: rgba(56, 189, 248, 0.4);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.account-preview-balance {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.account-preview-balance strong { color: var(--text-strong, #f1f5f9); }
.account-preview-notes {
  font-size: 0.78rem;
  font-style: italic;
  color: var(--text-muted);
  border-top: 1px dashed var(--line-soft, rgba(255,255,255,0.08));
  padding-top: 6px;
}

/* =============================================================================
   Toast
   ============================================================================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + 60px);
  transform: translateX(-50%);
  background: var(--bg-card-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: var(--shadow-pop);
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* =============================================================================
   Goal progress bars + currency progress
   ============================================================================= */
.goal-progress-bar {
  height: 8px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.goal-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--accent));
  transition: width 0.5s;
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.4);
}

.ccy-progress {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.ccy-progress:last-child { border-bottom: none; }
.ccy-progress-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  flex-shrink: 0;
}
.ccy-progress-icon.is-USD { background: var(--c-usd-soft); color: var(--c-usd); border: 1px solid rgba(52,211,153,0.25); }
.ccy-progress-icon.is-KES { background: var(--c-kes-soft); color: var(--c-kes); border: 1px solid rgba(56,189,248,0.25); }
.ccy-progress-icon.is-ETB { background: var(--c-etb-soft); color: var(--c-etb); border: 1px solid rgba(251,191,36,0.25); }
.ccy-progress-body { flex: 1; min-width: 0; }
.ccy-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 0.85rem;
}
.ccy-progress-row .ccy-name { font-weight: 600; color: var(--text-strong); }
.ccy-progress-row .ccy-amount { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.82rem; }
.ccy-progress-row .ccy-pct { color: var(--text-strong); font-weight: 700; font-family: var(--font-mono); font-size: 0.82rem; }
.ccy-progress-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
}
.ccy-progress-fill { height: 100%; transition: width 0.5s; border-radius: 999px; }
.ccy-progress-fill.is-USD { background: linear-gradient(90deg, var(--c-usd), #22d3ee); box-shadow: 0 0 10px rgba(52,211,153,0.4); }
.ccy-progress-fill.is-KES { background: linear-gradient(90deg, var(--c-kes), #22d3ee); box-shadow: 0 0 10px rgba(56,189,248,0.4); }
.ccy-progress-fill.is-ETB { background: linear-gradient(90deg, var(--c-etb), #f59e0b); box-shadow: 0 0 10px rgba(251,191,36,0.4); }

/* =============================================================================
   Status pills
   ============================================================================= */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid;
  font-family: var(--font-sans);
}
.pill.is-expected, .pill.is-upcoming { color: var(--accent-hi); border-color: var(--line-bright); background: var(--accent-soft); }
.pill.is-received, .pill.is-paid     { color: var(--success); border-color: rgba(52,211,153,0.4); background: var(--success-soft); }
.pill.is-partial                     { color: var(--warn); border-color: rgba(251,191,36,0.4); background: var(--warn-soft); }
.pill.is-overdue                     { color: var(--danger); border-color: rgba(248,113,133,0.4); background: var(--danger-soft); }
.pill.is-skipped, .pill.is-zero      { color: var(--text-soft); border-color: var(--line-strong); background: var(--bg-card-2); }

/* =============================================================================
   Side rail (right column on dashboard at >=1280px)
   ============================================================================= */
.dash-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
}
@media (min-width: 1280px) {
  .dash-grid { grid-template-columns: 1fr 320px; }
}
.side-rail { display: flex; flex-direction: column; gap: 16px; }

/* Due & Overdue card (confirm-first recurring) ----------------------------- */
.due-list { display: flex; flex-direction: column; gap: 8px; }
.due-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(34, 211, 238, 0.04);
}
.due-row.is-overdue {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.06);
}
.due-icon { font-size: 1.1rem; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: rgba(255,255,255,0.04); flex-shrink: 0; }
.due-body { flex: 1; min-width: 0; }
.due-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.due-meta { font-size: 0.76rem; }
.due-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.due-amount { width: 104px; padding: 6px 8px; font-size: 0.85rem; text-align: right; }
.due-ccy { font-size: 0.72rem; }
@media (max-width: 640px) {
  .due-row { flex-wrap: wrap; }
  .due-body { flex: 1 1 60%; }
  .due-actions { flex: 1 1 100%; justify-content: flex-end; }
}

.upcoming-list { display: flex; flex-direction: column; gap: 10px; }
.upcoming-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--bg-input);
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.upcoming-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 1.05rem;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent-hi);
}
.upcoming-body { flex: 1; min-width: 0; }
.upcoming-name { font-size: 0.88rem; font-weight: 600; color: var(--text-strong); }
.upcoming-date { font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono); }
.upcoming-amount {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-strong);
  white-space: nowrap;
}
.upcoming-amount.is-due { color: var(--danger); }

/* Loan overview card */
.loan-overview { display: flex; flex-direction: column; gap: 8px; }
.loan-overview-name { font-size: 0.92rem; font-weight: 600; color: var(--text-strong); }
.loan-overview-amount {
  font-size: 1.55rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-strong);
  letter-spacing: -0.02em;
}
.loan-overview-amount-sub { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.loan-overview-progress {
  margin: 14px 0 16px;
}
.loan-overview-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
}
.loan-overview-meta dt { color: var(--text-soft); margin-bottom: 2px; font-weight: 500; }
.loan-overview-meta dd { font-family: var(--font-mono); font-weight: 700; color: var(--text-strong); }

/* =============================================================================
   Mobile compact layout (per iPhone reference)
   ============================================================================= */
@media (max-width: 767px) {
  h1 { font-size: 1.45rem; }
  .topbar {
    /* Honor the iPhone notch — padding-top grows with the safe-area inset
       so the topbar content isn't covered by the front camera. */
    padding: max(10px, env(safe-area-inset-top)) 14px 10px;
    padding-left:  max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    min-height: 58px;
    height: auto;
  }
  .topbar-brand { font-size: 0.95rem; }
  .app-content { padding: 14px; }

  /* Mobile sidebar slides in as a 280px panel with a backdrop, instead of
     pushing all content to the right. The body class .sidebar-open is
     toggled by the topbar ☰ button (see assets/js/app.js).
     Override the base display:none on .sidebar (which only flips to block
     at min-width:1024px in the original layout). */
  .sidebar {
    display: block !important;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    z-index: 60;
    box-shadow: 0 0 32px rgba(0,0,0,0.5);
    height: 100vh;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(2px);
    z-index: 55;
    animation: famfin-fade-in 0.18s ease-out;
  }
  @keyframes famfin-fade-in { from { opacity: 0; } to { opacity: 1; } }
  /* The sidebar collapse button is irrelevant on mobile; the ☰ topbar
     toggle and the backdrop tap are the way to close. */
  .sidebar-collapse-btn { display: none; }

  .card { padding: 16px; border-radius: var(--radius); }
  .kpi-card { padding: 14px; border-radius: var(--radius); }
  .kpi-icon { width: 38px; height: 38px; margin-bottom: 10px; font-size: 0.95rem; }

  /* Dashboard hero card with mini chart (mobile) */
  .net-balance-hero {
    background:
      linear-gradient(135deg, rgba(34,211,238,0.10) 0%, transparent 60%),
      var(--bg-card);
    border: 1px solid var(--line-bright);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: 0 0 0 1px rgba(34,211,238,0.2), 0 16px 40px -16px var(--accent-glow);
    position: relative;
    overflow: hidden;
  }
  .net-balance-hero .card-label { margin-bottom: 6px; }
  .net-balance-hero .card-value { font-size: 2.3rem; }
  .net-balance-hero .mini-chart {
    height: 52px;
    margin-top: 6px;
  }

  /* 4-column compact KPI row on iPhone reference */
  .card-row.kpi-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .card-row.kpi-row .card-value { font-size: clamp(0.98rem, 4.4vw, 1.15rem); overflow-wrap: anywhere; }
  .card-row.kpi-row .card-label { font-size: 0.62rem; letter-spacing: 0.06em; margin-bottom: 4px; }
  .card-row.kpi-row .card-sub   { font-size: 0.7rem; margin-top: 4px; }

  .chart-container { height: 220px; }
}

/* =============================================================================
   Utilities
   ============================================================================= */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-soft); }
.strong { color: var(--text-strong); font-weight: 600; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
.text-accent { color: var(--accent); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.flex-end { display: flex; justify-content: flex-end; gap: 8px; }
.gap-sm { gap: 6px; }
.gap-md { gap: 12px; }
.gap-lg { gap: 18px; }
.stack > * + * { margin-top: 14px; }

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

/* =============================================================================
   GridStack — drag/resize dashboard layer.
   The grid itself ships with its own vendor CSS (gridstack.min.css). These are
   FamFin overrides — outline in edit mode, make widget content fill the cell,
   hide drag handles when locked, and stretch chart canvases.
   ============================================================================= */
.grid-stack { margin-bottom: 18px; }
.grid-stack-item-content {
  /* Let GridStack control the box via its absolute-positioned top/right/
     bottom/left (computed from the margin{Top,Right,Bottom,Left} options).
     Earlier we forced width/height: 100% here, which overrode the bottom
     and right insets and made adjacent rows visually abut each other.
     Just become a flex column for child cards. */
  display: flex;
  flex-direction: column;
  /* Override gridstack vendor CSS which sets overflow-y:auto on every
     item-content — that put a thin vertical scrollbar inside every KPI tile
     even when content fit. Inner cards that legitimately need scroll
     (Currency Breakdown, Recent transactions, Rentals) set their own
     overflow on the .chart-card / .tile-scroll wrappers, which still works. */
  overflow: hidden !important;
}
.grid-stack-item-content > .card,
.grid-stack-item-content > .kpi-card,
.grid-stack-item-content > .chart-card {
  flex: 1 1 auto;
  min-height: 0; /* allow chart-container shrink */
  display: flex;
  flex-direction: column;
  margin: 0;
}
.grid-stack-item-content .chart-container {
  flex: 1 1 auto;
  min-height: 120px;
}

/* Edit mode — body class applied by dashboard-grid.js when window.__editMode is true */
body.is-editing .grid-stack-item-content > .card,
body.is-editing .grid-stack-item-content > .kpi-card,
body.is-editing .grid-stack-item-content > .chart-card {
  outline: 1px dashed rgba(34, 211, 238, 0.55);
  outline-offset: -2px;
  cursor: move;
}
body.is-editing .grid-stack-item:hover .grid-stack-item-content > .card,
body.is-editing .grid-stack-item:hover .grid-stack-item-content > .kpi-card,
body.is-editing .grid-stack-item:hover .grid-stack-item-content > .chart-card {
  outline-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.3), var(--shadow-card);
}

/* Hide GridStack's resize handles when not editing */
body:not(.is-editing) .ui-resizable-handle { display: none !important; }

/* The default placeholder (drop target hint) */
.grid-stack-placeholder > .placeholder-content {
  background: rgba(34, 211, 238, 0.08) !important;
  border: 1px dashed rgba(34, 211, 238, 0.5) !important;
  border-radius: var(--radius-lg) !important;
}

/* Tables inside grid widgets: keep rows on a single line so the widget body
   fits the cell exactly instead of bleeding mid-row into the widget below.
   Other columns auto-size to their content; the description column gets the
   max-width:1px ellipsis trick so it absorbs the leftover width and truncates
   instead of wrapping. */
.grid-stack-item-content .chart-card { overflow: hidden; }
.grid-stack-item-content .chart-card .table td,
.grid-stack-item-content .chart-card .table th { white-space: nowrap; }
.grid-stack-item-content .chart-card .table td.is-truncate {
  width: 100%;
  max-width: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Compact dashboard toolbar: person chips · month picker · "All transactions". */
.dash-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}
.dash-toolbar .filter-chips { flex: 1 1 auto; }
.dash-toolbar .month-picker { flex-shrink: 0; }

/* Topbar welcome wave emoji — small visual lift, doesn't bloat the topbar height. */
.topbar-wave { font-size: 1rem; margin-left: 2px; }

.section { display: none; }
.section.is-active { display: block; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-soft);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.6; }

/* Print */
@media print {
  body { background: white; color: black; }
  .topbar, .sidebar, .bottomnav, .fab, .filter-chips, .modal, form button { display: none !important; }
  .app-content { padding: 8px !important; max-width: none !important; }
  .card { border: 1px solid #ccc !important; box-shadow: none !important; background: white !important; color: black !important; }
}

/* =============================================================================
   Category grid (quick add)
   ============================================================================= */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(95px, 1fr));
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.cat-btn {
  padding: 10px 6px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.72rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  line-height: 1.3;
}
.cat-btn:hover { border-color: var(--line-strong); }
.cat-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hi);
}
.cat-icon { display: block; font-size: 1.2rem; margin-bottom: 4px; }

/* ── Deep-link focus highlight ──────────────────────────────────────────
   Global search and dashboard tiles deep-link to a specific row/card via
   ?focus=/#anchor. Flash the target so the user sees what they clicked. */
@keyframes ff-focus-flash {
  0%   { background-color: var(--accent-soft); }
  100% { background-color: transparent; }
}
/* Transaction row floated to the top + flagged server-side, and any hash-targeted row */
tr.row-highlight > td,
tr:target > td { animation: ff-focus-flash 2.6s ease-out 1; }
/* Hash-targeted cards (properties, assets, loans): flash + a persistent accent ring.
   Uses box-shadow (not border-color) because .card's border is set !important elsewhere. */
.card:target {
  animation: ff-focus-flash 2.6s ease-out 1;
  box-shadow: 0 0 0 2px var(--accent-glow), var(--shadow-card);
}
@media (prefers-reduced-motion: reduce) {
  tr.row-highlight > td, tr:target > td { animation: none; background-color: var(--accent-soft); }
  .card:target { animation: none; }
}

/* ── Submit-button busy state (double-submit guard in app.js) ──────────── */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(148, 163, 184, 0.35);
  border-top-color: var(--accent);
  animation: ff-btn-spin 0.6s linear infinite;
}
@keyframes ff-btn-spin { to { transform: rotate(360deg); } }
button:disabled, .btn:disabled, .btn[disabled] { opacity: 0.7; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) {
  .btn.is-loading::after { animation: none; border-top-color: rgba(148, 163, 184, 0.35); }
}
