:root {
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e2ddd2;
  --field: #ffffff;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --warn: #a5610b;
  --bad: #b3261e;
  --ok: #2f6b4f;
  --switch-off: #e4e1d9;
  --press: rgb(0 0 0 / 0.05);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --card: #1f2227;
    --ink: #eceae4;
    --muted: #9a9ea6;
    --line: #2e3238;
    --field: #262a30;
    --accent: #6fbf95;
    --accent-ink: #10231a;
    --warn: #e0a24a;
    --bad: #f08a80;
    --ok: #6fbf95;
    --switch-off: #3a3e45;
    --press: rgb(255 255 255 / 0.06);
  }
}

* { box-sizing: border-box; }
html { touch-action: manipulation; } /* two quick taps (‹ › through the months) don't zoom the page on iOS; pinching still does */
[hidden] { display: none !important; } /* the display rules below would otherwise override it */

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  -webkit-tap-highlight-color: transparent;
}
html.sheet-open, html.sheet-open body { overflow: hidden; } /* the page doesn't scroll behind an open sheet */

main { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

h1 { font-size: 22px; margin: 0; flex: 1; }
h2 { font-size: 18px; margin: 0 0 8px; }

.bar {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
}

/* A page opened from the main screen: back on the left, its title in the middle */
.nav { display: grid; grid-template-columns: 1fr auto 1fr; min-height: 64px; }
.nav h1 { grid-column: 2; font-size: 17px; font-weight: 600; text-align: center; } /* centred even while back is hidden */
.back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 8px 0;
  background: none;
  color: var(--accent);
  font-size: 17px;
}
.back svg { width: 11px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

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

.muted { color: var(--muted); font-size: 14px; margin: 4px 0; }
.muted + .field { margin-top: 12px; }
.error { color: var(--bad); font-size: 14px; margin: 4px 0 10px; }
code { font-size: 13px; }

/* ---- Buttons ---- */

button, .icon-button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--line);
  text-decoration: none;
  font-size: 20px;
  line-height: 1;
}

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}
.pill[data-tone="ok"] { color: var(--ok); }
.pill[data-tone="warn"], .pill[data-tone="busy"] { color: var(--warn); }
.pill[data-tone="bad"] { color: var(--bad); }

.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.primary, .secondary { padding: 12px 18px; border-radius: 12px; font-weight: 600; }
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:disabled { opacity: 0.6; }
.secondary { background: transparent; border: 1px solid var(--line); }
.wide { display: block; width: 100%; margin-top: 6px; padding: 14px; font-size: 17px; }
.link { background: none; color: var(--accent); padding: 6px 0; font-size: 16px; }
.link.strong { font-weight: 600; }
.link:disabled { opacity: 0.5; }

/* ---- The form ---- */

.form-head, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; min-height: 30px; }
.form-head h2, .section-head h2 { margin: 0; }
.form-head .link { margin: -6px 0; } /* «Vaciar» appearing doesn't move the form */
.icon-button.add { width: 32px; height: 32px; font-size: 22px; color: var(--accent); }

.field { display: grid; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field label { display: grid; gap: 4px; min-width: 0; }
.field label > span { font-size: 13px; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input, select {
  font: inherit;
  font-size: 17px; /* 16px or more: iOS doesn't zoom into the field */
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  appearance: none;
  -webkit-appearance: none;
}
input[type="date"] { min-height: 46px; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; } /* iOS centres it */
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* «Gasto compartido»: an iOS switch */
.switch-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 10px;
  font-size: 16px;
  cursor: pointer;
}
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch { position: relative; flex: none; width: 51px; height: 31px; border-radius: 999px; background: var(--switch-off); transition: background 0.2s; }
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.2);
  transition: transform 0.2s;
}
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Suggestions ---- */

.suggest-host { position: relative; }
.suggest {
  position: absolute;
  z-index: 5;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
  max-height: 290px;
  overflow-y: auto;
}
.suggest li { padding: 9px 10px; border-radius: 8px; display: grid; cursor: pointer; }
.suggest li small { color: var(--muted); font-size: 13px; }
.suggest li .mark { display: inline-block; width: 1.3em; color: var(--accent); font-weight: 400; }
.suggest li:has(.mark) small { padding-left: 1.3em; } /* under the label, not under the mark */
.suggest li:hover, .suggest li.active { background: var(--bg); }

/* ---- The month ---- */

.summary { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; }
.summary span:first-child { flex: 1; color: var(--muted); }
.summary strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.chevron { color: var(--muted); font-size: 22px; line-height: 1; }
.summary:active, .tappable:active { background-color: var(--press); }

.month-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; text-align: center; gap: 8px; }
.total { font-size: 28px; font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; }

details { margin: 10px 0 4px; }
summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.categories { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.categories li {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 18%, transparent) calc(var(--share) * 100%), transparent 0);
}

.items { list-style: none; padding: 0; margin: 8px 0 0; }
.item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 12px;
  padding: 10px 6px;
  margin: 0 -6px;
  border-radius: 8px; /* for the pressed background */
}
/* The line between two items, straight and in line with the text, not following the rounded corners */
.item + .item::before { content: ""; position: absolute; top: 0; left: 6px; right: 6px; border-top: 1px solid var(--line); }
.item > div { display: grid; min-width: 0; }
.item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.item small { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amount { text-align: right; font-variant-numeric: tabular-nums; }
.item p { grid-column: 1 / -1; margin: 2px 0 0; font-size: 13px; }
.item.pending p { color: var(--warn); }
.item.failed p { color: var(--bad); }
.tappable { cursor: pointer; }

/* ---- Bottom sheets ---- */
/* They sit on the bottom of the visible part of the page (--vv-*, set in ui.js), so the keyboard doesn't cover them */

dialog.sheet {
  position: fixed;
  inset: auto 0 auto 0;
  top: calc(var(--vv-top, 0px) + var(--vv-height, 100dvh));
  transform: translateY(-100%);
  translate: 0 100%;
  transition: translate 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  width: 100%;
  max-width: 560px;
  max-height: calc(var(--vv-height, 100dvh) - 12px - env(safe-area-inset-top));
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 16px 16px 0 0;
  background: var(--card);
  color: var(--ink);
  overflow: hidden;
}
dialog.sheet.open { translate: 0 0; }
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.35); }

.sheet-body { display: flex; flex-direction: column; max-height: inherit; }
.sheet-head {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 18px 16px 10px;
  border-bottom: 1px solid var(--line);
  touch-action: none; /* dragged down to close */
}
.sheet-head h2 { margin: 0; font-size: 17px; outline: none; }
.sheet-head .link:first-of-type { justify-self: start; }
.sheet-head .link:last-of-type { justify-self: end; }
.grabber { position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--line); }
.sheet-content { overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }

.destructive {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border-radius: 12px;
  background: none;
  border: 1px solid var(--line);
  color: var(--bad);
  font-size: 17px;
}

/* The confirmation menu, as iOS asks before deleting */
dialog.action-sheet { background: none; border-radius: 0; }
.action-sheet .sheet-body { gap: 8px; padding: 0 8px calc(8px + env(safe-area-inset-bottom)); }
.action-sheet .group { display: grid; background: var(--card); border-radius: 14px; overflow: hidden; text-align: center; }
.confirm-title { margin: 14px 16px 2px; font-size: 13px; font-weight: 600; color: var(--muted); }
.confirm-message { margin: 0 16px 14px; font-size: 13px; color: var(--muted); }
.confirm-action { padding: 16px; border-top: 1px solid var(--line); background: none; color: var(--bad); font-size: 19px; }
.confirm-cancel { padding: 16px; font-size: 19px; font-weight: 600; color: var(--accent); outline: none; } /* it opens focused, without a ring */

/* ---- Toast ---- */

#toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 15px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.2);
}
