/* ================================================================
   Webhook Catcher — Design System & Styles
   ================================================================ */

/* ── Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Surface palette — deep navy / slate */
  --bg-base:    #0b0f1a;
  --bg-surface: #111827;
  --bg-raised:  #1e293b;
  --bg-hover:   #263146;

  /* Accent — electric indigo → cyan gradient */
  --accent-1: #6366f1;
  --accent-2: #06b6d4;
  --accent-gradient: linear-gradient(135deg, var(--accent-1), var(--accent-2));

  /* Text */
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;

  /* Method badges */
  --get:    #22d3ee;
  --post:   #a78bfa;
  --put:    #fbbf24;
  --patch:  #fb923c;
  --delete: #f87171;
  --head:   #38bdf8;
  --options:#34d399;

  /* Composite surfaces (overridden per theme) */
  --glass-bg:      rgba(17,24,39,.65);
  --header-bg:     rgba(11,15,26,.80);
  --tab-bg:        rgba(255,255,255,.03);
  --tab-bg-hover:  rgba(255,255,255,.06);
  --tab-bg-subtle: rgba(255,255,255,.06);
  --bg-glow-1:     rgba(99,102,241,.10);
  --bg-glow-2:     rgba(6,182,212,.08);

  /* Misc */
  --border:   rgba(148,163,184,.12);
  --radius:   12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow-lg: 0 8px 32px rgba(0,0,0,.45);

  /* Font */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ── Light theme overrides ──────────────────────────────────────── */
[data-theme="light"] {
  --bg-base:    #f1f5f9;
  --bg-surface: #ffffff;
  --bg-raised:  #f8fafc;
  --bg-hover:   #e2e8f0;

  --accent-1: #4f46e5;
  --accent-2: #0891b2;

  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #64748b;

  /* Method badges — darker so they stay legible on white */
  --get:    #0891b2;
  --post:   #7c3aed;
  --put:    #d97706;
  --patch:  #ea580c;
  --delete: #dc2626;
  --head:   #0284c7;
  --options:#059669;

  --glass-bg:      rgba(255,255,255,.78);
  --header-bg:     rgba(248,250,252,.85);
  --tab-bg:        rgba(15,23,42,.04);
  --tab-bg-hover:  rgba(15,23,42,.08);
  --tab-bg-subtle: rgba(15,23,42,.06);
  --bg-glow-1:     rgba(99,102,241,.06);
  --bg-glow-2:     rgba(6,182,212,.05);

  --border:   rgba(15,23,42,.10);
  --shadow-lg: 0 8px 32px rgba(15,23,42,.10);
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle animated gradient bg */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 60% at 10% 20%, var(--bg-glow-1) 0%, transparent 60%),
    radial-gradient(ellipse 60% 80% at 90% 80%, var(--bg-glow-2) 0%, transparent 60%);
}

/* ── Typography ─────────────────────────────────────────────────── */
h1 { font-size: 2.2rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.15; }
h2 { font-size: 1rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .06em; }
h3 { font-size: .95rem; font-weight: 600; }
code {
  font-family: var(--font-mono);
  font-size: .82rem;
  background: rgba(99,102,241,.12);
  color: var(--accent-2);
  padding: 2px 7px;
  border-radius: var(--radius-xs);
}

/* ── Glass card ─────────────────────────────────────────────────── */
.card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
}

/* ── Header ─────────────────────────────────────────────────────── */
#app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.logo {
  display: flex;
  align-items: center;
  gap: .6rem;
}
.logo-icon { width: 26px; height: 26px; color: var(--accent-2); }
.logo-text { font-size: 1.1rem; font-weight: 400; letter-spacing: -.01em; color: var(--text-secondary); }
.logo-text strong { color: var(--text-primary); font-weight: 700; }

.header-actions { display: flex; align-items: center; gap: .6rem; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-family: var(--font-sans);
  font-size: .85rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: .55rem 1rem;
  cursor: pointer;
  transition: all .2s ease;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 0 20px rgba(99,102,241,.30);
}
.btn-primary:hover { box-shadow: 0 0 32px rgba(99,102,241,.50); transform: translateY(-1px); }
.btn-accent {
  background: rgba(99,102,241,.15);
  color: var(--accent-1);
  border: 1px solid rgba(99,102,241,.25);
}
.btn-accent:hover { background: rgba(99,102,241,.25); }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-lg { padding: .75rem 1.6rem; font-size: .95rem; border-radius: var(--radius); }

.badge {
  font-size: .78rem;
  font-weight: 600;
  padding: .3rem .7rem;
  border-radius: 99px;
  background: rgba(6,182,212,.12);
  color: var(--accent-2);
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}

/* ── Main layout ────────────────────────────────────────────────── */
#app-main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Landing ────────────────────────────────────────────────────── */
#landing {
  padding: 4rem 2rem;
  text-align: center;
  animation: fadeUp .6s ease;
}
.landing-content { max-width: 620px; margin: 0 auto; }
.subtitle { color: var(--text-secondary); margin: .8rem 0 2rem; font-size: 1.05rem; line-height: 1.55; }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 1rem;
  margin-top: 2.5rem;
  text-align: left;
}
.feature {
  display: flex;
  gap: .7rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: var(--tab-bg);
  border: 1px solid var(--border);
  transition: border-color .2s;
}
.feature:hover { border-color: rgba(99,102,241,.3); }
.feature-icon { font-size: 1.5rem; flex-shrink: 0; }
.feature strong { display: block; margin-bottom: .2rem; font-size: .88rem; }
.feature p { color: var(--text-muted); font-size: .78rem; line-height: 1.4; }

/* ── URL Bar ────────────────────────────────────────────────────── */
.url-bar { padding: 1.25rem 1.5rem; margin-bottom: 1rem; }
.url-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: .5rem; display: block; }
.url-row { display: flex; gap: .5rem; }
.url-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: .88rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent-2);
  padding: .6rem .9rem;
  outline: none;
  transition: border-color .2s;
}
.url-input:focus { border-color: var(--accent-1); }
.url-meta {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .6rem;
  font-size: .75rem;
  color: var(--text-muted);
}
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot.live { background: #22c55e; box-shadow: 0 0 6px #22c55e80; animation: pulse 2s infinite; }
.dot.disconnected { background: #ef4444; }
.separator { opacity: .4; }

/* ── Panels ─────────────────────────────────────────────────────── */
.panels {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
  min-height: 480px;
}
.panel-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.panel-header-with-controls {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: .8rem;
  flex-wrap: wrap;
  min-width: 0;
}
.panel-header-with-controls h2 { flex-shrink: 0; }
.panel-controls {
  display: flex;
  align-items: center;
  gap: .4rem;
  min-width: 0;
  justify-content: flex-start;
}
.panel-controls .control-input {
  flex: 1 1 100px;
  min-width: 0;
  max-width: 160px;
  width: auto;
  font-family: var(--font-sans);
  font-size: .78rem;
  padding: .35rem .55rem;
}
.panel-controls .btn { flex-shrink: 0; }

/* Request list */
.panel-list { display: flex; flex-direction: column; }
.request-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  max-height: 520px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}
.request-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
  animation: slideIn .3s ease;
}
.request-item:hover { background: var(--bg-hover); }
.request-item.active { background: rgba(99,102,241,.10); border-left: 3px solid var(--accent-1); }
.method-badge {
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 700;
  padding: .2rem .45rem;
  border-radius: 4px;
  text-transform: uppercase;
  flex-shrink: 0;
  min-width: 52px;
  text-align: center;
}
.method-GET    { background: rgba(34,211,238,.12); color: var(--get); }
.method-POST   { background: rgba(167,139,250,.12); color: var(--post); }
.method-PUT    { background: rgba(251,191,36,.12); color: var(--put); }
.method-PATCH  { background: rgba(251,146,60,.12); color: var(--patch); }
.method-DELETE { background: rgba(248,113,113,.12); color: var(--delete); }
.method-HEAD   { background: rgba(56,189,248,.12); color: var(--head); }
.method-OPTIONS{ background: rgba(52,211,153,.12); color: var(--options); }

.status-badge {
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 700;
  padding: .2rem .45rem;
  border-radius: 4px;
  flex-shrink: 0;
  min-width: 52px;
  text-align: center;
}
.status-2xx { background: rgba(52,211,153,.12); color: rgb(52,211,153); }
.status-3xx { background: rgba(56,189,248,.12); color: rgb(56,189,248); }
.status-4xx { background: rgba(251,146,60,.18); color: rgb(251,146,60); }
.status-5xx { background: rgba(248,113,113,.15); color: rgb(248,113,113); }

.request-meta { flex: 1; min-width: 0; }
.request-time { font-size: .75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.request-ip   { font-size: .7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Detail panel */
.panel-detail { display: flex; flex-direction: column; }
.detail-content { flex: 1; overflow-y: auto; max-height: 520px; padding: 1.25rem; scrollbar-width: thin; scrollbar-color: var(--bg-hover) transparent; }

.detail-section { margin-bottom: 1.5rem; }
.detail-section h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: .6rem; display: flex; align-items: center; gap: .4rem; }
.detail-table { width: 100%; font-size: .82rem; border-collapse: collapse; }
.detail-table td {
  padding: .4rem .6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.detail-table td:first-child {
  font-family: var(--font-mono);
  color: var(--accent-2);
  white-space: nowrap;
  width: 180px;
  font-size: .78rem;
}
.detail-table td:last-child {
  color: var(--text-secondary);
  word-break: break-all;
}
.body-block {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem 1rem;
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 280px;
  overflow-y: auto;
  line-height: 1.55;
}

/* ── Template Editor ────────────────────────────────────────────── */
.template-editor { overflow: visible; }
.template-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.template-header h3 {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--text-primary);
}
.template-actions { display: flex; gap: .5rem; }
.btn-sm { padding: .35rem .7rem; font-size: .78rem; }

.template-body { padding: 1.25rem; }
.template-textarea {
  width: 100%;
  min-height: 160px;
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.6;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: .9rem 1rem;
  resize: vertical;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  tab-size: 2;
}
.template-textarea:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.template-textarea::placeholder { color: var(--text-muted); opacity: .6; }

.template-controls {
  display: flex;
  gap: 1rem;
  margin-top: .75rem;
}
.control-group { display: flex; flex-direction: column; gap: .3rem; }
.control-group label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.control-input {
  font-family: var(--font-mono);
  font-size: .82rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  padding: .45rem .65rem;
  outline: none;
  transition: border-color .2s;
  width: 160px;
}
.control-input:focus { border-color: var(--accent-1); }
input[type="number"].control-input { width: 90px; }

.template-preview {
  padding: 0 1.25rem 1.25rem;
}
.template-preview h4 {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .5rem;
}

.template-footer {
  padding: .9rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .8rem;
  flex-wrap: wrap;
}
.template-hint { font-size: .75rem; color: var(--text-muted); }
.var-chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip {
  font-family: var(--font-mono);
  font-size: .78rem;
  padding: .35rem .7rem;
  border-radius: 99px;
  background: rgba(99,102,241,.10);
  border: 1px solid rgba(99,102,241,.2);
  color: var(--accent-2);
  cursor: pointer;
  transition: border-color .2s, background .2s;
  user-select: none;
}
.chip:hover { background: rgba(99,102,241,.18); border-color: var(--accent-1); }

.template-saved {
  animation: flashSaved .6s ease;
}
@keyframes flashSaved {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50% { box-shadow: 0 0 0 4px rgba(34,197,94,.2); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ── Empty state ────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 3rem 1rem;
  color: var(--text-muted);
  text-align: center;
}
.empty-state p { font-size: .9rem; color: var(--text-secondary); }
.empty-state span { font-size: .78rem; }

/* ── Route search ───────────────────────────────────────────────── */
.route-search-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin: 0 0 .5rem 0;
}
.route-search-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.route-search-icon {
  position: absolute;
  left: .55rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.route-search-input {
  width: 100%;
  font-family: var(--font-sans);
  font-size: .82rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: .5rem .65rem .5rem 2rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.route-search-input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.route-search-input::-webkit-search-cancel-button {
  cursor: pointer;
}
.route-count {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.route-tab.hidden-by-search { display: none; }
.route-empty-match {
  font-size: .8rem;
  color: var(--text-muted);
  padding: .4rem .6rem;
  font-style: italic;
}

/* ── Route tabs ─────────────────────────────────────────────────── */
.route-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  padding: 0 0 .6rem 0;
  align-items: center;
  max-height: 180px;
  overflow-y: auto;
}
.route-tab {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--tab-bg);
  cursor: pointer;
  font-size: .78rem;
  font-family: var(--font-mono, monospace);
  color: var(--text-secondary);
  transition: background .15s, border-color .15s, color .15s;
}
.route-tab:hover { background: var(--tab-bg-hover); color: var(--text-primary); }
.route-tab.active {
  background: var(--accent-gradient, #4f46e5);
  border-color: transparent;
  color: #fff;
}
.route-tab .method-tag {
  font-weight: 700;
  font-size: .7rem;
  letter-spacing: .03em;
}
.route-tab .tab-close {
  margin-left: .15rem;
  opacity: .6;
  font-size: .9rem;
  line-height: 1;
}
.route-tab .tab-close:hover { opacity: 1; }
.route-tab.is-default { font-style: italic; }
.route-tab-add {
  border-style: dashed;
  color: var(--text-muted);
}

.route-meta-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  gap: .6rem;
  margin-bottom: .6rem;
  align-items: end;
}
.control-group-grow { min-width: 0; }
.hint-inline {
  font-weight: 400;
  font-size: .72rem;
  color: var(--text-muted);
  margin-left: .25rem;
}
.hint-inline code {
  font-size: .7rem;
  padding: 0 .25rem;
  background: var(--tab-bg-subtle);
  border-radius: 3px;
}

/* ── OpenAPI import panel ───────────────────────────────────────── */
.import-panel {
  margin: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--tab-bg);
}
.import-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
}
.import-panel-header h4 {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-primary);
}
.import-panel-body { padding: 1rem; display: flex; flex-direction: column; gap: .7rem; }
.import-row { display: flex; align-items: center; gap: .6rem; }
.import-file-label { cursor: pointer; }
.import-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.import-radio {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .8rem;
  color: var(--text-secondary);
  cursor: pointer;
}
.import-radio input { margin: 0; }
.import-status {
  font-size: .8rem;
  color: var(--text-muted);
  min-height: 1.2em;
}
.import-status.ok { color: #22c55e; }
.import-status.err { color: #ef4444; }

/* ── Base64 decoder ─────────────────────────────────────────────── */
.b64-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  margin-bottom: .6rem;
  background: var(--tab-bg);
}
.b64-item:last-child { margin-bottom: 0; }
.b64-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .8rem;
  align-items: center;
  margin-bottom: .5rem;
  font-size: .82rem;
}
.b64-meta .b64-key {
  font-family: var(--font-mono);
  color: var(--accent-2);
}
.b64-meta .b64-type {
  font-size: .75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.b64-meta .b64-actions { margin-left: auto; display: flex; gap: .4rem; }
.b64-preview-img {
  max-width: 280px;
  max-height: 200px;
  display: block;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}
.b64-preview-text {
  margin-top: .4rem;
  max-height: 220px;
  overflow: auto;
  font-size: .78rem;
}

/* ── Helpers ────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Animations ─────────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* ── Copied tooltip ─────────────────────────────────────────────── */
.copied-tooltip {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--accent-gradient);
  color: #fff;
  font-size: .82rem;
  font-weight: 600;
  padding: .5rem 1.2rem;
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  transition: all .3s ease;
  z-index: 999;
}
.copied-tooltip.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 800px) {
  .panels { grid-template-columns: 1fr; }
  .request-list { max-height: 300px; }
  h1 { font-size: 1.6rem; }
  .features { grid-template-columns: 1fr; }
}
