/* ---------------------------------------------------------------------
   Field Visit Portal — design tokens
   Palette and type are deliberately ledger/field-notebook inspired:
   ink navy for structure, an amber "verified stamp" accent for the
   moment a visit gets GPS-confirmed, and a monospace face reserved for
   coordinates, IDs and loan numbers — the precise, recorded data.
   ------------------------------------------------------------------ */
:root {
  --ink: #16233F;
  --ink-700: #22335A;
  --paper: #F1F2EE;
  --card: #FFFFFF;
  --amber: #B8863B;
  --amber-100: #F3E8D3;
  --amber-700: #8A6428;
  --success: #3C7A5B;
  --success-100: #E1EFE7;
  --error: #B23A34;
  --error-100: #F8E4E2;
  --text: #1B1E24;
  --text-muted: #5B6270;
  --border: #DDDFD8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 35, 63, 0.06), 0 1px 1px rgba(22, 35, 63, 0.04);
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ink); }

h1, h2, h3 { font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.topbar {
  background: var(--ink);
  color: #EDEFF4;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  color: #fff;
  text-decoration: none;
}
.brand .mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--amber);
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px; font-weight: 700;
  color: var(--ink);
}
.topbar nav { display: flex; align-items: center; gap: 4px; }
.topbar nav a {
  color: #C7CCDA;
  text-decoration: none;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
}
.topbar nav a:hover { color: #fff; background: rgba(255,255,255,0.08); }
.topbar nav a.active { color: #fff; background: rgba(255,255,255,0.14); }
.topbar .who { color: #9AA2B6; font-size: 13px; margin-left: 8px; }
.logout-form { display: inline-flex; margin: 0; }
.logout-btn {
  font-family: var(--font-sans);
  color: #C7CCDA;
  background: none;
  border: none;
  text-decoration: none;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.logout-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}
.page.wide { max-width: 1080px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.header-row p { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }

/* ---------- messages ---------- */
.messages { list-style: none; margin: 0 0 16px; padding: 0; }
.messages li {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 8px;
  background: var(--amber-100);
  color: var(--amber-700);
  border: 1px solid rgba(184,134,59,0.35);
}

/* ---------- forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=tel], input[type=password], input[type=date],
input[type=number], select, textarea {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
  border-color: var(--amber);
}
textarea { resize: vertical; }
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field-error { font-size: 12.5px; color: var(--error); margin-top: 4px; }
.error-banner {
  background: var(--error-100);
  color: var(--error);
  border: 1px solid rgba(178,58,52,0.35);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.error-banner:empty { display: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 14.5px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  width: 100%;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-700); }
.btn-primary:disabled { background: #A8ADB8; cursor: not-allowed; }
.btn-amber { background: var(--amber); color: #fff; }
.btn-amber:disabled { background: #D9C7A2; cursor: not-allowed; }
.btn-outline { background: transparent; color: var(--ink); border-color: var(--border); }
.btn-auto { width: auto; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* ---------- GPS / camera capture ---------- */
.capture-step {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
  background: #FAFAF8;
}
.capture-step.done { border-style: solid; border-color: var(--success); background: var(--success-100); }
.step-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 10px;
}
.step-num {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink); color: #fff;
  font-size: 11px; font-family: var(--font-mono);
  display: inline-flex; align-items: center; justify-content: center;
}
.capture-step.done .step-num { background: var(--success); }

.gps-status { font-size: 13.5px; color: var(--text-muted); margin-top: 8px; }
.gps-coords { font-family: var(--font-mono); font-size: 13px; color: var(--ink); }

/* the "verified" stamp — the one signature flourish */
.stamp {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  color: var(--success);
  border: 1.5px solid var(--success);
  border-radius: 999px;
  padding: 3px 10px 3px 8px;
  transform: rotate(-2deg);
  background: #fff;
}
.stamp svg { width: 13px; height: 13px; }

video#camera-preview, #photo-preview {
  width: 100%;
  border-radius: 8px;
  background: #000;
  display: block;
  margin-top: 10px;
  max-height: 360px;
  object-fit: cover;
}
.camera-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- dashboard ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card .value { font-family: var(--font-mono); font-size: 28px; font-weight: 600; color: var(--ink); }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.stat-card.warn .value { color: var(--error); }

.breakdown-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.breakdown-list { list-style: none; margin: 0; padding: 0; }
.breakdown-list li {
  display: flex; justify-content: space-between;
  padding: 7px 0; border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.breakdown-list li:last-child { border-bottom: none; }
.breakdown-list .count { font-family: var(--font-mono); color: var(--ink); font-weight: 600; }

/* ---------- reports ---------- */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  align-items: end;
}
.filter-bar .filter-actions { grid-column: span 4; display: flex; gap: 10px; margin-top: 4px; }
.filter-bar label { margin-top: 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table.report { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.report th {
  text-align: left; background: var(--paper); color: var(--text-muted);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
table.report td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
table.report tr:last-child td { border-bottom: none; }
table.report .coord { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
table.report a.photo-link { color: var(--amber-700); font-weight: 600; text-decoration: none; }
table.report a.photo-link:hover { text-decoration: underline; }
.no-gps { color: var(--error); font-family: var(--font-mono); font-size: 12px; }

.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }
.pagination a, .pagination span {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; text-decoration: none; color: var(--ink); background: #fff;
}
.pagination .current { background: var(--ink); color: #fff; border-color: var(--ink); }

.result-count { font-size: 13px; color: var(--text-muted); margin: 10px 0; }

/* ---------- misc ---------- */
.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card { width: 100%; max-width: 380px; }
.login-card .brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; justify-content: center; }
.success-icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--success-100); color: var(--success);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
}
.text-center { text-align: center; }
.muted { color: var(--text-muted); }
.mt-16 { margin-top: 16px; }

@media (max-width: 720px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .breakdown-grid { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: repeat(2, 1fr); }
  .filter-bar .filter-actions { grid-column: span 2; }
  .topbar .who { display: none; }
}
