:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --ink: #131a24;
  --muted: #565f6b;          /* darker than before — readable outdoors in daylight */
  --line: #d7dbe0;
  --brand: #1560d6;          /* AA contrast on white for button text */
  --brand-ink: #ffffff;
  --ok: #16713f;
  --warn: #9a4400;
  --danger: #b02a1c;
  --radius: 12px;
  --tap: 48px;               /* minimum interactive height — thumb, not cursor */
  --shadow: 0 1px 3px rgba(20, 30, 45, .08), 0 6px 20px rgba(20, 30, 45, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* System default sizing, not compact — this is read at arm's length, one-handed */
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; letter-spacing: -.01em; color: var(--ink); font-size: 17px; }
.topbar-link { color: var(--muted); font-size: 14px; }

.wrap { max-width: 620px; margin: 0 auto; padding: 16px 16px 120px; }

.flashes { max-width: 620px; margin: 12px auto 0; padding: 0 16px; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; font-size: 14px; }
.flash-danger { background: #fde8e6; color: var(--danger); }
.flash-warning { background: #fdf0e3; color: var(--warn); }
.flash-info, .flash-success { background: #e6f2ff; color: var(--brand); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card[hidden] { display: none; }
.card h2 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type=text], input[type=email], input[type=tel], input[type=number],
input[type=search], input[type=password], input:not([type]), select, textarea {
  width: 100%; min-height: var(--tap); padding: 12px 13px; font-size: 16px; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 10px; -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
textarea { min-height: 84px; resize: vertical; }

.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.row .grow-2 { flex: 2; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 12px 18px; font-size: 16px; font-weight: 600; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 18px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  min-height: 44px; display: inline-flex; align-items: center;
  padding: 8px 14px; font-size: 15px; border-radius: 999px; border: 1px solid var(--line);
  background: #f4f7fb; color: var(--ink); cursor: pointer;
}
.chip.is-star { border-color: var(--brand); color: var(--brand); font-weight: 600; }

.client-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow: auto; }
.client-list button {
  text-align: left; min-height: var(--tap); padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-size: 16px;
}
.client-list .sub { display: block; font-size: 14px; color: var(--muted); margin-top: 2px; }

/* Segmented toggle (client type) — big touch targets, no dropdown */
.segmented { display: flex; gap: 8px; }
.segmented label {
  flex: 1; margin: 0; text-align: center; min-height: var(--tap); display: flex; align-items: center;
  justify-content: center; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 15px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:checked + span { }
.segmented label:has(input:checked) { border-color: var(--brand); color: var(--brand); font-weight: 600; background: #eef4fe; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eef1f4; color: var(--muted); }
.pill-warn { background: #fdf0e3; color: var(--warn); }

.selected-client { display: flex; align-items: center; justify-content: space-between; }
.selected-client strong { font-size: 16px; }

.line {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fcfcfd;
}
.line .line-head { display: flex; gap: 8px; align-items: stretch; }
.line .line-head > .desc { flex: 1; }
.line .line-meta { display: flex; gap: 8px; margin-top: 10px; }
.line .line-meta .qty { flex: 1; }
.line .line-meta .amt { flex: 1.6; }
.line .line-meta .type { flex: 1.4; }
.line .rm {
  flex: 0 0 var(--tap); width: var(--tap); min-height: var(--tap); align-self: stretch;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--muted);
  font-size: 22px; cursor: pointer;
}

.totals { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 12px; font-size: 15px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 19px; font-weight: 700; padding-top: 8px; }

.sendbar {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--card);
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  z-index: 30; box-shadow: 0 -4px 16px rgba(20, 30, 45, .08);
}
.sendbar .inner { max-width: 620px; margin: 0 auto; }
.send-error { color: var(--danger); font-size: 15px; margin-bottom: 10px; text-align: center; font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 14px; }

/* --- Icon buttons/links --- */
.ico-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.ico-btn {
  display: inline-flex; flex-direction: column; align-items: center; gap: 5px;
  border: none; background: none; cursor: pointer; padding: 6px; min-height: var(--tap);
  color: var(--brand); font-size: 12px; font-weight: 600; text-decoration: none; line-height: 1.2;
}
.ico-btn img { width: auto; display: block; }
.ico-btn:active { opacity: .6; }
.ico-btn.compact { gap: 0; }
.ico-btn.compact span { display: none; }
.ico-add img { height: 64px; }

.actionbar { display: flex; align-items: center; gap: 12px; }
.actionbar > * { align-self: center; }
.actionbar .spacer { flex: 1; }
.actionbar .acct-logo { height: 44px; max-height: 44px; width: auto; max-width: 120px; object-fit: contain; }
.actionbar .ico-btn { padding: 2px; }
.actionbar .ico-add { padding: 0; }

.inv-row {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; line-height: 1.2; white-space: nowrap; overflow: hidden;
}
.inv-row form { margin: 0; flex: 0 0 auto; display: flex; }
.inv-num { font-weight: 600; flex: 0 0 auto; }
.inv-client { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.inv-ic { flex: 0 0 auto; border: none; background: none; padding: 2px; cursor: pointer; display: flex; }
/* beats `.client-list button` (which otherwise draws a box round these icons) */
.client-list .inv-ic { border: none; background: none; }
.inv-ic img { height: 26px; width: auto; display: block; }
.inv-status { flex: 0 0 auto; height: 26px; width: auto; display: block; }
.inv-amt { flex: 0 0 auto; text-align: right; font-variant-numeric: tabular-nums; }
.actionbar .msg-counts { display: flex; align-items: center; gap: 13px; font-size: 18px; line-height: 1; color: var(--muted); font-weight: 600; }
.actionbar .msg-counts > span { display: inline-flex; align-items: center; white-space: nowrap; }
.sms-left {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; margin-left: 6px; padding: 0 5px;
  border-radius: 999px; background: var(--ok); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
}
.od-green { color: var(--ok); font-weight: 600; }

dialog.pay-dlg {
  border: none; border-radius: 14px; padding: 20px;
  max-width: 340px; width: 92vw;
  box-shadow: 0 12px 44px rgba(0, 0, 0, .28); color: var(--ink);
}
dialog.pay-dlg::backdrop { background: rgba(0, 0, 0, .45); }
.od-amber { color: var(--warn); font-weight: 600; }
.od-red   { color: var(--danger); font-weight: 700; }

.copybox { display: flex; gap: 8px; align-items: stretch; }
.copybox input {
  flex: 1; min-width: 0; font-size: 14px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
}
.copybox .btn { flex: 0 0 auto; }
.copybox .btn.copied { background: var(--ok); border-color: var(--ok); color: #fff; }

.stat-grid { display: flex; gap: 12px; }
.stat-grid > * { flex: 1; }
.stat {
  display: block; border: 1px solid var(--line); border-radius: 10px; padding: 14px;
  text-decoration: none; color: var(--ink); background: #fbfcfd;
}
.stat .stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .stat-value { font-size: 22px; font-weight: 700; margin-top: 2px; display: block; }
a.stat:active { opacity: .6; }
.mt-1 { margin-top: 8px; }
.hide { display: none !important; }

.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.doc table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.doc th, .doc td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
.doc td.num, .doc th.num { text-align: right; }
