/* ================================================================
   GOOGLE FONTS — Manrope for body, Noto Serif for display
   (Stitch "Private Observatory" design language)
   ================================================================ */
@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Noto+Serif:wght@600;700&display=swap");

/* ================================================================
   CSS RESET & BOX-SIZING
   ================================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ================================================================
   CSS CUSTOM PROPERTIES (VARIABLES) — Premium Design System
   ================================================================ */
:root {
  /* Dark theme (default) — Stitch "Private Observatory" midnight + lavender */
  --accent: #d4bbff;
  --accent2: #c3abff;
  --accent-glow: rgba(212, 187, 255, 0.25);
  --bg: #101416;
  --surface: #181c1e;
  --card: #1c2022;
  --card-hover: #262b2c;
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(212, 187, 255, 0.18);
  --text: #e0e3e5;
  --muted: #ccc3d2;
  --muted-2: #958e9c;

  /* Service accent colours — distinct colours for each service */
  --life: #4ade80;
  --realty: #f59e0b;
  --family: #3b82f6;
  --store: #ec4899;

  /* Glassmorphism */
  --glass-bg: rgba(16, 20, 22, 0.55);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-blur: 16px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 25px var(--accent-glow);

  /* Radii */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;

  /* Timing */
  --t-fast: 0.15s ease;
  --t-base: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --t-spring: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Typography */
  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "Noto Serif", Georgia, serif;

  /* Gradients */
  --gradient-accent: linear-gradient(135deg, #552daa 0%, #d4bbff 100%);
  --gradient-surface: rgba(255, 255, 255, 0.03);

  /* Additional */
  --green: #4ade80;
  --red: #ffb4ab;

  /* Primary button (darker purple in dark mode) */
  --btn-primary: #6d4ca6;
  --btn-primary-hover: #7c5bb8;
  --btn-primary-text: #ffffff;
}

/* Dark theme (explicit) */
[data-theme="dark"] {
  --accent: #d4bbff;
  --accent2: #c3abff;
  --accent-glow: rgba(212, 187, 255, 0.25);
  --bg: #101416;
  --surface: #181c1e;
  --card: #1c2022;
  --card-hover: #262b2c;
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(212, 187, 255, 0.18);
  --text: #e0e3e5;
  --muted: #ccc3d2;
  --muted-2: #958e9c;
  --glass-bg: rgba(16, 20, 22, 0.55);
  --glass-border: rgba(255, 255, 255, 0.12);
  --btn-primary: #6d4ca6;
  --btn-primary-hover: #7c5bb8;
  --btn-primary-text: #ffffff;
}

/* Light theme — deeper purple tint for better visibility */
[data-theme="light"] {
  --accent: #6d28d9;
  --accent2: #7c3aed;
  --accent-glow: rgba(109, 40, 217, 0.24);
  --bg: #cec9dc;
  --surface: #d6d2e0;
  --card: #dedae7;
  --card-hover: #d9d5e4;
  --border: rgba(75, 45, 145, 0.18);
  --border-2: rgba(75, 45, 145, 0.28);
  --text: #18122a;
  --muted: #382e52;
  --muted-2: #524872;
  --gradient-accent: linear-gradient(135deg, #6d28d9 0%, #a78bfa 100%);
  --gradient-surface: rgba(109, 40, 217, 0.07);
  --glass-bg: rgba(210, 206, 220, 0.92);
  --glass-border: rgba(109, 40, 217, 0.16);
  --shadow-sm: 0 2px 8px rgba(45, 25, 105, 0.12);
  --shadow-md: 0 8px 32px rgba(45, 25, 105, 0.14);
  --shadow-lg: 0 20px 60px rgba(45, 25, 105, 0.16);
  --green: #15803d;
  --red: #dc2626;
  --btn-primary: #6d28d9;
  --btn-primary-hover: #7c3aed;
  --btn-primary-text: #ffffff;
}

/* ================================================================
   BASE BODY
   ================================================================ */
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  /* PWA safe area: fill top inset on iOS standalone mode */
  padding-top: env(safe-area-inset-top, 0px);
}

/* PWA safe area background fill — matches nav glassmorphism */
@supports (padding-top: env(safe-area-inset-top)) {
  body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top, 0px);
    z-index: 101;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom: none;
    pointer-events: none;
  }
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Selection */
::selection {
  background: rgba(212, 187, 255, 0.3);
  color: var(--text);
}

/* Global scrollbar — slim lavender (Stitch) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(212, 187, 255, 0.2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(212, 187, 255, 0.4); }

/* ================================================================
   AUTH GATE (loading overlay)
   ================================================================ */
html.zyoud-gate-pending body > *:not(#zyoudAuthGate) {
  visibility: hidden !important;
}

#zyoudAuthGate {
  visibility: hidden;
}

html.zyoud-gate-pending #zyoudAuthGate {
  visibility: visible !important;
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font-body);
  gap: 20px;
}

#zyoudAuthGate::before {
  content: "";
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: zyoud-spin 0.7s linear infinite;
}

@keyframes zyoud-spin {
  to { transform: rotate(360deg); }
}

/* ================================================================
   HOME PAGE
   ================================================================ */
.home-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 90% 70% at 10% 10%, rgba(85, 45, 170, 0.18) 0%, transparent 45%),
    radial-gradient(ellipse 80% 60% at 90% 90%, rgba(212, 187, 255, 0.12) 0%, transparent 45%),
    radial-gradient(1px 1px at 10% 12%, rgba(255, 255, 255, 0.9) 100%, transparent 0),
    radial-gradient(1px 1px at 22% 30%, rgba(255, 255, 255, 0.6) 100%, transparent 0),
    radial-gradient(1.5px 1.5px at 50% 48%, rgba(255, 255, 255, 0.85) 100%, transparent 0),
    radial-gradient(1px 1px at 80% 20%, rgba(255, 255, 255, 0.75) 100%, transparent 0),
    radial-gradient(1px 1px at 70% 82%, rgba(255, 255, 255, 0.85) 100%, transparent 0),
    var(--bg);
  background-attachment: fixed;
}

[data-theme="light"] .home-bg {
  background:
    radial-gradient(ellipse 90% 70% at 10% 10%, rgba(124, 58, 237, 0.1) 0%, transparent 45%),
    radial-gradient(ellipse 80% 60% at 90% 90%, rgba(167, 139, 250, 0.1) 0%, transparent 45%),
    var(--bg);
}

.home-container {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 32px;
}

.home-header {
  text-align: center;
  margin-bottom: 56px;
}

.home-title {
  font-size: clamp(3.5rem, 10vw, 7rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
  font-family: var(--font-display);
  font-style: normal;
  text-shadow:
    0 0 60px rgba(212, 187, 255, 0.45),
    0 0 120px rgba(212, 187, 255, 0.2);
  animation: titleFloat 5s ease-in-out infinite;
}

@keyframes titleFloat {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}

.home-title span {
  color: var(--accent);
}

.home-sub {
  margin-top: 14px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--accent);
  font-family: var(--font-body);
}

/* Cards grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  width: 100%;
  max-width: 760px;
}

/* ================================================================
   CARD COMPONENT (home page)
   ================================================================ */
.card {
  position: relative;
  border-radius: var(--r-lg);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  min-height: 200px;
  box-shadow: var(--shadow-sm);
  transition:
    box-shadow 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    transform 0.4s var(--ease-spring),
    border-color 0.4s ease,
    background 0.4s ease;
}

[data-theme="light"] .card {
  background: var(--card);
  border-color: var(--border);
}

.card:hover {
  transform: translateY(-8px) scale(1.01);
  border-color: var(--border-2);
  background: rgba(255, 255, 255, 0.08);
}

.card--life:hover,
.card--realty:hover,
.card--family:hover,
.card--store:hover {
  box-shadow: 0 24px 64px rgba(212, 187, 255, 0.18), 0 0 0 1px rgba(212, 187, 255, 0.2);
}

.card-img-wrap {
  min-height: 110px;
  height: auto;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  padding: 0;
}

.card-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  min-height: 110px;
  opacity: 1;
  transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.card:hover .card-img-wrap img {
  transform: scale(1.05);
}

.card-icon {
  font-size: 2.4rem;
  opacity: 0.3;
}

.card-img-wrap img + .card-icon {
  display: none;
}

.card-body {
  padding: 20px 22px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-body h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  font-family: var(--font-display);
}

.card-body p {
  font-size: 0.73rem;
  color: var(--muted);
  font-weight: 400;
  line-height: 1.5;
}

.card-body h2::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  position: relative;
  top: -1px;
}
.card--life .card-body h2::before { background: var(--life); box-shadow: 0 0 8px rgba(74, 222, 128, 0.4); }
.card--realty .card-body h2::before { background: var(--realty); box-shadow: 0 0 8px rgba(245, 158, 11, 0.4); }
.card--family .card-body h2::before { background: var(--family); box-shadow: 0 0 8px rgba(59, 130, 246, 0.4); }
.card--store .card-body h2::before { background: var(--store); box-shadow: 0 0 8px rgba(236, 72, 153, 0.4); }
.card .card-body h2::before { box-shadow: 0 0 8px var(--accent-glow); }

.card-glow { display: none; }

/* ================================================================
   TOP NAVIGATION — Glassmorphism
   ================================================================ */
.top-nav {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 100;
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  background: var(--glass-bg);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .top-nav {
  background: rgba(210, 206, 220, 0.95);
  border-bottom-color: rgba(75, 45, 145, 0.14);
  box-shadow: 0 4px 20px rgba(45, 25, 105, 0.09);
}

.nav-back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color var(--t-base);
}
.nav-back:hover { color: var(--accent); }

.nav-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  letter-spacing: -0.01em;
  font-family: var(--font-display);
}

/* Auth bar */
.auth-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--muted);
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 42vw;
}
.auth-bar .auth-name { color: var(--text); font-weight: 600; }
.auth-bar .auth-role { font-size: 0.7rem; opacity: 0.9; white-space: nowrap; }
.auth-bar a {
  color: var(--accent2);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  transition: color var(--t-fast);
}
.auth-bar a:hover { color: var(--accent); }
.home-auth-bar {
  display: flex !important;
  justify-content: center !important;
  flex-wrap: wrap;
  gap: 10px;
  width: 100% !important;
  max-width: none !important;
  margin-top: 18px;
  text-align: center;
}

/* Month / year picker */
.month-picker {
  display: flex;
  gap: 8px;
}
.month-picker select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xs);
  padding: 7px 12px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
  font-weight: 500;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b8db0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}
.month-picker select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.month-picker select option {
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
}

/* ================================================================
   PAGE BACKGROUNDS
   ================================================================ */
.life-bg, .realty-bg, .family-bg, .store-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 100% 0%, rgba(85, 45, 170, 0.15) 0%, transparent 45%),
    radial-gradient(ellipse 70% 50% at 0% 100%, rgba(212, 187, 255, 0.08) 0%, transparent 45%),
    var(--bg);
  background-attachment: fixed;
}

/* ================================================================
   SUMMARY BAR — Premium stat cards
   ================================================================ */
.summary-bar {
  display: grid !important;
  grid-template-columns: repeat(6, 1fr) !important;
  gap: 14px;
  margin-bottom: 28px;
}

.sum-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--r-md);
  padding: 20px 22px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100px;
  height: 100%;
  position: relative;
  overflow: hidden;
  transition: transform 0.35s ease, box-shadow 0.4s ease, border-color 0.35s ease, background 0.35s ease;
}

[data-theme="light"] .sum-card {
  background: var(--card);
  border-color: var(--border);
}

.sum-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-accent);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.sum-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 20px rgba(212, 187, 255, 0.12);
  border-color: var(--border-2);
}

.sum-card:hover::before {
  opacity: 1;
}

.sum-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.sum-value {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  font-family: var(--font-body);
}

.sum-income .sum-value { color: var(--accent); }
.sum-expenses .sum-value { color: var(--red); }
.sum-net .sum-value { color: var(--accent2); }
.sum-balance .sum-value { color: var(--accent); }

/* Cash on hand */
.sum-card--cash { gap: 4px; }
.sum-card--cash .sum-value { color: var(--accent); }
.cash-inline-row {
  display: flex;
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
  align-items: center;
}
.cash-inline-input {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xs);
  color: var(--text);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-family: var(--font-body);
  outline: none;
  flex: 1;
  min-width: 0;
  width: 100%;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.cash-inline-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.cash-inline-save {
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  border: none;
  border-radius: var(--r-xs);
  padding: 5px 12px;
  font-size: 0.72rem;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  transition: transform var(--t-fast), background var(--t-fast);
  white-space: nowrap;
  flex-shrink: 0;
}
.cash-inline-save:hover {
  transform: translateY(-1px);
  background: var(--btn-primary-hover);
}
[data-theme="light"] .cash-inline-save { color: #fff; }

/* ================================================================
   PANELS — Glass cards
   ================================================================ */
.panel {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

[data-theme="light"] .panel {
  background: var(--card);
  border-color: var(--border);
}

.panel:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-2);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.07);
}

[data-theme="light"] .panel-header {
  background: rgba(109, 40, 217, 0.03);
}

.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  font-family: var(--font-display);
}

/* Filter inputs inside panel headers — push to the right */
.panel-header input[type="text"] {
  margin-left: auto;
  margin-right: 10px;
  flex-shrink: 0;
}

/* Fixed-height panels with inner scroll */
.panel--income, .panel--expenses, .panel--income-log, .panel--expenses-log, .panel--sales, .panel--daily {
  display: flex;
  flex-direction: column;
  max-height: 400px;
}
.panel--debt-log, .panel--full.panel--debt-log {
  display: flex;
  flex-direction: column;
  max-height: 380px;
}

.panel--income .data-table-wrap, .panel--expenses .data-table-wrap,
.panel--income-log .data-table-wrap, .panel--expenses-log .data-table-wrap,
.panel--debt-log .data-table-wrap, .panel--sales .data-table-wrap,
.panel--daily .data-table-wrap {
  overflow-y: auto;
  flex: 1;
}
.detail-panel { display: flex; flex-direction: column; max-height: 420px; }
.detail-panel .data-table-wrap { overflow-y: auto; flex: 1; }

/* Scrollbar */
.data-table-wrap::-webkit-scrollbar { width: 4px; }
.data-table-wrap::-webkit-scrollbar-track { background: transparent; }
.data-table-wrap::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
.data-table-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ================================================================
   BUTTONS — Premium interactive
   ================================================================ */
.btn-add {
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  border: none;
  border-radius: 9999px;
  padding: 8px 18px;
  font-size: 0.78rem;
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  box-shadow: 0 2px 8px var(--accent-glow);
}
.btn-add:hover {
  transform: translateY(-1px);
  background: var(--btn-primary-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-add:active {
  transform: translateY(0) scale(0.97);
}

[data-theme="light"] .btn-add { color: #fff; }

.btn-del {
  background: rgba(239, 68, 68, 0.06);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.15);
  border-radius: var(--r-xs);
  padding: 5px 9px;
  cursor: pointer;
  font-size: 0;
  line-height: 1;
  font-family: inherit;
  transition: all var(--t-fast);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
}
.btn-del::before {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3 6 5 6 21 6'/%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3 6 5 6 21 6'/%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3C/svg%3E") center/contain no-repeat;
}
.btn-del:hover {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  transform: scale(1.05);
}

.family-page .btn-del, .realty-page .btn-del {
  font-size: 0;
  padding: 4px 8px;
  line-height: 1;
  color: rgba(248, 113, 113, 0.9);
}
.family-page .btn-del:hover, .realty-page .btn-del:hover {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
}

.btn-edit {
  background: rgba(212, 187, 255, 0.08);
  color: var(--accent);
  border: 1px solid rgba(212, 187, 255, 0.2);
  border-radius: var(--r-xs);
  padding: 5px 9px;
  cursor: pointer;
  font-size: 0;
  line-height: 1;
  font-family: inherit;
  transition: all var(--t-fast);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
}
.btn-edit::before {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7'/%3E%3Cpath d='M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z'/%3E%3C/svg%3E") center/contain no-repeat;
}
.btn-edit:hover {
  background: rgba(212, 187, 255, 0.16);
  border-color: rgba(212, 187, 255, 0.4);
  transform: scale(1.05);
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-2);
  border-radius: 9999px;
  color: var(--muted);
  padding: 8px 18px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 20px;
  font-family: var(--font-body);
  transition: all var(--t-base);
}
.btn-back:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Family pay/unpay buttons */
.family-page .btn-pay {
  background: var(--accent);
  color: #3e1975;
  border: 1px solid transparent;
  border-radius: 9999px;
  padding: 4px 14px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  transition: all var(--t-fast);
  box-shadow: 0 0 15px rgba(212, 187, 255, 0.2);
}
.family-page .btn-pay:hover {
  opacity: 0.9;
  transform: scale(1.05);
}
.family-page .btn-unpay {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(212, 187, 255, 0.4);
  border-radius: 9999px;
  padding: 4px 14px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  transition: all var(--t-fast);
}
.family-page .btn-unpay:hover {
  background: rgba(212, 187, 255, 0.1);
  transform: scale(1.05);
}
[data-theme="light"] .family-page .btn-pay { color: #fff; }

/* ================================================================
   TABLES — Clean modern design
   ================================================================ */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
}
.data-table th {
  padding: 12px 18px;
  text-align: left;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
}
[data-theme="light"] .data-table th {
  background: rgba(109, 40, 217, 0.04);
}
.data-table td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  transition: background 0.25s ease;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(212, 187, 255, 0.05); }

.clr-green { color: var(--green); font-weight: 600; }
.clr-red { color: var(--red); font-weight: 600; }

.debt-status-paid { color: var(--green); font-size: 0.75rem; font-weight: 700; }
.debt-status-partial { color: #d0bcff; font-size: 0.75rem; font-weight: 700; }
[data-theme="light"] .debt-status-partial { color: #7c3aed; }
.debt-status-unpaid { color: var(--red); font-size: 0.75rem; font-weight: 700; }

/* ================================================================
   MODAL — Glassmorphism overlay
   ================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: rgba(28, 32, 34, 0.85);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: 32px 36px;
  width: 440px;
  max-width: 95vw;
  position: relative;
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  box-shadow: var(--shadow-lg), 0 0 80px rgba(212, 187, 255, 0.08);
  animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="light"] .modal {
  background: rgba(218, 214, 228, 0.94);
}
@keyframes slideUp {
  from { transform: translateY(24px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xs);
  color: var(--muted);
  font-size: 1rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--t-fast);
  line-height: 1;
}
.modal-close:hover {
  background: var(--border-2);
  color: var(--text);
  transform: rotate(90deg);
}

.modal h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 22px;
  letter-spacing: -0.01em;
  font-family: var(--font-display);
}
.modal label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.modal input, .modal select, .modal textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  color: var(--text);
  padding: 11px 14px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  outline: none;
  margin-bottom: 16px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.modal input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.modal input:focus, .modal select:focus, .modal textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.modal select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(156,163,175,1)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 40px;
  cursor: pointer;
  border-radius: 10px;
}
.modal select:focus {
  border-radius: 10px 10px 0 0;
}
.modal select option {
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 0 0 8px 8px;
}
.modal textarea { resize: vertical; min-height: 70px; }

.modal-submit {
  width: 100%;
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  border: none;
  border-radius: 9999px;
  padding: 13px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  box-shadow: 0 10px 15px -3px var(--accent-glow), 0 4px 6px -4px var(--accent-glow);
}
.modal-submit:hover {
  transform: translateY(-1px);
  background: var(--btn-primary-hover);
  box-shadow: 0 6px 24px var(--accent-glow);
}
.modal-submit:active {
  transform: translateY(0) scale(0.98);
}

[data-theme="light"] .modal-submit { color: #fff; }

/* ================================================================
   TOAST NOTIFICATIONS
   ================================================================ */
.toast-container {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 14px 20px;
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s var(--ease-spring);
  pointer-events: all;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(12px);
}
.toast.success { border-color: rgba(74, 222, 128, 0.3); }
.toast.error { border-color: rgba(255, 180, 171, 0.3); }
.toast.info { border-color: rgba(212, 187, 255, 0.3); }

.toast-icon { font-size: 1rem; flex-shrink: 0; }
.toast.success .toast-icon::before { content: "✓"; color: var(--green); }
.toast.error .toast-icon::before { content: "✕"; color: var(--red); }
.toast.info .toast-icon::before { content: "ℹ"; color: var(--accent); }

@keyframes toastIn { from { opacity: 0; transform: translateX(20px) scale(0.95); } to { opacity: 1; transform: translateX(0) scale(1); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(20px) scale(0.95); } }

/* ================================================================
   HOME FAB
   ================================================================ */
.home-fab {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  background: var(--gradient-accent);
  border: 1px solid rgba(212, 187, 255, 0.3);
  border-radius: 50%;
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 10px 25px -5px rgba(85, 45, 170, 0.5), 0 0 15px rgba(212, 187, 255, 0.3);
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  color: #fff;
}
.home-fab:hover {
  color: #fff;
  border-color: transparent;
  transform: translateX(-50%) translateY(-4px);
  box-shadow: 0 12px 40px var(--accent-glow);
}
.home-fab svg { width: 20px; height: 20px; fill: currentColor; }

.life-main, .family-main, .store-main, .realty-main { padding-bottom: 90px; }

/* ================================================================
   BOTTOM NAVIGATION BAR (shared, injected by bottom-nav.js)
   Home button centered, two service icons on each side.
   ================================================================ */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  min-height: 84px;
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  gap: 4px;
  padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-top: 1px solid var(--glass-border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
}

/* Compact footer on desktop */
@media (min-width: 1025px) {
  .bottom-nav {
    min-height: 62px;
    padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 6px);
  }
  .bottom-nav__item svg {
    width: 20px;
    height: 20px;
  }
  .bottom-nav__item span {
    font-size: 0.58rem;
  }
  .bottom-nav__home {
    width: 50px;
    height: 50px;
    top: -18px;
  }
  .bottom-nav__home svg {
    width: 22px;
    height: 22px;
  }
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  transition: color var(--t-base), transform var(--t-base);
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
  padding-top: 4px;
}

.bottom-nav__item svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform var(--t-spring);
  flex-shrink: 0;
}

.bottom-nav__item span {
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  max-width: none;
  line-height: 1.3;
}

.bottom-nav__item:hover {
  color: var(--accent);
}
.bottom-nav__item:hover svg {
  transform: translateY(-2px);
}

.bottom-nav__item.is-active {
  color: var(--accent);
}

/* Center Home button — elevated gradient circle */
.bottom-nav__home {
  flex: 0 0 auto;
  align-self: flex-start;
  position: relative;
  top: -22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-accent);
  color: #fff;
  text-decoration: none;
  border: none;
  box-shadow: 0 8px 24px -4px rgba(85, 45, 170, 0.55), 0 0 16px rgba(212, 187, 255, 0.35);
  transition: transform var(--t-spring), box-shadow var(--t-base);
}
.bottom-nav__home svg {
  width: 26px;
  height: 26px;
  fill: #fff;
  stroke: none;
}
.bottom-nav__home:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 14px 36px -4px rgba(85, 45, 170, 0.6), 0 0 24px rgba(212, 187, 255, 0.5);
}
.bottom-nav__home:active {
  transform: translateY(0) scale(0.97);
}

/* Reserve space so content isn't hidden behind the nav */
body.has-bottom-nav .life-main,
body.has-bottom-nav .family-main,
body.has-bottom-nav .store-main,
body.has-bottom-nav .realty-main {
  padding-bottom: 120px;
}
body.has-bottom-nav .home-container {
  padding-bottom: 126px;
}
/* Lift toasts above the nav */
body.has-bottom-nav .toast-container {
  bottom: 110px;
}

@media (max-width: 480px) {
  .bottom-nav { min-height: 80px; padding: 11px 6px calc(env(safe-area-inset-bottom, 0px) + 10px); }
  .bottom-nav__item svg { width: 20px; height: 20px; }
  .bottom-nav__item span { font-size: 0.58rem; }
  .bottom-nav__home { width: 52px; height: 52px; top: -20px; }
  .bottom-nav__home svg { width: 23px; height: 23px; }
}

/* ================================================================
   FAMILY MEMBER AVATARS
   ================================================================ */
.member-avatar {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: none;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-transform: uppercase;
}
.member-avatar__initial {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 0;
}
.member-avatar img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.member-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.member-cell .member-name-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ================================================================
   HEADER USER AVATAR (top nav auth bar)
   ================================================================ */
.user-avatar {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-accent);
  border: none;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-transform: uppercase;
}
.user-avatar__initial {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 0;
}
.user-avatar img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Keep the avatar first in the auth bar even though it wraps/justifies right */
.auth-bar .user-avatar { order: -1; }

/* ================================================================
   ANIMATIONS & UTILITIES
   ================================================================ */
.page-enter { animation: pageIn 0.4s var(--ease-spring); }
@keyframes pageIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* Welcome overlay pop-in (used by require-auth.js) */
@keyframes popIn {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.hidden { display: none !important; }

/* Ripple */
.ripple-effect {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: scale(0);
  animation: ripple-anim 0.6s ease-out;
  pointer-events: none;
}
@keyframes ripple-anim { to { transform: scale(4); opacity: 0; } }

/* Page transition */
.page-transition-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: var(--bg);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.page-transition-overlay.active { opacity: 1; pointer-events: all; }

/* Scroll reveal */
.reveal-hidden { opacity: 0; transform: translateY(16px); transition: opacity 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94); }
.reveal-visible { opacity: 1; transform: translateY(0); }

/* Float label */
.float-label {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 0.88rem; color: var(--muted); pointer-events: none;
  transition: all 0.2s ease; background: var(--surface); padding: 0 4px; opacity: 0.7;
}
.float-label.active { top: -8px; left: 8px; font-size: 0.68rem; color: var(--accent); opacity: 1; background: var(--card); }

/* Button press feedback — smooth transitions */
button, .btn-add, .btn-save-wallet, .btn-pay, .btn-unpay, .btn-del, .btn-edit,
.btn-back, .btn-add-debt, .btn-debt-clear, .home-fab, .modal-submit {
  transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94), background 0.3s ease, border-color 0.3s ease, box-shadow 0.35s ease, color 0.3s ease, opacity 0.3s ease !important;
}

/* ================================================================
   THEME TOGGLE & LANGUAGE BUTTONS
   ================================================================ */
.theme-toggle-btn {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: all var(--t-base);
}
.theme-toggle-btn:hover {
  background: var(--card-hover);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.lang-toggle-wrapper { display: flex; align-items: center; margin-left: auto; gap: 8px; }
.lang-toggle-btn {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  font-family: var(--font-body);
  transition: all var(--t-base);
  white-space: nowrap;
}
.lang-toggle-btn:hover {
  background: var(--card-hover);
  border-color: var(--accent);
}

/* ================================================================
   FAMILY PAGE SPECIFIC
   ================================================================ */
.family-main {
  position: relative;
  z-index: 1;
  padding: 28px 32px;
  margin-bottom: 5rem;
}

.family-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel--full { grid-column: 1 / -1; }

.members-table-wrap {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  margin-bottom: 22px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
[data-theme="light"] .members-table-wrap {
  background: var(--card);
  border-color: var(--border);
}
.members-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.07);
}
[data-theme="light"] .members-table-header {
  background: rgba(109, 40, 217, 0.03);
}
.members-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.members-table th {
  padding: 12px 18px; text-align: left; font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
}
[data-theme="light"] .members-table th {
  background: rgba(109, 40, 217, 0.04);
}
.members-table td {
  padding: 12px 18px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 0.85rem; vertical-align: middle;
  transition: background 0.25s ease;
}
.members-table tr:last-child td { border-bottom: none; }
.members-table tr:hover td { background: rgba(212, 187, 255, 0.05); }
.member-name-cell { font-weight: 700; color: var(--text); }

/* Debt calculator */
.debt-calculator {
  display: flex; flex-direction: row; flex-wrap: nowrap; gap: 6px;
  padding: 10px 16px; border-top: 1px solid var(--border); flex-shrink: 0; align-items: center; overflow: hidden;
}
.debt-calc-label { color: var(--muted); white-space: nowrap; font-size: 0.68rem; }
.debt-calc-value { font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.debt-calc-sep { color: var(--border-2); flex-shrink: 0; font-size: 0.68rem; }

/* ================================================================
   RESPONSIVE STYLES
   ================================================================ */
@media (max-width: 1024px) {
  .top-nav { padding: 12px 20px; flex-wrap: wrap; gap: 10px; }
  .auth-bar { max-width: 55vw; font-size: 0.76rem; }
  .cards-grid { max-width: 600px; gap: 16px; }
  .summary-bar { gap: 12px; }
  .card-img-wrap { min-height: unset; height: auto; }
  .card-img-wrap img { width: 100%; height: 100%; object-fit: cover; min-height: 110px; }
}

@media (max-width: 900px) {
  .top-nav { padding: 11px 18px; }
  .auth-bar { max-width: 60vw; }
  .home-container { padding: 48px 24px; }
  .cards-grid { gap: 14px; }
  .modal { width: 92vw; padding: 28px 24px; }
}

@media (max-width: 700px) {
  * { box-sizing: border-box; }
  .top-nav { padding: 10px 14px; gap: 8px; }
  .nav-title { font-size: 0.88rem; }
  .nav-back { font-size: 0.78rem; }
  .auth-bar { max-width: 100%; width: 100%; font-size: 0.72rem; gap: 6px 10px; justify-content: flex-start; order: 3; }
  .month-picker { gap: 6px; }
  .month-picker select { font-size: 0.75rem; padding: 5px 8px; padding-right: 24px; }
  .summary-bar { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; overflow-x: hidden; }
  .sum-card { padding: 14px 16px; min-height: 80px; }
  .sum-label { font-size: 0.65rem; }
  .sum-value { font-size: 1.15rem; }
  .sum-card--cash { grid-column: 1 / -1; }
  .card-img-wrap { align-items: start; }
  .panel-header { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
  .panel-header h2 { font-size: 0.82rem; flex: 0 0 100%; min-width: 0; }
  .panel-header input[type="text"] { flex: 1; min-width: 0; margin-left: 0; margin-right: 0; }
  .btn-add { padding: 7px 14px; font-size: 0.76rem; min-height: 36px; white-space: nowrap; }
  .btn-edit, .btn-del, .btn-add-debt, .btn-pay, .btn-unpay, .btn-debt-clear {
    padding: 3px 6px; min-height: 24px; min-width: 24px; white-space: nowrap; flex-shrink: 0;
  }
  .btn-edit::before, .btn-del::before { width: 12px; height: 12px; }
  .btn-pay, .btn-unpay, .btn-add-debt, .btn-debt-clear { font-size: 0.68rem; }
  .btn-back { padding: 6px 12px; font-size: 0.78rem; }
  .data-table-wrap { overflow-x: hidden; overflow-y: auto; width: 100%; }
  .data-table { table-layout: fixed; width: 100%; word-break: break-word; }
  .data-table th { font-size: 0.6rem; padding: 8px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
  .data-table td { font-size: 0.72rem; padding: 8px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
  .data-table td:nth-child(4) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .data-table td:last-child { white-space: nowrap; text-align: right; padding: 8px 14px 8px 5px; min-width: 60px; }
  .data-table td:last-child > * { vertical-align: middle; }
  .panel--income .data-table-wrap, .panel--expenses .data-table-wrap,
  .panel--income-log .data-table-wrap, .panel--expenses-log .data-table-wrap,
  .panel--debt-log .data-table-wrap, .panel--sales .data-table-wrap,
  .panel--daily .data-table-wrap { max-height: calc(36px + 4 * 42px); overflow-y: auto; overflow-x: hidden; }
  .modal-overlay { align-items: center; justify-content: center; padding: 16px; }
  .modal { width: 90%; max-width: 380px; border-radius: var(--r-lg); padding: 24px 20px 28px; max-height: 85vh; overflow-y: auto; margin: auto; }
  .modal h3 { font-size: 0.9rem; margin-bottom: 16px; padding-right: 28px; }
  .modal label { font-size: 0.68rem; margin-bottom: 4px; }
  .modal input, .modal select, .modal textarea { font-size: 15px; padding: 9px 10px; border-radius: var(--r-xs); margin-bottom: 12px; }
  .modal input[type="date"] { -webkit-appearance: none; appearance: none; width: 100%; max-width: 100%; box-sizing: border-box; }
  .modal-submit { padding: 11px; font-size: 0.85rem; border-radius: var(--r-sm); min-height: 44px; }
  .modal-close { top: 12px; right: 12px; width: 28px; height: 28px; font-size: 1rem; }
  .modal button[id^="toggle"] { font-size: 0.75rem !important; padding: 8px 0 !important; }
  .toast-container { bottom: 84px; left: 12px; right: 12px; }
  .toast { max-width: 100%; font-size: 0.82rem; padding: 11px 14px; }
  .home-fab { bottom: 20px; width: 48px; height: 48px; }
  .cards-grid { grid-template-columns: repeat(1, 1fr); }
}

@media (min-width: 501px) and (max-width: 700px) {
  .card-img-wrap { height: 140px; min-height: 140px; }
  .card-img-wrap img { width: 100%; height: 100%; object-fit: cover; max-height: none; }
}

@media (max-width: 480px) {
  .top-nav { padding: 9px 12px; gap: 6px; }
  .nav-title { font-size: 0.82rem; }
  .home-container { padding: 32px 16px; }
  .home-header { margin-bottom: 28px; }
  .summary-bar { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .sum-card { padding: 12px 12px; min-height: 72px; }
  .sum-value { font-size: 1.05rem; }
  .modal { max-height: 90vh; padding: 20px 16px 28px; }
  .modal h3 { font-size: 0.88rem; margin-bottom: 14px; }
  .modal input, .modal select, .modal textarea { font-size: 14px; padding: 8px 9px; margin-bottom: 10px; }
  .modal input[type="date"] { -webkit-appearance: none; appearance: none; width: 100%; max-width: 100%; box-sizing: border-box; }
  .modal-submit { font-size: 0.82rem; min-height: 42px; }
  .panel-header { padding: 11px 12px; gap: 6px; }
  .panel-header h2 { font-size: 0.78rem; }
  .home-fab { width: 44px; height: 44px; bottom: 16px; }
  .toast-container { bottom: 72px; }
}

@media (max-width: 360px) {
  .top-nav { padding: 8px 10px; }
  .nav-title { font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
  .home-title { font-size: clamp(2.8rem, 12vw, 5rem); }
  .summary-bar { grid-template-columns: 1fr 1fr !important; gap: 6px; }
  .sum-card { padding: 10px 10px; }
  .sum-label { font-size: 0.6rem; }
  .sum-value { font-size: 0.95rem; }
  .panel-header { padding: 10px 10px; }
  .data-table th { padding: 7px 6px; font-size: 0.6rem; }
  .data-table td { padding: 7px 6px; font-size: 0.7rem; }
  .modal { padding: 18px 14px 24px; max-width: 340px; }
  .modal input, .modal select, .modal textarea { font-size: 13px; padding: 7px 8px; }
  .modal input[type="date"] { -webkit-appearance: none; appearance: none; width: 100%; max-width: 100%; box-sizing: border-box; }
  .cards-grid { gap: 10px; }
  .btn-add { padding: 6px 10px; font-size: 0.72rem; }
  .btn-edit, .btn-del { padding: 4px 7px; }
  .btn-edit::before, .btn-del::before { width: 11px; height: 11px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .home-container { padding: 24px 32px; justify-content: flex-start; }
  .home-header { margin-bottom: 20px; }
  .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { min-height: 120px; }
  .card-img-wrap { height: 60px; }
  .modal-overlay { align-items: center; }
  .modal { max-height: 88vh; border-radius: var(--r-md); margin: 0 auto; }
  .summary-bar { grid-template-columns: repeat(3, 1fr) !important; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .building-card, .apt-card, .home-fab, .btn-add, .modal, .modal-overlay, .toast {
    animation: none !important;
    transition: none !important;
  }
  .home-title { animation: none !important; }
}

/* ================================================================
   FILTER "NO MATCHES" ROW — always full-width & centered
   Fixes the message appearing left-aligned on mobile card-style
   tables (e.g. the family debt log) by forcing a normal table cell.
   ================================================================ */
tr[data-filter-empty] {
  display: table-row !important;
  width: 100% !important;
}
tr[data-filter-empty] td {
  display: table-cell !important;
  width: 100% !important;
  text-align: center !important;
  white-space: normal !important;
  overflow: visible !important;
  padding: 16px 8px !important;
}
tr[data-filter-empty] td::before {
  content: none !important;
}

/* Generic empty-state colspan cells stay centered even inside mobile
   card-style table overrides. */
.data-table td[colspan] {
  text-align: center;
}

/* ================================================================
   RESPONSIVE — TABLET REFINEMENTS (≤ 1024px)
   The previous breakpoints jumped straight from desktop multi-column
   summary bars to mobile layouts, leaving tablets cramped. These
   rules give tablets a comfortable, intentional layout.
   Page-scoped selectors (.family-main etc.) are used so they win over
   the page-specific summary-bar overrides regardless of source order.
   ================================================================ */
@media (min-width: 701px) and (max-width: 1024px) {
  .family-main .summary-bar,
  .life-main .summary-bar,
  .store-main .summary-bar {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  .family-grid,
  .life-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 901px) and (max-width: 1024px) {
  .modal {
    width: 460px;
  }
}

/* ================================================================
   ACTION BUTTONS — alignment for PWA/mobile
   ================================================================ */
.data-table td:last-child[style*="display:flex"],
.data-table td:last-child[style*="display: flex"] {
  justify-content: flex-end;
}

@media (max-width: 700px) {
  .data-table td:last-child[style*="display:flex"],
  .data-table td:last-child[style*="display: flex"] {
    padding-right: 14px;
  }
}

/* ================================================================
   NO-PERMISSION TABLE ALIGNMENT FIX
   When action buttons are hidden for read-only users, the actions
   column should remain as a proper table cell so rows stay aligned.
   ================================================================ */
.realty-readonly .data-table td:last-child,
.data-table td.actions-cell--empty {
  display: table-cell !important;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  min-width: 40px;
}

/* Family page: when canDeleteInFamily() is false, ensure the empty
   actions cell doesn't collapse */
.data-table td:last-child:empty {
  display: table-cell !important;
  min-width: 40px;
}

/* Realty read-only: action cells show "—" as centered text */
.realty-readonly .detail-panel .data-table td:last-child {
  display: table-cell !important;
  text-align: center;
  vertical-align: middle;
  padding: 7px 12px;
}

@media (max-width: 700px) {
  .realty-readonly .detail-panel .data-table td:last-child {
    padding: 7px 10px;
  }
}
