/* ============ Design Tokens ============ */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans", "Noto Sans JP", "Noto Sans KR", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Cascadia Code", monospace;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --topbar-h: 60px;
  --sidebar-w: 264px;
  --transition: 0.18s cubic-bezier(.4, 0, .2, 1);
}

html[data-theme="dark"] {
  --bg: #0b0e17;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, .14), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(34, 211, 238, .08), transparent 55%);
  --surface: #121624;
  --surface-2: #181d30;
  --surface-3: #1f2540;
  --border: rgba(148, 163, 184, .14);
  --border-strong: rgba(148, 163, 184, .26);
  --text: #e6eaf5;
  --text-dim: #9aa5c0;
  --text-faint: #626d8a;
  --accent: #818cf8;
  --accent-strong: #6366f1;
  --accent-soft: rgba(99, 102, 241, .16);
  --cyan: #22d3ee;
  --success: #34d399;
  --error: #f87171;
  --shadow-lg: 0 20px 50px -12px rgba(0, 0, 0, .55);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .3);
  --topbar-bg: rgba(13, 16, 27, .78);
  --code-bg: #0d1120;
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, rgba(99, 102, 241, .10), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(34, 211, 238, .07), transparent 55%);
  --surface: #ffffff;
  --surface-2: #f0f2f9;
  --surface-3: #e6eaf5;
  --border: rgba(15, 23, 42, .09);
  --border-strong: rgba(15, 23, 42, .16);
  --text: #17203a;
  --text-dim: #55607a;
  --text-faint: #8b94ab;
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --accent-soft: rgba(99, 102, 241, .10);
  --cyan: #0891b2;
  --success: #059669;
  --error: #dc2626;
  --shadow-lg: 0 20px 45px -18px rgba(30, 41, 59, .25);
  --shadow-sm: 0 1px 4px rgba(30, 41, 59, .08);
  --topbar-bg: rgba(255, 255, 255, .82);
  --code-bg: #fafbfe;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: background-color var(--transition), color var(--transition);
}

::selection { background: var(--accent-soft); }

.icon { width: 18px; height: 18px; flex: none; }
.chevron { width: 14px; height: 14px; opacity: .7; transition: transform var(--transition); }

button { font-family: inherit; cursor: pointer; }
select, input[type="text"] { font-family: inherit; color: var(--text); }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; border: 2px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ Topbar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--text);
  flex: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -1px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-strong), var(--cyan));
  border-radius: 10px;
  box-shadow: 0 4px 14px -2px rgba(99, 102, 241, .5);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: .2px; }
.brand-text small { font-size: 11px; color: var(--text-faint); }

.mainnav { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; }

.nav-item {
  position: relative;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
  background: none;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
  white-space: nowrap;
}
.nav-item:hover { color: var(--text); background: var(--surface-2); }
.nav-item.open, .nav-item.active { color: var(--accent); }
.nav-item.open .chevron { transform: rotate(180deg); }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 230px;
  padding: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-6px) scale(.98);
  pointer-events: none;
  transition: all var(--transition);
  z-index: 200;
}
.dropdown-menu.show { opacity: 1; transform: none; pointer-events: auto; }

.dropdown-menu.right { left: auto; right: 0; min-width: 170px; }

.menu-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-dim);
  text-decoration: none;
  background: none;
  border: none;
  text-align: left;
  transition: all var(--transition);
}
.menu-link:hover { background: var(--accent-soft); color: var(--text); }
.menu-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.menu-link .menu-ico { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-family: var(--font-mono); font-size: 10px; font-weight: 700; color: #fff; flex: none; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 8px; }
.menu-group-label { padding: 10px 12px 5px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); }

.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; }

/* Search */
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-faint); pointer-events: none; }
.search-box input {
  width: 200px;
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  outline: none;
  transition: all var(--transition);
}
.search-box input::placeholder { color: var(--text-faint); }
.search-box input:focus { width: 250px; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 300px;
  max-height: 340px;
  overflow: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
}
.search-results .menu-link small { margin-left: auto; color: var(--text-faint); font-size: 11px; }
.search-empty { padding: 14px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-strong), #7c3aed);
  box-shadow: 0 4px 14px -4px rgba(99, 102, 241, .55);
}
.btn.primary:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn.primary:active { transform: none; }
.btn.secondary { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn.secondary:hover { background: var(--surface-3); }
.btn.ghost { background: none; color: var(--text-dim); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.tiny { padding: 4px 9px; font-size: 12px; font-weight: 500; }
.btn.icon-btn { padding: 8px; }
.btn:disabled { opacity: .45; pointer-events: none; }

#langSwitch { position: relative; }
.theme-sun { display: none; }
html[data-theme="light"] .theme-sun { display: block; }
html[data-theme="light"] .theme-moon { display: none; }

/* ============ Layout ============ */
.layout {
  flex: 1;
  display: flex;
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 24px;
  gap: 24px;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  padding: 22px 0;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  scrollbar-width: thin;
}

.side-group { margin-bottom: 20px; }
.side-group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 0 12px 8px;
}
.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-dim);
  text-decoration: none;
  transition: all var(--transition);
  position: relative;
}
.side-link:hover { background: var(--surface-2); color: var(--text); }
.side-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.side-link.active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.side-link .menu-ico { width: 24px; height: 24px; font-size: 10.5px; }

/* Content */
.content { flex: 1; min-width: 0; padding: 22px 0 40px; }

.tool-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.tool-head h1 { font-size: 24px; font-weight: 750; letter-spacing: -.01em; }
.tool-desc { margin-top: 5px; font-size: 13.5px; color: var(--text-dim); max-width: 640px; }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-faint); }
.breadcrumb a { color: var(--text-faint); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep::after { content: "/"; margin: 0 2px; }

/* Home cards */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.home-section-title { margin: 26px 0 14px; font-size: 15px; font-weight: 700; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.home-section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.home-section-title:first-child { margin-top: 0; }
.tool-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text);
  transition: all var(--transition);
}
.tool-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.tool-card .menu-ico { width: 34px; height: 34px; font-size: 12.5px; border-radius: 9px; }
.tool-card div { min-width: 0; }
.tool-card strong { display: block; font-size: 14px; font-weight: 650; }
.tool-card small { display: block; margin-top: 2px; font-size: 12px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ Editor card ============ */
.editor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.toolbar-left { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 14px; }
.opt { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim); }
.opt select {
  padding: 5px 8px;
  font-size: 12.5px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
}
.opt select:focus { border-color: var(--accent); }
.stats { font-size: 12px; color: var(--text-faint); font-family: var(--font-mono); }

.panes {
  display: grid;
  grid-template-columns: 1fr 6px 1fr;
  height: clamp(420px, 58vh, 720px);
  background: var(--code-bg);
}
.pane { display: flex; flex-direction: column; min-width: 0; }
.pane-divider { cursor: col-resize; background: var(--border); transition: background var(--transition); }
.pane-divider:hover, .pane-divider.dragging { background: var(--accent); }

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}
.pane-head-actions { display: flex; gap: 4px; }

.panes textarea {
  flex: 1;
  width: 100%;
  padding: 14px 16px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
}
.pane-input { border-right: 1px solid var(--border); }
.panes textarea::placeholder { color: var(--text-faint); }
.panes textarea:focus { box-shadow: inset 0 0 0 1.5px var(--accent-soft); }

/* result table (cookie/header/url tools) */
.result-table-wrap { padding: 4px 16px 16px; overflow: auto; }
table.result-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.result-table th, .result-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  word-break: break-all;
}
.result-table th { color: var(--text-faint); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
.result-table tr:hover td { background: var(--accent-soft); }

/* naming converter chips */
.name-results { padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.name-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  cursor: pointer;
}
.name-chip:hover { border-color: var(--accent); }
.name-chip small { display: block; color: var(--text-faint); font-size: 11px; margin-bottom: 3px; }
.name-chip code { font-family: var(--font-mono); font-size: 13px; color: var(--cyan); word-break: break-all; }

/* Message bar */
.msg-bar {
  padding: 10px 16px;
  font-size: 13px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-bar.error { color: var(--error); background: rgba(248, 113, 113, .08); }
.msg-bar.success { color: var(--success); background: rgba(52, 211, 153, .07); }
.msg-bar.info { color: var(--text-dim); }
.msg-bar[hidden] { display: none; }
.msg-close {
  margin-left: auto;
  border: 0;
  background: none;
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: .7;
}
.msg-close:hover { opacity: 1; background: rgba(128, 128, 128, .15); }

.tool-extra { margin-top: 18px; }
.tool-extra .note {
  font-size: 12.5px;
  color: var(--text-faint);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}

/* Footer */
.footer {
  padding: 18px 24px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  margin-top: 20px;
}
.footer .dot { margin: 0 8px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translate(-50%, 20px);
  padding: 10px 20px;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all .25s ease;
  z-index: 300;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  .search-box input { width: 140px; }
  .search-box input:focus { width: 180px; }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .panes { grid-template-columns: 1fr; grid-template-rows: 1fr 6px 1fr; height: auto; }
  .pane { height: 300px; }
  .pane-divider { cursor: row-resize; }
  .pane-input { border-right: none; }
  .mainnav { display: none; }
  .topbar { gap: 12px; padding: 0 14px; }
  .layout { padding: 0 14px; }
}
@media (max-width: 560px) {
  .search-box { display: none; }
  .brand-text { display: none; }
}

/* ============ JSON tools era additions ============ */
.nav-item.current { color: var(--accent); }

.dropdown-menu.cols { display: flex; align-items: flex-start; gap: 6px; max-width: min(80vw, 780px); }
.menu-col { min-width: 218px; }
.menu-col .menu-link { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-col .menu-link span { overflow: hidden; text-overflow: ellipsis; }

/* sidebar collapsible groups */
.side-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  transition: color var(--transition);
}
.side-group-title:hover { color: var(--text-dim); }
.grp-chev { width: 14px; height: 14px; transition: transform var(--transition); }
.grp-chev.rot { transform: rotate(-90deg); }
.side-group-list { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .26s ease; }
.side-group-list.closed { grid-template-rows: 0fr; }
.side-group-inner { overflow: hidden; min-height: 0; }

/* tool options bar */
.tool-options { display: flex; align-items: center; gap: 14px; margin-left: auto; flex-wrap: wrap; }
.tool-options label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim); }
.tool-options select,
.tool-options input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12.5px;
  outline: none;
}
.tool-options select:focus, .tool-options input:focus { border-color: var(--accent); }
.tool-options input[type="text"] { width: 120px; }

/* JSON tree viewer */
.json-tree { padding: 14px 16px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.75; }
.jt-toggle { display: inline-block; width: 18px; cursor: pointer; color: var(--text-faint); user-select: none; }
.jt-toggle.leaf { cursor: default; }
.jt-body { cursor: pointer; }
.jt-children { margin-left: 8px; padding-left: 10px; border-left: 1px dashed var(--border); }
.jt-children.closed { display: none; }
.jt-key { color: var(--jt-key, #a855f7); }
.jt-str { color: var(--jt-str, #16a34a); word-break: break-all; }
.jt-num { color: var(--jt-num, #d97706); }
.jt-bool { color: var(--jt-bool, #2563eb); }
.jt-null { color: var(--text-faint); font-style: italic; }
.jt-meta { color: var(--text-faint); }
html[data-theme="dark"] .jt-key { color: #c084fc; }
html[data-theme="dark"] .jt-str { color: #4ade80; }
html[data-theme="dark"] .jt-num { color: #fbbf24; }
html[data-theme="dark"] .jt-bool { color: #60a5fa; }
