/* Shopflo Webhook Monitor — clean, neutral diagnostic UI. No heavy gradients. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #111827;
  --accent: #2563eb;
  --green: #16a34a;
  --green-bg: #ecfdf5;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --gray-bg: #f3f4f6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

/* ---- Top bar ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.user { color: var(--muted); font-size: 13px; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* ---- Buttons ---- */
.btn { font: inherit; border-radius: 8px; padding: 8px 14px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; display: inline-block; }
.btn:hover { background: var(--gray-bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); width: 100%; }
.btn-primary:hover { background: #000; }
.btn-secondary { background: var(--surface); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--gray-bg); }

/* ---- Badges ---- */
.badge { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; }
.badge-healthy { background: var(--green-bg); color: var(--green); border-color: #a7f3d0; }
.badge-idle { background: var(--amber-bg); color: var(--amber); border-color: #fde68a; }
.badge-never { background: var(--gray-bg); color: var(--muted); border-color: var(--border); }
.badge-muted { background: var(--gray-bg); color: var(--muted); }

/* ---- Date ranges ---- */
.ranges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.range-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 14px; cursor: pointer; font: inherit; color: var(--text); }
.range-btn:hover { background: var(--gray-bg); }
.range-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.custom-range { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.custom-range input[type=date] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }

/* ---- Summary cards ---- */
.cards { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-num { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.card-label { color: var(--muted); font-size: 12.5px; margin-top: 4px; text-transform: uppercase; letter-spacing: .03em; }

.lastline { display: flex; justify-content: space-between; align-items: baseline; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 20px; box-shadow: var(--shadow); flex-wrap: wrap; gap: 6px; }
.ll-label { color: var(--muted); }
.ll-since { color: var(--muted); font-size: 13px; }

/* ---- Controls ---- */
.controls { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.search { flex: 1 1 320px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.control-group { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.control-group label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.control-group select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; color: var(--text); background: var(--surface); }

/* ---- Table ---- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table.events { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 900px; }
table.events thead th { position: sticky; top: 0; background: var(--gray-bg); text-align: left; padding: 10px 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
table.events tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.events tbody tr:hover { background: #fafafa; }
table.events .num { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px 0; }

.tag { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.tag-yes { background: var(--amber-bg); color: var(--amber); }
.tag-no { background: var(--green-bg); color: var(--green); }
.tag-valid { background: var(--green-bg); color: var(--green); }
.tag-invalid { background: var(--red-bg); color: var(--red); }
.link-btn { color: var(--accent); background: none; border: none; cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* ---- Pager ---- */
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 18px 0 40px; }
#page-info { color: var(--muted); font-size: 13px; }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 760px; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; }
.detail-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin-bottom: 18px; }
.detail-grid dt { color: var(--muted); font-size: 12.5px; }
.detail-grid dd { margin: 0; word-break: break-all; }
.json-viewer { background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 14px; overflow: auto; max-height: 320px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; white-space: pre; }
.json-head { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; }
.copy-ok { color: var(--green); font-size: 12px; margin-left: 8px; }

/* ---- Login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.login-title { margin: 0 0 4px; font-size: 19px; }
.login-sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; margin-bottom: 14px; }
.login-form input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.login-error { background: var(--red-bg); color: var(--red); border: 1px solid #fecaca; padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }

/* ---- Responsive ---- */
@media (max-width: 1000px) { .cards { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .custom-range { margin-left: 0; }
  .card-num { font-size: 26px; }
  .detail-grid { grid-template-columns: 1fr; gap: 2px 0; }
  .detail-grid dt { margin-top: 8px; }
}
