/* ── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: #222;
  background: #f4f5f7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navigation ─────────────────────────────────────────────────────────── */
nav {
  background: rgb(230, 78, 78);
  color: #fff;
  padding: 0 1rem 0 0;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: 56px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 200;
}
nav .nav-brand { font-weight: 700; font-size: 1.05rem; margin-right: auto; }
nav a { color: rgba(255,255,255,.88); font-size: .9rem; }
nav a:hover { color: #fff; text-decoration: none; }
.nav-icon { height: 56px; width: auto; display: block; flex-shrink: 0; }
nav > a:first-child { margin-left: 0rem; }

/* ── Main content ───────────────────────────────────────────────────────── */
main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

h1 { font-size: 1.5rem; margin-bottom: 1.25rem; color: #1e3a5f; }
h2 { font-size: 1.1rem; margin-bottom: .9rem; color: #334155; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid #dde1e9;
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

/* ── Flash messages ─────────────────────────────────────────────────────── */
.flash {
  padding: .75rem 1rem;
  border-radius: 5px;
  margin-bottom: 1rem;
  font-size: .9rem;
}
.flash.success { background: #dcfce7; border: 1px solid #86efac; color: #166534; }
.flash.error   { background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; }
.flash.info    { background: #dbeafe; border: 1px solid #93c5fd; color: #1e3a8a; }

/* ── Dashboard grid ─────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: #fff;
  border: 1px solid #dde1e9;
  border-radius: 6px;
  padding: 1.1rem 1rem;
  text-align: center;
}
.stat-card.stat-warn { border-color: #fbbf24; background: #fffbeb; }
.stat-num   { display: block; font-size: 2rem; font-weight: 700; color: #1e3a5f; }
.stat-label { display: block; font-size: .8rem; color: #64748b; margin-top: .15rem; }

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.action-card {
  display: block;
  background: #fff;
  border: 1px solid #dde1e9;
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.action-card:hover {
  border-color: #2563eb;
  box-shadow: 0 2px 8px rgba(37,99,235,.12);
  text-decoration: none;
}
.action-card h2 { color: #2563eb; margin-bottom: .35rem; }
.action-card p  { font-size: .88rem; color: #555; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-row {
  margin-bottom: 1rem;
}
.form-row label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .35rem;
  color: #374151;
}
.hint-label { font-weight: 400; color: #6b7280; }

input[type=text],
input[type=number],
input[type=file] {
  width: 100%;
  padding: .45rem .65rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: .95rem;
  background: #fff;
  outline: none;
  transition: border-color .15s;
}
input[type=text]:focus,
input[type=number]:focus { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
input[type=number] { width: auto; }

button {
  padding: .5rem 1.15rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s;
}
button:hover    { background: #1d4ed8; }
button:disabled { background: #94a3b8; cursor: not-allowed; }

/* ── Hint / autocomplete ─────────────────────────────────────────────────── */
.hint-wrap { position: relative; }
.hint-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 220px;
  overflow-y: auto;
  list-style: none;
  z-index: 100;
  display: none;
}
.hint-list.open { display: block; }
.hint-list li {
  padding: .45rem .65rem;
  cursor: pointer;
  font-size: .9rem;
  border-bottom: 1px solid #f1f5f9;
}
.hint-list li:last-child { border-bottom: none; }
.hint-list li:hover,
.hint-list li.active { background: #eff6ff; }
.hint-list .loc { color: #94a3b8; font-size: .82rem; }

.hint-selected {
  font-size: .82rem;
  color: #2563eb;
  margin-top: .3rem;
  min-height: 1em;
}

/* ── Progress bar ───────────────────────────────────────────────────────── */
.progress-bar-outer {
  background: #e2e8f0;
  border-radius: 4px;
  height: 14px;
  overflow: hidden;
  margin: .75rem 0 .35rem;
}
.progress-bar-inner {
  height: 100%;
  background: #2563eb;
  width: 0;
  transition: width .2s;
}

/* ── Import log ─────────────────────────────────────────────────────────── */
#process-log {
  max-height: 300px;
  overflow-y: auto;
  font-size: .8rem;
  font-family: monospace;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 4px;
  padding: .5rem .75rem;
  margin-top: .5rem;
}
.log-line { padding: .1rem 0; }
.log-inserted  { color: #86efac; }
.log-duplicate { color: #fbbf24; }
.log-error     { color: #f87171; }

/* ── FA table ───────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
th, td {
  padding: .45rem .65rem;
  border: 1px solid #e2e8f0;
  text-align: left;
}
th { background: #f8fafc; font-weight: 600; color: #334155; }
td.note-cell { max-width: 280px; font-size: .82rem; }

/* ── Save status ────────────────────────────────────────────────────────── */
.save-ok    { color: #166534; font-size: .88rem; margin-left: .75rem; }
.save-error { color: #991b1b; font-size: .88rem; margin-left: .75rem; }

/* ── Login page ─────────────────────────────────────────────────────────── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 52px - 40px);
}
.login-card {
  background: #fff;
  border: 1px solid #dde1e9;
  border-radius: 8px;
  padding: 2rem 2.25rem;
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  font-size: 1.25rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

/* ── Nav user / logout ──────────────────────────────────────────────────── */
.nav-user   { font-size: .85rem; color: rgba(255,255,255,.75); margin-left: auto; }
.nav-logout { font-size: .85rem; color: rgba(255,255,255,.88) !important; }
.nav-logout:hover { color: #fff !important; }

/* ── Summary table helpers ──────────────────────────────────────────────── */
.table-card { padding: 0; overflow-x: auto; }
.num-cell   { text-align: right; white-space: nowrap; width: 1%; }
.loc-cell   { font-size: .8rem; max-width: 260px; }

table th a  { color: inherit; text-decoration: none; }
table th a:hover { text-decoration: underline; }

.count-badge {
  display: inline-block;
  background: #e2e8f0;
  color: #475569;
  font-size: .75rem;
  font-weight: 600;
  border-radius: 999px;
  padding: .1em .55em;
  vertical-align: middle;
  margin-left: .4rem;
}

/* ── Route type badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  padding: .1em .45em;
  border-radius: 3px;
  white-space: nowrap;
}
.badge-trad  { background: #fef3c7; color: #92400e; }
.badge-sport { background: #dbeafe; color: #1e40af; }
.badge-tr    { background: #f3e8ff; color: #6b21a8; }
.badge-pmc   { background: #dcfce7; color: #166534; }
.badge-dmv   { background: #dbeafe; color: #1e40af; }
.badge-fa    { background: #dcfce7; color: #166534; }

.pmc-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .88rem;
  color: #374151;
  cursor: pointer;
}
#add-person-wrap {
  align-items: center;
  gap: 1rem;
  margin-top: .5rem;
  flex-wrap: wrap;
}

/* ── Location tree (routes2) ────────────────────────────────────────────── */
.loc-tree { display: flex; flex-direction: column; gap: .3rem; }

.loc-summary {
  cursor: pointer;
  padding: .5rem .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 600;
  font-size: .92rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  list-style: none;
  user-select: none;
}
.loc-summary::-webkit-details-marker { display: none; }
.loc-summary::before { content: '▶'; font-size: .65rem; color: #94a3b8; flex-shrink: 0; transition: transform .15s; }
details[open] > .loc-summary::before { transform: rotate(90deg); }
.loc-summary:hover { background: #f1f5f9; }

.loc-body {
  padding-left: 1.5rem;
  padding-top: .3rem;
  padding-bottom: .1rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.route-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .35rem .65rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: .88rem;
}
.route-row:hover { border-color: #cbd5e1; background: #f8fafc; }
.route-name { flex: 1; min-width: 0; }
.route-meta { display: flex; align-items: center; gap: .35rem; flex-shrink: 0; }

/* ── Misc ───────────────────────────────────────────────────────────────── */
.muted { color: #94a3b8; font-size: .88rem; }
code {
  background: #f1f5f9;
  padding: .1em .35em;
  border-radius: 3px;
  font-size: .85em;
}

footer {
  background: rgb(230, 78, 78);
  color: rgba(255,255,255,.75);
  text-align: center;
  font-size: .8rem;
  padding: .75rem;
}
