*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.hidden { display: none !important; }

/* ── Light theme (default) ───────────────────────────────── */
:root {
  /* Topbar — always dark in light mode */
  --topbar-bg:     #1e293b;
  --topbar-border: #334155;
  --topbar-text:   #f1f5f9;
  --topbar-text2:  #94a3b8;
  --urlbar-bg:     #e8edf2;

  /* Sidebar — light grey */
  --sidebar-bg:    #f8fafc;

  /* Center panel — white */
  --panel-bg:      #ffffff;

  /* General */
  --bg:        #f1f5f9;
  --bg2:       #ffffff;
  --bg3:       #e2e8f0;
  --border:    #e2e8f0;
  --text:      #1e293b;
  --text2:     #64748b;
  --accent:    #6366f1;
  --green:     #16a34a;
  --red:       #dc2626;
  --yellow:    #ca8a04;
  --purple:    #7c3aed;
  --orange:    #ea580c;
  --shadow:    0 1px 3px rgba(0,0,0,.08);
  --radius:    6px;
  --mono:      'Consolas', 'Monaco', 'Courier New', monospace;
}

/* ── Dark theme ─────────────────────────────────────────── */
[data-theme="dark"] {
  --topbar-bg:     #0d1117;
  --topbar-border: #30363d;
  --topbar-text:   #e6edf3;
  --topbar-text2:  #8b949e;
  --urlbar-bg:     #1c2128;

  --sidebar-bg:    #161b22;
  --panel-bg:      #0f1117;

  --bg:        #0f1117;
  --bg2:       #161b22;
  --bg3:       #1c2128;
  --border:    #30363d;
  --text:      #e6edf3;
  --text2:     #8b949e;
  --accent:    #818cf8;
  --green:     #3fb950;
  --red:       #f85149;
  --yellow:    #d29922;
  --purple:    #bc8cff;
  --orange:    #ffa657;
  --shadow:    0 1px 3px rgba(0,0,0,.4);
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; transition: background .2s, color .2s; }

a { color: var(--accent); text-decoration: none; }

/* ── Layout ─────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--topbar-border);
  background: var(--topbar-bg); flex-shrink: 0;
}
.topbar .logo { font-size: 16px; font-weight: 700; color: var(--topbar-text); letter-spacing: -.3px; }
.topbar .logo span { color: var(--accent); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.topbar-actions .btn { background: transparent; border-color: var(--topbar-border); color: var(--topbar-text); }
.topbar-actions .btn:hover { background: var(--topbar-border); }
.topbar-actions .btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Theme toggle ────────────────────────────────────────── */
.theme-toggle {
  background: none; border: 1px solid var(--topbar-border); border-radius: var(--radius);
  cursor: pointer; padding: 5px 8px; font-size: 15px; line-height: 1;
  color: var(--topbar-text2); transition: background .15s, border-color .15s;
}
.theme-toggle:hover { background: var(--topbar-border); }

/* ── Dashboard layout ───────────────────────────────────── */
#dashboard { display: flex; flex: 1; overflow: hidden; }

/* Left panel */
.sidebar {
  width: 340px; flex-shrink: 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; background: var(--sidebar-bg);
}
.sidebar-header {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.sidebar-header h2 { font-size: 11px; font-weight: 600; flex: 1; color: var(--text2); text-transform: uppercase; letter-spacing: .6px; }
.sidebar-search {
  position: relative; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-search input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 28px 6px 10px; color: var(--text);
  font-size: 13px; font-family: inherit;
}
.sidebar-search input:focus { outline: none; border-color: var(--accent); }
.search-clear {
  position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text2);
  font-size: 16px; line-height: 1; padding: 2px 4px;
}
.search-clear:hover { color: var(--text); }
.search-clear.hidden { display: none; }

.load-more-btn {
  display: block; width: calc(100% - 24px); margin: 10px 12px;
  padding: 8px; text-align: center; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text2); font-size: 12px; cursor: pointer;
}
.load-more-btn:hover { background: var(--bg3); color: var(--text); }

.upgrade-hint {
  margin: 10px 12px; padding: 10px 12px; font-size: 12px; line-height: 1.5;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text2);
}
.upgrade-hint a { color: var(--accent); font-weight: 600; }

.req-list { flex: 1; overflow-y: auto; }
.req-item {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; align-items: flex-start; gap: 10px;
  transition: background .1s; background: var(--sidebar-bg);
}
.req-item:hover  { background: var(--bg3); }
.req-item.active { background: var(--accent); border-left: none; padding-left: 12px; }
.req-item.active .path,
.req-item.active .time { color: rgba(255,255,255,.85); }
.req-item.active .del-btn { color: rgba(255,255,255,.6); }
.req-item.active .del-btn:hover { color: #fff; }
.req-item.active .method { opacity: .92; }
.req-item .method { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px; flex-shrink: 0; }
.req-item .meta  { flex: 1; min-width: 0; }
.req-item .path  { font-family: var(--mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.req-item .time  { font-size: 11px; color: var(--text2); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.req-item .del-btn { font-size: 16px; color: var(--text2); opacity: 0; padding: 0 4px; line-height: 1; background: none; border: none; cursor: pointer; }
.req-item:hover .del-btn { opacity: 1; }
.req-item .del-btn:hover { color: var(--red); }
.empty-state { text-align: center; color: var(--text2); padding: 40px 20px; }
.empty-state p { margin-top: 8px; font-size: 13px; }
.ping { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; flex-shrink: 0; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* Right panel */
.detail-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--panel-bg); }
.detail-header {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-shrink: 0; flex-wrap: wrap;
  background: var(--panel-bg);
}
.detail-header .method-badge { font-family: var(--mono); font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 4px; }
.detail-header .full-url { font-family: var(--mono); font-size: 12px; color: var(--text2); flex: 1; word-break: break-all; }
.tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; padding: 0 16px; background: var(--panel-bg); }
.tab-btn {
  padding: 8px 14px; font-size: 13px; cursor: pointer; color: var(--text2);
  border-bottom: 2px solid transparent; background: none; border-top: none;
  border-left: none; border-right: none; transition: color .15s;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover  { color: var(--text); }
.tab-content { flex: 1; overflow-y: auto; padding: 16px; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.no-selection {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text2); flex-direction: column; gap: 8px;
}

/* ── Tables ─────────────────────────────────────────────── */
.kv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv-table th { text-align: left; padding: 6px 10px; color: var(--text2); font-weight: 500; border-bottom: 1px solid var(--border); background: var(--bg3); }
.kv-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 12px; word-break: break-all; vertical-align: top; }
.kv-table td:first-child { color: var(--accent); white-space: nowrap; }

/* ── Body viewer ────────────────────────────────────────── */
.body-viewer {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
  word-break: break-word; color: var(--text); overflow: auto; min-height: 200px;
}
.body-empty { color: var(--text2); font-style: italic; }

/* ── Method colors — light ──────────────────────────────── */
.m-GET     { background: #dcfce7; color: #15803d; }
.m-POST    { background: #dbeafe; color: #1d4ed8; }
.m-PUT     { background: #fef9c3; color: #a16207; }
.m-PATCH   { background: #cffafe; color: #0e7490; }
.m-DELETE  { background: #fee2e2; color: #b91c1c; }
.m-HEAD    { background: #ede9fe; color: #6d28d9; }
.m-OPTIONS { background: #ffedd5; color: #c2410c; }

/* ── Method colors — dark override ─────────────────────── */
[data-theme="dark"] .m-GET     { background: #1a3a1a; color: #3fb950; }
[data-theme="dark"] .m-POST    { background: #1a2a3a; color: #818cf8; }
[data-theme="dark"] .m-PUT     { background: #2a2a1a; color: #d29922; }
[data-theme="dark"] .m-PATCH   { background: #1f2a2a; color: #79c0ff; }
[data-theme="dark"] .m-DELETE  { background: #3a1a1a; color: #f85149; }
[data-theme="dark"] .m-HEAD    { background: #2a1a3a; color: #bc8cff; }
[data-theme="dark"] .m-OPTIONS { background: #2a1f1a; color: #ffa657; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  cursor: pointer; font-size: 13px; font-family: inherit; transition: background .15s;
  background: var(--bg2); color: var(--text);
}
.btn:hover { background: var(--bg3); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { opacity: .88; }
.btn-danger  { color: var(--red); border-color: var(--border); }
.btn-danger:hover { background: #fee2e2; border-color: var(--red); }
[data-theme="dark"] .btn-danger:hover { background: #3a1a1a; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Webhook URL bar ─────────────────────────────────────── */
.url-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  background: var(--urlbar-bg); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.url-bar .endpoint {
  font-family: var(--mono); font-size: 12px; flex: 1;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 10px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.url-bar .btn { background: #fff; border-color: var(--border); color: var(--text); }
.url-bar .btn:hover { background: var(--bg3); }
.url-bar .btn-danger { color: var(--red); }
.url-bar .btn-danger:hover { background: #fee2e2; border-color: var(--red); }
[data-theme="dark"] .btn-danger:hover { background: #3a1a1a; }

[data-theme="dark"] .url-bar { background: var(--urlbar-bg); border-bottom-color: var(--border); }
[data-theme="dark"] .url-bar .endpoint { background: var(--bg2); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .url-bar .btn { background: var(--bg2); border-color: var(--border); color: var(--text); }
[data-theme="dark"] .url-bar .btn:hover { background: var(--bg3); }
[data-theme="dark"] .url-bar .btn-danger:hover { background: #3a1a1a; border-color: var(--red); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.6); }
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  width: 520px; max-width: 95vw; box-shadow: 0 8px 30px rgba(0,0,0,.12);
  max-height: 85vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-header h3 { margin-bottom: 0; }
.modal-close {
  background: none; border: none; cursor: pointer; line-height: 1;
  font-size: 22px; color: var(--text2); padding: 0 4px; border-radius: var(--radius);
}
.modal-close:hover { color: var(--text); background: var(--bg3); }
.modal h3 { font-size: 16px; }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text2); }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 7px 10px; color: var(--text);
  font-family: var(--mono); font-size: 13px;
}
.form-group textarea { resize: vertical; min-height: 100px; }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none; border-color: var(--accent);
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 24px; border-top: 1px solid var(--border); flex-shrink: 0;
}

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: var(--text); color: var(--bg2);
  border-radius: var(--radius); padding: 10px 16px; font-size: 13px;
  transform: translateY(100px); opacity: 0; transition: all .25s; pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
#toast.show { transform: translateY(0); opacity: 1; }

/* ── Upgrade banner ──────────────────────────────────────── */
.upgrade-banner {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 210; display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 10px 12px 10px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
  font-size: 13px; color: var(--text); max-width: 90vw;
}
.upgrade-banner.hidden { display: none; }
.upgrade-banner .modal-close { font-size: 18px; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Replay result ───────────────────────────────────────── */
.replay-status {
  display: inline-block; padding: 6px 12px; border-radius: var(--radius);
  font-family: var(--mono); font-size: 13px; font-weight: 600;
}
.replay-ok       { background: #dcfce7; color: #15803d; }
.replay-redirect { background: #fef9c3; color: #a16207; }
.replay-error    { background: #fee2e2; color: #b91c1c; }
[data-theme="dark"] .replay-ok       { background: #1a3a1a; color: #3fb950; }
[data-theme="dark"] .replay-redirect { background: #2a2a1a; color: #d29922; }
[data-theme="dark"] .replay-error    { background: #3a1a1a; color: #f85149; }

/* ── Export dropdown ─────────────────────────────────────── */
.export-dropdown { position: relative; }
.export-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 50;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 150px; overflow: hidden;
}
.export-menu.hidden { display: none; }
.export-menu a {
  display: block; padding: 8px 12px; font-size: 13px; color: var(--text);
  white-space: nowrap;
}
.export-menu a:hover { background: var(--bg3); }

/* ── Overview layout (mirrors webhook.site) ──────────────── */
.overview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.overview-section { min-width: 0; }
.section-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text2); margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.empty-note { color: var(--text2); font-size: 13px; font-style: italic; }
.tab-count {
  display: inline-block; background: var(--bg3); color: var(--text2);
  font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 10px; margin-left: 4px;
}

/* ── Admin panel ──────────────────────────────────────────── */
.admin-tabs {
  display: flex; gap: 2px; padding: 0 16px; background: var(--bg2);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.admin-tab {
  padding: 12px 16px; font-size: 13px; cursor: pointer; color: var(--text2);
  background: none; border: none; border-bottom: 2px solid transparent;
}
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-tab:hover { color: var(--text); }
.admin-body { flex: 1; overflow-y: auto; padding: 20px; background: var(--bg); }
.admin-section {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 18px; margin-bottom: 16px;
}
.admin-section h3 { font-size: 14px; margin-bottom: 12px; }
.admin-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.stat-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 18px;
}
.stat-val { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 13px; color: var(--text2); margin-top: 4px; }
.stat-sub { font-size: 11px; color: var(--text2); margin-top: 6px; }

.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.bar-label { width: 90px; color: var(--text2); flex-shrink: 0; }
.bar { height: 14px; background: var(--accent); border-radius: 3px; min-width: 2px; }
.bar-val { color: var(--text2); }

.event-badge {
  font-family: var(--mono); font-size: 11px; background: var(--bg3); color: var(--text);
  padding: 2px 6px; border-radius: 4px;
}
.pill {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px;
  background: var(--bg3); color: var(--text2); margin-right: 3px;
}
.pill-premium { background: #dbeafe; color: #1d4ed8; }
.pill-admin   { background: #ede9fe; color: #6d28d9; }
.pill-warn    { background: #fef3c7; color: #a16207; }
[data-theme="dark"] .pill-premium { background: #1a2a3a; color: #79c0ff; }
[data-theme="dark"] .pill-admin   { background: #2a1a3a; color: #bc8cff; }
[data-theme="dark"] .pill-warn    { background: #2a2410; color: #d29922; }

.admin-tabs .btn, .admin-section select, .admin-section input[type="text"], .admin-section input[type="number"] {
  font-family: inherit;
}

/* ── Analytics (admin) ────────────────────────────────────── */
.chart-box { position: relative; height: 240px; width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  padding: 5px 12px; font-size: 12px; background: var(--bg2); color: var(--text2);
  border: none; cursor: pointer; border-right: 1px solid var(--border);
}
.seg-btn:last-child { border-right: none; }
.seg-btn.active { background: var(--accent); color: #fff; }
.seg-btn:hover:not(.active) { background: var(--bg3); color: var(--text); }

/* ===========================================================================
   Responsive — Google indexes mobile-first, and the app must be usable
   on phones/tablets. Desktop layout is unchanged above 900px.
   =========================================================================== */

/* Tablet and below */
@media (max-width: 900px) {
  .overview-grid { grid-template-columns: 1fr; }
  .admin-grid2   { grid-template-columns: 1fr; }
  .stat-grid     { grid-template-columns: repeat(2, 1fr); }
  .modal         { width: 100% !important; max-width: 95vw; }
}

/* Phones */
@media (max-width: 720px) {
  /* Topbar wraps instead of overflowing */
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .topbar .logo { font-size: 15px; }
  .topbar-actions { gap: 6px; flex-wrap: wrap; }
  .topbar-actions .btn { padding: 4px 8px; font-size: 12px; }

  /* URL bar stacks so the endpoint + actions stay reachable */
  .url-bar { flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
  .url-bar .endpoint { flex: 1 1 100%; font-size: 11px; }
  .url-bar .btn { padding: 4px 9px; font-size: 12px; }

  /* Dashboard becomes a single scrolling column: list above, detail below */
  #dashboard > div[style*="display:flex"] { flex-direction: column !important; }
  .sidebar {
    width: 100%; max-height: 42vh; border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .detail-panel { min-height: 50vh; }
  .detail-header { gap: 8px; }
  .detail-header .full-url { flex: 1 1 100%; font-size: 11px; }

  /* Tabs scroll horizontally rather than wrapping awkwardly */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { white-space: nowrap; }

  .stat-grid { grid-template-columns: 1fr; }
  .admin-tabs { overflow-x: auto; }
  .admin-tab { white-space: nowrap; }
  .admin-body { padding: 12px; }
  .admin-section { padding: 14px; }

  /* Wide tables scroll inside their own container */
  .kv-table { display: block; overflow-x: auto; white-space: nowrap; }

  /* Modals fill the screen comfortably */
  .modal { max-height: 92vh; }
  .modal-header, .modal-body, .modal-footer { padding-left: 16px; padding-right: 16px; }

  .upgrade-banner { left: 12px; right: 12px; transform: none; }
}
