/* Mobile first: one column, thumb-sized targets (44px+), 16px inputs so iOS
   doesn't zoom, safe-area padding for notched phones. Wider screens (iPad)
   get a centred column. */
:root {
  --brand: #2f5bea;
  --brand-ink: #fff;
  --bg: #f5f7fb;
  --card: #fff;
  --ink: #18202f;
  --muted: #5d6779;
  --line: #e2e6ee;
  --good: #137a3f;
  --good-bg: #e3f5ea;
  --warn: #8a5a00;
  --warn-bg: #fff2d6;
  --bad: #b3261e;
  --bad-bg: #fde7e5;
  --radius: 14px;
  --tabbar: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Layout */
.screen { max-width: 720px; margin: 0 auto; padding: 0 16px calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  margin: 0 -16px 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; font-size: 28px; padding: 0; border: 0; background: none; color: var(--brand); }
.env-pill { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted); position: relative;
}
.tabbar a .ico { font-size: 22px; line-height: 1; }
.tabbar a[aria-current='page'] { color: var(--brand); font-weight: 600; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* Cards and lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card h3 { margin: 12px 0 6px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; min-height: 60px; width: 100%; text-align: left;
}
button.row { cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .side { text-align: right; font-size: 14px; white-space: nowrap; }
.muted { color: var(--muted); }
.row.contact { flex-wrap: wrap; }
.row.contact .main .sub { white-space: normal; }
.contact-actions { display: flex; gap: 8px; width: 100%; }
.contact-actions .btn { flex: 1; }
.small { font-size: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.rates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.rates div { background: var(--bg); border-radius: 10px; padding: 8px; text-align: center; }
.rates b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.rates span { font-size: 12px; color: var(--muted); }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; margin: 2px 4px 2px 0; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

/* Forms */
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  font-size: 16px; /* 16px stops iOS zooming on focus */
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.search { position: sticky; top: calc(64px + env(safe-area-inset-top)); z-index: 4; background: var(--bg); padding-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 label { margin-top: 6px; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); font-size: 15px; }
.toggle input { width: 22px; min-height: 22px; height: 22px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--brand);
  background: var(--brand); color: var(--brand-ink); font-weight: 600; cursor: pointer;
}
.btn.block { width: 100%; margin-top: 12px; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.actions .btn { flex: 1; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 8px; }
.segmented button { min-height: 40px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed='true'] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Login */
.login { max-width: 420px; margin: 0 auto; padding: calc(48px + env(safe-area-inset-top)) 20px 32px; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 12px; }
.login h1 { margin: 0 0 4px; font-size: 26px; }

/* Feedback */
.error { background: var(--bad-bg); color: var(--bad); border-radius: 12px; padding: 10px 12px; margin: 10px 0; font-size: 15px; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 12px; margin: 10px 0; font-size: 15px; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.spinner { display: block; width: 28px; height: 28px; margin: 24px auto; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar) + 12px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 560px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
  background: var(--ink); color: #fff; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.total { display: flex; justify-content: space-between; font-size: 20px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; }

@media (min-width: 768px) {
  .screen { padding-top: 8px; }
  .results { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
}
