:root {
  --bg: #0b0d10;
  --bg-elev: #15191f;
  --bg-elev-2: #1c2129;
  --border: #242a33;
  --text: #e7ecf2;
  --text-dim: #97a2b0;
  --muted: #6b7484;
  --accent: #6ea8ff;
  --accent-strong: #4a8cff;
  --danger: #ff6b6b;
  --success: #5fd38c;
  --radius: 14px;
  --radius-lg: 22px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --bg-elev: #ffffff;
    --bg-elev-2: #ffffff;
    --border: #e6e8ec;
    --text: #11161d;
    --text-dim: #4d5663;
    --muted: #8a93a1;
    --accent: #2563eb;
    --accent-strong: #1d4ed8;
    --shadow: 0 8px 24px rgba(15,23,42,.08);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 120px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 16px;
}
.topbar h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.icon-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg-elev-2); }

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.summary-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 78px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.summary-card .label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.summary-card .value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.summary-card .sublabel {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}

.sub-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: transform .08s ease, background .15s;
}
.sub-item:active { transform: scale(0.995); }
.sub-item:hover { background: var(--bg-elev-2); }

.sub-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.sub-main { min-width: 0; }
.sub-name {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub-meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-cost {
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}
.sub-cost .cycle {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.due-soon { color: var(--accent); }
.due-today { color: var(--danger); }

.empty {
  text-align: center;
  color: var(--text-dim);
  margin-top: 60px;
}
.empty .muted { color: var(--muted); font-size: 14px; }

.fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s, background .15s;
  z-index: 5;
}
.fab:hover { background: var(--accent-strong); }
.fab:active { transform: scale(0.94); }

/* Sheet (modal) */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn .2s ease;
}
.sheet[hidden] { display: none; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
}
.sheet-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: var(--bg-elev);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  border: 1px solid var(--border);
  border-bottom: none;
  animation: slideUp .25s ease;
  max-height: 90vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-card {
    border-radius: var(--radius-lg);
    border-bottom: 1px solid var(--border);
    padding: 16px 22px 22px;
  }
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 6px auto 12px;
}
.sheet-card h2 {
  margin: 4px 0 14px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.choice {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  margin-bottom: 10px;
  transition: background .15s;
}
.choice:hover { background: var(--border); }
.choice-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg-elev);
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}
.choice-text { display: flex; flex-direction: column; min-width: 0; }
.choice-title { font-weight: 600; font-size: 15px; }
.choice-sub { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

/* Form */
form { display: flex; flex-direction: column; gap: 12px; }
form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
form input, form select, form textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
form input:focus, form select:focus, form textarea:focus {
  border-color: var(--accent);
}
form textarea { resize: vertical; min-height: 60px; }

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
  flex-wrap: wrap;
}

.text-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
}
.text-btn:hover { background: var(--bg-elev-2); }
.text-btn.danger { color: var(--danger); }

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
}
.primary-btn:hover { background: var(--accent-strong); }

.toast {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 20;
  box-shadow: var(--shadow);
  animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
