/* ---- VARIABLES ---- */
:root {
  --sky-50: #f0f9ff;
  --sky-100: #e0f2fe;
  --sky-200: #bae6fd;
  --sky-300: #7dd3fc;
  --sky-400: #38bdf8;
  --sky-500: #0ea5e9;
  --sky-600: #0284c7;
  --sky-700: #0369a1;
  --sky-800: #075985;
  --sky-900: #0c4a6e;
  --white: #ffffff;
  --surface: #ffffff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --green: #22c55e;
  --green-bg: #f0fdf4;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --amber: #f59e0b;
  --amber-bg: #fffbeb;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-full: 9999px;
  --shadow: 0 1px 3px rgba(14,165,233,0.08), 0 1px 2px rgba(14,165,233,0.04);
  --shadow-md: 0 4px 14px rgba(14,165,233,0.1), 0 2px 6px rgba(14,165,233,0.04);
  --shadow-lg: 0 10px 30px rgba(14,165,233,0.12), 0 4px 10px rgba(14,165,233,0.05);
  --transition: all 0.2s ease;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

/* ---- DARK MODE ---- */
[data-theme="dark"] {
  --sky-50: #0d1626;
  --sky-100: #17233c;
  --sky-200: #1f3050;
  --sky-300: #33517a;
  --sky-400: #38bdf8;
  --sky-500: #0ea5e9;
  --sky-600: #0284c7;
  --sky-700: #7dd3fc;
  --sky-800: #38bdf8;
  --sky-900: #0c4a6e;
  --surface: #121a2c;
  --gray-50: #0d1524;
  --gray-100: #1a2438;
  --gray-200: #26344f;
  --gray-300: #35476a;
  --gray-400: #7e93b5;
  --gray-500: #96a9c8;
  --gray-600: #b6c5db;
  --gray-700: #d2ddef;
  --gray-800: #ecf1f9;
  --green: #4ade80;
  --green-bg: rgba(34,197,94,0.14);
  --red: #f87171;
  --red-bg: rgba(239,68,68,0.14);
  --amber: #fbbf24;
  --amber-bg: rgba(245,158,11,0.14);
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.55), 0 4px 10px rgba(0,0,0,0.35);
  color-scheme: dark;
}

/* ---- RESET ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--sky-50);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: clip;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--safe-bottom);
  transition: background 0.3s ease, color 0.3s ease;
}
input, select, textarea, button { font-family: inherit; font-size: 1rem; }
img { max-width: 100%; display: block; }

/* ---- ANIMATIONS ---- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(100%); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.05); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(30px); }
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.animated { animation: fadeInUp 0.5s ease-out both; }
.animated:nth-child(2) { animation-delay: 0.1s; }
.animated:nth-child(3) { animation-delay: 0.2s; }

.hidden { display: none !important; }

/* ---- SPLASH ---- */
.splash {
  position: fixed; inset: 0; z-index: 1000;
  background: linear-gradient(135deg, var(--sky-400) 0%, var(--sky-600) 100%);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.3s ease;
}
.splash-inner { text-align: center; color: var(--white); }
.logo-bounce { animation: bounceIn 1s ease-out; }
.logo-bounce img { width: 120px; height: 120px; border-radius: 30px; margin: 0 auto 20px; object-fit: cover; box-shadow: 0 8px 30px rgba(0,0,0,0.2); }
.splash h1 { font-size: 1.8rem; font-weight: 800; margin-bottom: 4px; }
.splash p { font-size: 1rem; opacity: 0.85; }

/* ---- LOGIN ---- */
.login-card {
  max-width: 380px; margin: 15vh auto 0; padding: 40px 32px;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.4s ease-out;
}
.login-logo { width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.login-logo img { width: 100%; height: 100%; object-fit: cover; }
.login-card h2 { text-align: center; font-size: 1.4rem; font-weight: 700; color: var(--gray-800); }
.subtitle { text-align: center; color: var(--gray-400); margin-bottom: 24px; font-size: 0.9rem; }

/* ---- FIELDS ---- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--gray-500); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm); background: var(--gray-50); color: var(--gray-800);
  transition: var(--transition); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--sky-400); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.15);
}
.field textarea { resize: vertical; }
.field select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; cursor: pointer; }

.error-msg { color: var(--red); font-size: 0.85rem; margin-bottom: 12px; padding: 8px 12px; background: var(--red-bg); border-radius: 8px; }

/* ---- MVR SYMBOL ---- */
/* Maldivian convention: the Rufiyaa symbol renders smaller than the amount
   figures (roughly 2/3 of the font size), e.g. Rf 1,250.00 */
.mvr-symbol {
  height: 0.7em; width: auto; vertical-align: -0.08em; display: inline-block;
  user-select: none; pointer-events: none;
}
[data-theme="dark"] .mvr-symbol { filter: invert(1); }
.input-currency { display: flex; align-items: center; gap: 8px; }
.input-currency .mvr-symbol { height: 1.15em; flex-shrink: 0; }
.input-currency input { flex: 1; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border: none; border-radius: var(--radius-sm); font-weight: 600;
  font-size: 0.95rem; cursor: pointer; transition: var(--transition); text-decoration: none;
}
.btn .icons { width: 18px; height: 18px; }
.btn-primary { background: var(--sky-500); color: var(--white); box-shadow: 0 2px 8px rgba(14,165,233,0.25); }
.btn-primary:hover { background: var(--sky-600); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(14,165,233,0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: transparent; color: var(--gray-500); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { opacity: 0.9; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }
.btn-sm .icons { width: 16px; height: 16px; }
.btn-link { background: none; border: none; color: var(--sky-500); font-weight: 600; font-size: 0.85rem; cursor: pointer; padding: 4px 8px; border-radius: 8px; transition: var(--transition); }
.btn-link:hover { background: var(--sky-100); }

/* ---- CARDS ---- */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--sky-100);
}

/* ---- APP HEADER ---- */
.app-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + var(--safe-top));
  background: var(--surface); border-bottom: 1px solid var(--sky-100);
  box-shadow: 0 2px 10px rgba(14,165,233,0.06);
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-size: 0.95rem; font-weight: 700; color: var(--sky-700); line-height: 1.2; }
.brand-user { font-size: 0.72rem; color: var(--gray-400); font-weight: 500; }
.header-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: 12px; cursor: pointer;
  transition: var(--transition); position: relative; color: var(--gray-600);
}
.icon-btn:hover { background: var(--sky-100); color: var(--sky-600); }
.icon-btn .icons { width: 22px; height: 22px; }
.badge {
  position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px;
  background: var(--red); color: var(--white); font-size: 0.68rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border-radius: 10px;
  padding: 0 4px; animation: scaleIn 0.3s ease;
}

/* ---- PANELS ---- */
.panel {
  position: fixed; top: 0; right: 0; width: 320px; max-width: 90vw; height: 100vh;
  background: var(--surface); box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  z-index: 150; overflow-y: auto; padding-top: calc(16px + var(--safe-top));
  animation: slideDown 0.25s ease-out;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; border-bottom: 1px solid var(--gray-100); }
.panel-head h3 { font-size: 1.1rem; font-weight: 700; }
.menu-list { padding: 8px; }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  border: none; background: none; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.95rem; font-weight: 500; color: var(--gray-700); transition: var(--transition);
  text-align: left;
}
.menu-item:hover { background: var(--sky-50); color: var(--sky-600); }
.menu-item i, .menu-item svg { width: 20px; height: 20px; color: var(--gray-400); }
.menu-sep { height: 1px; background: var(--gray-100); margin: 8px 16px; }
.notif-list { padding: 8px; }
.notif-item {
  padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 4px;
  cursor: pointer; transition: var(--transition); border-left: 3px solid transparent;
}
.notif-item:hover { background: var(--sky-50); }
.notif-item.unread { background: var(--sky-50); border-left-color: var(--sky-400); }
.notif-title { font-weight: 600; font-size: 0.88rem; margin-bottom: 2px; }
.notif-msg { font-size: 0.82rem; color: var(--gray-500); }
.notif-time { font-size: 0.72rem; color: var(--gray-400); margin-top: 4px; }
.notif-empty { text-align: center; color: var(--gray-400); padding: 40px 20px; }

/* ---- MAIN ---- */
.main { padding: 16px; padding-bottom: 100px; max-width: 640px; margin: 0 auto; }

/* ---- VIEW TRANSITION (bottom ribbon tab switching) ---- */
@keyframes viewSlideIn {
  from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.99); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
.view {
  animation: viewSlideIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
  transform-origin: top center;
}
@media (prefers-reduced-motion: reduce) {
  .view { animation: none; }
}

/* ---- BALANCE CARD ---- */
.balance-card {
  background: linear-gradient(135deg, var(--sky-400) 0%, var(--sky-600) 100%);
  color: var(--white); border: none; text-align: center; padding: 28px 20px;
  position: relative; overflow: hidden;
  transition: background 0.4s ease;
}
.balance-card.balance-good { background: linear-gradient(135deg, #22c55e 0%, #15803d 100%); }
.balance-card.balance-mid { background: linear-gradient(135deg, var(--sky-400) 0%, var(--sky-600) 100%); }
.balance-card.balance-bad { background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%); }
.balance-card::before {
  content: ''; position: absolute; top: -40px; right: -40px; width: 120px; height: 120px;
  background: rgba(255,255,255,0.1); border-radius: 50%;
}
.balance-card::after {
  content: ''; position: absolute; bottom: -30px; left: -30px; width: 90px; height: 90px;
  background: rgba(255,255,255,0.08); border-radius: 50%;
}
.balance-glow {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 70%);
  animation: floatOrb 6s ease-in-out infinite;
}
.balance-glow-a { width: 120px; height: 120px; bottom: -35px; left: -25px; }
.balance-glow-b { width: 90px; height: 90px; top: -25px; right: 10px; animation-delay: -3s; }
@keyframes floatOrb {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.55; }
  50% { transform: translateY(-14px) scale(1.15); opacity: 0.9; }
}
/* Continuously floating budget coins (rufiyaa signs) */
.balance-floating { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.balance-floating .fl-coin {
  position: absolute; bottom: -20px; height: 20px; width: auto; opacity: 0;
  filter: invert(1) brightness(2);
  animation: coinFloat 12s linear infinite;
}
.balance-floating .fl-coin:nth-child(1) { left: 8%;  height: 16px; animation-duration: 11s; animation-delay: 0s; }
.balance-floating .fl-coin:nth-child(2) { left: 22%; height: 22px; animation-duration: 14s; animation-delay: -3.5s; }
.balance-floating .fl-coin:nth-child(3) { left: 40%; height: 14px; animation-duration: 10s; animation-delay: -6s; }
.balance-floating .fl-coin:nth-child(4) { left: 58%; height: 24px; animation-duration: 15s; animation-delay: -2s; }
.balance-floating .fl-coin:nth-child(5) { left: 74%; height: 17px; animation-duration: 12s; animation-delay: -8s; }
.balance-floating .fl-coin:nth-child(6) { left: 90%; height: 13px; animation-duration: 9s; animation-delay: -5s; }
@keyframes coinFloat {
  0% { transform: translateY(18px) rotate(-10deg) scale(0.5); opacity: 0; }
  12% { opacity: 0.3; }
  55% { transform: translateY(-90px) rotate(8deg) scale(1.05); opacity: 0.4; }
  100% { transform: translateY(-180px) rotate(-6deg) scale(1.2); opacity: 0; }
}
.balance-head { display: flex; align-items: center; justify-content: center; gap: 8px; opacity: 0.85; font-size: 0.88rem; font-weight: 500; margin-bottom: 4px; position: relative; z-index: 1; }
.balance-head .icons { width: 20px; height: 20px; }
.balance-amount { font-size: 2.2rem; font-weight: 800; position: relative; z-index: 1; }
.balance-sub { font-size: 0.82rem; opacity: 0.75; margin-top: 4px; position: relative; z-index: 1; }

/* ---- STAT ROW ---- */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
/* Everyone / Mine switch above the Income & Expenses cards */
.stat-scope { display: inline-flex; gap: 3px; background: var(--gray-100); border-radius: var(--radius-full); padding: 3px; margin-top: 16px; }
.stat-scope .scope-btn {
  border: none; background: transparent; color: var(--gray-500);
  font-size: 0.78rem; font-weight: 600; padding: 6px 16px; border-radius: var(--radius-full);
  cursor: pointer; transition: var(--transition);
}
.stat-scope .scope-btn.active { background: var(--sky-500); color: var(--white); box-shadow: 0 2px 8px rgba(14,165,233,0.25); }
.stat-card {
  display: flex; align-items: center; gap: 12px; padding: 16px;
}
.stat-icon { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.stat-icon .icons { width: 22px; height: 22px; }
.stat-icon.income { background: var(--green-bg); color: var(--green); }
.stat-icon.expense { background: var(--red-bg); color: var(--red); }
.stat-label { font-size: 0.78rem; color: var(--gray-400); font-weight: 500; }
.stat-value { font-size: 1.1rem; font-weight: 700; }
.stat-value.income { color: var(--green); }
.stat-value.expense { color: var(--red); }

/* ---- SECTION HEAD ---- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 10px; }
.section-head h3 { font-size: 1rem; font-weight: 700; color: var(--gray-700); }

/* ---- ACCOUNT CARDS ---- */
.account-grid { display: grid; gap: 10px; }
.acc-card {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  position: relative; overflow: hidden; transition: var(--transition);
}
.acc-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.acc-color { width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--white); font-weight: 800; font-size: 1.1rem; }
.acc-color .icons { width: 22px; height: 22px; }
.acc-info { flex: 1; min-width: 0; }
.acc-name { font-weight: 600; font-size: 0.95rem; color: var(--gray-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-balance { font-size: 1.05rem; font-weight: 700; margin-top: 2px; }
.acc-balance.pos { color: var(--green); }
.acc-balance.neg { color: var(--red); }
.acc-actions { display: flex; gap: 4px; }
.acc-actions .icon-btn { width: 34px; height: 34px; }
.acc-actions .icon-btn .icons { width: 16px; height: 16px; }

.account-balance-summary {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px; padding: 16px 20px;
}
.account-balance-summary strong { font-size: 1.2rem; color: var(--sky-600); }

/* ---- ENTRIES ---- */
.entry-list { display: grid; gap: 8px; }
.entry-item {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px 10px;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--sky-100);
  cursor: pointer; transition: var(--transition); position: relative;
}
.entry-item:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.entry-item::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; }
.entry-item.income::before { background: var(--green); }
.entry-item.expense::before { background: var(--red); }
.entry-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.entry-cat { flex: 1; min-width: 0; font-weight: 700; font-size: 0.95rem; color: var(--gray-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-amount { font-weight: 800; font-size: 1.1rem; white-space: nowrap; }
.entry-amount.income { color: var(--green); }
.entry-amount.expense { color: var(--red); }
.entry-details { display: flex; flex-direction: column; gap: 2px; }
.entry-meta { font-size: 0.75rem; color: var(--gray-400); }
.entry-note { font-size: 0.8rem; color: var(--gray-500); word-break: break-word; }
.entry-actions {
  display: flex; gap: 4px; justify-content: flex-end;
  border-top: 1px solid var(--sky-100); padding-top: 4px; margin-top: 2px;
}
.entry-actions .icon-btn { width: 34px; height: 34px; }
.entry-actions .icon-btn .icons { width: 15px; height: 15px; }
.entry-empty { color: var(--gray-400); font-size: 0.85rem; padding: 12px; }
.entry-end { text-align: center; font-size: 0.78rem; color: var(--gray-400); padding: 14px 0 4px; }

/* ---- PAGE HEAD ---- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.page-head h2 { font-size: 1.3rem; font-weight: 800; }

/* ---- LEDGER FILTERS ---- */
.ledger-filters { display: flex; gap: 8px; flex-wrap: wrap; width: 100%; }
.ledger-filters select, .ledger-filters input { padding: 8px 12px; border: 1.5px solid var(--gray-200); border-radius: 8px; background: var(--white); font-size: 0.85rem; flex: 1; min-width: 0; }
.ledger-filters select { appearance: none; padding-right: 28px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; cursor: pointer; }

/* ---- CHART ---- */
.chart-controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.chart-controls .field { flex: 1; min-width: 100px; margin: 0; }
.chart-card { position: relative; min-height: 300px; display: flex; flex-direction: column; align-items: center; padding: 20px; }
.chart-card canvas { max-height: 280px; }
#chartLegend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; justify-content: center; }
#chartLegend .legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 500; color: var(--gray-600); }
#chartLegend .legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.chart-empty { color: var(--gray-400); font-style: italic; padding: 40px 0; }

/* ---- FORECAST ---- */
.forecast-head { width: 100%; text-align: left; margin-bottom: 6px; }
.forecast-head h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; font-weight: 700; color: var(--gray-700); margin: 0; }
.forecast-head .icons { width: 18px; height: 18px; color: var(--sky-500); }

/* Two-column tile grid in all sizes: the app column is capped at 640px, so four
   horizontal cards never fit — vertical tiles always have room and never overflow. */
.forecast-stats {
  width: 100%;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 10px 0 8px;
}
.forecast-stats .stat-card {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px 14px;
  min-width: 0;
}
.forecast-stats .stat-icon { width: 32px; height: 32px; border-radius: 9px; }
.forecast-stats .stat-icon .icons { width: 17px; height: 17px; }
.forecast-stats .stat-card > div:last-child { width: 100%; min-width: 0; }
.forecast-stats .stat-label { font-size: 0.72rem; line-height: 1.25; }
.forecast-stats .stat-value { font-size: 1.05rem; line-height: 1.25; overflow-wrap: break-word; }
.forecast-stats .stat-sub { font-size: 0.7rem; line-height: 1.3; margin-top: 3px; overflow-wrap: break-word; }
@media (max-width: 359px) { .forecast-stats { grid-template-columns: 1fr; } }

.forecast-chart { width: 100%; margin-top: 8px; }
.forecast-chart canvas { max-height: 220px; }
.forecast-chart.monthly canvas { max-height: 160px; }
.forecast-subhead { font-size: 0.75rem; font-weight: 600; color: var(--gray-400); margin: 0 0 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.forecast-note { width: 100%; text-align: left; font-size: 0.8rem; color: var(--gray-400); margin: 12px 0 0; line-height: 1.4; }
.forecast-note strong { color: var(--gray-600); }

/* ---- DAILY SPEND ALLOWANCE (monthly limit - spent) / days left ---- */
.allowance-card {
  width: 100%; text-align: left; padding: 14px 16px; border-radius: 14px; margin-top: 8px;
  background: linear-gradient(135deg, rgba(34,197,94,0.10), rgba(14,165,233,0.10));
  border: 1px solid rgba(34,197,94,0.28);
}
.allowance-card.over { background: linear-gradient(135deg, rgba(239,68,68,0.12), rgba(245,158,11,0.10)); border-color: rgba(239,68,68,0.32); }
.allowance-card.allowance-empty { background: var(--gray-100); border-color: transparent; }
.allowance-head { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.allowance-head .icons { width: 17px; height: 17px; color: var(--green); }
.allowance-card.over .allowance-head .icons { color: var(--red); }
.allowance-label { font-size: 0.74rem; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.04em; }
.allowance-value {
  font-size: 1.7rem; font-weight: 800; color: var(--green); line-height: 1.2;
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px;
}
.allowance-card.over .allowance-value { color: var(--red); }
.allowance-value .per { font-size: 0.74rem; font-weight: 600; color: var(--gray-500); }
.allowance-sub { font-size: 0.76rem; color: var(--gray-500); margin-top: 6px; line-height: 1.45; }
.allowance-sub strong { color: var(--gray-700); }
.allowance-bar { height: 8px; background: var(--gray-200); border-radius: var(--radius-full); margin-top: 10px; overflow: hidden; }
.allowance-bar > span { display: block; height: 100%; background: var(--green); border-radius: inherit; transition: width 0.4s ease; }
.allowance-card.over .allowance-bar > span { background: var(--red); }

/* ---- USERS ---- */
.users-list { display: grid; gap: 8px; }
.user-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.user-avatar { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, var(--sky-300), var(--sky-500)); display: flex; align-items: center; justify-content: center; color: var(--white); font-weight: 700; font-size: 1rem; }
.user-info { flex: 1; }
.user-name { font-weight: 600; font-size: 0.95rem; }
.user-detail { font-size: 0.78rem; color: var(--gray-400); }
.user-actions .icon-btn { width: 34px; height: 34px; }

/* ---- SETTINGS ---- */
.setting-card h3 { font-size: 1.1rem; margin-bottom: 4px; }
.setting-card .muted { color: var(--gray-400); font-size: 0.85rem; margin-bottom: 16px; }
.limit-row { display: flex; gap: 10px; }
.limit-row input { flex: 1; padding: 10px 14px; border: 1.5px solid var(--gray-200); border-radius: 8px; }
.limit-row input:focus { border-color: var(--sky-400); outline: none; }
.limit-status { margin-top: 12px; font-size: 0.85rem; padding: 10px 14px; border-radius: 8px; }
.limit-status.info { background: var(--sky-50); color: var(--sky-700); }

.setting-card { margin-bottom: 16px; }
.push-status { margin-top: 12px; font-size: 0.85rem; padding: 10px 14px; border-radius: 8px; }
.push-status.info { background: var(--green-bg); color: var(--green); }
.push-status.error { background: var(--red-bg); color: var(--red); }
.push-status.warn { background: var(--amber-bg); color: var(--amber); }

/* ---- NIGHT MODE ---- */
.night-mode-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.night-mode-label { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--gray-700); }
.night-mode-label .icons { width: 20px; height: 20px; color: var(--sky-500); }
.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--gray-300); border-radius: var(--radius-full);
  transition: var(--transition);
}
.slider::before {
  content: ''; position: absolute; height: 24px; width: 24px; left: 3px; top: 3px;
  background: var(--surface); border-radius: 50%; transition: var(--transition);
  box-shadow: 0 2px 5px rgba(0,0,0,0.25);
}
.switch input:checked + .slider { background: var(--sky-500); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ---- LOANS ---- */
.loan-list { display: grid; gap: 10px; }
.loan-card {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px 10px;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--sky-100);
  position: relative; overflow: hidden;
}
.loan-card::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; }
.loan-card.outstanding::before { background: var(--amber); }
.loan-card.partially_repaid::before { background: var(--sky-400); }
.loan-card.repaid::before { background: var(--green); }
.loan-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.loan-person { flex: 1; min-width: 0; font-weight: 700; font-size: 0.95rem; color: var(--gray-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loan-status {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem; font-weight: 700;
  padding: 3px 10px; border-radius: var(--radius-full); text-transform: capitalize;
}
.loan-status.outstanding { background: var(--amber-bg); color: var(--amber); }
.loan-status.partially_repaid { background: var(--sky-50); color: var(--sky-600); }
.loan-status.repaid { background: var(--green-bg); color: var(--green); }
.loan-status.income { background: var(--green-bg); color: var(--green); }
.loan-status.expense { background: var(--red-bg); color: var(--red); }
.loan-amount { font-weight: 800; font-size: 1.3rem; color: var(--gray-800); }
.loan-details { display: flex; flex-direction: column; gap: 2px; }
.loan-meta { font-size: 0.75rem; color: var(--gray-400); }
.loan-note { font-size: 0.8rem; color: var(--gray-500); }
.loan-remaining { color: var(--amber); font-weight: 600; }
.repay-hint { margin-top: 6px; font-size: 0.78rem; color: var(--gray-400); }
.repay-hint strong { color: var(--gray-500); }
.loan-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  border-top: 1px solid var(--sky-100); padding-top: 8px; margin-top: 4px;
}
.loan-actions .icon-btn { width: 38px; height: 38px; }
.loan-actions .icon-btn .icons { width: 16px; height: 16px; }

/* ---- MODAL ---- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); animation: fadeIn 0.2s; }
.modal-content.sheet {
  position: relative; z-index: 1; background: var(--surface); width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom)); animation: slideUp 0.3s ease-out;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.1);
}
.modal-content.confirm {
  position: relative; z-index: 1; background: var(--surface); border-radius: var(--radius);
  padding: 28px 24px; max-width: 360px; margin: auto; animation: scaleIn 0.25s ease-out;
  text-align: center; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-head h3 { font-size: 1.15rem; font-weight: 700; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

/* ---- TYPE TOGGLE ---- */
.type-toggle { display: flex; background: var(--gray-100); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.type-btn { flex: 1; padding: 12px; border: none; border-radius: 10px; font-weight: 600; font-size: 0.95rem; cursor: pointer; transition: var(--transition); background: transparent; color: var(--gray-500); }
.type-btn.active.expense { background: var(--red-bg); color: var(--red); box-shadow: var(--shadow); }
.type-btn.active.income { background: var(--green-bg); color: var(--green); box-shadow: var(--shadow); }

/* ---- LIMIT WARNING ---- */
.limit-warning {
  padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px; font-size: 0.9rem; font-weight: 500;
  animation: pulse 2s infinite;
}
.limit-warning.exceeded { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }
.limit-warning.near { background: var(--amber-bg); color: var(--amber); border: 1px solid rgba(245,158,11,0.2); }

/* ---- TOAST ---- */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--gray-800); color: var(--white); padding: 12px 24px;
  border-radius: 12px; font-size: 0.9rem; font-weight: 500; z-index: 300;
  box-shadow: var(--shadow-lg); max-width: 90vw; text-align: center;
  animation: toastIn 0.3s ease-out;
}
.toast.show { animation: toastIn 0.3s ease-out; }
.toast.hiding { animation: toastOut 0.3s ease-in forwards; }

/* ---- BOTTOM NAV ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 12px calc(12px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--sky-100);
  box-shadow: 0 -2px 10px rgba(14,165,233,0.06);
  z-index: 100;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 6px 12px; border: none; background: none; border-radius: 12px;
  cursor: pointer; transition: var(--transition); color: var(--gray-400);
  font-size: 0.68rem; font-weight: 500; position: relative;
}
.nav-btn .icons { width: 22px; height: 22px; }
.nav-btn.active { color: var(--sky-500); }
.nav-btn.active::after { content: ''; position: absolute; top: -8px; width: 20px; height: 3px; background: var(--sky-400); border-radius: 0 0 4px 4px; }
.nav-btn span { line-height: 1; }

/* FAB wrapper — keeps the round button perfectly centred inside its column
   while still allowing it to float above the ribbon. */
.fab-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  flex: 0 0 56px;
}
.nav-btn.fab {
  width: 54px; height: 54px; min-width: 54px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--sky-400), var(--sky-600));
  color: var(--white); box-shadow: 0 4px 14px rgba(14,165,233,0.35);
  transform: translateY(-10px);
  display: flex; align-items: center; justify-content: center;
  padding: 0; gap: 0;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease, background 0.2s ease;
}
.nav-btn.fab .icons { width: 24px; height: 24px; stroke-width: 2.6; }
.nav-btn.fab:hover { transform: translateY(-13px); box-shadow: 0 7px 20px rgba(14,165,233,0.45); }
.nav-btn.fab:active { transform: translateY(-8px) scale(0.94); }
.nav-btn.fab.active::after { display: none; }
.nav-btn.fab.open { transform: translateY(-10px) rotate(45deg); }
.nav-btn.fab.open .icons { transform: rotate(180deg); }

/* FAB popup menu */
.fab-menu {
  position: absolute; bottom: 62px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  animation: fabMenuIn 0.24s cubic-bezier(0.34, 1.4, 0.64, 1);
  z-index: 101;
}
@keyframes fabMenuIn {
  from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(0.9); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
.fab-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px 11px 14px;
  background: var(--surface); border: 1px solid var(--sky-100);
  border-radius: var(--radius-full); box-shadow: var(--shadow-md);
  font-size: 0.88rem; font-weight: 600; color: var(--gray-700);
  cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.fab-menu-item:hover { background: var(--sky-50); color: var(--sky-600); transform: translateY(-2px); }
.fab-menu-item .icons { width: 18px; height: 18px; color: var(--sky-500); }

/* ---- COLOR ROW ---- */
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] { width: 48px; height: 40px; border: 2px solid var(--gray-200); border-radius: 10px; cursor: pointer; padding: 2px; }

/* ---- LOADING SPINNER ---- */
.spinner { animation: spin 0.8s linear infinite; }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sky-300); border-radius: 3px; }

/* ---- RESPONSIVE ---- */
@media (min-width: 480px) {
  .modal-content.sheet { border-radius: var(--radius); margin: auto; }
  .stat-row { gap: 16px; }
}
@media (max-width: 380px) {
  .balance-amount { font-size: 1.7rem; }
  .stat-card { padding: 12px; }
  .entry-item { padding: 12px; }
}

/* ---- DARK MODE EXTRA ---- */
[data-theme="dark"] body { background: #0b1322; }
[data-theme="dark"] .splash { background: linear-gradient(135deg, #0c4a6e 0%, #0369a1 100%); }
[data-theme="dark"] .toast { background: #1e293b; color: #ffffff; }
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,0.6); }
[data-theme="dark"] .limit-row input,
[data-theme="dark"] .ledger-filters select,
[data-theme="dark"] .ledger-filters input { background: var(--surface); color: var(--gray-800); }
[data-theme="dark"] .field input, [data-theme="dark"] .field select, [data-theme="dark"] .field textarea { border-color: var(--gray-200); }
[data-theme="dark"] .stat-card, [data-theme="dark"] .acc-card, [data-theme="dark"] .loan-card, [data-theme="dark"] .user-card { background: var(--surface); }

/* ---- MONTHLY RECAP ---- */
.recap-wrap { margin: 16px 0 0; }
.recap-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 16px 18px;
  border: none; border-radius: var(--radius); color: #fff; cursor: pointer; text-align: left;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  box-shadow: 0 10px 25px rgba(139, 92, 246, 0.35);
  animation: slideDown 0.5s ease-out;
}
.recap-btn .recap-icon {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,0.22); display: flex; align-items: center; justify-content: center;
}
.recap-btn .recap-icon .icons { width: 22px; height: 22px; }
.recap-btn .recap-text { flex: 1; display: flex; flex-direction: column; }
.recap-btn .recap-text strong { font-size: 1.05rem; font-weight: 800; }
.recap-btn .recap-text small { opacity: 0.88; font-size: 0.8rem; }
.recap-btn:active { transform: scale(0.98); }
.recap-btn.pop { animation: recapPop 0.45s ease; }
@keyframes recapPop {
  0% { transform: scale(1); }
  30% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
.burst-coin {
  position: fixed; width: 15px; height: 15px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ffe08a, #f59e0b 60%, #b45309);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3); pointer-events: none; z-index: 10050;
  animation: burstFly 0.9s ease-out forwards;
}
@keyframes burstFly {
  0% { opacity: 1; transform: translate(0, 0) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0.35) rotate(var(--rot)); }
}
.recap-sheet { max-height: 88dvh; overflow-y: auto; overscroll-behavior-y: contain; }
.recap-strip {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; margin-bottom: 12px;
}
.recap-strip-label { font-size: 0.85rem; color: var(--gray-500); }
.recap-strip-value { font-size: 1.35rem; font-weight: 800; }
.recap-strip-value.pos { color: var(--green); }
.recap-strip-value.neg { color: var(--red); }
.recap-balance {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 16px; margin-bottom: 12px;
}
.recap-balance div { display: flex; flex-direction: column; }
.recap-balance-label { font-size: 0.72rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.05em; }
.recap-balance strong { font-size: 1.1rem; font-weight: 800; margin-top: 4px; }
.recap-balance-arrow { color: var(--gray-400); flex-shrink: 0; }
.recap-meta { text-align: center; color: var(--gray-400); font-size: 0.8rem; margin-bottom: 12px; }
.recap-section { padding: 16px; margin-bottom: 12px; }
.recap-section h4 { font-size: 0.95rem; font-weight: 700; margin-bottom: 12px; color: var(--gray-700); }
.recap-chart { position: relative; }
.recap-chart.taller canvas { max-height: 240px; }