/* Jam — homemade software for two.
   Palette from the pantry: paper labels, damson ink, berry dots.
   Martin = bilberry, Johanna = raspberry, together = the split dot. */

@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces-latin.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f8f2e9;
  --card: #fffdf8;
  --ink: #362436;
  --muted: #8d7386;
  --line: rgba(54, 36, 54, 0.14);
  --line-soft: rgba(54, 36, 54, 0.08);
  --raspberry: #c23652;
  --bilberry: #4d58a3;
  --apricot: #b97d1e;
  --greengage: #587f4f;
  --accent: var(--raspberry);
  --accent-ink: #fffdf8;
  --good: var(--greengage);
  --danger: #a92e2e;
  --ai-bg: #e3ecfb;
  --ai-edge: #7d9bd8;
  --shadow: 0 1px 2px rgba(54, 36, 54, 0.05), 0 6px 24px -12px rgba(54, 36, 54, 0.25);
  --display: "Fraunces", ui-serif, Georgia, serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #221724;
    --card: #2e2130;
    --ink: #f4ebe3;
    --muted: #b096a9;
    --line: rgba(244, 235, 227, 0.16);
    --line-soft: rgba(244, 235, 227, 0.08);
    --raspberry: #e05a75;
    --bilberry: #99a3e0;
    --apricot: #e0aa58;
    --greengage: #97c089;
    --accent: #e05a75;
    --accent-ink: #2b1420;
    --danger: #e57373;
    --ai-bg: #2b3a55;
    --ai-edge: #5f7cb0;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 6px 24px -12px rgba(0, 0, 0, 0.5);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

a { color: inherit; }

/* ---- shell + topbar -------------------------------------------------- */

.shell {
  max-width: 620px;
  margin: 0 auto;
  padding: 16px 16px calc(48px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.topbar-side { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; }
.topbar-side:last-child { justify-content: flex-end; }

.topbar-title {
  flex: 2;
  text-align: center;
  font-family: var(--display);
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-back {
  text-decoration: none;
  font-size: 15px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
}
.topbar-back .icon { flex-shrink: 0; }
.topbar-back span { overflow: hidden; text-overflow: ellipsis; }

.topbar-action { color: var(--muted); }

.icon { width: 22px; height: 22px; vertical-align: -5px; }

/* ---- the dots -------------------------------------------------------- */

.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: baseline;
}
.dot-raspberry { background: var(--raspberry); }
.dot-bilberry { background: var(--bilberry); }
.dot-apricot { background: var(--apricot); }
.dot-greengage { background: var(--greengage); }
.dot-split { background: linear-gradient(90deg, var(--bilberry) 50%, var(--raspberry) 50%); }

/* ---- brand + login --------------------------------------------------- */

.brand-dots { display: inline-flex; gap: 3px; align-items: center; }
.brand-word { font-family: var(--display); font-weight: 700; }
.brand-word-small { font-family: var(--display); font-weight: 700; font-size: 20px; }
.brand-small { gap: 8px; }

.login-screen {
  min-height: 80dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 28px;
}

.login-brand { text-align: center; }
.login-brand .brand-word { font-size: 64px; line-height: 1.1; display: block; }
.login-brand .brand-dots .dot { width: 16px; height: 16px; }
.brand-tag { color: var(--muted); font-size: 15px; }

/* ---- home ------------------------------------------------------------ */

.greeting { padding: 12px 4px 0; }
.greeting-line { font-family: var(--display); font-size: 30px; font-weight: 600; line-height: 1.15; }
.greeting-date { color: var(--muted); margin-top: 4px; }

.launcher {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tile {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px 16px 14px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: transform 0.15s ease;
  animation: rise 0.4s 0.05s ease-out backwards;
}
.tile:nth-child(2) { animation-delay: 0.11s; }
.tile:nth-child(3) { animation-delay: 0.17s; }
.tile:nth-child(4) { animation-delay: 0.23s; }
.tile:active { transform: scale(0.97); }

.tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  background: var(--line-soft);
  color: var(--ink);
}
.tile-icon .icon { width: 24px; height: 24px; }
.tile-icon-spendings { background: color-mix(in srgb, var(--bilberry) 16%, transparent); color: var(--bilberry); }
.tile-icon-savings { background: color-mix(in srgb, var(--greengage) 18%, transparent); color: var(--greengage); }
.tile-icon-notes { background: color-mix(in srgb, var(--apricot) 18%, transparent); color: var(--apricot); }

.tile-name { font-family: var(--display); font-weight: 600; font-size: 18px; }
.tile-tag { color: var(--muted); font-size: 13px; }
.tile-scope {
  margin-top: 8px;
  align-self: flex-start;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 2px 8px;
}

.tile-ghost {
  border-style: dashed;
  border-color: var(--line);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}
.tile-ghost .tile-name { color: var(--muted); }

/* ---- cards + hero ---------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title { font-family: var(--display); font-size: 17px; font-weight: 600; }

.hero {
  position: relative;
  text-align: center;
  padding: 26px 18px 20px;
  gap: 6px;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--line);
  border-radius: 15px;
  pointer-events: none;
}

.hero-eyebrow {
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.hero-amount {
  font-family: var(--display);
  font-size: 44px;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.hero-good { color: var(--good); }

.hero-link {
  margin-top: 6px;
  font-size: 15px;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: center;
}
.hero-link .icon { width: 18px; height: 18px; }

.hero-chips { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 4px 12px;
}
.hero-foot { color: var(--muted); font-size: 13px; margin-top: 2px; }

.lead { color: var(--muted); padding: 0 4px; }

/* ---- forms ------------------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-pair { display: flex; gap: 10px; }

.input {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  width: 100%;
  min-height: 46px;
  appearance: none;
  -webkit-appearance: none;
}
.input::placeholder { color: var(--muted); opacity: 0.7; }
.input:focus { border-color: var(--accent); outline: none; }
.input-amount { font-variant-numeric: tabular-nums; }
input[type="date"].input { min-width: 0; }

.seg { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 8px;
  font-size: 15px;
  cursor: pointer;
  background: var(--paper);
  color: var(--muted);
  border-left: 1px solid var(--line);
}
.seg label:first-of-type { border-left: none; }
.seg input:checked + label { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.seg input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg-stack { flex-direction: column; }
.seg-stack label { border-left: none; border-top: 1px solid var(--line); }
.seg-stack label:first-of-type { border-top: none; }

.toggle { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 2px 2px; }
.toggle input { position: absolute; opacity: 0; }
.toggle-box {
  width: 24px; height: 24px;
  flex-shrink: 0;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  position: relative;
  margin-top: 1px;
}
.toggle input:checked + .toggle-box { background: var(--apricot); border-color: var(--apricot); }
.toggle input:checked + .toggle-box::after {
  content: "";
  position: absolute;
  left: 8px; top: 4px;
  width: 5px; height: 10px;
  border: solid var(--card);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.toggle input:focus-visible + .toggle-box { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-text { font-size: 14px; color: var(--muted); }
.toggle-text strong { color: var(--ink); font-weight: 600; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 18px;
  min-height: 48px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn .icon { width: 19px; height: 19px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn-quiet { background: transparent; }
.btn-block { width: 100%; }
.btn-small { min-height: 34px; padding: 5px 12px; font-size: 13px; border-radius: 9px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row form { display: contents; }

.inline-form { flex-direction: row; align-items: center; }
.inline-form .input { flex: 1; }

/* ---- ledger / entry lists --------------------------------------------- */

.ledger { display: flex; flex-direction: column; gap: 8px; }

.ledger-month {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--display);
  font-size: 16px;
  font-weight: 600;
  padding: 6px 6px 0;
}
.ledger-total { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; font-family: var(--body); }

.ledger-breakdown {
  display: flex;
  gap: 14px;
  padding: 0 6px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ledger-breakdown span { display: inline-flex; align-items: center; gap: 5px; }
.ledger-breakdown .dot { width: 9px; height: 9px; }

.entries {
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.entries > li + li { border-top: 1px solid var(--line-soft); }
.entries-cardlist { background: transparent; border: none; box-shadow: none; border-radius: 0; display: flex; flex-direction: column; gap: 10px; }
.entries-cardlist > li { border: none !important; }
.entries-cardlist .entry { background: var(--card); border: 1px solid var(--line-soft); border-radius: 16px; box-shadow: var(--shadow); }

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  text-decoration: none;
  min-height: 56px;
}
a.entry:active { background: var(--line-soft); }
.entry > .dot { margin-top: 1px; }
.entry-swap { color: var(--muted); display: flex; }
.entry-swap .icon { width: 18px; height: 18px; }
.entry-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.entry-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.entry-amount-good { color: var(--good); }
.entry-settle .entry-title { color: var(--muted); font-style: italic; }
.entry > .icon-chevron { color: var(--muted); width: 18px; height: 18px; flex-shrink: 0; }
.entry-static { cursor: default; }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }

/* ---- members / settings ----------------------------------------------- */

.member-row { display: flex; align-items: center; gap: 10px; }
.member-name { font-weight: 500; }
.member-sub { color: var(--muted); font-size: 14px; }
.signout { margin-top: 4px; }
.footnote { text-align: center; color: var(--muted); font-size: 13px; padding: 0 12px; }
.footnote a { color: var(--accent); }

/* ---- notes: rendering, AI highlights, editor --------------------------- */

.note-card { gap: 8px; }
.note-meta { color: var(--muted); font-size: 13px; border-top: 1px solid var(--line-soft); padding-top: 10px; }

.md-render { display: flex; flex-direction: column; gap: 4px; overflow-wrap: break-word; }
.md-render h1, .md-render h2, .md-render h3 { font-family: var(--display); line-height: 1.25; margin: 10px 0 2px; }
.md-render h1 { font-size: 24px; }
.md-render h2 { font-size: 20px; }
.md-render h3 { font-size: 17px; }
.md-render p, .md-render ul, .md-render ol { margin: 4px 0; }
.md-render ul, .md-render ol { padding-left: 22px; }
.md-render li { margin: 2px 0; }
.md-render code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.9em; background: var(--line-soft); border-radius: 5px; padding: 1px 5px; }
.md-render pre { background: var(--line-soft); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md-render pre code { background: none; padding: 0; }
.md-render blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--muted); margin: 6px 0; }
.md-render a { color: var(--accent); }
.md-render hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }
.md-render table { border-collapse: collapse; font-size: 14px; }
.md-render th, .md-render td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md-render img { max-width: 100%; border-radius: 10px; }

.ai-block {
  background: var(--ai-bg);
  border-left: 3px solid var(--ai-edge);
  border-radius: 0 10px 10px 0;
  padding: 6px 10px;
  margin: 4px 0;
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ai-edge);
  background: var(--ai-bg);
  border-radius: 99px;
  padding: 1px 8px;
  vertical-align: 2px;
}
.ai-badge .icon { width: 12px; height: 12px; }

.editor { display: flex; flex-direction: column; gap: 10px; }
.input-title { font-family: var(--display); font-weight: 600; font-size: 19px; }
.editor-tabs { display: flex; gap: 4px; padding: 0 2px; }
.editor-tab {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 10px;
  cursor: pointer;
}
.editor-tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }
.editor-body {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 15px;
  line-height: 1.55;
  min-height: 44dvh;
  resize: vertical;
}
.editor-preview { background: var(--card); border: 1px solid var(--line-soft); border-radius: 16px; padding: 16px; min-height: 44dvh; }
.editor-hint { font-size: 12px; color: var(--muted); padding: 0 4px; }
.editor-hint code { background: var(--line-soft); border-radius: 4px; padding: 0 4px; }

.card-token { border-color: color-mix(in srgb, var(--apricot) 50%, transparent); }
.token {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}
.key-id { color: var(--muted); font-size: 13px; font-weight: 400; }

.docs { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; line-height: 1.55; white-space: pre-wrap; overflow-x: auto; }

/* ---- toasts ------------------------------------------------------------ */

.toasts {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
}
.toast {
  margin: 0 auto;
  max-width: 480px;
  background: var(--ink);
  color: var(--paper);
  font-size: 15px;
  border-radius: 13px;
  padding: 12px 18px;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease-out backwards;
  transition: opacity 0.4s ease;
}
.toast.is-leaving { opacity: 0; }

/* ---- misc -------------------------------------------------------------- */

.folder-settings summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.folder-settings[open] summary { margin-bottom: 4px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (min-width: 480px) {
  .greeting-line { font-size: 34px; }
  .launcher { grid-template-columns: 1fr 1fr; }
}
