/* ===== Reset & Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
  font-size: 15px;
  line-height: 1.45;
}

/* ===== Theme Variables ===== */
body[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elev: #121a2c;
  --bg-elev-2: #1a2440;
  --text: #e9eef7;
  --muted: #8a93a6;
  --border: #1f2940;
  --primary: #5b8cff;
  --primary-2: #7aa2ff;
  --success: #2ecc71;
  --danger: #ff5c5c;
  --warning: #ffb547;
  --lend: #ffb547;
  --borrow: #a17bff;
  --shadow: 0 10px 30px rgba(0,0,0,0.45);
  --gradient: linear-gradient(135deg, #5b8cff 0%, #a17bff 100%);
}
body[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef2f9;
  --text: #1a2238;
  --muted: #5b6478;
  --border: #e3e8f0;
  --primary: #3a6dff;
  --primary-2: #5b8cff;
  --success: #1e9e58;
  --danger: #e23b3b;
  --warning: #d98a16;
  --lend: #d98a16;
  --borrow: #6f4cd1;
  --shadow: 0 10px 30px rgba(20,30,60,0.08);
  --gradient: linear-gradient(135deg, #3a6dff 0%, #6f4cd1 100%);
}

/* ===== Utility ===== */
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error-text { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; margin: 6px 0; }
.row-flex { display: flex; gap: 10px; align-items: center; }

/* ===== Splash ===== */
.splash {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  animation: fadeIn 0.3s ease;
}
.splash-logo {
  width: 96px; height: 96px; border-radius: 28px;
  background: var(--gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 52px; font-weight: 800; color: #fff;
  box-shadow: var(--shadow);
  animation: pulseLogo 1.4s ease infinite;
}
.splash h1 { margin-top: 18px; font-size: 1.8rem; letter-spacing: 0.5px; }
.splash p { color: var(--muted); margin-top: 6px; }

@keyframes pulseLogo {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

/* ===== Auth Screens ===== */
.auth-screen {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--bg-elev);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.auth-logo {
  width: 72px; height: 72px; border-radius: 22px;
  background: var(--gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 800; color: #fff;
  margin: 0 auto 14px;
}
.auth-card h2 { text-align: center; margin-bottom: 6px; }
.auth-card .muted { text-align: center; display: block; margin-bottom: 18px; }

.pin-dots { display: flex; gap: 12px; justify-content: center; margin: 14px 0 8px; }
.pin-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  transition: all 0.2s ease;
}
.pin-dots span.filled { background: var(--primary); border-color: var(--primary); transform: scale(1.15); }

.pin-input {
  text-align: center; letter-spacing: 12px; font-size: 1.3rem;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,140,255,0.18);
}
textarea { resize: vertical; }

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: 12px 18px;
  border: none;
  border-radius: 12px;
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.2s ease;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--gradient); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-block { display: block; width: 100%; margin-top: 8px; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 10px; border: none;
  background: var(--bg-elev-2); color: var(--text);
  font-size: 1rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.icon-btn:hover { background: var(--border); }

.link-btn {
  background: transparent; border: none; color: var(--primary);
  font-size: 0.85rem; cursor: pointer; font-weight: 600;
}

/* Pills */
.pill-group { display: flex; gap: 8px; flex-wrap: wrap; background: var(--bg-elev-2); padding: 4px; border-radius: 12px; }
.pill {
  flex: 1; min-width: 70px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 600; font-size: 0.85rem;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}
.pill.active { background: var(--gradient); color: #fff; box-shadow: 0 4px 12px rgba(91,140,255,0.3); }

/* ===== App Layout ===== */
#app { padding-bottom: 100px; min-height: 100vh; }

.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: #fff;
}
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.3px; }
.header-actions { display: flex; gap: 8px; }

/* Views */
.view { display: none; padding: 16px; animation: fadeUp 0.3s ease; }
.view.active { display: block; }
.view-title { font-size: 1.3rem; margin-bottom: 14px; font-weight: 700; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Balance card */
.balance-card {
  background: var(--gradient);
  color: #fff;
  border-radius: 20px;
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  position: relative; overflow: hidden;
}
.balance-card::before {
  content: ''; position: absolute; top: -50px; right: -50px;
  width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255,255,255,0.08);
}
.balance-card.negative { background: linear-gradient(135deg, #e23b3b 0%, #ff7676 100%); }
.bc-label { font-size: 0.85rem; opacity: 0.85; }
.bc-amount { font-size: 2.1rem; font-weight: 800; margin: 4px 0 16px; letter-spacing: 0.3px; }
.bc-row { display: flex; gap: 10px; margin-top: 10px; }
.bc-row > div { flex: 1; background: rgba(255,255,255,0.12); padding: 10px 12px; border-radius: 12px; }
.bc-row span { font-size: 0.75rem; opacity: 0.85; display: block; }
.bc-row strong { font-size: 0.95rem; font-weight: 700; }

/* Quick actions */
.quick-actions {
  display: grid; grid-template-columns: repeat(4,1fr);
  gap: 8px; margin: 14px 0;
}
.qa {
  padding: 12px 6px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 600; font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}
.qa:active { transform: scale(0.96); }
.qa-income { color: var(--success); }
.qa-expense { color: var(--danger); }
.qa-lend { color: var(--lend); }
.qa-borrow { color: var(--borrow); }

/* Sections */
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 0 10px;
}
.section-title h3 { font-size: 1rem; font-weight: 700; }
.section-title span { font-size: 0.8rem; color: var(--muted); }

/* Card */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
}
.chart-card h4 { font-size: 0.95rem; margin-bottom: 10px; font-weight: 700; }
.chart-card canvas { width: 100%; height: 220px; display: block; }

/* Tx List */
.tx-list { display: flex; flex-direction: column; gap: 8px; }
.tx-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}
.tx-item:active { transform: scale(0.98); }
.tx-icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; flex-shrink: 0;
  color: #fff;
}
.tx-icon.income { background: var(--success); }
.tx-icon.expense { background: var(--danger); }
.tx-icon.lend { background: var(--lend); }
.tx-icon.borrow { background: var(--borrow); }
.tx-info { flex: 1; min-width: 0; }
.tx-title { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.tx-amount { font-weight: 700; font-size: 0.95rem; flex-shrink: 0; text-align: right; }
.tx-amount.pos { color: var(--success); }
.tx-amount.neg { color: var(--danger); }
.tx-amount.lend { color: var(--lend); }
.tx-amount.borrow { color: var(--borrow); }

.empty {
  text-align: center; padding: 30px 10px;
  color: var(--muted); font-size: 0.9rem;
}

/* Filters */
.filters { margin-bottom: 14px; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 8px; }

/* Settings */
.settings-card h4 { margin-bottom: 12px; font-size: 1rem; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0;
}
.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 26px; transition: 0.25s;
}
.slider::before {
  content: ''; position: absolute;
  height: 20px; width: 20px; left: 2px; top: 2px;
  background: var(--text);
  border-radius: 50%; transition: 0.25s;
}
.switch input:checked + .slider { background: var(--gradient); border-color: transparent; }
.switch input:checked + .slider::before { transform: translateX(20px); background: #fff; }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  background: var(--bg-elev-2);
  padding: 6px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
}
.chip button {
  border: none; background: transparent; color: var(--danger);
  font-size: 0.85rem; cursor: pointer;
}

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.nav-btn {
  flex: 1; background: transparent; border: none;
  color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.7rem; padding: 6px;
  transition: color 0.2s;
  font-family: inherit;
}
.nav-btn span { font-size: 1.25rem; }
.nav-btn.active { color: var(--primary); }
.nav-btn.fab {
  background: var(--gradient); color: #fff; border-radius: 50%;
  width: 56px; height: 56px; flex: 0 0 56px;
  margin-top: -22px;
  box-shadow: 0 8px 22px rgba(91,140,255,0.4);
  font-weight: 800;
}
.nav-btn.fab span { font-size: 1.6rem; }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--bg-elev);
  width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  max-height: 92vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}
.modal.modal-sm { max-width: 420px; border-radius: 18px; margin-bottom: auto; margin-top: auto; }
@media (min-width: 600px) {
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 18px; }
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; }
.modal-body { padding: 16px 18px; }

/* Toasts */
.toast-container {
  position: fixed; bottom: 92px; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  z-index: 2000;
  padding: 0 16px;
}
.toast {
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  font-weight: 600;
  display: flex; align-items: center; gap: 8px;
  animation: toastIn 0.25s ease forwards;
  pointer-events: auto;
  max-width: 90%;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.hide { animation: toastOut 0.25s ease forwards; }
@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toastOut {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(20px); opacity: 0; }
}

/* Responsive */
@media (min-width: 720px) {
  .view { max-width: 720px; margin: 0 auto; }
  .app-header { max-width: 720px; margin: 0 auto; }
}
@media (min-width: 1024px) {
  .quick-actions { grid-template-columns: repeat(4,1fr); }
  .chart-card canvas { height: 260px; }
}

/* ===== Settlement ===== */
.tx-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}

.settle-btn {
  background: transparent;
  border: 1px solid rgba(91,140,255,0.35);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
  font-family: inherit;
  line-height: 1.4;
  transition: background 0.18s ease, box-shadow 0.18s ease, transform 0.13s ease, border-color 0.18s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  white-space: nowrap;
}
.settle-btn:hover {
  background: rgba(91,140,255,0.12);
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(91,140,255,0.45), 0 0 3px rgba(161,123,255,0.3);
  transform: scale(1.04);
}
.settle-btn:active {
  transform: scale(0.97);
  box-shadow: none;
}

.settled-badge {
  font-size: 0.72rem;
  color: var(--success);
  font-weight: 600;
  opacity: 0.85;
  letter-spacing: 0.2px;
}

.settled-item {
  opacity: 0.52;
  filter: grayscale(0.65);
  pointer-events: auto; /* allow click to view/edit */
}
.settled-item .settle-btn {
  pointer-events: none;
  display: none;
}
/* ================================================
   FIREBASE SYNC & AUTH STYLES
   Replaces old Firebase CSS block entirely.
   All existing app styles above are untouched.
   ================================================ */

/* ===== Sync Status Indicator ===== */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--muted);
  transition: color 0.3s ease, border-color 0.3s ease, background 0.3s ease;
  user-select: none;
  white-space: nowrap;
}
.sync-status::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s ease;
}

/* Idle / default */
.sync-status[data-state="idle"] { color: var(--muted); }
.sync-status[data-state="idle"]::before { background: var(--muted); }

/* Synced */
.sync-status[data-state="synced"] {
  color: var(--success);
  border-color: rgba(46,204,113,0.25);
  background: rgba(46,204,113,0.07);
}
.sync-status[data-state="synced"]::before { background: var(--success); }

/* Syncing — pulsing dot */
.sync-status[data-state="syncing"] {
  color: var(--primary);
  border-color: rgba(91,140,255,0.25);
  background: rgba(91,140,255,0.07);
}
.sync-status[data-state="syncing"]::before {
  background: var(--primary);
  animation: syncPulse 0.9s ease infinite;
}

/* Offline */
.sync-status[data-state="offline"] {
  color: var(--warning);
  border-color: rgba(255,181,71,0.25);
  background: rgba(255,181,71,0.07);
}
.sync-status[data-state="offline"]::before { background: var(--warning); }

/* Error */
.sync-status[data-state="error"] {
  color: var(--danger);
  border-color: rgba(255,92,92,0.25);
  background: rgba(255,92,92,0.07);
}
.sync-status[data-state="error"]::before { background: var(--danger); }

@keyframes syncPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.45; }
}

/* ===== Cloud Auth Form (shown inside Cloud Sync card when logged out) ===== */
.cloud-auth-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Email/password inputs inside the cloud sync card */
.cloud-auth-section .form-group {
  margin-bottom: 0;
}
.cloud-auth-section input {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  border-radius: 11px;
  font-size: 0.93rem;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.cloud-auth-section input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,140,255,0.16);
}
.cloud-auth-section input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

/* Auth error message inside cloud card */
.cloud-auth-error {
  font-size: 0.8rem;
  color: var(--danger);
  min-height: 1em;
  margin: -2px 0 2px;
  line-height: 1.4;
}

/* Login/Register button inside cloud card */
.cloud-auth-section .btn-primary {
  width: 100%;
  padding: 11px 14px;
  font-size: 0.93rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 2px;
}

/* ===== Auth Divider ("or" separator) ===== */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 2px 0;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===== Google Sign-In Button ===== */
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 0.93rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}
.btn-google:hover {
  background: var(--bg-elev);
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
}
.btn-google:active { transform: scale(0.97); }
.btn-google svg {
  width: 19px; height: 19px;
  flex-shrink: 0;
}

/* ===== Cloud Sync — Logged-In Panel ===== */
.cloud-user-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* User info row at top of logged-in panel */
.cloud-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.cloud-user-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.18);
}
.cloud-user-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.cloud-user-info { flex: 1; min-width: 0; }
.cloud-user-name {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.cloud-user-email {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* Sync info row — "Last synced: ..." */
.sync-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.85rem;
  color: var(--text);
}
.sync-info-row .sync-timestamp {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Sync status indicator row */
.sync-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

/* Action buttons inside cloud sync card */
.sync-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}
.sync-actions .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 0;
  padding: 10px 14px;
  font-size: 0.88rem;
  width: 100%;
}
.sync-actions .btn-danger {
  background: rgba(255,92,92,0.1);
  color: var(--danger);
  border: 1px solid rgba(255,92,92,0.22);
}
.sync-actions .btn-danger:hover {
  background: rgba(255,92,92,0.18);
}

/* ===== User Avatar in App Header ===== */
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
  cursor: pointer;
  flex-shrink: 0;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
}
.user-avatar:hover {
  box-shadow: 0 0 0 3px rgba(91,140,255,0.28);
  transform: scale(1.05);
}

/* Fallback initials avatar in header */
.user-avatar-fallback {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  user-select: none;
}
.user-avatar-fallback:hover {
  box-shadow: 0 0 0 3px rgba(91,140,255,0.28);
  transform: scale(1.05);
}

/* ===== User Profile Dropdown (from header avatar) ===== */
.user-dropdown {
  position: absolute;
  top: 58px;
  right: 12px;
  z-index: 300;
  min-width: 230px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
  animation: fadeUp 0.2s ease;
}
.user-dropdown-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.user-dropdown-info { flex: 1; min-width: 0; }
.user-dropdown-name {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-dropdown-email {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.user-dropdown .btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  font-size: 0.85rem;
  background: var(--bg-elev-2);
  margin-top: 0;
  margin-bottom: 6px;
  border-radius: 10px;
}
.user-dropdown .btn:last-child { margin-bottom: 0; }
.user-dropdown .btn-danger {
  background: rgba(255,92,92,0.1);
  color: var(--danger);
  border: 1px solid rgba(255,92,92,0.2);
}

/* ===== Login Prompt Banner (shown in views when user is logged out) ===== */
.cloud-login-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(91,140,255,0.08);
  border: 1px solid rgba(91,140,255,0.22);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 0 16px 14px;
  font-size: 0.85rem;
  animation: fadeIn 0.3s ease;
}
.cloud-login-banner p {
  color: var(--muted);
  margin: 0;
  line-height: 1.4;
}
.cloud-login-banner p strong { color: var(--text); }
.cloud-login-banner .btn {
  flex-shrink: 0;
  padding: 9px 14px;
  font-size: 0.82rem;
  margin-top: 0;
  white-space: nowrap;
}

/* ===== Offline Queue Badge ===== */
.queue-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--warning);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  margin-left: 4px;
  animation: fadeIn 0.2s ease;
}

/* ===== Conflict toast variant ===== */
.toast.conflict {
  border-left: 4px solid var(--borrow);
  max-width: 96%;
}

/* ===== Restore Confirmation Overlay ===== */
.restore-overlay {
  position: fixed; inset: 0; z-index: 1500;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.restore-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 20px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
  text-align: center;
}
.restore-card .auth-logo { margin-bottom: 14px; }
.restore-card h3 { margin-bottom: 8px; }
.restore-card p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 18px;
  line-height: 1.5;
}
.restore-card .row-flex { justify-content: center; gap: 12px; }
.restore-card .btn { min-width: 110px; margin-top: 0; }

/* ===== Responsive adjustments for Firebase UI ===== */
@media (max-width: 380px) {
  .cloud-auth-section input {
    font-size: 0.88rem;
    padding: 10px 11px;
  }
  .btn-google {
    font-size: 0.88rem;
    padding: 10px 12px;
  }
  .cloud-user-name { font-size: 0.84rem; }
  .sync-actions .btn { font-size: 0.84rem; padding: 9px 12px; }
}
