/* Mobile-first PWA styles for the Collector app. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: #f1f5f9;
  color: #0f172a;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  overscroll-behavior-y: contain;
}
input, button, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: #1e40af; text-decoration: none; }

/* ---------- Loading screen ---------- */
.loading-screen {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: linear-gradient(135deg, #1e40af 0%, #65a30d 100%);
  color: #fff; text-align: center;
}
.loading-screen img { filter: brightness(0) invert(1); opacity: 0.95; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: flex; flex-direction: column;
  background: linear-gradient(135deg, #1e40af 0%, #65a30d 100%);
  padding: 40px 20px; color: #fff;
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo img { max-width: 200px; }
.login-logo h1 { font-size: 20px; margin: 12px 0 4px; }
.login-logo p { font-size: 13px; opacity: .85; margin: 0; }
.login-card {
  background: #fff; color: #0f172a; padding: 28px 24px;
  border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.2);
}
.login-card h2 { margin: 0 0 18px; font-size: 18px; color: #1e3a8a; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border: 1px solid #cbd5e1; border-radius: 10px;
  font-size: 16px; outline: none; background: #fff;
}
.field input:focus { border-color: #1e40af; box-shadow: 0 0 0 3px rgba(30,64,175,.15); }

.btn {
  width: 100%; padding: 14px 16px;
  background: linear-gradient(135deg, #1e40af 0%, #65a30d 100%);
  color: #fff; border: 0; border-radius: 10px;
  font-size: 16px; font-weight: 600; margin-top: 8px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .6; }
.btn.outline {
  background: #fff; color: #1e40af;
  border: 1px solid #93c5fd;
}
.btn.danger { background: #dc2626; }
.btn.small { padding: 10px 12px; font-size: 14px; }

.error-msg { color: #b91c1c; font-size: 13px; margin-top: 12px; text-align: center; }

/* ---------- App shell ---------- */
.shell { display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 76px; }

/* Pending-sync banner */
.sync-badge {
  display: flex; align-items: center; gap: 8px;
  background: #fef3c7; color: #92400e;
  padding: 10px 14px; font-size: 13px;
  border-bottom: 1px solid #fcd34d;
  position: sticky; top: 0; z-index: 70;
}
.sync-badge .ico { font-size: 16px; }
.sync-badge .count { font-weight: 700; }
.sync-badge .text { flex: 1; }
.sync-badge .sync-btn {
  background: #92400e; color: #fff; border: 0;
  padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600;
}
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%);
  color: #fff; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.1);
}
.topbar .back {
  background: none; border: 0; color: #fff; font-size: 22px; padding: 0 4px;
}
.topbar .title { flex: 1; font-size: 16px; font-weight: 600; }
.topbar .sub { font-size: 12px; opacity: .85; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  background: #fff; border-top: 1px solid #e2e8f0;
  display: flex; padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.tabbar a {
  flex: 1; text-align: center; padding: 8px 4px;
  color: #64748b; font-size: 11px; text-decoration: none;
  display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.tabbar a .ico { font-size: 22px; line-height: 1; }
.tabbar a.active { color: #1e40af; font-weight: 600; }

/* ---------- Lists ---------- */
.content { padding: 14px 14px 20px; }
.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi {
  background: #fff; padding: 14px; border-radius: 12px;
  box-shadow: 0 2px 8px rgba(15,23,42,.06);
}
.kpi .label { color: #64748b; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 22px; font-weight: 700; color: #1e3a8a; margin-top: 4px; line-height: 1.1; }
.kpi.good .value { color: #15803d; }
.kpi.bad .value { color: #b91c1c; }

.list { background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(15,23,42,.06); overflow: hidden; }
.list-row {
  display: flex; gap: 12px; padding: 14px 14px; border-bottom: 1px solid #f1f5f9;
  cursor: pointer; align-items: stretch;
}
.list-row:last-child { border-bottom: 0; }
.list-row:active { background: #f8fafc; }
.list-row .stripe { width: 4px; border-radius: 4px; background: #cbd5e1; }
.list-row.late .stripe { background: #dc2626; }
.list-row.due .stripe { background: #f59e0b; }
.list-row.paid .stripe { background: #15803d; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .name { font-weight: 600; font-size: 15px; }
.list-row .meta { color: #64748b; font-size: 12px; margin-top: 2px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.list-row .amount { text-align: right; }
.list-row .amount .big { font-size: 15px; font-weight: 700; color: #1e3a8a; }
.list-row .amount .small { font-size: 11px; color: #64748b; margin-top: 2px; }
.list-row.late .amount .big { color: #b91c1c; }

.empty { text-align: center; padding: 40px 20px; color: #94a3b8; font-size: 14px; }
.empty .icon { font-size: 48px; opacity: .6; margin-bottom: 8px; }

/* ---------- Detail page ---------- */
.detail-section { background: #fff; border-radius: 12px; padding: 16px; margin-bottom: 14px; box-shadow: 0 2px 8px rgba(15,23,42,.06); }
.detail-section h3 { margin: 0 0 10px; font-size: 14px; color: #1e3a8a; text-transform: uppercase; letter-spacing: .5px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; font-size: 14px; }
.kv .k { color: #64748b; font-size: 12px; }
.kv .v { font-weight: 600; }

.contact-actions { display: flex; gap: 8px; margin-top: 12px; }
.contact-actions a {
  flex: 1; text-align: center; padding: 12px; border-radius: 10px;
  background: #dbeafe; color: #1e40af; font-weight: 600; font-size: 14px;
  text-decoration: none;
}
.contact-actions a.call { background: #dcfce7; color: #15803d; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.badge.late { background: #fee2e2; color: #991b1b; }
.badge.due { background: #fef3c7; color: #92400e; }
.badge.ok { background: #dcfce7; color: #15803d; }

/* ---------- Payment form ---------- */
.amount-input {
  font-size: 32px !important; text-align: center; font-weight: 700;
  padding: 18px 14px !important; color: #1e3a8a;
}
.method-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 6px; }
.method-btn {
  padding: 14px; border: 2px solid #e2e8f0; border-radius: 10px;
  background: #fff; font-weight: 600; color: #475569; font-size: 14px;
}
.method-btn.active { border-color: #1e40af; background: #dbeafe; color: #1e40af; }

.suggest-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.suggest-row button {
  flex: 1; min-width: 80px; padding: 10px 4px; font-size: 13px;
  background: #f1f5f9; color: #1e3a8a; border: 0; border-radius: 8px; font-weight: 600;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 18px;
  border-radius: 10px; font-size: 14px; z-index: 999;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 90vw;
}
.toast.ok { background: #15803d; }
.toast.bad { background: #b91c1c; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: flex-end; z-index: 200;
}
.modal {
  width: 100%; background: #fff; border-radius: 16px 16px 0 0;
  padding: 20px 18px max(20px, env(safe-area-inset-bottom));
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal .actions { display: flex; gap: 8px; margin-top: 14px; }
.modal .actions .btn { margin: 0; }

/* ---------- CI app: photo tiles ---------- */
.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-tile {
  background: #f8fafc; border: 2px dashed #cbd5e1; border-radius: 10px;
  padding: 14px 10px; text-align: center; cursor: pointer; transition: 0.15s;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.photo-tile:active { transform: scale(0.98); }
.photo-tile.done { border-style: solid; border-color: #15803d; background: #f0fdf4; }
.photo-tile .ico { font-size: 28px; line-height: 1; }
.photo-tile .lbl { font-size: 13px; font-weight: 600; color: #1e3a8a; }
.photo-tile.done .lbl { color: #15803d; }
.photo-tile .status { font-size: 11px; color: #64748b; }
.photo-tile.done .status { color: #15803d; font-weight: 600; }
.photo-input { display: none; }

/* ---------- CI app: checklist ---------- */
.check-list { display: flex; flex-direction: column; gap: 6px; }
.check-row {
  display: flex; gap: 12px; padding: 12px; background: #f8fafc;
  border-radius: 8px; cursor: pointer; align-items: flex-start;
}
.check-row:active { background: #f1f5f9; }
.check-row .cb {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #cbd5e1; background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: transparent;
}
.check-row .cb.verified { background: #15803d; border-color: #15803d; color: #fff; }
.check-row .cb.failed { background: #dc2626; border-color: #dc2626; color: #fff; }
.check-row .check-text { flex: 1; font-size: 14px; }
.check-row .check-text .meta { color: #64748b; font-size: 12px; margin-top: 2px; }

@media (min-width: 600px) {
  .shell, .login { max-width: 540px; margin: 0 auto; }
  .modal-bg { align-items: center; justify-content: center; }
  .modal { max-width: 480px; border-radius: 16px; }
}
