*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0ea5e9;
  --primary-d: #0284c7;
  --accent: #14b8a6;
  --bg: #f0f9ff;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #bae6fd;
  --text: #0c4a6e;
  --muted: #64748b;
  --success: #10b981;
  --danger: #ef4444;
  --r: 14px;
  --r-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* NAV */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 10px 4px 8px; border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 11px; gap: 3px; text-decoration: none;
  transition: color 0.15s;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 22px; height: 22px; }

/* HEADER */
.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 12px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 18px; font-weight: 600; color: var(--text); }
.page-subtitle { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* CONTAINER */
.container { max-width: 480px; margin: 0 auto; padding: 16px; }

/* CARDS */
.card {
  background: var(--surface);
  border-radius: var(--r);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title { font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; text-decoration: none;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* FORMS */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--r-sm); background: var(--surface); color: var(--text);
  font-size: 15px; font-family: inherit; transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14,165,233,.12);
}
textarea { resize: vertical; min-height: 80px; }

/* COUNTDOWN */
.countdown { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.cd-box { background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 12px 6px; text-align: center; }
.cd-num { font-size: 30px; font-weight: 700; color: var(--primary); line-height: 1; }
.cd-label { font-size: 10px; color: var(--muted); margin-top: 3px; text-transform: uppercase; }

/* HERO */
.hero { border-radius: var(--r); overflow: hidden; position: relative; height: 200px;
  background: linear-gradient(135deg, #0ea5e9, #14b8a6); margin-bottom: 12px; }
.hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-overlay { position: absolute; bottom: 0; left: 0; right: 0;
  padding: 20px 16px 16px;
  background: linear-gradient(transparent, rgba(0,0,0,0.6)); }
.hero-title { color: #fff; font-size: 24px; font-weight: 700; }
.hero-sub { color: rgba(255,255,255,0.85); font-size: 13px; margin-top: 3px; }
.hero-placeholder { width: 100%; height: 100%; display: flex; align-items: center;
  justify-content: center; font-size: 60px; }

/* PHOTOS GRID */
.photo-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; }
.photo-cell { aspect-ratio: 1; position: relative; overflow: hidden;
  border-radius: var(--r-sm); background: var(--surface2); cursor: pointer; }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell .ph-del {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px;
  border-radius: 50%; background: rgba(0,0,0,0.6); border: none; color: #fff;
  font-size: 13px; cursor: pointer; display: none; align-items: center; justify-content: center;
}
.photo-cell:hover .ph-del { display: flex; }
.photo-cell .ph-author {
  position: absolute; bottom: 0; left: 0; right: 0; padding: 4px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.55));
  font-size: 10px; color: #fff;
}

/* UPLOAD AREA */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--r);
  padding: 28px 16px; text-align: center; cursor: pointer; margin-bottom: 16px;
  transition: all 0.15s; color: var(--muted);
}
.upload-zone:hover { border-color: var(--primary); background: #e0f2fe40; color: var(--primary); }
.upload-zone .icon { font-size: 36px; margin-bottom: 8px; }
.upload-zone p { font-size: 14px; }

/* EXPENSE ITEMS */
.expense-row { display: flex; align-items: flex-start; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border); }
.expense-row:last-child { border-bottom: none; }
.exp-desc { font-size: 15px; font-weight: 500; }
.exp-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.exp-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; flex-wrap: nowrap; }
.exp-amount { font-size: 16px; font-weight: 600; color: var(--text); }
.exp-del { background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 15px; padding: 2px 4px; line-height: 1; display: inline-flex; align-items: center; }

/* BALANCE */
.balance-row { display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.balance-row:last-child { border-bottom: none; }
.bal-pos { color: var(--success); font-weight: 600; }
.bal-neg { color: var(--danger); font-weight: 600; }
.bal-zero { color: var(--muted); }

/* STATS */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat-box { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 14px; text-align: center; }
.stat-val { font-size: 22px; font-weight: 700; color: var(--primary); }
.stat-lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* MODAL */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 200; align-items: flex-end; justify-content: center; padding: 0; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--r) var(--r) 0 0;
  padding: 20px 16px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; }
.modal-handle { width: 40px; height: 4px; background: var(--border);
  border-radius: 2px; margin: 0 auto 16px; }
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 16px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* LOGIN PAGE */
.login-wrap { min-height: 100vh; display: flex; align-items: center;
  justify-content: center; padding: 24px; background: var(--bg); }
.login-card { background: var(--surface); border-radius: var(--r);
  border: 1px solid var(--border); padding: 28px 24px; width: 100%; max-width: 380px; }
.login-logo { text-align: center; font-size: 48px; margin-bottom: 4px; }
.login-title { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-sub { text-align: center; font-size: 14px; color: var(--muted); margin-bottom: 24px; }
.alert { padding: 10px 14px; border-radius: var(--r-sm); font-size: 14px; margin-bottom: 14px; display: none; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }

/* AVATAR */
.avatar { width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* CHIP */
.chip { display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; background: var(--surface2);
  border: 1px solid var(--border); color: var(--muted); margin: 2px; }

/* LOCATION LINK */
a.maps-link { color: var(--primary); font-size: 14px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; }
a.maps-link:hover { text-decoration: underline; }

/* EMPTY STATE */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .empty-icon { font-size: 48px; margin-bottom: 10px; }
.empty p { font-size: 14px; }

/* CHECKBOXES GRID */
.cb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  max-height: 180px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 10px; }
.cb-grid label { display: flex; align-items: center; gap: 6px; font-size: 13px;
  cursor: pointer; color: var(--text); font-weight: 400; }
.cb-grid input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; }

/* SPINNER */
.spinner { border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; width: 24px; height: 24px; animation: spin 0.7s linear infinite;
  margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* NAME MODAL GRID */
.name-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.name-grid .form-group { margin-bottom: 0; }

/* SET NAME PROMPT */
.set-name-wrap { padding-top: 20px; }

/* Lightbox */
.lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.92);
  z-index: 300; align-items: center; justify-content: center; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 95vw; max-height: 90vh; border-radius: var(--r-sm); }
.lightbox-close { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,0.2);
  border: none; color: #fff; font-size: 20px; width: 36px; height: 36px;
  border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; }
