:root { color-scheme: light; }
* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #fafafa;
  color: #1a1a1a;
  margin: 0;
  padding: 16px;
  font-size: 14px;
}
.header {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 12px;
}
.header-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.header h1 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.header .meta { color: #666; font-size: 12px; margin-bottom: 12px; }
.auth-box { font-size: 12px; color: #666; white-space: nowrap; }
.auth-box a, .auth-box button.linkish {
  color: #1e6c3a; font-weight: 600; cursor: pointer; background: none; border: none; font-size: 12px; padding: 0;
}
.stat-row { display: flex; gap: 8px; flex-wrap: wrap; }
.stat {
  padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: #f0f0f0; color: #444; border: 1px solid #e0e0e0;
}
.stat.in_transit { background: #fff4e0; color: #8a5a00; border-color: #ffd789; }
.stat.arrived { background: #e0efff; color: #0f4d8a; border-color: #b7d4f5; }
.stat.delivered { background: #e6f5ea; color: #1e6c3a; border-color: #b5dbc3; }
.stat.stale { background: #fde2e2; color: #8a1414; border-color: #f5b7b7; }
.stat.unknown { background: #eee; color: #666; }
.toolbar {
  background: #fff; border: 1px solid #e5e5e5; border-radius: 12px;
  padding: 12px 16px; margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.toolbar input {
  flex: 1; min-width: 200px; padding: 8px 12px; border: 1px solid #d0d0d0;
  border-radius: 8px; font-size: 14px; background: #fff; color: #1a1a1a;
}
.toolbar button {
  padding: 7px 13px; border: 1px solid #d0d0d0; background: #fff; border-radius: 8px;
  cursor: pointer; font-size: 13px; color: #444; font-weight: 500;
}
.toolbar button:hover { background: #f5f5f5; }
.toolbar button.active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.toolbar .spacer { flex: 1; min-width: 8px; }
.refresh-btn, .admin-btn {
  background: #1e6c3a !important; color: #fff !important; border-color: #1e6c3a !important;
  display: inline-flex; align-items: center; gap: 6px;
}
.refresh-btn:hover, .admin-btn:hover { background: #185a2f !important; }
.refresh-btn:disabled { background: #888 !important; border-color: #888 !important; cursor: not-allowed; }
.admin-btn { background: #1a1a1a !important; border-color: #1a1a1a !important; }
.admin-btn:hover { background: #333 !important; }
.refresh-icon { font-size: 14px; }
.refresh-icon.spinning { animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg) } to { transform: rotate(360deg) } }
.refresh-banner {
  background: #fff4e0; border: 1px solid #ffd789; color: #8a5a00;
  padding: 10px 16px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; display: none;
}
.refresh-banner.show { display: block; }
.table-wrap { background: #fff; border: 1px solid #e5e5e5; border-radius: 12px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 12px 14px; background: #f7f7f7; border-bottom: 1px solid #e5e5e5;
  font-size: 12px; color: #555; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
  cursor: pointer; user-select: none;
}
th:hover { background: #efefef; }
th .arrow { opacity: 0.4; font-size: 10px; margin-left: 4px; }
th.sort-active .arrow { opacity: 1; }
td { padding: 12px 14px; border-bottom: 1px solid #f0f0f0; vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.row:hover { background: #fafafa; cursor: pointer; }
.num { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-weight: 600; }
.route { color: #444; }
.route .arrow { color: #999; margin: 0 4px; }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.3px;
}
.badge.in_transit { background: #fff4e0; color: #8a5a00; }
.badge.arrived { background: #e0efff; color: #0f4d8a; }
.badge.delivered { background: #e6f5ea; color: #1e6c3a; }
.badge.stale { background: #fde2e2; color: #8a1414; }
.badge.unknown { background: #eee; color: #666; }
.status-label { color: #444; font-size: 13px; margin-top: 3px; }
.scrape-fail { color: #8a1414; font-size: 11px; margin-top: 3px; }
.latest-event { color: #444; font-size: 13px; max-width: 320px; }
.days { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.days.normal { color: #4a4a4a; }
.days.warn { color: #8a5a00; }
.days.bad { color: #8a1414; }
.timeline-row td { background: #fcfcfc; padding: 0; }
.timeline { padding: 16px 24px 20px; border-top: 1px solid #f0f0f0; }
.timeline h4 { margin: 0 0 12px; font-size: 13px; color: #555; }
.event {
  display: grid; grid-template-columns: 150px 1fr; gap: 14px; padding: 8px 0;
  border-left: 2px solid #e5e5e5; padding-left: 14px; margin-left: 6px; position: relative;
}
.event::before {
  content: ''; position: absolute; left: -5px; top: 14px; width: 8px; height: 8px;
  border-radius: 50%; background: #b5b5b5;
}
.event:last-child::before { background: #1a1a1a; }
.event-date { color: #666; font-size: 12px; font-variant-numeric: tabular-nums; }
.event-body .desc { font-weight: 500; }
.event-body .loc { color: #777; font-size: 12px; margin-top: 2px; }
.predicted { color: #8a5a00; font-style: italic; }
.expand-icon { color: #999; font-size: 14px; transition: transform 0.15s; display: inline-block; }
tr.expanded .expand-icon { transform: rotate(90deg); }
.remove-btn {
  border: 1px solid #f5b7b7; background: #fff; color: #8a1414; border-radius: 6px;
  font-size: 12px; padding: 3px 8px; cursor: pointer;
}
.remove-btn:hover { background: #fde2e2; }
.empty { padding: 40px; text-align: center; color: #999; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none;
  align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 12px; padding: 22px 24px; width: 100%; max-width: 460px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.modal h2 { margin: 0 0 4px; font-size: 17px; }
.modal .sub { color: #777; font-size: 12px; margin-bottom: 16px; }
.modal section { border-top: 1px solid #eee; padding-top: 14px; margin-top: 14px; }
.modal section:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.modal h3 { font-size: 13px; margin: 0 0 8px; color: #333; }
.modal label { display: block; font-size: 12px; color: #555; margin: 8px 0 3px; }
.modal input[type=text], .modal input[type=password], .modal input[type=file] {
  width: 100%; padding: 8px 10px; border: 1px solid #d0d0d0; border-radius: 8px; font-size: 14px;
}
.modal .row { display: flex; gap: 8px; align-items: center; }
.modal .row input { flex: 1; }
.btn {
  padding: 8px 14px; border-radius: 8px; border: 1px solid #1e6c3a; background: #1e6c3a;
  color: #fff; font-weight: 600; cursor: pointer; font-size: 13px;
}
.btn:hover { background: #185a2f; }
.btn.secondary { background: #fff; color: #444; border-color: #d0d0d0; }
.btn.secondary:hover { background: #f5f5f5; }
.modal .close { float: right; cursor: pointer; color: #999; font-size: 20px; line-height: 1; border: none; background: none; }
.msg { font-size: 12px; margin-top: 8px; min-height: 16px; }
.msg.ok { color: #1e6c3a; }
.msg.err { color: #8a1414; }

/* Login page */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: #fff; border: 1px solid #e5e5e5; border-radius: 12px; padding: 28px 30px;
  width: 100%; max-width: 360px; box-shadow: 0 6px 24px rgba(0,0,0,0.06);
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p { color: #777; font-size: 13px; margin: 0 0 18px; }
.login-card label { display: block; font-size: 12px; color: #555; margin: 10px 0 4px; }
.login-card input {
  width: 100%; padding: 9px 11px; border: 1px solid #d0d0d0; border-radius: 8px; font-size: 14px;
}
.login-card .btn { width: 100%; margin-top: 16px; padding: 10px; }
.login-error { color: #8a1414; font-size: 13px; margin-top: 12px; }

@media (max-width: 720px) {
  .latest-event { max-width: 200px; }
  th, td { padding: 10px 8px; font-size: 12px; }
  body { padding: 8px; }
}
