:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #3b5bdb;
  --accent-soft: #e7ebfb;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

html[data-theme="dark"] {
  --bg: #0e1013;
  --panel: #16191e;
  --panel-2: #1c2026;
  --border: #282e36;
  --text: #e6e9ef;
  --muted: #8b939f;
  --accent: #748ffc;
  --accent-soft: #1f2637;
  --danger: #ff6b6b;
  --ok: #51cf66;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0e1013;
    --panel: #16191e;
    --panel-2: #1c2026;
    --border: #282e36;
    --text: #e6e9ef;
    --muted: #8b939f;
    --accent: #748ffc;
    --accent-soft: #1f2637;
    --danger: #ff6b6b;
    --ok: #51cf66;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

/* Class-level `display` would otherwise beat the UA rule for [hidden]. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  height: 100vh;
  overflow: hidden;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
code, pre { font-family: var(--mono); }
.muted { color: var(--muted); }

/* ---------------------------------------------------------------- gate --- */

.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.gate-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; width: min(360px, 90vw); box-shadow: var(--shadow); text-align: center;
}
.gate-card h1 { margin: 0 0 6px; font-size: 20px; }
.gate-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.gate-card input { width: 100%; margin-bottom: 12px; }
.gate-card button { width: 100%; }
.gate-error { color: var(--danger) !important; margin-top: 12px !important; }

/* -------------------------------------------------------------- layout --- */

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -.2px; }
.brand-icon { width: 20px; height: 20px; color: var(--accent); }
.topbar-stats { color: var(--muted); font-size: 12px; font-family: var(--mono); flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

.layout {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: 240px minmax(320px, 1fr) minmax(360px, 1.15fr);
}

.col { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); background: var(--panel); }
.col-detail { border-right: none; background: var(--bg); }
.scroll { overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; min-height: 0; }

.col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.col-title { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.col-foot:empty { display: none; }
.col-foot { padding: 8px; }

/* --------------------------------------------------------------- forms --- */

.btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 6px 11px; border-radius: 7px; cursor: pointer; line-height: 1.3;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }

.input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 7px; outline: none; min-width: 0;
}
.input:focus { border-color: var(--accent); }
.input-sm { padding: 5px 8px; font-size: 12px; }
textarea.input { font-family: var(--mono); font-size: 12px; resize: vertical; width: 100%; }

/* ----------------------------------------------------------- bins list --- */

.bin-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  border-bottom: 1px solid var(--border); padding: 9px 12px; cursor: pointer;
}
.bin-item:hover { background: var(--panel-2); }
.bin-item.active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.bin-item .bin-id { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.bin-item .bin-sub { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.bin-item .bin-sub .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------ bin head --- */

.bin-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.bin-url-row { display: flex; gap: 6px; align-items: center; }
.bin-url {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  padding: 7px 10px; font-size: 12.5px; overflow-x: auto; white-space: nowrap; user-select: all;
}
.bin-meta { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.bin-name { background: none; border: 1px dashed transparent; border-radius: 6px; padding: 3px 6px; font-weight: 600; flex: 1; min-width: 120px; }
.bin-name:hover { border-color: var(--border); }
.bin-name:focus { outline: none; border-color: var(--accent); border-style: solid; }
.bin-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.filters { display: flex; gap: 6px; }
.filters .input:first-child { flex: 1; }

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: middle; }
.dot.off { background: var(--muted); }

/* -------------------------------------------------------- request list --- */

.req {
  display: grid; grid-template-columns: 62px 1fr auto; gap: 8px; align-items: baseline;
  width: 100%; text-align: left; background: none; border: none;
  border-bottom: 1px solid var(--border); padding: 8px 12px; cursor: pointer;
}
.req:hover { background: var(--panel-2); }
.req.active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.req.fresh { animation: flash 1.1s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }

.method { font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.m-GET { color: #2b8a3e; } .m-POST { color: #1971c2; } .m-PUT { color: #e8590c; }
.m-PATCH { color: #7048e8; } .m-DELETE { color: #c92a2a; } .m-HEAD, .m-OPTIONS { color: #868e96; }
html[data-theme="dark"] .m-GET { color: #51cf66; }
html[data-theme="dark"] .m-POST { color: #4dabf7; }
html[data-theme="dark"] .m-PUT { color: #ffa94d; }
html[data-theme="dark"] .m-PATCH { color: #b197fc; }
html[data-theme="dark"] .m-DELETE { color: #ff8787; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .m-GET { color: #51cf66; }
  html:not([data-theme="light"]) .m-POST { color: #4dabf7; }
  html:not([data-theme="light"]) .m-PUT { color: #ffa94d; }
  html:not([data-theme="light"]) .m-PATCH { color: #b197fc; }
  html:not([data-theme="light"]) .m-DELETE { color: #ff8787; }
}

.req-main { min-width: 0; }
.req-path, .req-preview { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.req-path { font-family: var(--mono); font-size: 12.5px; }
.req-preview { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.req-time { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- detail --- */

.detail { padding: 14px 16px 60px; }
.detail-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.detail-head .method { font-size: 13px; }
.detail-head .path { font-family: var(--mono); font-size: 14px; word-break: break-all; }
.detail-sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; display: flex; gap: 12px; flex-wrap: wrap; }
.detail-actions { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }

.section { margin-bottom: 18px; }
.section > h3 {
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 7px; font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.section > h3 .tag { text-transform: none; letter-spacing: 0; font-weight: 500; }

.kv { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.kv td { padding: 5px 9px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 12.5px; font-family: var(--mono); }
.kv tr:last-child td { border-bottom: none; }
.kv td:first-child { color: var(--muted); width: 1%; white-space: nowrap; }
.kv td:last-child { word-break: break-all; }

pre.code {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin: 0; font-size: 12.5px; line-height: 1.5;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word; max-height: 55vh;
}
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab { background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 8px; font-size: 11px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--panel); border-color: var(--border); color: var(--text); }

.tok-key { color: var(--accent); }
.tok-str { color: #2b8a3e; }
.tok-num { color: #e8590c; }
.tok-lit { color: #7048e8; }
html[data-theme="dark"] .tok-str { color: #8ce99a; }
html[data-theme="dark"] .tok-num { color: #ffc078; }
html[data-theme="dark"] .tok-lit { color: #b197fc; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .tok-str { color: #8ce99a; }
  html:not([data-theme="light"]) .tok-num { color: #ffc078; }
  html:not([data-theme="light"]) .tok-lit { color: #b197fc; }
}

.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty code { background: var(--panel-2); padding: 2px 6px; border-radius: 5px; }
.empty .big { display: block; font-size: 15px; color: var(--text); margin-bottom: 8px; font-weight: 600; }

.tag { font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; color: var(--muted); }
.tag.warn { color: var(--danger); border-color: var(--danger); }

img.body-img { max-width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }

/* --------------------------------------------------------------- modal --- */

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: min(560px, 100%); max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 14px; font-size: 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field .input { width: 100%; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* --------------------------------------------------------------- toast --- */

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px;
  font-size: 13px; z-index: 60; box-shadow: var(--shadow);
}

/* ------------------------------------------------------------ narrow ----- */

@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px minmax(280px, 1fr); }
  .col-detail { position: fixed; inset: 0; z-index: 30; border-left: 1px solid var(--border); }
  .col-detail:not(.open) { display: none; }
  .detail-close { display: inline-block !important; }
}
.detail-close { display: none; }

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .col-bins { position: fixed; inset: 0; z-index: 25; }
  .col-bins:not(.open) { display: none; }
  .topbar-stats { display: none; }
}
