/* Casa — warm, light, homey. One accent, soft surfaces, big friendly type. */
:root {
  --bg: #FBF6EF;
  --surface: #FFFFFF;
  --surface-2: #F6EFE6;
  --ink: #2E2723;
  --ink-2: #6F635A;
  --line: #EADFD2;
  --accent: #C8553D;
  --accent-ink: #FFFFFF;
  --accent-soft: #FBE7DF;
  --good: #3D7A57;
  --good-soft: #E3F1E8;
  --warn: #B7791F;
  --warn-soft: #FBF0D9;
  --bad: #B3261E;
  --bad-soft: #FBE3E0;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 6px 20px rgba(60, 40, 20, .06);
  --tabbar-h: 72px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1E1A17; --surface: #28231F; --surface-2: #322B26; --ink: #F3ECE4; --ink-2: #B9ADA2;
    --line: #3D3530; --accent: #E0735A; --accent-soft: #43291F; --good: #7CC39B; --good-soft: #20352A;
    --warn: #E6B35A; --warn-soft: #3D311C; --bad: #F08A80; --bad-soft: #452523;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* Components set display (e.g. .field), which would beat the UA [hidden] rule. */
[hidden] { display: none !important; }
form > .help { display: block; margin-top: 8px; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 800; }
h3 { font-size: 1.02rem; font-weight: 700; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--ink-2); }
.muted { font-size: .92rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }

/* ---------- Layout ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 980px; margin: 0 auto; padding: 18px 20px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; font-size: 1.15rem; }
.brand:hover { text-decoration: none; }
.brand img { width: 34px; height: 34px; border-radius: 10px; }
.topbar .lang { font-size: .85rem; font-weight: 700; color: var(--ink-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px; }
.wrap { max-width: 980px; margin: 0 auto; padding: 8px 20px calc(var(--tabbar-h) + 40px); }
.narrow { max-width: 640px; margin-left: auto; margin-right: auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; margin: 6px 0 2px; color: var(--ink-2); }

.grid { display: grid; gap: 14px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
.grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 760px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}
.stack > * + * { margin-top: 14px; }
/* Grid items default to min-width:auto; long no-wrap titles would push cards past the screen edge. */
.grid > *, .grid-2 > *, .grid-3 > *, .stack > * { min-width: 0; }
.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; border: 1px solid transparent;
}
.card.soft { background: var(--surface-2); box-shadow: none; }
.card.accent { background: var(--accent-soft); box-shadow: none; }
.card h2 { margin-bottom: 10px; }
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; border-color: var(--line); }

.stat .label { color: var(--ink-2); font-size: .9rem; font-weight: 700; }
.stat .value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; margin: 2px 0; }
.stat .hint { color: var(--ink-2); font-size: .88rem; }
.value.good { color: var(--good); }
.value.bad { color: var(--bad); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.item { display: flex; align-items: center; gap: 14px; padding: 12px 2px; color: inherit; }
a.item:hover { text-decoration: none; background: var(--surface-2); border-radius: var(--radius-sm); }
.item .ico {
  flex: none; width: 42px; height: 42px; border-radius: 14px; background: var(--surface-2);
  display: grid; place-items: center; font-size: 1.25rem;
}
.item .main { flex: 1; min-width: 0; }
.item .title { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { display: block; color: var(--ink-2); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 800; white-space: nowrap; text-align: right; }
.amt.in { color: var(--good); }
.empty { text-align: center; color: var(--ink-2); padding: 22px 10px; }
.empty .big { font-size: 2rem; display: block; margin-bottom: 6px; }

/* ---------- Pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 800;
  padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 800; font-size: .98rem; line-height: 1;
  padding: 13px 18px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; min-height: 48px;
}
.btn:hover { text-decoration: none; border-color: var(--ink-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(.95); border-color: var(--accent); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-danger { color: var(--bad); border-color: var(--bad-soft); }
.btn-sm { padding: 8px 12px; min-height: 38px; font-size: .88rem; border-radius: 11px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: default; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.actions .btn-primary { flex: 1 1 auto; }
form.inline { display: inline; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 16px; }
.field > span, .label { display: block; font-weight: 800; font-size: .92rem; margin-bottom: 6px; }
.field .help { display: block; color: var(--ink-2); font-size: .85rem; margin-top: 5px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
input[type=tel], input[type=search], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-size: 1.02rem; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 12px 14px; min-height: 50px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
input.money { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; }
.error { color: var(--bad); font-size: .88rem; font-weight: 700; margin-top: 6px; display: block; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 14px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
fieldset { border: 0; padding: 0; margin: 0 0 16px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Segmented choice (radio chips) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); font-weight: 800; font-size: .95rem; cursor: pointer;
}
.chips input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chips input:focus-visible + span { box-shadow: 0 0 0 4px var(--accent-soft); }
.chips.checks input:checked + span { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* Type-ahead picker */
.picker { position: relative; }
.picker .menu {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  max-height: 280px; overflow: auto; padding: 6px; display: none;
}
.picker.open .menu { display: block; }
.picker .opt { display: flex; justify-content: space-between; gap: 10px; padding: 11px 12px; border-radius: 10px; cursor: pointer; }
.picker .opt:hover, .picker .opt.active { background: var(--surface-2); }
.picker .opt small { color: var(--ink-2); }
.picker .opt.create { color: var(--accent); font-weight: 800; }
.picker .chosen { display: none; margin-top: 6px; }
.picker.has-value .clear { display: inline-flex; }
.picker .clear { display: none; position: absolute; right: 10px; top: 11px; border: 0; background: var(--surface-2);
  color: var(--ink-2); border-radius: 999px; width: 28px; height: 28px; cursor: pointer; font-size: 1rem; align-items: center; justify-content: center; }

/* ---------- Flash ---------- */
.flash { border-radius: 14px; padding: 12px 16px; margin: 6px 0 14px; font-weight: 700; background: var(--good-soft); color: var(--good); }
.flash.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tabbar-h); align-items: center; }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink-2); font-size: .72rem; font-weight: 800; position: relative; }
.tabbar a:hover { text-decoration: none; color: var(--ink); }
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a.on { color: var(--accent); }
.tabbar a.add span.plus {
  width: 56px; height: 56px; border-radius: 20px; background: var(--accent); color: #fff;
  display: grid; place-items: center; margin-top: -26px; box-shadow: 0 8px 20px rgba(200, 85, 61, .35);
}
.tabbar a.add svg { width: 30px; height: 30px; }
.badge { position: absolute; top: -4px; right: calc(50% - 22px); background: var(--bad); color: #fff; border-radius: 999px;
  font-size: .68rem; min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; }

/* ---------- Add sheet ---------- */
.big-choice { display: flex; align-items: center; gap: 16px; padding: 18px; }
.big-choice .ico { width: 54px; height: 54px; border-radius: 18px; font-size: 1.6rem; display: grid; place-items: center; background: var(--accent-soft); flex: none; }
.big-choice b { display: block; font-size: 1.08rem; }
.snap { background: var(--accent); color: #fff; border-radius: var(--radius); padding: 22px; display: flex; align-items: center; gap: 16px; cursor: pointer; box-shadow: var(--shadow); }
.snap .ico { width: 54px; height: 54px; border-radius: 18px; font-size: 1.6rem; display: grid; place-items: center; flex: none; background: rgba(255,255,255,.18); }
.snap b { font-size: 1.2rem; }
.snap small { color: rgba(255,255,255,.85); }
.snap input { display: none; }

/* ---------- Bars (reports) ---------- */
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.good i { background: var(--good); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--ink-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.table td.num, .table th.num { text-align: right; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Photos ---------- */
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumbs a { display: block; width: 92px; height: 92px; border-radius: 14px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); position: relative; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.thumbs .doc { display: grid; place-items: center; height: 100%; font-weight: 800; color: var(--ink-2); }

.ocr { border: 1.5px dashed var(--accent); background: var(--accent-soft); border-radius: 16px; padding: 14px 16px; margin-bottom: 16px; }
.ocr .use { margin-left: 8px; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.filters a { flex: none; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.kv dt { color: var(--ink-2); font-weight: 700; }
.kv dd { margin: 0; font-weight: 700; }

/* Auth / portal */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; margin-bottom: 18px; font-size: 1.4rem; }
.auth-card .brand img { width: 48px; height: 48px; border-radius: 14px; }
.portal .wrap { padding-bottom: 40px; }
.receipt-amount { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; }
.confirmed { display: flex; gap: 12px; align-items: center; background: var(--good-soft); color: var(--good); padding: 14px 16px; border-radius: 16px; font-weight: 800; }

@media (min-width: 900px) {
  .wrap { padding-left: 28px; padding-right: 28px; }
}
/* Phones: summary numbers become compact full-width rows (label left, number right). */
@media (max-width: 559px) {
  .grid-3 { grid-template-columns: 1fr; gap: 10px; }
  .grid-3 > .stat, .grid-3 .card.stat { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px; padding: 14px 16px; }
  .grid-3 .stat .label { grid-column: 1; grid-row: 1; }
  .grid-3 .stat .hint { grid-column: 1; grid-row: 2; font-size: .8rem; }
  .grid-3 .stat .value { grid-column: 2; grid-row: 1 / span 2; font-size: 1.35rem !important; margin: 0; text-align: right; }
  h1 { font-size: 1.55rem; }
  .receipt-amount { font-size: 2rem; }
}
@media print {
  .tabbar, .topbar, .actions, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* Dashboard summary: four cards — 2x2 on tablets, one row on wide screens. */
@media (min-width: 560px) { .grid-3.four { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 980px) { .grid-3.four { grid-template-columns: repeat(4, 1fr); } }
