/* ---------- Base ---------- */
:root {
  --bg: #0f1115;
  --bg-panel: #161a22;
  --bg-input: #1c212c;
  --bg-hover: #222836;
  --border: #2a3142;
  --text: #e2e6ef;
  --text-dim: #8b93a7;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.15);
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --radius: 10px;
  --mono: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  display: flex;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#sidebar .brand {
  padding: 16px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

#sidebar .brand .dot { color: var(--accent); }

#search-wrap { padding: 10px 12px; }

#tool-search {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
#tool-search:focus { border-color: var(--accent); }

#nav {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
}

#nav .group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 14px 10px 6px;
}

#nav button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
}
#nav button:hover { background: var(--bg-hover); }
#nav button.active { background: var(--accent-soft); color: var(--accent); }
#nav button .ico { width: 18px; text-align: center; }

/* ---------- Main ---------- */
#main {
  flex: 1;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 36px 80px;
}

.tool-panel { display: none; max-width: 1060px; }
.tool-panel.active { display: block; }

.tool-panel h1 { font-size: 21px; margin-bottom: 4px; }
.tool-panel .subtitle { color: var(--text-dim); margin-bottom: 22px; font-size: 13.5px; }

/* ---------- Shared controls ---------- */
textarea, input[type="text"], input[type="number"], select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
}
textarea:focus, input[type="text"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--accent);
}

textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}
textarea.small { min-height: 120px; }

label.lbl {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 6px 2px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 14px 0; }
.row.tight { margin: 8px 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

button.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s;
}
button.btn:hover { filter: brightness(1.12); }
button.btn:disabled { opacity: 0.45; cursor: not-allowed; }

button.btn.ghost {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
}
button.btn.ghost:hover { background: var(--bg-hover); }
button.btn.sm { padding: 5px 10px; font-size: 12.5px; }
button.btn.danger { background: #b91c1c; }

/* ---------- Dropzones ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 20px;
  color: var(--text-dim);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.dropzone input[type="file"] { display: none; }
.dropzone .dz-icon { font-size: 26px; }

/* ---------- File lists ---------- */
.file-list { margin: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
}
.file-item .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .fmeta { color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.file-item button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 15px; padding: 2px 6px; border-radius: 5px; }
.file-item button:hover { color: var(--text); background: var(--bg-hover); }

/* ---------- Output boxes ---------- */
.output-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 48px;
  max-height: 480px;
  overflow-y: auto;
}
.output-box:empty::before { content: "—"; color: var(--text-dim); }

.md-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  min-height: 220px;
  max-height: 560px;
  overflow-y: auto;
  line-height: 1.65;
}
.md-preview h1, .md-preview h2, .md-preview h3 { margin: 0.8em 0 0.4em; }
.md-preview h1:first-child, .md-preview h2:first-child, .md-preview p:first-child { margin-top: 0; }
.md-preview p, .md-preview ul, .md-preview ol, .md-preview pre, .md-preview blockquote, .md-preview table { margin: 0.55em 0; }
.md-preview ul, .md-preview ol { padding-left: 1.6em; }
.md-preview code { background: var(--bg-hover); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 12.5px; }
.md-preview pre { background: var(--bg-hover); padding: 12px; border-radius: 8px; overflow-x: auto; }
.md-preview pre code { background: none; padding: 0; }
.md-preview blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-dim); }
.md-preview a { color: var(--accent); }
.md-preview table { border-collapse: collapse; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 5px 10px; }
.md-preview img { max-width: 100%; }

/* ---------- Status / results ---------- */
.status { font-size: 13px; margin: 10px 0; min-height: 18px; }
.status.ok { color: var(--green); }
.status.err { color: var(--red); }

.kv-grid { display: grid; grid-template-columns: max-content 1fr max-content; gap: 8px 14px; align-items: center; margin: 14px 0; }
.kv-grid .k { color: var(--text-dim); font-size: 12.5px; white-space: nowrap; }
.kv-grid .v { font-family: var(--mono); font-size: 13px; word-break: break-all; }

/* diff */
.diff-out ins { background: rgba(74, 222, 128, 0.18); color: var(--green); text-decoration: none; }
.diff-out del { background: rgba(248, 113, 113, 0.18); color: var(--red); text-decoration: line-through; }

/* regex */
.regex-out mark { background: rgba(91, 140, 255, 0.35); color: var(--text); border-radius: 3px; padding: 0 1px; }

/* image results */
.img-results { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; }
.img-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  width: 190px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
}
.img-card img { width: 100%; height: 110px; object-fit: contain; background: var(--bg-input); border-radius: 6px; }
.img-card .meta { color: var(--text-dim); }

/* color tool */
.swatch { width: 72px; height: 72px; border-radius: 12px; border: 1px solid var(--border); }

/* toast */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 99;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* qr */
#qr-out { background: #fff; padding: 16px; border-radius: var(--radius); display: inline-block; min-width: 100px; min-height: 100px; }
#qr-out img, #qr-out canvas { display: block; }

input[type="range"] { accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
input[type="color"] { width: 44px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-input); cursor: pointer; padding: 2px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
