:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #191e24;
  --border: #262b31;
  --text: #e6edf3;
  --dim: #7d8590;
  --accent: #4dd8c0;
  --accent-dim: #245e54;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --info: #58a6ff;
  --sans: "Inter", -apple-system, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app { height: 100dvh; overflow: hidden; }

.screen { height: 100%; }
.hidden { display: none !important; }

/* ---------------- Connect screen ---------------- */

.connect-wrap {
  max-width: 440px;
  margin: 0 auto;
  padding: 64px 20px 32px;
  height: 100%;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 40px; }
.brand-mark {
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 26px; font-weight: 600;
  color: var(--accent);
  background: var(--panel-2);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
}
.brand-text h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.brand-text p { margin: 2px 0 0; font-size: 13px; color: var(--dim); font-family: var(--mono); }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 6px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%;
}

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 13px;
  border-radius: 8px;
  font-size: 15px;
  font-family: var(--sans);
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.mono-area, .num-input { font-family: var(--mono); font-size: 13px; }
textarea { resize: vertical; }

.field-row { margin-bottom: 18px; }

.switch-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; }
.switch-label input[type="checkbox"] {
  appearance: none; width: 40px; height: 24px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border);
  position: relative; cursor: pointer; flex: none;
}
.switch-label input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--dim); transition: transform .15s ease, background .15s ease;
}
.switch-label input[type="checkbox"]:checked { border-color: var(--accent-dim); background: var(--accent-dim); }
.switch-label input[type="checkbox"]:checked::after { background: var(--accent); transform: translateX(16px); }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #06211c;
  border: none;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 9px;
  cursor: pointer;
  margin-top: 6px;
}
.btn-primary:active { opacity: .85; }

.btn-ghost-sm {
  background: transparent; border: 1px solid var(--border); color: var(--dim);
  padding: 8px 12px; font-size: 12px; border-radius: 7px; cursor: pointer; font-family: var(--mono);
}

.error-text { color: var(--err); font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.hint { color: var(--dim); font-size: 12px; line-height: 1.6; margin-top: 28px; }
.hint-sm { color: var(--dim); font-size: 11.5px; margin: 4px 0 10px; font-family: var(--mono); }
.hint-sm code { color: var(--accent); }

/* ---------------- App shell ---------------- */

#screen-app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(63,185,80,.15); }
.dot.off { background: var(--err); box-shadow: 0 0 0 3px rgba(248,81,73,.15); }
.conn-label { font-size: 12px; color: var(--dim); font-family: var(--mono); }
.icon-btn { background: none; border: none; color: var(--dim); font-size: 18px; cursor: pointer; padding: 4px 8px; }

.tab-content { flex: 1; overflow: hidden; position: relative; }
.tab-pane { height: 100%; overflow-y: auto; padding: 12px 12px calc(env(safe-area-inset-bottom) + 90px); }

.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
  flex: none;
}
.tabbar-btn {
  flex: 1; background: none; border: none; color: var(--dim);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 8px; font-size: 11px; font-family: var(--sans); cursor: pointer;
}
.tabbar-icon { font-size: 18px; }
.tabbar-btn.active { color: var(--accent); }

/* ---------------- Proxy tab ---------------- */

.pane-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.scope-input { width: 150px; padding: 8px 10px; font-size: 12px; font-family: var(--mono); }

.flow-list { display: flex; flex-direction: column; gap: 6px; }

.flow-row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  cursor: pointer;
}
.flow-row.intercepted { border-color: var(--warn); background: #1d1a10; }
.flow-row-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.badge {
  font-family: var(--mono); font-size: 10.5px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px; letter-spacing: .02em;
}
.badge-get { background: #17324a; color: var(--info); }
.badge-post { background: #1d3a24; color: var(--ok); }
.badge-put, .badge-patch { background: #3a331a; color: var(--warn); }
.badge-delete { background: #3a1c1c; color: var(--err); }
.badge-other { background: var(--panel-2); color: var(--dim); }

.status-chip { font-family: var(--mono); font-size: 11px; margin-left: auto; color: var(--dim); }
.status-2xx { color: var(--ok); }
.status-3xx { color: var(--info); }
.status-4xx { color: var(--warn); }
.status-5xx { color: var(--err); }

.flow-url { font-family: var(--mono); font-size: 12.5px; color: var(--text); word-break: break-all; }
.flow-meta { font-size: 10.5px; color: var(--dim); margin-top: 3px; font-family: var(--mono); }

.empty-state { color: var(--dim); font-size: 13px; text-align: center; padding: 60px 20px; line-height: 1.6; }

/* ---------------- Repeater ---------------- */

.repeater-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 4px; }
.rep-tab-chip {
  flex: none; font-family: var(--mono); font-size: 11.5px; color: var(--dim);
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; cursor: pointer;
}
.rep-tab-chip.active { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-dim); }

.editor-block { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.method-url-row { display: flex; gap: 8px; }
.method-url-row select { flex: none; width: 100px; }
.method-url-row input { flex: 1; font-family: var(--mono); font-size: 13px; }
.row-buttons { display: flex; gap: 8px; }
.row-buttons .btn-primary { flex: 1; margin-top: 0; }

.response-block {
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  padding: 12px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all;
  min-height: 60px;
}
.response-status { font-weight: 700; margin-bottom: 8px; display: inline-block; }

/* ---------------- Intruder ---------------- */

.results-table { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.result-row {
  display: grid; grid-template-columns: 34px 56px 56px 1fr; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 7px;
  padding: 8px 10px; font-family: var(--mono); font-size: 11.5px;
}
.result-row .idx { color: var(--dim); }
.result-row .len { color: var(--dim); text-align: right; }
.result-row .payloads { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- Detail sheet ---------------- */

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--panel); border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  max-height: 85dvh; overflow-y: auto;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
}
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 999px; margin: 6px auto 14px; }
.sheet-body { font-family: var(--mono); font-size: 12.5px; }
.sheet-body h3 { font-family: var(--sans); font-size: 14px; margin: 16px 0 8px; color: var(--dim); font-weight: 600; }
.sheet-body h3:first-child { margin-top: 0; }
.sheet-body pre { white-space: pre-wrap; word-break: break-all; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin: 0; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet-actions button { flex: 1; }
.btn-danger { background: var(--err); color: #2a0a08; border: none; padding: 12px; border-radius: 9px; font-weight: 700; cursor: pointer; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); padding: 12px; border-radius: 9px; font-weight: 600; cursor: pointer; }
