:root {
  --bg: #f5f6f8;
  --bg-panel: #ffffff;
  --bg-input: #ffffff;
  --border: #e0e2e7;
  --text: #1b1e26;
  --text-dim: #6b7280;
  --accent: #4f6df5;
  --accent-text: #ffffff;
  --add-bg: #d9f4e3;
  --add-text: #10763a;
  --del-bg: #fbe0e1;
  --del-text: #b4232a;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --radius: 8px;
}

:root[data-theme="dark"] {
  --bg: #14161b;
  --bg-panel: #1b1e26;
  --bg-input: #101217;
  --border: #2a2e38;
  --text: #e7e9ee;
  --text-dim: #8a8f9c;
  --accent: #6d87ff;
  --accent-text: #0b0d12;
  --add-bg: #103322;
  --add-text: #4fd88a;
  --del-bg: #3a1418;
  --del-text: #f47b82;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161b;
    --bg-panel: #1b1e26;
    --bg-input: #101217;
    --border: #2a2e38;
    --text: #e7e9ee;
    --text-dim: #8a8f9c;
    --accent: #6d87ff;
    --accent-text: #0b0d12;
    --add-bg: #103322;
    --add-text: #4fd88a;
    --del-bg: #3a1418;
    --del-text: #f47b82;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  overflow: hidden;
  transition: width 0.15s ease;
}

.sidebar.collapsed { width: 60px; }

.nav-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
}

.nav-group + .nav-group { margin-top: 14px; }
.nav-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding: 4px 12px 6px;
  opacity: 0.75;
  white-space: nowrap;
}
.nav-group-title.collapsible {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border-radius: 6px;
}
.nav-group-title.collapsible:hover { opacity: 1; color: var(--text); background: var(--bg); }
.nav-group-chevron { font-size: 9px; flex-shrink: 0; transition: transform 0.1s ease; }
.nav-group.group-collapsed .nav-btn { display: none; }
.sidebar.collapsed .nav-group-title { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 18px 10px;
  font-weight: 700;
  font-size: 16px;
}
.sidebar.collapsed .brand { padding: 6px 0 18px; justify-content: center; }
.sidebar.collapsed .brand-text { display: none; }

.sidebar-toggle-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  width: 22px;
  height: 22px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 12px;
}
.sidebar-toggle-btn:hover { color: var(--text); border-color: var(--accent); }
.sidebar.collapsed .sidebar-toggle-btn { margin-left: 0; transform: rotate(180deg); }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 4px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
}

.nav-btn:hover { background: var(--bg); color: var(--text); }
.nav-btn.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.nav-icon { width: 22px; flex-shrink: 0; display: inline-block; text-align: center; font-size: 12px; opacity: 0.9; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar.collapsed .nav-btn { justify-content: center; padding: 10px 6px; }
.sidebar.collapsed .nav-label { display: none; }

.sidebar-footer { margin-top: auto; padding: 10px; }
.sidebar.collapsed .sidebar-footer { padding: 10px 4px; }
#theme-toggle {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
  width: 100%;
}

/* ---------- Content ---------- */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.tool-panel { display: none; }
.tool-panel.active { display: block; }

.panel-header h2 { margin: 0 0 4px; font-size: 20px; }
.panel-header p { margin: 0 0 18px; color: var(--text-dim); font-size: 13px; }
.panel-header code {
  background: var(--bg-input);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); color: var(--accent-text); }

.btn-row { display: flex; gap: 6px; }

.select-label, .switch-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

select {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
}

.panel-body.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .panel-body.split { grid-template-columns: 1fr; }
}

.panel-body.stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.col { display: flex; flex-direction: column; min-width: 0; }

.code-area.curl-input { min-height: 150px; }
.stack .error-box { margin-top: 8px; }

/* ---------- VS Code–style output editor (Dark+) ---------- */
.vsc-editor {
  background: #1e1e1e;
  border: 1px solid #2b2b2b;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
.vsc-bar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  background: #252526;
  border-bottom: 1px solid #2b2b2b;
  min-height: 36px;
}
.vsc-tabs { display: flex; overflow-x: auto; scrollbar-width: none; }
.vsc-tabs::-webkit-scrollbar { display: none; }
.vsc-tabs .tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #2d2d2d;
  color: #969696;
  border: 0;
  border-right: 1px solid #252526;
  border-top: 2px solid transparent;
  border-radius: 0;
  padding: 0 14px;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}
.vsc-tabs .tab-btn:hover { color: #cccccc; }
.vsc-tabs .tab-btn.active {
  background: #1e1e1e;
  color: #ffffff;
  border-top-color: #3794ff;
}
.vsc-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.vsc-dot.py { background: #3572a5; }
.vsc-dot.js { background: #f1e05a; }
.vsc-dot.node { background: #6cc24a; }
.vsc-dot.json { background: #cbcb41; }
.vsc-copy {
  background: transparent;
  color: #cccccc;
  border: 0;
  border-left: 1px solid #2b2b2b;
  padding: 0 14px;
  font-size: 12.5px;
  cursor: pointer;
  flex: none;
}
.vsc-copy:hover { background: #2a2d2e; color: #ffffff; }

.vsc-code {
  margin: 0;
  min-height: 320px;
  max-height: 70vh;
  overflow: auto;
  padding: 12px 16px 14px 0;
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: Consolas, "SFMono-Regular", "Cascadia Code", "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  counter-reset: ln;
  tab-size: 4;
}
.vsc-code::selection, .vsc-code *::selection { background: #264f78; }
.vsc-code .ln {
  display: block;
  position: relative;
  min-height: 1.6em;
  padding-left: 56px;
}
.vsc-code .ln::before {
  counter-increment: ln;
  content: counter(ln);
  position: absolute;
  left: 0;
  width: 40px;
  text-align: right;
  color: #6e7681;
  user-select: none;
}
.vsc-code .ln:hover { background: #2a2d2e; }
.vsc-code .ln:hover::before { color: #c6c6c6; }
.vsc-empty { padding-left: 16px; color: #6e7681; font-style: italic; }

/* Dark+ token colors */
.tk-kw   { color: #569cd6; }  /* def, const, let, true/None */
.tk-ctl  { color: #c586c0; }  /* import, from, return */
.tk-str  { color: #ce9178; }
.tk-key  { color: #9cdcfe; }  /* object / dict keys */
.tk-num  { color: #b5cea8; }
.tk-com  { color: #6a9955; font-style: italic; }
.tk-fn   { color: #dcdcaa; }
.tk-var  { color: #9cdcfe; }
.tk-type { color: #4ec9b0; }  /* requests, json, console, FormData */
.tk-op   { color: #d4d4d4; }
.tk-b0   { color: #ffd700; }  /* bracket pair colorization */
.tk-b1   { color: #da70d6; }
.tk-b2   { color: #179fff; }

.col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  gap: 10px;
}

.tabs { display: flex; gap: 4px; }
.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.tab-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.code-area {
  width: 100%;
  min-height: 320px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  resize: vertical;
  white-space: pre;
  overflow: auto;
}

pre.code-area.output { margin: 0; white-space: pre-wrap; word-break: break-word; }

.error-box {
  margin-top: 12px;
  background: var(--del-bg);
  color: var(--del-text);
  border: 1px solid var(--del-text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  white-space: pre-wrap;
}
.error-box.ok {
  background: var(--add-bg);
  color: var(--add-text);
  border-color: var(--add-text);
}
.hidden { display: none !important; }

.stats { font-size: 12px; color: var(--text-dim); }

/* ---------- diff result ---------- */
.diff-result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: Consolas, Menlo, monospace;
  font-size: 12.5px;
}
.diff-col { overflow-x: auto; }
.diff-col + .diff-col { border-left: 1px solid var(--border); }
.diff-line {
  display: flex;
  white-space: pre;
  min-height: 20px;
}
.diff-line .ln {
  flex-shrink: 0;
  width: 40px;
  text-align: right;
  padding: 1px 8px;
  color: var(--text-dim);
  user-select: none;
  background: var(--bg-panel);
}
.diff-line .txt { padding: 1px 10px 1px 4px; flex: 1; }
.diff-line.added { background: var(--add-bg); }
.diff-line.added .txt { color: var(--add-text); }
.diff-line.removed { background: var(--del-bg); }
.diff-line.removed .txt { color: var(--del-text); }
.diff-line.empty { background: repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(128,128,128,0.06) 6px, rgba(128,128,128,0.06) 12px); }
.word-add { background: var(--add-bg); color: var(--add-text); border-radius: 2px; }
.word-del { background: var(--del-bg); color: var(--del-text); border-radius: 2px; text-decoration: line-through; }

/* ---------- json viewer: CodeMirror (VS Code Dark+) ---------- */
.vsc-actions { display: flex; flex: none; }
.vsc-actions .hidden { display: none; }
.vsc-dot.code { background: #3794ff; }

.vsc-cm .CodeMirror {
  height: max(320px, 62vh);
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: Consolas, "SFMono-Regular", "Cascadia Code", "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.6;
}
.vsc-cm .CodeMirror-lines { padding: 12px 0 14px; }
.vsc-cm .CodeMirror-gutters { background: #1e1e1e; border-right: 0; }
.vsc-cm .CodeMirror-linenumber { color: #6e7681; padding: 0 6px 0 12px; }
.vsc-cm .CodeMirror-foldgutter { width: 16px; }
.vsc-cm .CodeMirror-foldgutter-open,
.vsc-cm .CodeMirror-foldgutter-folded { color: #c5c5c5; cursor: pointer; font-size: 13px; }
.vsc-cm .CodeMirror-foldgutter-open { opacity: 0; transition: opacity .15s; }
.vsc-cm .CodeMirror:hover .CodeMirror-foldgutter-open { opacity: 1; }
.vsc-cm .CodeMirror-foldmarker {
  color: #d4d4d4;
  background: #3a3d41;
  border-radius: 3px;
  padding: 0 5px;
  margin: 0 2px;
  font-family: inherit;
  text-shadow: none;
  line-height: 1.2;
  cursor: pointer;
}
.vsc-cm .CodeMirror-cursor { border-left-color: #aeafad; }
.vsc-cm .CodeMirror-selected,
.vsc-cm .CodeMirror-focused .CodeMirror-selected { background: #264f78; }
.vsc-cm .CodeMirror-line::selection, .vsc-cm .CodeMirror-line > span::selection,
.vsc-cm .CodeMirror-line > span > span::selection { background: #264f78; }
.vsc-cm .CodeMirror-activeline-background { background: #2a2d2e; }
.vsc-cm div.CodeMirror span.CodeMirror-matchingbracket {
  color: #d4d4d4;
  outline: 1px solid #888;
  background: rgba(255,255,255,0.06);
}
.vsc-cm .cm-string   { color: #ce9178; }
.vsc-cm .cm-property { color: #9cdcfe; }
.vsc-cm .cm-number   { color: #b5cea8; }
.vsc-cm .cm-atom     { color: #569cd6; }
.vsc-cm .cm-error    { color: #f48771; background: transparent; }
.vsc-cm div.CodeMirror span.cm-b0 { color: #ffd700; }
.vsc-cm div.CodeMirror span.cm-b1 { color: #da70d6; }
.vsc-cm div.CodeMirror span.cm-b2 { color: #179fff; }

/* ---------- base64 file box ---------- */
.file-box {
  margin-top: 18px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.file-box .col-header { width: 100%; margin-bottom: 4px; }

/* ---------- params table ---------- */
.params-table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}
.params-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.params-row + .params-row { border-top: 1px solid var(--border); }
.params-row > div { padding: 8px 12px; word-break: break-all; }
.params-row > div:first-child { border-right: 1px solid var(--border); color: var(--accent); font-weight: 600; background: var(--bg-panel); }
.params-empty { padding: 14px; color: var(--text-dim); font-size: 13px; }

/* ---------- generic text input ---------- */
.text-input {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  font-family: Consolas, Menlo, monospace;
}
.text-input:focus, select:focus { outline: 1px solid var(--accent); }

/* ---------- timestamp ---------- */
.ts-row { display: flex; gap: 8px; margin-bottom: 10px; }
.ts-row .text-input { flex: 1; }
#ts-date-input { width: 100%; margin-bottom: 10px; }
.kv-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}
.kv-row { display: grid; grid-template-columns: 130px 1fr; }
.kv-row + .kv-row { border-top: 1px solid var(--border); }
.kv-row > div { padding: 8px 12px; word-break: break-all; }
.kv-row > div:first-child { color: var(--text-dim); background: var(--bg-panel); border-right: 1px solid var(--border); }

/* ---------- regex tester ---------- */
.regex-slash { color: var(--text-dim); font-family: Consolas, Menlo, monospace; font-size: 15px; }
.flags-input { width: 90px; }
#regex-pattern { flex: 1; }
.regex-highlight {
  min-height: 60px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, Menlo, monospace;
  font-size: 12.5px;
}
.regex-match { background: var(--add-bg); color: var(--add-text); border-radius: 2px; padding: 0 1px; }
.regex-match.current { outline: 1px solid var(--accent); }

/* ---------- password generator ---------- */
.pw-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.pw-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: Consolas, Menlo, monospace;
  font-size: 14px;
}
.pw-item .pw-value { flex: 1; word-break: break-all; user-select: all; }
.pw-item .btn { padding: 4px 10px; font-size: 12px; flex-shrink: 0; }
.pw-strength { font-size: 11px; padding: 2px 8px; border-radius: 10px; flex-shrink: 0; }
.pw-strength.weak { background: var(--del-bg); color: var(--del-text); }
.pw-strength.medium { background: #3a3113; color: #e0b64e; }
.pw-strength.strong { background: var(--add-bg); color: var(--add-text); }

/* ---------- data table (fake info generator) ---------- */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
.data-table th, .data-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--bg-panel); color: var(--text-dim); position: sticky; top: 0; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-panel); }

/* ---------- 2FA / TOTP ---------- */
.totp-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.totp-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.totp-item .totp-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text-dim); }
.totp-item .totp-code {
  font-family: Consolas, Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  min-width: 130px;
}
.totp-item .totp-ring {
  width: 30px; height: 30px; flex-shrink: 0;
}
.totp-item .btn { padding: 4px 10px; font-size: 12px; flex-shrink: 0; }
.totp-item.totp-error { color: var(--del-text); font-size: 13px; }

/* ---------- account list processor ---------- */
.al-columns-box { margin-top: 16px; }

.al-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 16px;
}
@media (max-width: 800px) {
  .al-actions-grid { grid-template-columns: 1fr; }
}

.al-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: 14px;
}
.al-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}
.al-card-body {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.al-card-body .text-input { flex: 1; min-width: 110px; }
.al-card-body .btn { flex-shrink: 0; }

.al-col-checks { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.al-col-checks label {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
}

.al-bottom-row { margin-top: 14px; display: flex; justify-content: flex-end; }

.al-stat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 14px;
}
.al-stat-chip {
  font-size: 14px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
}
.al-stat-chip .num { font-size: 15px; }
.al-stat-chip.accent { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.al-stat-chip.success { background: var(--add-bg); color: var(--add-text); border-color: var(--add-text); }
.al-stat-chip.neutral { background: var(--bg-input); color: var(--text-dim); }
.al-stat-chip.danger { background: var(--del-bg); color: var(--del-text); border-color: var(--del-text); }
