/* Monkey Business — phone first. One DOM for every width: a line is a card on a phone and a table row at ≥ 1024 px. */
:root {
  --green: #2d6a4f; --green-dark: #1a3a2a; --banana: #f2c230; --banana-soft: #fff6d6;
  --bg: #f6f7f4; --card: #ffffff; --ink: #1d2420; --muted: #5f6b64; --line: #dfe4df;
  --ok: #1f7a46; --ok-bg: #e5f4ea; --bad: #b3261e; --bad-bg: #fdecea; --warn: #8a5a00; --warn-bg: #fff3d6;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --card: #1b201d; --ink: #e6ebe7; --muted: #9aa69f; --line: #2c342f;
    --ok-bg: #173323; --bad-bg: #3a1b18; --warn-bg: #3a2e12; --banana-soft: #2e2810;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: 96px; overflow-x: hidden; }
a { color: var(--green); }
button, input, select, textarea { font: inherit; font-size: 16px; color: inherit; }
input, select, textarea {
  min-height: 44px; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--banana); outline-offset: 1px; }
button {
  min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
}
button.primary { background: var(--green); color: #fff; border-color: var(--green); font-weight: 600; }
button.accent { background: var(--banana); color: #2b2200; border-color: var(--banana); font-weight: 600; }
button.link { border: 0; background: none; color: var(--green); padding: 8px 4px; text-decoration: underline; }
button:disabled { opacity: .5; cursor: default; }

header.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: var(--green-dark); color: #fff;
}
header.top .brand { font-weight: 700; display: flex; align-items: center; gap: 8px; min-width: 0; }
header.top .brand span.biz { font-weight: 500; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .spacer { flex: 1; }
header.top button { min-height: 36px; padding: 4px 10px; background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
nav.tabs { display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; }
nav.tabs a { padding: 10px 14px; border-radius: 10px 10px 0 0; text-decoration: none; color: var(--muted); white-space: nowrap; }
nav.tabs a.on { background: var(--card); color: var(--ink); font-weight: 600; }

main { padding: 0 16px 16px; max-width: 1280px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card h2 { margin: 0 0 12px; font-size: 18px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
label.field { display: block; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.pill.confirmed { background: var(--ok-bg); color: var(--ok); }
.pill.draft { background: var(--warn-bg); color: var(--warn); }
.pill.missing { background: var(--bad-bg); color: var(--bad); }
.pill.new { background: var(--banana-soft); color: var(--warn); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.ok { color: var(--ok); } .bad { color: var(--bad); }
.toast { position: fixed; left: 16px; right: 16px; bottom: 88px; z-index: 30; padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); text-align: center; }
.banner { padding: 12px 16px; border-radius: 10px; margin: 12px 0; }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }

/* Month */
.month-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-head h2 { margin: 0; text-transform: capitalize; }
.cal { display: grid; gap: 8px; grid-template-columns: 1fr; margin-top: 12px; }
.cal .dow, .cal .blank { display: none; }
.cal a.cell { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: inherit; background: var(--card); min-height: 56px; }
.cal a.cell.missing { border-style: dashed; }
.cal a.cell.future { opacity: .45; }
.cal .d { font-weight: 700; }
.cal .meta { text-align: right; font-size: 14px; }

/* Sheet lines: cards on a phone */
.lines .head { display: none; }
.line { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.line.flagged { border-color: var(--bad); background: var(--bad-bg); }
.line .name { font-weight: 600; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; }
.line .boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 6px; }
.line .boxes input { padding: 8px 6px; }
.line .boxes label > span { font-size: 13px; color: var(--muted); display: block; }
.line .out { display: flex; justify-content: space-between; margin-top: 8px; font-weight: 600; }
.line .out .lbl { font-weight: 400; color: var(--muted); }
.line .why { font-size: 14px; color: var(--bad); margin-top: 6px; }

/* Money */
.counts { display: grid; gap: 12px; grid-template-columns: 1fr; }
.count { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.count h3 { margin: 0 0 8px; font-size: 16px; }
.notes { display: grid; grid-template-columns: 96px minmax(0, 1fr) minmax(96px, auto); gap: 6px 8px; align-items: center; }
.notes .den { font-weight: 600; font-size: 15px; }
.notes .sub { min-width: 90px; }
.cur + .cur { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.balance table { width: 100%; border-collapse: collapse; }
.balance td { padding: 6px 0; border-bottom: 1px solid var(--line); }
.flags { margin: 0; padding-left: 20px; }
.flags li { margin: 4px 0; color: var(--bad); }

.actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; gap: 8px; padding: 12px 16px; background: var(--card); border-top: 1px solid var(--line); }
.actions .state { flex: 1; align-self: center; font-size: 14px; color: var(--muted); min-width: 0; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photos figure { margin: 0; width: 120px; }
.photos img { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
dialog { width: min(640px, calc(100vw - 32px)); max-height: 80vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.hist li { margin-bottom: 10px; }
.hist .ch { font-size: 14px; color: var(--muted); }

/* Settings */
.items .it { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.items .it.retired { opacity: .6; }
.items .it .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.items .it .forms { display: grid; gap: 8px; grid-template-columns: 1fr; margin-top: 8px; }
.items form, .inline { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; }

@media (min-width: 700px) {
  .grid2 { grid-template-columns: 1fr 1fr; }
  .counts { grid-template-columns: 1fr 1fr; }
  .items .it .forms { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1024px) {
  .cal { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .cal .dow { display: block; text-align: center; font-size: 13px; color: var(--muted); }
  .cal .blank { display: block; }
  .cal a.cell { flex-direction: column; align-items: flex-start; min-height: 96px; }
  .cal .meta { text-align: left; }
  /* A line becomes a table row. */
  .lines .head, .line { display: grid; grid-template-columns: minmax(160px, 2fr) repeat(var(--cols), minmax(70px, 1fr)) minmax(90px, 1fr) minmax(110px, 1fr); gap: 8px; align-items: center; }
  .lines .head { font-size: 13px; color: var(--muted); padding: 0 12px 6px; }
  .line { padding: 8px 12px; margin-bottom: 6px; }
  .line .name { margin: 0; }
  .line .boxes { display: contents; }
  .line .boxes label > span { display: none; }
  .line .out { display: contents; }
  .line .out > * { text-align: right; }
  .line .why { grid-column: 1 / -1; margin: 0; }
  .line .out .lbl { display: none; }
  body { padding-bottom: 88px; }
}
