* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
:root {
  --bg: #0e1116;
  --card: #171b23;
  --card2: #1e2430;
  --line: #262d3a;
  --text: #e8ecf3;
  --muted: #8b95a7;
  --accent: #5b9cff;
  --green: #43c478;
  --red: #ef5b64;
  --amber: #e8b24a;
}
html { color-scheme: dark; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select { font: inherit; color: inherit; }

header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: rgba(14,17,22,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; }
.month-controls { display: flex; gap: 8px; align-items: center; }
#monthSelect {
  background: var(--card2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; outline: none;
}
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
#avatars { display: flex; gap: 6px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--card2);
  font-size: 13px; font-weight: 700; color: var(--muted); cursor: default;
}
.avatar.me { border-color: var(--accent); color: var(--accent); cursor: pointer; }
.avatar.online::after {
  content: ''; position: absolute; right: -2px; bottom: -2px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--bg);
}

.ghost {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px;
  color: var(--muted); transition: .15s;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }
.ghost.wide { display: block; width: 100%; padding: 12px; margin-top: 4px; }
.primary {
  background: var(--accent); color: #fff; border-radius: 8px; padding: 9px 14px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.1); }

.user-menu { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  min-width: 170px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.dropdown button { display: block; width: 100%; text-align: left; padding: 10px 14px; }
.dropdown button:hover { background: var(--card); }

main { max-width: 760px; margin: 0 auto; padding: 16px 12px 150px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 14px;
}

/* summary — pinned to the bottom */
.summary {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  z-index: 20;
  width: min(760px, 100%);
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px;
  margin-bottom: 0;
  border-radius: 14px 14px 0 0;
  border-bottom: 0;
  background: rgba(23,27,35,.94); backdrop-filter: blur(10px);
  box-shadow: 0 -10px 30px rgba(0,0,0,.45);
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
.stat { padding: 6px 4px; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.stat .formula { font-size: 11px; color: var(--muted); }
.stat.rest-pos .value { color: var(--green); }
.stat.rest-neg .value { color: var(--red); }
.stat input {
  width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 8px; font-size: 20px; font-weight: 700; outline: none;
}
.stat input:focus { border-color: var(--accent); }

/* groups */
.group-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px;
}
.group-name {
  background: none; border: 0; outline: none; font-size: 16px; font-weight: 700;
  color: var(--accent); max-width: 60%; padding: 2px 0;
}
.group-sub { margin-left: auto; font-weight: 600; color: var(--muted); font-size: 14px; }
.group-del {
  width: 20px; height: 20px; flex: none; align-self: center;
  border: 1px solid var(--line); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; line-height: 1;
  opacity: 0; transition: .15s;
}
.card:hover .group-del { opacity: .7; }
.group-del:hover { color: var(--red); border-color: var(--red); opacity: 1; }

.bill {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid transparent;
}
.bill + .bill { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 3px; }
.bill-title {
  flex: 1; min-width: 0; text-align: left; padding: 4px 2px; border-radius: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bill-title:hover { color: var(--accent); }
.bill-title.empty { color: var(--muted); font-style: italic; }
.bill-amount:focus { background: var(--card2); }
.amount-wrap {
  flex: none; display: flex; align-items: center; justify-content: flex-end;
  min-width: 76px;
}
.amount-wrap .cur { color: var(--muted); font-size: 13px; }
.bill-amount {
  text-align: right; background: none; border: 0; outline: none;
  padding: 4px 4px 4px 1px; border-radius: 6px; font-variant-numeric: tabular-nums;
  appearance: textfield;
}
.bill-amount::-webkit-inner-spin-button, .bill-amount::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.paid-pill {
  flex: none; margin-left: auto; border: 1px solid var(--line); border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  height: 20px; padding: 0 9px; line-height: 1;
  font-size: 9px; font-weight: 700; letter-spacing: .06em; text-indent: .06em;
  color: var(--muted); opacity: .4; transition: .15s;
}
.paid-pill:hover { opacity: .8; }
.paid-pill.on {
  opacity: 1; color: var(--red); border-color: var(--red);
}
.link-btn {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  border: 1px solid var(--line); color: var(--muted); font-size: 13px;
  opacity: .4; transition: .15s;
}
.link-btn:hover { opacity: .8; }
.link-btn.set { color: var(--accent); border-color: var(--accent); opacity: 1; }
.link-btn.set:hover { background: var(--accent); color: #fff; }
.mlabel {
  display: block; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; margin: 2px 2px 5px;
}
.add-bill { color: var(--muted); font-size: 13px; padding: 8px 2px 2px; }
.add-bill:hover { color: var(--accent); }

/* overlays */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8,10,14,.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.login-card, .modal-card { width: 100%; max-width: 360px; }
.login-card { text-align: center; padding: 28px 24px; }
.login-card h1 { font-size: 26px; margin-bottom: 4px; }
.muted { color: var(--muted); }
.user-pick { display: flex; gap: 10px; margin: 18px 0 12px; }
.user-pick button {
  flex: 1; padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card2); font-weight: 600; transition: .15s;
}
.user-pick button.selected { border-color: var(--accent); background: rgba(91,156,255,.15); color: var(--accent); }
.login-card input, .modal-card input {
  width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; outline: none; margin-bottom: 12px;
}
.login-card input:focus, .modal-card input:focus { border-color: var(--accent); }
.login-card .primary { width: 100%; }
.error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 1em; }
.modal-card h2 { font-size: 17px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.modal-actions .danger { color: var(--red); border-color: rgba(239,91,100,.4); }
.modal-actions .danger:hover { border-color: var(--red); }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 18px; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}

@media (max-width: 480px) {
  header { flex-wrap: wrap; }
  .nm-text { display: none; }
  #newMonthBtn { width: 32px; padding: 6px 0; text-align: center; }
  main { padding-bottom: 210px; }
  .summary { gap: 4px 10px; padding-top: 10px; }
  .brand { font-size: 15px; }
  .stat .value { font-size: 18px; }
  .amount-wrap { min-width: 62px; }
  .group-del { opacity: .5; }
}
