/* Marden app styles. Black, white, and grays only (BRIEF.md Section 7). */

@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-var-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --black: #000000;
  --ink: #111111;
  --gray-700: #3d3d3d;
  --gray-600: #555555;
  --gray-400: #8a8a8a;
  --gray-200: #d9d9d9;
  --gray-100: #f2f2f2;
  --white: #ffffff;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
  --tabbar-h: 64px;
  --sidebar-w: 248px;
  --header-bg: rgba(255, 255, 255, 0.94);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

/* Dark mode: the same black-and-white system, flipped. "Auto" follows the device;
   Settings can force light or dark (data-theme on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --black: #ffffff;
    --ink: #f2f2f2;
    --gray-700: #d4d4d4;
    --gray-600: #b3b3b3;
    --gray-400: #7a7a7a;
    --gray-200: #2f2f2f;
    --gray-100: #0d0d0d;
    --white: #171717;
    --header-bg: rgba(23, 23, 23, 0.94);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --black: #ffffff;
  --ink: #f2f2f2;
  --gray-700: #d4d4d4;
  --gray-600: #b3b3b3;
  --gray-400: #7a7a7a;
  --gray-200: #2f2f2f;
  --gray-100: #0d0d0d;
  --white: #171717;
  --header-bg: rgba(23, 23, 23, 0.94);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--gray-100);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }
p { margin: 0 0 0.75em; }
a { color: var(--ink); text-underline-offset: 3px; }

:focus-visible { outline: 3px solid var(--black); outline-offset: 2px; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -100px; z-index: 100;
  padding: 10px 14px; background: var(--black); color: var(--white); font-weight: 700;
}
.skip-link:focus { top: 12px; }

.noscript { margin: 24px; padding: 16px; border: 2px solid var(--black); border-radius: var(--radius); background: var(--white); }

/* ---------- Header and tabs ---------- */

.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--gray-200);
}

.wordmark {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 1.25rem; font-weight: 800; letter-spacing: -0.04em; text-decoration: none; color: var(--black);
}

.logo-mark { width: 28px; height: 28px; flex-shrink: 0; }
/* The logo follows the theme: a dark tile with a light receipt, flipped in dark mode. */
.lm-tile { fill: var(--black); }
.lm-paper { fill: var(--white); }
.lm-lines { stroke: var(--black); }

.version-tag {
  padding: 3px 10px; border: 1.5px solid var(--black); border-radius: 999px;
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 6px 4px env(safe-area-inset-bottom);
  background: var(--white);
  border-top: 1px solid var(--gray-200);
}

.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0; border-radius: 10px; color: var(--gray-600); text-decoration: none; font-weight: 600;
  /* Capped like a phone's own tab bar, so very large text settings can't push tabs off screen. */
  font-size: clamp(11px, 0.6875rem, 13px);
}
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabbar svg {
  width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}

.tabbar a[aria-current="page"] { color: var(--black); font-weight: 800; }
.tabbar a[aria-current="page"] svg { stroke-width: 2.4; }

@media (min-width: 900px) {
  body { padding-bottom: 48px; }

  .tabbar {
    position: sticky; top: 59px; height: auto; justify-content: center; gap: 4px;
    padding: 8px 16px; border-top: 0; border-bottom: 1px solid var(--gray-200);
  }

  .tabbar a {
    flex: none; flex-direction: row; gap: 8px; padding: 8px 14px; font-size: 0.9375rem; border-radius: 999px;
  }

  .tabbar svg { width: 20px; height: 20px; }
  .tabbar a:hover { background: var(--gray-100); color: var(--black); }
  .tabbar a[aria-current="page"] { background: var(--black); color: var(--white); }
}

.app-main {
  width: 100%; max-width: 760px; margin: 0 auto; padding: 16px;
  display: flex; flex-direction: column; gap: 16px;
}

.shortcut-hint { display: none; }

@media (min-width: 1024px) {
  body { padding-left: var(--sidebar-w); }

  .app-header {
    position: fixed; left: 0; top: 0; width: var(--sidebar-w); z-index: 30;
    flex-direction: column; align-items: flex-start; gap: 10px;
    padding: 26px 22px 18px; border-bottom: 0; border-right: 1px solid var(--gray-200);
    background: var(--white); backdrop-filter: none;
  }
  .wordmark { font-size: 1.5rem; }
  .logo-mark { width: 32px; height: 32px; }

  .tabbar {
    position: fixed; left: 0; top: 118px; bottom: 0; width: var(--sidebar-w); height: auto; z-index: 30;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 8px 14px 18px; border: 0; border-right: 1px solid var(--gray-200); background: var(--white);
  }
  .tabbar a {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 11px 14px; font-size: 0.9375rem; border-radius: 10px;
  }
  .tabbar svg { width: 20px; height: 20px; }
  .tabbar a:hover { background: var(--gray-100); color: var(--black); }
  .tabbar a[aria-current="page"] { background: var(--black); color: var(--white); }

  .shortcut-hint {
    display: block; margin-top: auto; padding: 14px; border-radius: 10px; background: var(--gray-100);
    font-size: 0.8125rem; color: var(--gray-600); line-height: 1.7;
  }
  .shortcut-hint kbd { margin-right: 4px; }

  .app-main { max-width: 1120px; padding: 36px 40px; gap: 20px; }
  .toast { bottom: 28px; left: calc(50% + var(--sidebar-w) / 2); }
}

kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 6px; border: 1px solid var(--gray-400); border-bottom-width: 2px;
  border-radius: 5px; background: var(--white); font: inherit; font-size: 0.75rem; font-weight: 700; text-align: center; color: var(--ink);
}
.app-main:focus { outline: none; }

/* ---------- Panels ---------- */

.panel {
  padding: 20px; border: 1px solid var(--gray-200); border-radius: var(--radius); background: var(--white);
}

.panel-title { font-size: 1.125rem; margin-bottom: 14px; }

.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px;
}
.panel-head .panel-title { margin: 0; }
.panel-total { font-weight: 800; font-variant-numeric: tabular-nums; }
.panel-head { flex-wrap: wrap; }
.table-scroll { max-width: 100%; overflow-x: auto; }

.note { color: var(--gray-600); font-size: 0.9375rem; }
.note.small, .small { font-size: 0.8125rem; }
.empty { margin: 0; padding: 20px 0; text-align: center; color: var(--gray-600); }
.link { font-weight: 600; font-size: 0.9375rem; }

.summary-card {
  padding: 22px 20px; border-radius: var(--radius); background: var(--black); color: var(--white);
}
.summary-label { margin: 0; font-size: 0.875rem; font-weight: 600; color: var(--gray-200); }
.summary-total { margin: 2px 0 4px; font-size: 2.5rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.summary-detail { margin: 0; font-size: 0.875rem; color: var(--gray-200); }

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.month-title { font-size: 1.25rem; text-align: center; }

.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0; border: 2px solid var(--black); border-radius: 50%;
  background: var(--white); color: var(--black); font: inherit; font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--gray-100); }

.nudge {
  display: block; padding: 14px 16px; border: 2px solid var(--black); border-radius: var(--radius);
  background: var(--white); text-decoration: none; font-size: 0.9375rem;
}
.nudge:hover { background: var(--gray-100); }

.welcome p { color: var(--gray-700); }
.welcome-list, .steps-list { margin: 0; padding-left: 1.2em; color: var(--gray-700); }
.welcome-list li, .steps-list li { margin-bottom: 8px; }

.tips { margin: 0 0 8px; padding: 0; list-style: none; }
.tips li {
  margin-bottom: 8px; padding: 12px 14px; border-radius: 10px 10px 10px 4px; background: var(--gray-100);
  font-size: 0.9375rem; line-height: 1.45;
}

/* ---------- Buttons and forms ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 20px;
  border: 2px solid var(--black); border-radius: 999px; background: var(--black); color: var(--white);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--gray-700); border-color: var(--gray-700); }
.btn-outline { background: var(--white); color: var(--black); }
.btn-outline:hover { background: var(--gray-100); border-color: var(--black); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 6px 16px; font-size: 0.9375rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }

.link-btn {
  min-height: 40px; padding: 4px 8px; border: 0; background: none; color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

.field { margin-bottom: 14px; min-width: 0; }
.field label, .inline-label { display: block; margin-bottom: 6px; font-size: 0.875rem; font-weight: 700; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"], input[type="date"], input[type="search"], select {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1.5px solid var(--gray-600); border-radius: 8px;
  background: var(--white); color: var(--ink); font: inherit; font-size: 1rem;
}
input:hover, select:hover { border-color: var(--black); }
input::placeholder { color: var(--gray-600); }

.field-hint { min-height: 1.3em; margin: 6px 0 0; font-size: 0.8125rem; color: var(--gray-600); }

.form-error {
  margin: 0 0 14px; padding: 10px 12px; border: 2px solid var(--black); border-radius: 8px; font-weight: 700;
}
.form-error::before { content: "! "; }

.search-row input { background: var(--white); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar .inline-label { margin: 0; }
.toolbar select { width: auto; min-height: 40px; }
.toolbar .spacer { flex: 1; }

.check {
  display: flex; align-items: center; gap: 10px; margin: -2px 0 16px; font-size: 0.9375rem; font-weight: 600; cursor: pointer;
}
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--black); flex-shrink: 0; }
.check .note { font-weight: 500; font-size: 0.875rem; }

.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  padding: 14px 16px; border: 2px dashed var(--black); border-radius: var(--radius); background: var(--white);
}
.banner p { margin: 0; font-size: 0.9375rem; }
.banner-alert { border-style: solid; border-width: 3px; }
p.banner { margin: 0 0 16px; display: block; font-size: 0.9375rem; }

.rule-list { margin: 0 0 8px; padding: 0; list-style: none; }
.rule-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--gray-200); }
.rule-list li:first-child { border-top: 0; }
.rule-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Quick add ---------- */

.add-panel { padding: 22px 20px 16px; }
.quick-label { display: block; margin-bottom: 8px; font-size: 0.875rem; font-weight: 700; }
.quick-row { display: flex; gap: 8px; }
.quick-row input {
  flex: 1; min-height: 56px; font-size: 1.1875rem; font-weight: 600; border-width: 2px; border-color: var(--black); border-radius: 12px;
}
.quick-row .btn { min-height: 56px; padding: 10px 22px; border-radius: 12px; }
.quick-preview { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 2.2em; margin: 10px 0 0; }
.quick-preview .note { font-size: 0.875rem; margin: 0; }
.chip-static {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: var(--gray-100); font-size: 0.875rem; font-weight: 600;
}
.chip-static.strong { background: var(--black); color: var(--white); }
.chip-static .swatch { width: 12px; height: 12px; }

.more-details { margin-top: 14px; border-top: 1px solid var(--gray-200); padding-top: 10px; }
.more-details > summary {
  cursor: pointer; font-size: 0.9375rem; font-weight: 600; color: var(--gray-700); padding: 6px 0; list-style: none;
}
.more-details > summary::-webkit-details-marker { display: none; }
.more-details > summary::before { content: "+"; display: inline-block; width: 1.2em; font-weight: 800; }
.more-details[open] > summary::before { content: "\2212"; }
.more-details[open] > summary { margin-bottom: 10px; }

.import-link {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding: 14px 16px;
  border: 1.5px dashed var(--gray-600); border-radius: 12px; text-decoration: none; font-size: 0.9375rem; color: var(--ink);
}
.import-link:hover { border-color: var(--black); background: var(--gray-100); }

/* ---------- Import ---------- */

.page-head { padding: 8px 2px 0; }
.page-title { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 6px; }
.lead { font-size: 1.0625rem; color: var(--gray-700); margin: 0 0 6px; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 36px 20px; text-align: center;
  border: 2px dashed var(--black); border-radius: 14px; background: var(--gray-100); transition: background-color 0.15s;
}
.dropzone.is-over { background: var(--gray-200); }
.drop-title { margin: 0; font-size: 1.125rem; font-weight: 800; }
.dropzone .btn { margin-top: 10px; }

.privacy-line { display: flex; align-items: flex-start; gap: 10px; margin: 16px 0 0; font-size: 0.875rem; color: var(--gray-700); }
.icon svg { width: 20px; height: 20px; fill: none; stroke: var(--black); stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; display: block; }

.howto > summary { cursor: pointer; font-weight: 700; }
.howto[open] > summary { margin-bottom: 12px; }

.step-actions { margin-top: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 6px 14px; border: 1.5px solid var(--black); border-radius: 999px; background: var(--white);
  font: inherit; font-size: 0.875rem; font-weight: 700; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--black); color: var(--white); }

.review-panel { padding: 8px 16px; }
.review-tools { display: flex; justify-content: flex-end; gap: 4px; }
.review-list { margin: 0; padding: 0; list-style: none; }
.review-row { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; border-top: 1px solid var(--gray-200); }
.review-row.is-off .review-main, .review-row.is-off .review-amount { opacity: 0.45; }
.review-check { padding-top: 2px; }
.review-check input { width: 22px; height: 22px; accent-color: var(--black); }
.review-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.review-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.8125rem; color: var(--gray-600); }
.review-main input[type="text"] { min-height: 40px; padding: 6px 10px; font-weight: 600; }
.review-cat { display: flex; align-items: center; gap: 8px; }
.review-cat select { min-height: 40px; padding: 6px 10px; }
.review-amount { font-weight: 800; font-variant-numeric: tabular-nums; padding-top: 2px; white-space: nowrap; }

.tag {
  display: inline-block; padding: 2px 8px; border: 1px solid var(--gray-600); border-radius: 999px;
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.02em; color: var(--gray-700); text-transform: uppercase;
}
.tag-strong { border-color: var(--black); background: var(--black); color: var(--white); }

.import-bar {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 10;
  display: flex; align-items: center; gap: 12px; padding: 12px; border: 2px solid var(--black); border-radius: 16px;
  background: var(--white); box-shadow: 0 6px 0 var(--black);
}
.import-total { flex: 1; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.btn-lg { min-height: 52px; padding: 12px 22px; }
/* On the import screen, messages sit above the import bar instead of covering it. */
body:has(.import-bar) .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 140px); }
@media (min-width: 900px) { body:has(.import-bar) .toast { bottom: 100px; } }
@media (min-width: 900px) { .import-bar { bottom: 16px; } }
@media (max-width: 420px) {
  .import-bar { flex-wrap: wrap; }
  .import-bar .btn-lg { flex: 1 1 100%; order: 3; }
}

.done { text-align: center; padding: 36px 20px; }
.done-mark {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%; background: var(--black); color: var(--white);
  display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 800;
}
.btn-row.center { justify-content: center; margin-top: 18px; }
.link-btn.inline { min-height: 0; padding: 0; }

.search-row { display: flex; gap: 8px; align-items: center; }
.search-row input { flex: 1; }

/* ---------- Purchases ---------- */

.purchases { margin: 0; padding: 0; list-style: none; }
.purchases li + li { border-top: 1px solid var(--gray-200); }

.purchase {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 4px; border: 0;
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 8px;
}
.purchase:hover { background: var(--gray-100); }

.p-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.p-desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-meta { font-size: 0.8125rem; color: var(--gray-600); }
.p-amount { font-weight: 700; font-variant-numeric: tabular-nums; }

.swatch { display: inline-block; width: 14px; height: 14px; flex-shrink: 0; border: 1.5px solid var(--black); border-radius: 3px; }

/* ---------- Charts (patterns + labels, never color) ---------- */

.fill-solid { background: var(--black); }
.fill-dark { background: var(--gray-700); }
.fill-stripe { background: repeating-linear-gradient(45deg, var(--black) 0 3px, var(--white) 3px 7px); }
.fill-dots { background: radial-gradient(circle, var(--black) 1.5px, var(--white) 1.6px) 0 0 / 6px 6px; }
.fill-light { background: var(--gray-200); }
.fill-lines { background: repeating-linear-gradient(0deg, var(--black) 0 2px, var(--white) 2px 5px); }
.fill-check { background: repeating-conic-gradient(var(--black) 0 25%, var(--white) 0 50%) 0 0 / 6px 6px; }

.bars { margin: 0; padding: 0; list-style: none; container-type: inline-size; }
.bars li {
  display: grid; grid-template-columns: 6.5em 1fr 6.6em; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 0.9375rem;
}
.bar-label { font-weight: 600; }
.bar-track { height: 18px; border-radius: 4px; background: var(--gray-100); overflow: hidden; }
.bar { display: block; height: 100%; border: 1.5px solid var(--black); border-radius: 4px; }
.bar-amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-share { display: inline-block; min-width: 2.6em; font-weight: 500; color: var(--gray-600); }

.trend { display: flex; gap: 8px; margin: 0 0 12px; padding: 0; list-style: none; }
.trend li { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.trend-amount { font-size: 0.75rem; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.trend-col { display: flex; align-items: flex-end; width: 100%; height: 140px; margin: 6px 0 8px; border-bottom: 2px solid var(--black); }
.trend-bar { display: block; width: 100%; max-width: 48px; margin: 0 auto; border-radius: 4px 4px 0 0; background: var(--gray-400); }
.trend-bar.is-current { background: var(--black); }
.trend-label { font-size: 0.8125rem; color: var(--gray-600); }

@media (max-width: 420px) {
  .bars li { grid-template-columns: 5.4em 1fr 6.2em; gap: 8px; font-size: 0.875rem; }
  .trend { gap: 4px; }
  .trend-amount { font-size: 0.625rem; }
}
/* Narrow for the text size (small phone, large text): name and amount on one line, bar below. */
@container (max-width: 19em) {
  .bars li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
  .bar-label { overflow-wrap: break-word; min-width: 0; }
  .bar-amount { margin-left: auto; }
  .bar-track { flex: 0 0 100%; order: 3; }
}

@keyframes grow-x { from { transform: scaleX(0); } }
@keyframes grow-y { from { transform: scaleY(0); } }
.grow .bar { transform-origin: left center; animation: grow-x 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.grow .trend-bar { transform-origin: center bottom; animation: grow-y 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both; }

/* ---------- Tables ---------- */

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.data-table th, .data-table td { padding: 10px 6px; border-bottom: 1px solid var(--gray-200); text-align: left; }
/* Small phones (iPhone SE): big amounts still fit without sideways scrolling. */
@media (max-width: 360px) {
  .data-table { font-size: 0.8125rem; }
  .data-table th, .data-table td { padding: 9px 3px; }
}
.data-table thead th { font-size: 0.8125rem; color: var(--gray-600); border-bottom: 2px solid var(--black); }
.data-table tbody th { font-weight: 600; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tfoot th, .data-table tfoot td { border-top: 2px solid var(--black); border-bottom: 0; font-weight: 800; }
.cat-cell { display: inline-flex; align-items: center; gap: 8px; }
.months-table th { font-weight: 500; }

@media (max-width: 480px) {
  .hide-sm { display: none; }
}

.sheet-head { margin-bottom: 8px; }
.sheet-head .panel-title { margin-bottom: 4px; }
.sheet-total { margin: 0; font-size: min(2rem, 10vw); font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.sheet-sub { margin: 22px 0 6px; font-size: 1rem; }

.print-only { display: none; }
.danger { border: 2px solid var(--black); }
.about { text-align: center; }

/* ---------- Toast and editor ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 50;
  /* max-content: with left: 50%, the default width would shrink to half the screen on phones. */
  display: flex; align-items: center; gap: 14px; width: max-content; max-width: calc(100% - 32px); padding: 12px 16px;
  border-radius: 12px; background: var(--black); color: var(--white); font-size: 0.9375rem; font-weight: 600;
  transform: translate(-50%, 20px); opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform 0.2s, opacity 0.2s, visibility 0s 0.2s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; pointer-events: auto; transition: transform 0.2s, opacity 0.2s; }
.toast:empty { display: none; }
.toast-action {
  padding: 4px 10px; border: 1.5px solid var(--white); border-radius: 999px; background: none; color: var(--white);
  flex-shrink: 0; font: inherit; font-weight: 700; cursor: pointer;
}
@media (min-width: 900px) { .toast { bottom: 24px; } }

.editor {
  width: min(480px, calc(100% - 24px)); padding: 22px; border: 2px solid var(--black); border-radius: 16px;
  background: var(--white); color: var(--ink);
}
.editor::backdrop { background: rgba(0, 0, 0, 0.55); }
.editor h2 { margin-bottom: 16px; font-size: 1.25rem; }
.editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.editor-actions .link-btn { margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
  .grow .bar, .grow .trend-bar { animation: none; }
  .toast { transition: none; }
}

/* ---------- Printing (Summary tab) ---------- */

@media print {
  /* Always print black on white, even when the app is in dark mode. */
  :root:not([data-theme="light"]), :root[data-theme="dark"] {
    --black: #000000; --ink: #111111; --gray-700: #3d3d3d; --gray-600: #555555;
    --gray-400: #8a8a8a; --gray-200: #d9d9d9; --gray-100: #f2f2f2; --white: #ffffff;
    color-scheme: light;
  }
  body { background: var(--white); color: var(--ink); padding: 0; }
  .swatch { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .data-table tr { break-inside: avoid; }
  .print-only { display: block !important; }
  .app-header, .tabbar, .toolbar, .no-print, .toast, .skip-link { display: none !important; }
  .app-main { max-width: none; padding: 0; }
  .panel { border: 0; padding: 0; }
}

/* =====================================================================
   Design upgrade (early-7): Home layout, money story, badges, motion,
   welcome flow, appearance, shortcuts.
   ===================================================================== */

/* ---------- Home: one column on phones, two on wide screens ---------- */

.home-grid { display: flex; flex-direction: column; gap: 16px; }
.home-grid .col { display: contents; }
/* Phone order: money story, log, tips, where it went, recent */
.home-grid .money-story { order: 1; }
.home-grid .add-panel { order: 2; }
.home-grid .area-tips { order: 3; }
.home-grid .area-cats { order: 4; }
.home-grid .area-recent { order: 5; }
.home-grid .welcome { order: 6; }

@media (min-width: 1024px) {
  .home-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; }
  .home-grid.is-single { grid-template-columns: minmax(0, 720px); }
  .home-grid .col { display: flex; flex-direction: column; gap: 20px; }
}

/* ---------- Money story ---------- */

.money-story {
  padding: 18px 20px 20px; border-radius: 18px; background: var(--black); color: var(--white);
}
.ms-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ms-month { font-size: 1rem; font-weight: 700; letter-spacing: 0; }
.ms-nav {
  width: 40px; height: 40px; border: 1.5px solid currentColor; border-radius: 50%; background: transparent;
  color: var(--white); font: inherit; font-size: 1.375rem; line-height: 1; cursor: pointer; opacity: 0.85;
}
.ms-nav:hover { opacity: 1; background: rgba(127, 127, 127, 0.25); }
.ms-nav:focus-visible { outline-color: var(--white); }
.ms-label { margin: 0; font-size: 0.875rem; font-weight: 600; opacity: 0.75; }
.ms-total {
  /* Capped by screen width too, so a big total fits a small phone even with large text. */
  margin: 2px 0 6px; font-size: min(clamp(2.5rem, 9vw, 3.5rem), 12vw); font-weight: 800; letter-spacing: -0.04em;
  line-height: 1.05; font-variant-numeric: tabular-nums;
}
.ms-detail { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 0; font-size: 0.875rem; opacity: 0.9; }
.ms-pill { padding: 3px 10px; border: 1px solid currentColor; border-radius: 999px; font-weight: 700; }
.day-strip { display: flex; align-items: flex-end; gap: 2px; height: 56px; margin-top: 18px; }
.day-bar { flex: 1; min-width: 0; border-radius: 2px 2px 0 0; background: var(--white); opacity: 0.55; }
.day-bar.is-max { opacity: 1; }
.day-bar.is-today { opacity: 1; box-shadow: 0 0 0 1.5px var(--black), 0 0 0 3px var(--white); }
.day-bar.is-future { opacity: 0.18; }
.ms-foot { margin: 8px 0 0; font-size: 0.8125rem; opacity: 0.75; }
.ms-later { margin: 8px 0 0; font-size: 0.8125rem; font-weight: 600; opacity: 0.85; }

/* ---------- Category badges ---------- */

.cat-badge {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex-shrink: 0;
  border: 1.5px solid var(--black); border-radius: 50%; background-clip: padding-box; overflow: hidden;
}
.cat-badge.has-icon { background: var(--gray-100); border-color: var(--gray-200); }
.ico svg { display: block; width: 20px; height: 20px; fill: none; stroke: var(--black); stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Motion (all of it is skipped when reduced motion is on) ---------- */

/* Never start fully transparent: if a browser pauses animations (for example a background
   tab), content must still be readable. */
@keyframes enter { from { opacity: 0.5; transform: translateY(6px); } }
@keyframes slide-in { from { opacity: 0.4; transform: translateY(-8px); } }
@keyframes flash { from { background: var(--gray-200); } }
@keyframes draw { from { stroke-dashoffset: 30; } }
@keyframes pop { from { transform: scale(0.6); opacity: 0.5; } }

.app-main.is-entering { animation: enter 0.22s var(--ease) both; }
.purchases li.is-new { animation: slide-in 0.35s var(--ease) both; }
.purchases li.is-new .purchase { animation: flash 1.6s ease-out both; }
.btn:active, .chip:active, .trade-tile:active, .start-card:active { transform: scale(0.98); }

.done-mark {
  display: flex; align-items: center; justify-content: center; width: 72px; height: 72px; margin: 0 auto 16px;
  border-radius: 50%; background: var(--black); animation: pop 0.35s var(--ease) both;
}
.done-mark svg { width: 38px; height: 38px; fill: none; stroke: var(--white); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 30; animation: draw 0.5s 0.2s var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  .app-main.is-entering, .purchases li.is-new, .purchases li.is-new .purchase, .done-mark, .done-mark svg { animation: none; }
  .btn:active, .chip:active, .trade-tile:active, .start-card:active { transform: none; }
}

/* ---------- First load ---------- */

body.is-loading .tabbar { visibility: hidden; }
.loading { margin: 30vh auto 0; text-align: center; font-weight: 700; color: var(--gray-600); }

/* ---------- Welcome flow ---------- */

body.is-welcoming .tabbar { display: none; }
body.is-welcoming { padding-bottom: 32px; }
@media (min-width: 1024px) { body.is-welcoming { padding-left: 0; } body.is-welcoming .app-header { position: sticky; width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--gray-200); padding: 14px 24px; } }

.welcome-flow { max-width: 760px; padding-top: 28px; }
.wf-progress { display: flex; gap: 6px; margin: 0; }
.wf-dot { width: 28px; height: 5px; border-radius: 999px; background: var(--gray-200); }
.wf-dot.is-on { background: var(--black); }
.wf-head { margin: 8px 0 4px; }
.wf-title { font-size: clamp(2rem, 7vw, 3rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1.05; margin-bottom: 10px; }

.trade-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .trade-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.trade-tile {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 18px; min-height: 120px;
  padding: 18px; border: 2px solid var(--gray-200); border-radius: 16px; background: var(--white); color: var(--ink);
  font: inherit; font-weight: 700; text-align: left; cursor: pointer; transition: border-color 0.15s, transform 0.1s;
}
.trade-tile:hover { border-color: var(--black); }
.trade-tile[aria-pressed="true"] { border-color: var(--black); background: var(--black); color: var(--white); }
.trade-tile[aria-pressed="true"] .ico svg { stroke: var(--white); }
.trade-ico svg { width: 30px; height: 30px; }

.start-grid { display: grid; gap: 12px; }
.start-card {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 20px 52px 20px 20px;
  border: 2px solid var(--gray-200); border-radius: 16px; background: var(--white); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer; transition: border-color 0.15s, transform 0.1s;
}
.start-card:hover, .start-card.is-recommended { border-color: var(--black); }
.start-title { font-size: 1.125rem; font-weight: 800; }
.start-body { color: var(--gray-700); font-size: 0.9375rem; }
.start-arrow { position: absolute; right: 20px; top: 50%; transform: translateY(-50%); font-size: 1.25rem; font-weight: 800; }

.wf-privacy { margin: 8px 0 0; padding: 14px 16px; border-radius: 12px; background: var(--white); border: 1px solid var(--gray-200); font-size: 0.9375rem; }
.wf-skip { margin: 0; text-align: center; }

/* "Before you start" notice and the Help page */
.notice-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.notice-list li { padding: 16px 18px; border-radius: 12px; background: var(--white); border: 1px solid var(--gray-200); color: var(--gray-700); line-height: 1.5; }
.notice-list strong { display: block; margin-bottom: 2px; color: var(--ink); }
.notice-ok { width: 100%; }
.help-example { padding: 1px 6px; border-radius: 6px; background: var(--gray-100); color: var(--ink); font: inherit; font-weight: 600; white-space: nowrap; }

/* ---------- Settings: appearance ---------- */

.choices { display: grid; gap: 8px; margin-bottom: 16px; }
@media (min-width: 640px) { .choices { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.choice {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1.5px solid var(--gray-200); border-radius: 12px; cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--black); box-shadow: inset 0 0 0 1px var(--black); }
.choice input { margin-top: 3px; accent-color: var(--black); width: 18px; height: 18px; }
.choice > span { display: flex; flex-direction: column; }
.choice .note { font-size: 0.8125rem; }

/* ---------- Shortcuts list ---------- */

.shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0 0 20px; align-items: center; }
.shortcut-list dt { text-align: right; }
.shortcut-list dd { margin: 0; }

/* Wide screens: messages center in the content area, not the whole window. */
@media (min-width: 1024px) {
  .toast { left: calc(50% + var(--sidebar-w) / 2); }
  body:has(.import-bar) .toast { bottom: 100px; }
}

/* ---------- Plain pages (Privacy) ---------- */

body.doc-page { padding-bottom: 32px; }
a.version-tag { color: inherit; text-decoration: none; }
a.version-tag:hover { background: var(--black); color: var(--white); }
.doc-page .lead { margin-bottom: 20px; }
