:root {
  --bg: #0f172a;
  --bg-2: #111c33;
  --card: #1a2540;
  --card-2: #233056;
  --text: #e6edf7;
  --muted: #9aa6c2;
  --line: #2c395f;
  --primary: #3b82f6;
  --primary-2: #60a5fa;
  --good: #22c55e;
  --warn: #ef4444;
  --recommend: #facc15;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(180deg, var(--bg), var(--bg-2));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Segoe UI', 'Noto Sans KR', sans-serif;
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--warn); }

.row { display: flex; align-items: stretch; }
.row.gap { gap: 8px; }
.row.between { justify-content: space-between; }
.row.center-y { align-items: center; }
.row.wrap { flex-wrap: wrap; }
.mt { margin-top: 16px; }
.mt-sm { margin-top: 8px; }

.label { color: var(--muted); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
}
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50vw; }
.topbar-right { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}
.icon-btn:hover { background: var(--card-2); }

main, #onboarding {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card h3 { margin: 0 0 8px; font-size: 14.5px; color: var(--muted); font-weight: 500; }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 540px) {
  .grid2 { grid-template-columns: 1fr; }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > span { font-size: 13px; color: var(--muted); }
.field input, .select, .modal-card input[type="text"], .modal-card input[type="email"] {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  width: 100%;
  font-family: inherit;
}
.field input:focus, .select:focus { border-color: var(--primary-2); }

.btn {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn-ghost { background: transparent; }

.ratio-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ratio-btn {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  min-width: 56px;
}
.ratio-btn.active {
  background: var(--primary);
  border-color: var(--primary);
}
.ratio-input { max-width: 90px; }

details.expense-details > summary {
  cursor: pointer;
  color: var(--muted);
  padding: 8px 0;
  list-style: none;
}
details.expense-details > summary::before {
  content: '▸ ';
  display: inline-block;
  transition: transform 0.15s;
}
details.expense-details[open] > summary::before { content: '▾ '; }

.big-emergency { text-align: center; padding: 8px 0; }
.huge {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.huge.deficit { color: var(--warn); }
.warn {
  color: var(--warn);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 8px 12px;
  border-radius: 10px;
  margin-top: 8px;
  display: inline-block;
}

.chart-block { display: flex; flex-direction: column; gap: 8px; }
.chart-block canvas { max-width: 100%; max-height: 220px; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.mini-table td { padding: 4px 0; }
.mini-table td:first-child { color: var(--muted); }
.mini-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; }
.cmp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.cmp-table th, .cmp-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}
.cmp-table th { color: var(--muted); font-weight: 500; text-align: right; }
.cmp-table th:first-child, .cmp-table td:first-child { text-align: left; }
.cmp-table tr.recommended {
  background: rgba(250, 204, 21, 0.08);
  outline: 1px solid rgba(250, 204, 21, 0.4);
}
.cmp-table tr.deficit td.emergency { color: var(--warn); }
.cmp-table tr.current td:first-child::before {
  content: '● ';
  color: var(--primary-2);
}

.history-chart { width: 100%; max-height: 200px; }
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.list li {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.list .ym { font-weight: 600; }
.list .meta { color: var(--muted); font-size: 12.5px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 600px) {
  .modal { align-items: center; }
}
.modal-card {
  background: var(--card);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}
@media (min-width: 600px) {
  .modal-card { border-radius: 16px; }
}

.invite-result input { font-size: 12px; }
.invite-result { display: flex; flex-direction: column; gap: 6px; }

.toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 200;
  pointer-events: none;
}

#syncStatus { transition: color 0.3s; }
#syncStatus.online { color: var(--good); }
#syncStatus.offline { color: var(--warn); }
#syncStatus.busy { color: var(--recommend); }

/* ---- 로그인 ---- */
.login-body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 12px 18px;
  text-decoration: none;
  font-size: 15px;
}
.g-logo {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  color: var(--primary);
  font-weight: 700;
}
