:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #15181d;
  --text-dim: #6b7280;
  --border: #e4e6eb;
  --primary: #14b8a6;
  --primary-dark: #0d9488;
  --primary-soft: #d6f5f0;
  --positive: #16a34a;
  --negative: #dc2626;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #21252d;
    --text: #e7e9ee;
    --text-dim: #9aa1ad;
    --border: #2a2f38;
    --primary: #2dd4bf;
    --primary-dark: #14b8a6;
    --primary-soft: #14342f;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

#app { min-height: 100dvh; }

/* ---------------------------------------------------------------- splash */
.splash {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.splash-logo { font-size: 64px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- layout */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
}
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.appbar h1 { font-size: 19px; margin: 0; font-weight: 700; flex: 1; }
.appbar .sub { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.icon-btn {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 12px;
  font-size: 18px;
  display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.92); }

.content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--safe-bottom) + 96px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card.tap { cursor: pointer; transition: transform .08s; }
.card.tap:active { transform: scale(.985); }

.list { display: flex; flex-direction: column; gap: 10px; }

.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }
.row .ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  font-size: 15px;
}
.emoji-tile {
  width: 46px; height: 46px;
  border-radius: 14px;
  background: var(--primary-soft);
  display: grid; place-items: center;
  font-size: 24px;
  flex-shrink: 0;
}

.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.bold { font-weight: 700; }
.tabular { font-variant-numeric: tabular-nums; }
.pos { color: var(--positive); }
.neg { color: var(--negative); }
.center { text-align: center; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

h2.section { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin: 6px 4px 0; }

/* ----------------------------------------------------------------- inputs */
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-dim); }
input, select, textarea, .input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

.btn {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  background: var(--primary);
  color: #04201c;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--negative); box-shadow: inset 0 0 0 1px var(--border); }
.btn.sm { padding: 9px 12px; font-size: 14px; width: auto; border-radius: 11px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.chip.on { background: var(--primary); color: #04201c; border-color: transparent; }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }

/* fixed bottom action bar (e.g. add expense) */
.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 18px);
  z-index: 30;
  width: min(608px, calc(100% - 32px));
}

.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.segmented button {
  flex: 1; border: none; background: transparent; color: var(--text-dim);
  font: inherit; font-weight: 600; padding: 9px; border-radius: 9px; cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ----------------------------------------------------------------- charts */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 130px; padding-top: 8px; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; justify-content: flex-end; height: 100%; }
.bars .bar { width: 100%; max-width: 28px; background: var(--primary); border-radius: 6px 6px 2px 2px; min-height: 3px; transition: height .3s; }
.bars .bar-lbl { font-size: 10px; color: var(--text-dim); }

.breakdown-row { display: flex; align-items: center; gap: 10px; }
.breakdown-bar { flex: 1; height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.breakdown-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 6px; }

/* ------------------------------------------------------------------ misc */
.empty { text-align: center; color: var(--text-dim); padding: 40px 16px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }

.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 90px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  z-index: 100;
  box-shadow: var(--shadow);
  max-width: 90%;
  text-align: center;
}

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  background: var(--surface);
  width: 100%; max-width: 640px;
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(var(--safe-bottom) + 20px);
  max-height: 88dvh; overflow-y: auto;
  animation: slideup .22s cubic-bezier(.2,.8,.2,1);
}
.sheet .grab { width: 40px; height: 4px; border-radius: 3px; background: var(--border); margin: 8px auto 14px; }
@keyframes fade { from { opacity: 0 } }
@keyframes slideup { from { transform: translateY(40px); opacity: .6 } }

.divider { height: 1px; background: var(--border); margin: 4px 0; border: none; }

.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-dim); }
.badge.you { background: var(--primary-soft); color: var(--primary-dark); }

a { color: var(--primary-dark); }

.link-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: 12px; padding: 10px 12px;
  font-size: 13px; word-break: break-all;
}
