/* Laskut design tokens. Neutral palette only: black, white and greys. */
:root {
  --bg: #ffffff;
  --surface: #f2f2f2;
  --surface-2: #e4e4e4;
  --text: #000000;
  --text-2: #6b6b6b;
  --line: #e3e3e3;
  --primary: #000000;
  --on-primary: #ffffff;
  --overlay: rgba(0, 0, 0, .4);
  --r: 12px;
  --tap: 48px;
  --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1a1a1a;
    --surface-2: #2a2a2a;
    --text: #ffffff;
    --text-2: #9a9a9a;
    --line: #262626;
    --primary: #ffffff;
    --on-primary: #000000;
    --overlay: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); color: var(--text); }
body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
svg { display: block; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: minmax(72px, auto) 1fr minmax(72px, auto); align-items: center;
  height: calc(56px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { grid-column: 2; text-align: center; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.topbar .action {
  justify-self: end;
  height: 44px; padding: 0 16px;
  font-size: 17px; font-weight: 500; color: var(--text);
  border-radius: var(--r);
}
.topbar .action:active { background: var(--surface); }
.topbar .action[hidden] { display: none; }
.topbar #sel-cancel, .topbar #menu-btn { grid-column: 1; justify-self: start; }
.iconbtn { width: 44px; height: 44px; margin-left: 6px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text); }
.iconbtn:active { background: var(--surface); }
.iconbtn svg { width: 24px; height: 24px; }
.iconbtn[hidden] { display: none; }
.topbar #edit-toggle, .topbar #sel-all { grid-column: 3; }
.topbar h1 { grid-column: 2; }

/* ---------- Content ---------- */
main {
  flex: 1; width: 100%; max-width: 560px; margin: 0 auto;
  padding: 16px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
}
.stack > * + * { margin-top: 16px; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.tabbar ul { list-style: none; display: flex; max-width: 560px; margin: 0 auto; height: var(--tab-h); }
.tabbar li { flex: 1; }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  height: 100%; color: var(--text-2); text-decoration: none; font-size: 12px; font-weight: 500;
}
.tabbar .pill {
  display: flex; align-items: center; justify-content: center;
  width: 56px; height: 32px; border-radius: 16px;
  transition: background .15s;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--text); font-weight: 600; }
.tabbar a.active .pill { background: var(--primary); color: var(--on-primary); }

/* ---------- Buttons: one height, two tones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--tap); padding: 0 20px;
  border-radius: var(--r);
  background: var(--primary); color: var(--on-primary);
  font-size: 16px; font-weight: 600; white-space: nowrap;
  transition: opacity .1s, transform .1s;
  user-select: none;
}
.btn:active { opacity: .8; transform: scale(.98); }
.btn:disabled { opacity: .35; pointer-events: none; }
.btn.tonal { background: var(--surface); color: var(--text); }
.btn.icon { width: var(--tap); padding: 0; flex: none; }
.btn svg { width: 24px; height: 24px; }
.btn.block { width: 100%; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Fields ---------- */
.field {
  display: block; width: 100%; min-width: 0;
  height: var(--tap); padding: 0 14px;
  border: 0; border-radius: var(--r);
  background: var(--surface); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
.field::placeholder { color: var(--text-2); }
.field:focus { outline: 2px solid var(--primary); outline-offset: -2px; }
.field[type=date] { line-height: var(--tap); }
select.field {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 20px;
}
label.lbl { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.inline-add { display: flex; gap: 8px; }
.inline-add .field { flex: 1; }

/* ---------- Summary card ---------- */
.card { background: var(--surface); border-radius: var(--r); padding: 16px; }
.summary { background: var(--primary); color: var(--on-primary); padding: 8px 8px 16px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.navbtn { width: var(--tap); height: var(--tap); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--on-primary); flex: none; }
.navbtn svg { width: 24px; height: 24px; }
.navbtn:active { background: rgba(128, 128, 128, .35); }
.month-name { text-align: center; min-width: 0; }
.month-name .label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; opacity: .7; height: 18px; }
.month-name .label button { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.month-name .month { font-size: 22px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; }
.summary .big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 6px 8px 12px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.summary .big small { font-size: 13px; font-weight: 500; opacity: .7; letter-spacing: 0; }
.summary .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 8px; border-top: 1px solid rgba(128, 128, 128, .4); padding-top: 12px; }
.summary .stats span { display: block; font-size: 12px; opacity: .7; }
.summary .stats b { display: block; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.summary .stats small { display: block; font-size: 12px; opacity: .7; }

.subsection { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 18px 4px 4px; }
.subsection .who { font-size: 16px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.subsection .who i { display: inline-flex; width: 18px; height: 18px; border-radius: 50%; background: var(--primary); color: var(--on-primary); align-items: center; justify-content: center; }
.subsection .who i svg { width: 12px; height: 12px; }
.subsection .sec-count { font-weight: 500; }
.subsection.all-paid .who { color: var(--text-2); }
.selecting .subsection { cursor: pointer; }

/* ---------- Lists ---------- */
.section { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 16px 0 4px; }
.sec-title {
  height: 30px; padding: 0 12px; margin-left: -12px; border-radius: 15px;
  font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-2);
  display: inline-flex; align-items: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
button.sec-title:active { background: var(--surface); }
.sec-title.on { background: var(--primary); color: var(--on-primary); }
.sec-count { font-size: 13px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.list { list-style: none; }
li.section { list-style: none; }
.section.tappable { cursor: pointer; }
.section .chev { width: 16px; height: 16px; align-self: center; }
.row-empty { padding: 12px 4px; font-size: 14px; color: var(--text-2); border-bottom: 1px solid var(--line); }
.rowbtn { flex: none; width: 40px; height: 40px; margin-right: -8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-2); }
.rowbtn svg { width: 20px; height: 20px; }
.rowbtn:active { background: var(--surface-2); color: var(--text); }
.section { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.row {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  border-radius: var(--r);
  transition: background .12s;
}
.row.selected { background: var(--surface); }
.selecting .row { border-bottom-color: transparent; padding-left: 8px; padding-right: 12px; margin: 0 -4px; }
.selecting .row + .row { margin-top: 2px; }
.row .body { flex: 1; min-width: 0; }
.row .title { font-size: 16px; font-weight: 500; overflow-wrap: anywhere; transition: opacity .15s; }
.row .sub { font-size: 13px; color: var(--text-2); margin-top: 1px; }
.row .sub.alert { color: var(--text); font-weight: 600; }
.row .amount { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.row.done .title, .row.done .amount { opacity: .45; text-decoration: line-through; }
.row.done .sub { opacity: .6; }
.check {
  flex: none; width: var(--tap); height: var(--tap); display: flex; align-items: center; justify-content: center;
  margin-left: -12px; border-radius: 50%;
}
.check i {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--text-2); color: var(--on-primary);
  transition: background .12s, border-color .12s;
}
.check svg { width: 16px; height: 16px; opacity: 0; transition: opacity .12s; }
.check.on i { background: var(--primary); border-color: var(--primary); }
.check.on svg { opacity: 1; }
.chev { flex: none; color: var(--text-2); width: 20px; height: 20px; }

.empty { text-align: center; padding: 56px 16px; color: var(--text-2); }
.empty svg { width: 40px; height: 40px; margin: 0 auto 12px; stroke: var(--text-2); }
.empty b { display: block; color: var(--text); font-weight: 600; margin-bottom: 4px; }
.empty p { font-size: 14px; }

/* ---------- Dialog / sheet ---------- */
.scrim { position: fixed; inset: 0; z-index: 20; background: var(--overlay); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
.scrim.bottom { align-items: flex-end; padding: 0; }
.dialog { width: 100%; max-width: 320px; background: var(--bg); border-radius: 16px; padding: 20px; animation: pop .15s; }
.dialog h2 { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.dialog p { font-size: 15px; color: var(--text-2); margin-bottom: 20px; }
.sheet {
  width: 100%; max-width: 560px; background: var(--bg);
  border-radius: 16px 16px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  animation: rise .2s;
}
.sheet .handle { width: 36px; height: 4px; border-radius: 2px; background: var(--surface-2); margin: 0 auto 12px; }
.sheet h2 { font-size: 17px; font-weight: 600; }
.sheet .btn-row { margin-top: 20px; }
.sheet .danger { margin-top: 8px; }
@keyframes fade { from { opacity: 0 } }
@keyframes pop { from { transform: scale(.96); opacity: 0 } }
@keyframes rise { from { transform: translateY(24px); opacity: 0 } }

/* ---------- Selection action bar ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
  animation: rise .15s;
}
.actionbar .btn-row { max-width: 528px; margin: 0 auto; }
.actionbar[hidden] { display: none; }

/* ---------- Drawer ---------- */
.scrim[hidden] { display: none; }
.scrim.left { align-items: stretch; justify-content: flex-start; padding: 0; }
.drawer {
  width: min(300px, 85vw); height: 100%; background: var(--bg);
  padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 4px;
  animation: slide .2s;
}
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 8px 12px 20px; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.drawer-head .mark { width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; justify-content: center; }
.drawer-head .mark svg { width: 20px; height: 20px; }
.drawer a { display: flex; align-items: center; gap: 14px; height: var(--tap); padding: 0 16px; border-radius: 24px; color: var(--text); text-decoration: none; font-weight: 500; }
.drawer a svg { width: 22px; height: 22px; }
.drawer a.active { background: var(--primary); color: var(--on-primary); font-weight: 600; }
.drawer a:active { background: var(--surface); color: var(--text); }
@keyframes slide { from { transform: translateX(-24px); opacity: 0 } }

/* ---------- Settings ---------- */
.group-label { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-2); padding: 8px 4px 0; }
.stack > .settings { margin-top: 8px; }
.settings { list-style: none; background: var(--surface); border-radius: var(--r); padding: 0 16px; }
.settings li + li { border-top: 1px solid var(--surface-2); }
.settings label { display: flex; align-items: center; gap: 16px; min-height: 64px; padding: 12px 0; cursor: pointer; }
.settings .body { flex: 1; }
.settings .title { display: block; font-weight: 500; }
.settings .sub { display: block; font-size: 13px; color: var(--text-2); margin-top: 2px; }
.switch {
  flex: none; appearance: none; -webkit-appearance: none; margin: 0;
  width: 52px; height: 32px; border-radius: 16px; position: relative;
  background: var(--surface-2); transition: background .15s; cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--bg); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(20px); background: var(--on-primary); }
.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.note { font-size: 13px; color: var(--text-2); padding: 0 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 15;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
  max-width: 528px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap); padding: 0 8px 0 16px;
  border-radius: var(--r); background: var(--primary); color: var(--on-primary);
  font-size: 15px; animation: rise .2s;
}
.toast span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button { height: 40px; padding: 0 12px; border-radius: 8px; font-weight: 600; color: var(--on-primary); }
.toast button:active { background: rgba(128, 128, 128, .3); }

/* ---------- Login ---------- */
.login { max-width: 320px; margin: 48px auto 0; text-align: center; }
.login .mark { width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 18px; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; justify-content: center; }
.login .mark svg { width: 36px; height: 36px; }
.login h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.login p { color: var(--text-2); margin: 4px 0 28px; }
.login form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.login .error { font-size: 14px; padding: 12px 14px; border-radius: var(--r); background: var(--surface); }
