@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@600;700;800&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #16212B;
  --steel: #4A5A64;
  --steel-line: #C9CDBF;
  --paper: #EDE9DC;
  --paper-raised: #F7F4EA;
  --amber: #EE9B2A;
  --amber-dark: #B9740F;
  --stamp-red: #A6392C;
  --stamp-green: #2E6B4C;
  --stamp-amber: #B9740F;
  --tabbar-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: 'Archivo', sans-serif; letter-spacing: .01em; margin: 0; }

.app { min-height: 100vh; padding-bottom: var(--tabbar-h); }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--ink);
  color: var(--paper-raised);
  padding: 16px 16px;
  border-bottom: 4px solid var(--amber);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.brand h1 { font-size: 17px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.brand span.sub { font-size: 10.5px; color: var(--amber); text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }

/* ---------- Bottom tab bar (mobile-first nav) ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tabbar-h);
  background: var(--ink);
  display: flex;
  border-top: 1px solid rgba(247,244,234,.15);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: rgba(247,244,234,.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: 'Archivo', sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  cursor: pointer;
  padding: 6px 4px;
}
.tab-btn .tab-icon { font-size: 19px; line-height: 1; }
.tab-btn.active { color: var(--amber); }

/* ---------- Content ---------- */
.content { max-width: 720px; margin: 0 auto; padding: 16px 12px 24px; }

.card {
  background: var(--paper-raised);
  border: 1px solid var(--steel-line);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 2px 2px 0 rgba(22,33,43,.06);
}
.card h2 { font-size: 16px; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
.card .hint { color: var(--steel); font-size: 13px; margin: 4px 0 14px; line-height: 1.4; }
.eyebrow { font-size: 10.5px; text-transform: uppercase; letter-spacing: .13em; color: var(--amber-dark); font-weight: 700; margin-bottom: 6px; }

label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--steel); margin-bottom: 6px; }

select, input[type=text], input[type=file] {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 16px; /* avoid iOS zoom-on-focus */
  padding: 13px 12px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: #fff;
  width: 100%;
  color: var(--ink);
}
select:focus, input[type=text]:focus { outline: 2px solid var(--amber); outline-offset: 1px; }

.scan-row { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.scan-row input { flex: 1; }

.btn {
  font-family: 'Archivo', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-size: 13.5px;
  background: var(--ink);
  color: var(--paper-raised);
  border: none;
  border-radius: 4px;
  padding: 14px 18px;
  cursor: pointer;
  width: 100%;
  min-height: 48px;
}
.btn:active { background: #233544; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-amber { background: var(--amber); color: var(--ink); }
.btn-amber:active { background: var(--amber-dark); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--ink); }
.btn-danger { background: transparent; color: var(--stamp-red); border: 1.5px solid var(--stamp-red); }
.btn-danger:active { background: var(--stamp-red); color: #fff; }
.btn-sm { width: auto; padding: 10px 14px; font-size: 12px; min-height: 40px; }

.danger-actions { display: flex; flex-direction: column; gap: 10px; }

.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  text-transform: none; letter-spacing: normal; font-size: 13.5px; color: var(--ink);
  margin: 4px 0;
}
.checkbox-row input { width: auto; }

#registerForm, #loginForm, #forgotForm { display: flex; flex-direction: column; gap: 12px; }
#registerForm[hidden], #loginForm[hidden], #forgotForm[hidden] { display: none; }

/* ---------- Entry list ---------- */
.pill { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--steel); margin-bottom: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--steel-line); flex-shrink: 0; }
.dot.on { background: var(--stamp-green); }

.entry-list { max-height: 50vh; overflow-y: auto; margin-top: 14px; border: 1px solid var(--steel-line); border-radius: 4px; background: #fff; }
.entry-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--steel-line); font-size: 13.5px; }
.entry-row:last-child { border-bottom: none; }
.entry-row .ref { font-family: 'IBM Plex Mono', monospace; font-weight: 700; }
.entry-row .desig { flex: 1; color: var(--steel); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-row .unknown { color: var(--stamp-red); font-size: 11px; text-transform: uppercase; font-weight: 700; letter-spacing: .03em; flex: 1; }
.entry-row button { background: none; border: none; color: var(--stamp-red); cursor: pointer; font-size: 20px; line-height: 1; padding: 4px 6px; flex-shrink: 0; }
.entry-row-duplicate { background: var(--warning-bg, #fff7ed); }

.entry-count { margin-top: 12px; font-size: 13px; color: var(--steel); }

/* ---------- Stamps / badges ---------- */
.stamp {
  display: inline-block; font-family: 'Archivo', sans-serif; font-weight: 700; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .05em; padding: 3px 9px; border-radius: 2px;
  border: 1.5px dashed currentColor; transform: rotate(-2deg); white-space: nowrap;
}
.stamp-bad { color: var(--stamp-red); }
.stamp-ok { color: var(--stamp-green); }
.stamp-warn { color: var(--stamp-amber); }

.badge {
  display: inline-block; background: var(--ink); color: var(--paper-raised); font-size: 10.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 10px; margin: 0 5px 5px 0; font-family: 'IBM Plex Mono', monospace;
}
.agency-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }

/* ---------- Tables (horizontal scroll on mobile) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 480px; }
thead th {
  text-align: left; font-family: 'Archivo', sans-serif; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--steel); border-bottom: 2px solid var(--ink); padding: 8px 6px; white-space: nowrap;
}
tbody td { padding: 9px 6px; border-bottom: 1px solid var(--steel-line); vertical-align: top; }
.mono { font-family: 'IBM Plex Mono', monospace; font-weight: 600; white-space: nowrap; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.stat-card { background: var(--paper-raised); border: 1px solid var(--steel-line); border-radius: 6px; padding: 14px; text-align: center; box-shadow: 2px 2px 0 rgba(22,33,43,.06); }
.stat-n { font-family: 'Archivo', sans-serif; font-size: 26px; font-weight: 800; }
.stat-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--steel); margin-top: 2px; }
.stat-bad .stat-n { color: var(--stamp-red); }
.stat-ok .stat-n { color: var(--stamp-green); }

.empty { padding: 22px; text-align: center; color: var(--steel); font-size: 13px; border: 1.5px dashed var(--steel-line); border-radius: 4px; }

/* ---------- Collapsible per-agency missing report ---------- */
details { border: 1px solid var(--steel-line); border-radius: 4px; margin-bottom: 8px; background: #fff; }
summary { cursor: pointer; padding: 12px 14px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; list-style: none; gap: 10px; font-size: 13.5px; }
summary::-webkit-details-marker { display: none; }
details[open] summary { border-bottom: 1px solid var(--steel-line); }
details .table-wrap { padding: 10px 12px; }

/* ---------- Import dropzone ---------- */
.dropzone {
  border: 2px dashed var(--ink); border-radius: 6px; padding: 32px 16px; text-align: center; cursor: pointer;
  background: repeating-linear-gradient(45deg, rgba(22,33,43,.02) 0 10px, transparent 10px 20px);
  font-size: 14px;
}
.error-text { color: var(--stamp-red); margin-top: 10px; font-size: 13px; }
.ok-text { color: var(--stamp-green); margin-top: 10px; font-size: 13px; }
.muted-inline { display: block; margin-top: 10px; font-size: 12px; color: var(--steel); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 14px); left: 12px; right: 12px; z-index: 50;
  font-size: 13.5px; padding: 12px 16px; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.25);
  font-weight: 500; text-align: center;
}
.toast-ok { background: var(--stamp-green); color: #fff; }
.toast-warn { background: var(--stamp-amber); color: #fff; }
.toast-error { background: var(--stamp-red); color: #fff; }

/* ---------- Larger screens ---------- */
@media (min-width: 640px) {
  .content { max-width: 900px; padding: 24px 20px 32px; }
  .scan-row { flex-direction: row; align-items: flex-end; }
  .scan-row input { margin-bottom: 0; }
  .btn { width: auto; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .danger-actions { flex-direction: row; }
}

@media (min-width: 860px) {
  .app { padding-bottom: 0; }
  .tabbar {
    position: sticky; top: 0; height: auto; border-top: none; border-bottom: 4px solid var(--amber);
    padding-bottom: 0; justify-content: flex-end; gap: 4px; padding: 10px 16px;
  }
  .tab-btn { flex: none; flex-direction: row; gap: 6px; padding: 9px 14px; border: 1px solid rgba(247,244,234,.25); border-radius: 3px; }
  .tab-btn.active { background: var(--amber); color: var(--ink); border-color: var(--amber); }
  .tab-btn .tab-icon { font-size: 14px; }
  .toast { left: auto; right: 22px; bottom: 22px; max-width: 360px; }
}
