/* App styles on top of tokens.css. Semantic variables only. Phone-first; 44px touch targets. */

.page { max-width: 560px; margin: 0 auto; padding: 16px var(--gutter) 96px; } /* room for the chat button */

a { color: var(--accent); text-underline-offset: 3px; }

/* Cards: every form, list and table sits on one. */
.card, form.stack, .list, .table-card {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card, form.stack { padding: 18px; margin: 12px 0; }
.card h2 { margin-top: 0; }

.stack { display: grid; gap: 16px; }
.stack label { display: grid; gap: 6px; font-weight: 550; font-size: 15px; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: 400 16px var(--font-body); /* 16px: no zoom-on-focus on iOS */
  accent-color: var(--accent);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 1px;
  border-color: var(--accent);
}
/* iOS Safari gives date inputs a built-in minimum width (they spill out of the card) and centres the date.
   Drop its native look so width: 100% holds, and left-align like every other field. */
input[type="date"] { -webkit-appearance: none; appearance: none; display: block; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; min-width: 0; }
legend { font-weight: 550; font-size: 15px; padding: 0; margin-bottom: 8px; }
.hint { color: var(--text-muted); font-size: 14px; margin: 0; }

/* Tick boxes as chips: the whole pill is the target, and the tick stays visible (not colour alone). */
.stack label.check {
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--card-border); border-radius: 999px;
  background: var(--surface-2); font-weight: 500; cursor: pointer;
}
.stack label.check input { width: 20px; height: 20px; min-height: 0; margin: 0; }
.stack label.check:has(input:checked) { background: var(--chip-on-bg); border-color: var(--chip-on-bg); color: var(--chip-on-text); }
.chips { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.chips legend { grid-column: 1 / -1; }
.expense { display: grid; grid-template-columns: 1fr 112px; gap: 10px; padding: 12px 0; border-top: 1px solid var(--rule); }
.expense .wide { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--btn-primary-bg); border-radius: var(--radius-sm);
  background: var(--btn-primary-bg); color: var(--btn-primary-text);
  font: 600 15px var(--font-body); text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn-quiet { background: var(--btn-secondary-bg); color: var(--btn-secondary-text); border-color: var(--btn-secondary-bg); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.stack .btn { justify-self: start; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
.actions form { margin: 0; padding: 0; border: 0; box-shadow: none; background: none; }

.notice { margin: 12px 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-bg); color: var(--warn-text); font-weight: 500; }

.list { list-style: none; padding: 4px 16px; margin: 8px 0; }
.list li { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.list li:last-child { border-bottom: 0; }
.list:empty { display: none; }

.table-card { padding: 4px 16px; margin: 8px 0; overflow-x: auto; }
.rows { width: 100%; border-collapse: collapse; }
.card .rows { margin: 8px 0; }
.rows th, .rows td { padding: 12px 4px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: middle; }
.rows thead th { color: var(--text-muted); font-weight: 500; font-size: 14px; }
.rows tbody tr:last-child td { border-bottom: 0; }
.rows tfoot th, .rows tfoot td { border-top: 1px solid var(--rule); border-bottom: 0; font-weight: 650; }
.num { text-align: right !important; white-space: nowrap; }
.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.pos { color: var(--positive); }

.badge { display: inline-block; margin-right: 8px; padding: 1px 8px; border: 1.5px solid var(--warn-border); border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); font-size: 12px; font-weight: 600; }
.tag { margin-left: 8px; color: var(--text-muted); font-size: 13px; }
.muted { color: var(--text-muted); }
details.expenses { border-top: 1px solid var(--rule); padding-top: 4px; }
details.expenses summary { min-height: 44px; display: flex; align-items: center; color: var(--accent); font-weight: 550; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Balances: each player opens to their history. */
.balances { background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); margin: 8px 0; }
details.player { border-bottom: 1px solid var(--rule); padding: 0 16px; }
details.player:last-child { border-bottom: 0; }
summary { list-style: none; cursor: pointer; }
summary::-webkit-details-marker { display: none; }
details.player > summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px; font-weight: 550; }
details.player > summary::before { content: "›"; color: var(--text-muted); margin-right: 6px; transition: transform .15s; }
details.player[open] > summary::before { transform: rotate(90deg); }
details.player > summary > span:first-of-type { flex: 1; }
details.player[open] { padding-bottom: 12px; }
.history { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--rule); }
.line { padding-left: 12px; font-size: 15px; }
.line .head, .line > details > summary { display: flex; justify-content: space-between; gap: 10px; min-height: 44px; align-items: center; }
.line.payment .head { color: var(--positive); font-weight: 600; }
.line .date { color: var(--text-muted); font-variant-numeric: tabular-nums; margin-right: 6px; }
.line .after { color: var(--text-muted); font-size: 13px; font-weight: 400; }
/* A session line opens to its rows: the same › as a player, turning when open, and a row count. */
.line > details > summary.more > span:first-child::before { content: "›"; display: inline-block; width: 12px; color: var(--accent); font-weight: 700; transition: transform .15s; }
.line > details[open] > summary.more > span:first-child::before { transform: rotate(90deg); }
.line .count { color: var(--accent); font-size: 13px; }
.items { list-style: none; margin: 0 0 8px; padding: 8px 12px; background: var(--surface-2); border-radius: var(--radius-sm); font-size: 14px; }
.items li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }
details.earlier > summary { color: var(--accent); min-height: 44px; display: flex; align-items: center; padding-left: 14px; font-weight: 550; font-size: 15px; }

/* Icon buttons: 44px targets; the label is on the link (aria-label, title). */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; }
button.icon-btn { border: 0; background: none; padding: 0; cursor: pointer; font: inherit; }
.icon-btn:hover { background: var(--surface-2); }
.title-row { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; min-height: 48px; }
.title-row > .icon-btn { margin-left: -12px; margin-right: -6px; }
.logo { display: inline-flex; flex: none; border-radius: 9px; }
.title-row h1 { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }
.quick { display: flex; gap: 0; margin-right: -10px; }
.quick .icon-btn { color: var(--text-muted); }
.sticky { position: sticky; top: 0; z-index: 2; background: var(--bg); margin: -16px calc(-1 * var(--gutter)) 0; padding: 16px var(--gutter) 4px; border-bottom: 1px solid transparent; }
.sticky .actions { margin: 0 0 8px; }
section[id] { scroll-margin-top: 140px; } /* land below the sticky bar */
[hidden] { display: none !important; }
textarea { resize: vertical; line-height: 1.4; }

/* Chat: a floating button opens a panel (the browser's popover): a bottom sheet on a phone, docked on a laptop. */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 3;
  display: flex; align-items: center; justify-content: center; width: 56px; height: 56px;
  border: 0; border-radius: 50%; background: var(--btn-primary-bg); color: var(--btn-primary-text);
  box-shadow: 0 6px 18px rgb(0 0 0 / 22%); cursor: pointer;
}
.fab .icon { width: 26px; height: 26px; }
.chat-panel[popover] {
  margin: 0; padding: 0; inset: auto 0 0 0; width: 100%; max-width: 100%; max-height: 85vh; max-height: 85dvh; /* dvh: fits above the phone keyboard; vh where unsupported */
  border: 1px solid var(--card-border); border-radius: 18px 18px 0 0;
  background: var(--surface); color: var(--text); box-shadow: 0 -8px 30px rgb(0 0 0 / 18%);
}
.chat-panel:popover-open { display: flex; flex-direction: column; }
.chat-panel::backdrop { background: rgb(0 0 0 / 25%); }
@media (min-width: 640px) {
  .chat-panel[popover] { inset: auto 24px 24px auto; width: 400px; max-height: 75vh; max-height: 75dvh; border-radius: 18px; }
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--rule); }
/* Sized by its messages, shrinking to scroll when the panel hits max-height. Not flex: 1 (a 0% basis): with no fixed
   panel height, Safari can size that to nothing, leaving one line of messages. */
.chat-log { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.bubble { max-width: 88%; padding: 10px 12px; border-radius: 16px; font-size: 15px; line-height: 1.4; }
.bubble p { margin: 0 0 8px; }
.bubble.you { align-self: flex-end; border-bottom-right-radius: 4px; background: var(--btn-primary-bg); color: var(--btn-primary-text); white-space: pre-wrap; }
.bubble.kanakku { align-self: flex-start; border: 1px solid var(--rule); border-bottom-left-radius: 4px; background: var(--surface-2); }
.bubble.kanakku:has(.card) { width: 100%; max-width: 100%; }
.bubble .card { margin: 0; padding: 4px 0 0; border: 0; box-shadow: none; background: none; }
.bubble .card h2 { font-size: 15px; }
.chat-input { display: flex; align-items: flex-end; gap: 8px; padding: 10px; border-top: 1px solid var(--rule); padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.chat-input textarea { flex: 1; max-height: 30vh; }
.btn.send { padding: 0 14px; }
.bubble.kanakku, .answer { white-space: pre-line; } /* answers are lines of text */
.chat-head .chat-clear { margin-left: auto; margin-right: 4px; }
button.link { border: 0; background: none; padding: 0 8px; min-height: 44px; color: var(--accent); font: 500 14px var(--font-body); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.remind {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin: 0 10px 0 8px;
  border: 1px solid var(--card-border); border-radius: 999px; background: var(--btn-secondary-bg); color: var(--btn-secondary-text);
  text-decoration: none;
}

/* Homepage: one column on a phone; wider, multi-column sections on big screens. */
.page.wide { max-width: 1120px; }
.hero { display: grid; gap: 28px; align-items: center; margin: 8px 0 12px; }
.hero .lead { font-size: 22px; font-weight: 650; line-height: 1.3; margin: 0 0 10px; }
.steps, .features { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 12px; }
.steps .card, .features .card { margin: 0; }
.steps p, .features p { margin: 6px 0 0; color: var(--text-muted); font-size: 15px; }
.feature-icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin-bottom: 8px; border-radius: 12px; background: var(--btn-secondary-bg); color: var(--btn-primary-bg); }
.feature-icon .icon { width: 22px; height: 22px; }
.feature-icon + strong { display: block; }
.split { display: grid; gap: 24px; align-items: center; margin: 24px 0; }
.split h2 { margin-top: 0; }
.split.top { align-items: start; }
@media (min-width: 640px) {
  .steps { grid-template-columns: repeat(2, 1fr); }
  .features { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  .hero { grid-template-columns: 1.1fr 1fr; gap: 48px; margin: 24px 0 32px; }
  .hero .lead { font-size: 30px; }
  .split { grid-template-columns: 1fr 1fr; gap: 48px; }
  .steps { grid-template-columns: repeat(4, 1fr); }
  .features { grid-template-columns: repeat(3, 1fr); }
}

/* The product previews: the app's own pieces in a phone and a browser frame. */
.phone { justify-self: center; width: 100%; max-width: 340px; border: 10px solid var(--text); border-radius: 34px; background: var(--surface); box-shadow: 0 20px 50px rgb(0 0 0 / 18%); overflow: hidden; }
.phone-bar { padding: 12px 16px; border-bottom: 1px solid var(--rule); font-weight: 650; }
.phone .chat-log { overflow: visible; }
.phone .bubble .card h2 { margin: 0 0 4px; font-size: 14px; }
.phone .rows td { padding: 6px 4px; font-size: 14px; }
.btn.mini { min-height: 32px; padding: 0 12px; margin-top: 8px; font-size: 13px; }
.browser { border: 1px solid var(--card-border); border-radius: 14px; background: var(--surface); box-shadow: 0 16px 40px rgb(0 0 0 / 12%); overflow: hidden; }
.browser-bar { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--rule); background: var(--surface-2); }
.browser-bar .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--card-border); }
.browser-bar .url { margin-left: 8px; padding: 3px 10px; border-radius: 999px; background: var(--surface); color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browser-body { padding: 16px; }
.browser-body .balances { margin: 8px 0 0; box-shadow: none; }
.mock-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-bottom: 1px solid var(--rule); font-weight: 550; }
.mock-row:last-child { border-bottom: 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; } /* the honeypot: off screen, skipped by tab */

/* Settings' players table: a grid, so the four columns fit a phone. Pill inputs, × in the last column. */
.card-head { display: flex; gap: 14px; align-items: center; }
.card-head h2 { margin: 0; }
.tile { display: grid; place-items: center; flex: none; width: 48px; height: 48px; border-radius: 12px; background: var(--logo-bg); color: var(--logo-fg); }
.ptable { border: 1px solid var(--card-border); border-radius: var(--radius); overflow: hidden; }
.prow { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 36px; gap: 6px; align-items: center; padding: 8px 4px 8px 8px; border-top: 1px solid var(--rule); }
.prow:first-child { border-top: 0; }
.phead { font-weight: 600; font-size: 14px; padding-top: 10px; padding-bottom: 10px; }
.prow input { border-radius: 999px; padding: 10px 12px; }
/* Line two: the balance (read-only), or a new player's amount and owes / is owed. */
.pbal { grid-column: 1 / 3; display: flex; gap: 8px; align-items: center; padding-left: 12px; white-space: nowrap; }
.pbal input { flex: none; width: 6.5rem; }
.plabel { color: var(--text-muted); font-size: 14px; }
.prow .x { grid-column: 3; grid-row: 1; }
.prow .x { display: grid; place-items: center; width: 36px; min-height: 44px; padding: 0; border: 0; background: none; color: var(--text-muted); cursor: pointer; }
.add-row { display: flex; gap: 8px; align-items: center; width: 100%; min-height: 48px; padding: 0 14px; border: 0; border-top: 1px solid var(--rule); background: var(--surface-2); color: var(--accent); font: 600 16px var(--font-body); cursor: pointer; }
.add-row[hidden], .prow .x[hidden] { display: none; }
.pbal select { width: auto; padding: 0 10px; border-radius: 999px; }

/* The group page's two totals over the balances. */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.totals p { display: grid; gap: 2px; margin: 0; padding: 12px 16px; background: var(--surface); border: 1px solid var(--card-border); border-radius: var(--radius); box-shadow: var(--shadow); }
.totals strong { font-size: 22px; font-weight: 650; }

/* The name: serif italic, a little larger than the text around it. */
.wordmark { font-family: var(--font-wordmark); font-style: italic; font-weight: 700; letter-spacing: 0.2px; }
h1 .wordmark { font-size: 1.15em; }
