/* =========================================================================
   JsonForge — dark theme matching kaneky.dev
   ========================================================================= */

:root {
  --bg: #0a0a0a;
  --bg-1: #111112;
  --bg-2: #161618;
  --bg-3: #1d1d20;
  --bg-hover: #222226;
  --border: #26262b;
  --border-strong: #32323a;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --text-faint: #6b7280;
  --accent: #60a5fa;
  --accent-dim: #3b82f6;
  --accent-bg: rgba(96, 165, 250, 0.12);
  --ok: #34d399;
  --warn: #f59e0b;
  --err: #f87171;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --sb-w: 232px;
  --tb-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  color: inherit;
}

kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--text-dim);
}

/* ─── Topbar ───────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--tb-h);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.15s;
}
.back-link svg { width: 14px; height: 14px; }
.back-link:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
}
.brand:hover { text-decoration: none; }
.brand-icon {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
}

.cmdk-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  padding: 6px 10px;
  transition: background 0.15s;
}
.cmdk-btn svg { width: 14px; height: 14px; }
.cmdk-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ─── Layout ───────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: calc(100vh - var(--tb-h) - 38px);
}

.sidebar {
  width: var(--sb-w);
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--tb-h);
  height: calc(100vh - var(--tb-h));
  overflow-y: auto;
}

.tool-nav {
  flex: 1;
  padding: 16px 10px;
}

.tool-group {
  margin-bottom: 18px;
}
.tool-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 0 10px 6px;
}
.tool-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}
.tool-link:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}
.tool-link.active {
  background: var(--accent-bg);
  color: var(--accent);
}
.tool-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-family: var(--mono);
  font-weight: 600;
  color: currentColor;
}
.tool-icon svg { width: 100%; height: 100%; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.privacy-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--ok);
}
.privacy-badge svg { width: 14px; height: 14px; }

/* ─── Main ─────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  padding: 24px 28px;
}

.tool-container { max-width: 1400px; margin: 0 auto; }

.tool-header {
  margin-bottom: 20px;
}
.tool-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text);
}
.tool-desc {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0;
}

.tool-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}
.btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn svg { width: 14px; height: 14px; }
.btn-primary {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-primary:hover { background: rgba(96, 165, 250, 0.2); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 500;
  font-family: var(--mono);
}
.status-pill.ok { background: rgba(52, 211, 153, 0.14); color: var(--ok); }
.status-pill.warn { background: rgba(245, 158, 11, 0.14); color: var(--warn); }
.status-pill.err { background: rgba(248, 113, 113, 0.14); color: var(--err); }
.status-pill.info { background: var(--accent-bg); color: var(--accent); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-header {
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.panel-body { flex: 1; min-height: 0; }

textarea.editor, .editor {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  border: none;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  outline: none;
  tab-size: 2;
}
textarea.editor::placeholder { color: var(--text-faint); }

.output {
  background: var(--bg);
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  max-height: 680px;
  min-height: 360px;
  margin: 0;
}

input[type="text"], input[type="number"], select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
  border-color: var(--accent);
}
input.mono { font-family: var(--mono); }

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

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.field-row > label { min-width: 90px; }

.copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.12s;
}
.copy-btn svg { width: 12px; height: 12px; }
.copy-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }
.copy-btn.copied { color: var(--ok); border-color: var(--ok); }

/* Drag-drop highlight */
.drop-zone.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: var(--accent-bg);
}

/* ─── JSON syntax coloring ──────────────────────────────────────────── */
.tok-str { color: #a5d6a7; }
.tok-num { color: #ffb86c; }
.tok-bool { color: #c792ea; }
.tok-null { color: #c792ea; }
.tok-key { color: #82aaff; }
.tok-punct { color: var(--text-dim); }
.tok-tag { color: #82aaff; }
.tok-attr { color: #c792ea; }
.tok-val { color: #a5d6a7; }
.tok-comment { color: var(--text-faint); font-style: italic; }

/* ─── JSON tree viewer ──────────────────────────────────────────────── */
.tree {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 14px 16px;
}
.tree ul {
  list-style: none;
  padding-left: 18px;
  margin: 0;
  border-left: 1px dotted var(--border);
}
.tree li { position: relative; }
.tree .toggle {
  display: inline-block;
  width: 14px;
  cursor: pointer;
  user-select: none;
  color: var(--text-dim);
}
.tree .collapsed > ul { display: none; }
.tree .collapsed .toggle::before { content: '▶'; }
.tree .expanded .toggle::before { content: '▼'; }
.tree .count { color: var(--text-faint); font-size: 11px; margin-left: 4px; }

/* ─── Diff ─────────────────────────────────────────────────────────── */
.diff-line {
  display: block;
  padding: 1px 8px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre;
}
.diff-line.add { background: rgba(52, 211, 153, 0.12); color: #a5d6a7; }
.diff-line.del { background: rgba(248, 113, 113, 0.12); color: #ffa0a0; }
.diff-line.ctx { color: var(--text-dim); }
.diff-line.hdr { color: var(--text-faint); background: var(--bg-2); }

/* ─── JWT ──────────────────────────────────────────────────────────── */
.jwt-segments {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
@media (max-width: 900px) { .jwt-segments { grid-template-columns: 1fr; } }

/* ─── Regex ────────────────────────────────────────────────────────── */
.regex-highlight mark {
  background: rgba(96, 165, 250, 0.3);
  color: var(--text);
  padding: 0;
  border-radius: 2px;
}
.regex-match-row {
  font-family: var(--mono);
  font-size: 12px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.regex-match-row:last-child { border-bottom: 0; }
.regex-match-row strong { color: var(--accent); }
.regex-match-row .group { color: var(--text-dim); }

/* ─── Color tool ───────────────────────────────────────────────────── */
.color-preview {
  width: 100%;
  height: 140px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.color-formats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 700px) { .color-formats { grid-template-columns: 1fr; } }
.color-swatch {
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 6px;
}

/* ─── Command palette ───────────────────────────────────────────────── */
.cmdk {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 120px;
}
.cmdk.hidden { display: none; }
.cmdk-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}
.cmdk-panel {
  position: relative;
  width: 100%;
  max-width: 540px;
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
#cmdk-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  border-radius: 0;
}
.cmdk-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 360px;
  overflow-y: auto;
}
.cmdk-list li {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.cmdk-list li .cmdk-name { color: var(--text); font-weight: 500; }
.cmdk-list li .cmdk-group { color: var(--text-faint); font-size: 11px; margin-left: auto; }
.cmdk-list li.active, .cmdk-list li:hover {
  background: var(--accent-bg);
  color: var(--accent);
}
.cmdk-list li.active .cmdk-name { color: var(--accent); }
.cmdk-hint {
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  font-size: 11px;
  color: var(--text-faint);
  display: flex;
  gap: 12px;
}
.cmdk-hint kbd { margin-right: 4px; }

/* ─── Toast ─────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease-out;
}
.toast.hidden { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── Footer ─────────────────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  padding: 10px 20px;
  font-size: 12px;
  color: var(--text-faint);
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.footer-icon { display: inline-flex; color: var(--ok); }
.footer-icon svg { width: 14px; height: 14px; }
.footer-sep { color: var(--border-strong); }

/* ─── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .icon-btn { display: flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--tb-h);
    transform: translateX(-100%);
    transition: transform 0.2s;
    z-index: 40;
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 16px; }
  .back-link span { display: none; }
  .cmdk-btn span { display: none; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

.hidden { display: none !important; }
