/* kevin-tools — design tokens mirrored from sub2api.kevindesign.uk (Tailwind slate + teal). */
:root {
  /* surfaces */
  --bg: #020617;                       /* slate-950 — page */
  --sidebar: #0f172a;                  /* slate-900 */
  --card: rgba(30, 41, 59, .5);        /* slate-800/50 */
  --surface: #1e293b;                  /* slate-800 — solid inputs/controls */
  --surface-hover: #334155;            /* slate-700 */
  --border: #1e293b;                   /* slate-800 — sidebar / subtle dividers */
  --border-strong: #334155;            /* slate-700 — cards, table heads */
  --border-input: #475569;             /* slate-600 */
  /* text */
  --text: #f3f4f6;                     /* gray-100 */
  --text-dim: #94a3b8;                 /* slate-400 */
  --text-soft: #cbd5e1;                /* slate-300 — nav idle */
  --text-faint: #64748b;               /* slate-500 — section titles */
  /* accent */
  --accent: #2dd4bf;                   /* teal-400 */
  --accent-soft: rgba(19, 78, 74, .2); /* teal-900/20 */
  --accent-soft-hover: rgba(19, 78, 74, .3);
  --accent-1: #14b8a6;                 /* teal-500 — gradient from */
  --accent-2: #0d9488;                 /* teal-600 — gradient to */
  --accent-1h: #0d9488;
  --accent-2h: #0f766e;
  --ring: rgba(20, 184, 166, .5);
  /* status */
  --danger: #f87171;  --danger-soft: rgba(127, 29, 29, .3);
  --ok: #34d399;      --ok-soft: rgba(6, 78, 59, .3);
  --warn: #fbbf24;    --warn-soft: rgba(120, 53, 15, .3);
  /* card + table + glass surfaces */
  --card-border: rgba(51, 65, 85, .5);
  --card-shadow: none;
  --th-bg: rgba(30, 41, 59, .5);
  --th-color: #cbd5e1;
  --glass: rgba(30, 41, 59, .8);
  --glass-border: rgba(51, 65, 85, .5);
  --btn-glow: rgba(20, 184, 166, .2);
  --row-hover: rgba(30, 41, 59, .3);
  --hover: #1e293b;             /* nav/ghost hover fill */
  /* shape */
  --r: 12px;          /* rounded-xl — links, buttons, inputs */
  --r-lg: 16px;       /* rounded-2xl — cards */
  --r-sm: 8px;
  --sidebar-w: 256px;
  --topbar-h: 64px;
  --mono: "SFMono-Regular", "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
:root[data-theme="light"] {
  --bg: #f9fafb;
  --sidebar: #ffffff;
  --card: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #e5e7eb;
  --border-input: #e5e7eb;
  --text: #111827;
  --text-dim: #6b7280;
  --text-soft: #4b5563;
  --text-faint: #9ca3af;
  --accent: #0d9488;
  --accent-soft: #f0fdfa;
  --accent-soft-hover: #ccfbf1;
  --danger: #dc2626;  --danger-soft: #fee2e2;
  --ok: #059669;      --ok-soft: #d1fae5;
  --warn: #d97706;    --warn-soft: #fef3c7;
  --card-border: #f3f4f6;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, .04), 0 1px 2px rgba(0, 0, 0, .06);
  --th-bg: #f9fafb;
  --th-color: #6b7280;
  --glass: rgba(255, 255, 255, .8);
  --glass-border: rgba(229, 231, 235, .5);
  --btn-glow: rgba(20, 184, 166, .25);
  --row-hover: #f9fafb;
  --hover: #f3f4f6;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans); background: var(--bg); color: var(--text);
  font-size: 14px; -webkit-font-smoothing: antialiased;
}
/* Ambient mesh wash behind the content (target's .bg-mesh-gradient), same in both themes.
   Fixed + pointer-events:none; the opaque sidebar covers it, so it reads only in the content area. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(at 40% 20%, rgba(20, 184, 166, .12) 0px, transparent 50%),
    radial-gradient(at 80% 0%,  rgba(6, 182, 212, .08) 0px, transparent 50%),
    radial-gradient(at 0% 50%,  rgba(20, 184, 166, .08) 0px, transparent 50%);
}
#app { position: relative; z-index: 1; display: flex; height: 100vh; overflow: hidden; }
.ico { width: 20px; height: 20px; flex: 0 0 20px; }

/* ---------------- Sidebar ---------------- */
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: margin-left .3s cubic-bezier(.4,0,.2,1);
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }

.brand {
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  border-bottom: 1px solid var(--border);
}
.brand-logo { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 10px; object-fit: contain; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }

.search-box { position: relative; padding: 12px 12px 4px; }
.search-box .search-ico {
  position: absolute; left: 24px; top: 50%; transform: translateY(-40%);
  color: var(--text-dim); pointer-events: none; display: inline-flex;
}
.search-box .search-ico .ico { width: 16px; height: 16px; }
/* `input[type=text]` below shares this specificity, so qualify by type to keep the icon gutter. */
.search-box input[type="text"] {
  width: 100%; padding: 10px 14px 10px 40px; font-size: 14px;
  border: 1px solid var(--border-input); border-radius: var(--r);
  background: var(--surface); color: var(--text); outline: none;
  transition: all .2s cubic-bezier(.4,0,.2,1);
}
.search-box input::placeholder { color: var(--text-dim); }
.search-box input[type="text"]:focus { border-color: var(--accent-1); box-shadow: 0 0 0 2px var(--ring); }

#nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
#nav::-webkit-scrollbar, .hex-scroll::-webkit-scrollbar, #tool-view::-webkit-scrollbar,
textarea::-webkit-scrollbar, .diff-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
#nav::-webkit-scrollbar-thumb, .hex-scroll::-webkit-scrollbar-thumb, #tool-view::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb, .diff-wrap::-webkit-scrollbar-thumb {
  background: rgba(156,163,175,.5); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box;
}
#nav::-webkit-scrollbar-thumb:hover, .hex-scroll::-webkit-scrollbar-thumb:hover { background: rgba(209,213,219,.7); background-clip: padding-box; }

/* Two-level nav.
   Level 1 = 首页 + category headers — identical box/typography so they align and read as peers.
   Level 2 = tool links — indented and lighter, so a child never outweighs its parent. */
.nav-cat { margin-bottom: 4px; }
.nav-item,
.nav-cat-title {
  display: flex; align-items: center; gap: 12px; overflow: hidden;
  padding: 10px 14px 10px 17px; margin-bottom: 4px;
  border-radius: var(--r); cursor: pointer; user-select: none;
  font-size: 14px; font-weight: 600; color: var(--text-soft);
  text-transform: none; letter-spacing: normal;
  transition: all .2s cubic-bezier(.4,0,.2,1);
}
.nav-item > span,
.nav-cat-title > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .ico,
.nav-cat-title .ico { width: 20px; height: 20px; flex: 0 0 20px; color: currentColor; }
.nav-item:hover,
.nav-cat-title:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.active:hover { background: var(--accent-soft-hover); }
/* a collapsed category whose tool is active still signals where you are */
.nav-cat-title.has-active { color: var(--accent); }

.nav-cat-title .count-badge { margin-left: auto; }
.nav-cat-title .chev { flex: 0 0 auto; font-size: 10px; transition: transform .2s; opacity: .8; }
.nav-cat.collapsed .chev { transform: rotate(-90deg); }
.nav-cat.collapsed .nav-items { display: none; }
.nav-items { display: flex; flex-direction: column; padding-bottom: 4px; }

/* Level 2 — indented under the parent label, lighter weight and slightly smaller. */
.nav-cat .nav-item {
  padding: 8px 14px 8px 33px; margin-bottom: 2px;
  font-size: 13.5px; font-weight: 500; color: var(--text-dim);
}
.nav-cat .nav-item .ico { width: 18px; height: 18px; flex: 0 0 18px; }
.nav-cat .nav-item:hover { color: var(--text); }
.nav-cat .nav-item.active { color: var(--accent); font-weight: 600; }

.sidebar-bottom { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; }
.bottom-row .bottom-ico { display: inline-flex; }
#theme-row .bottom-ico { color: var(--warn); }

/* ---------------- Main ---------------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
/* glass: translucent + blurred, like the target's sticky header */
#topbar {
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
  background: var(--glass); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--glass-border);
}
#topbar h1 { font-size: 16px; margin: 0; font-weight: 500; color: var(--text); }
#menu-toggle {
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  width: 38px; height: 38px; border-radius: var(--r); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .2s cubic-bezier(.4,0,.2,1);
}
#menu-toggle:hover { background: var(--hover); color: var(--text); }
#tool-view { flex: 1; overflow: auto; padding: 32px; }

/* ---------------- Home ---------------- */
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.home-cat-title {
  margin: 32px 0 12px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint);
  display: flex; align-items: center; gap: 8px;
}
.home-cat-title .ico { width: 16px; height: 16px; color: var(--accent); }
.home-card {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--r-lg);
  box-shadow: var(--card-shadow); padding: 16px 18px; cursor: pointer;
  transition: all .3s cubic-bezier(.4,0,.2,1);
}
.home-card:hover { border-color: var(--accent-1); transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(20,184,166,.15), 0 4px 6px -4px rgba(0,0,0,.2); }
.home-card .hc-name { font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.home-card .hc-name .ico { color: var(--accent); }
.home-card .hc-desc { font-size: 12px; color: var(--text-dim); line-height: 1.6; }
.home-hero { margin-bottom: 4px; }
.home-hero h2 { font-size: 20px; font-weight: 600; margin: 0 0 6px; }
.home-hero p { color: var(--text-dim); margin: 0; font-size: 14px; }

/* ---------------- Tool layout ---------------- */
.tool { display: flex; flex-direction: column; gap: 16px; height: 100%; }
.tool-desc { color: var(--text-dim); font-size: 14px; line-height: 1.6; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; flex: 1; min-height: 280px; }
.panes.single { grid-template-columns: 1fr; }
.pane { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.pane-label { font-size: 14px; color: var(--text-soft); font-weight: 500; display: flex; align-items: center; gap: 8px; }

/* HTML 渲染: the preview frame is sized in px by JS (panel height, or the full
   document height when 适应内容高度 is on), so the tool grows past the viewport
   and #tool-view scrolls — instead of the old fixed 260px box. */
.html-preview { height: auto; }
.html-preview .panes { flex: none; align-items: start; min-height: 0; }
.html-preview .pane { min-height: 0; }
/* Keep the editor in view while scrolling a long preview. */
.html-preview .panes:not(.single) .pane:first-child { position: sticky; top: 0; }
.preview-frame {
  display: block; width: 100%; flex: none; min-height: 320px;
  border: 1px solid var(--border-input); border-radius: var(--r);
  background: #fff;
}
.html-preview textarea { flex: none; }

textarea, .code-area {
  width: 100%; flex: 1; min-height: 220px; resize: vertical;
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  padding: 12px 16px; border: 1px solid var(--border-input); border-radius: var(--r);
  background: var(--surface); color: var(--text); outline: none; tab-size: 2;
  transition: all .2s cubic-bezier(.4,0,.2,1);
}
textarea::placeholder { color: var(--text-dim); }
textarea:focus { border-color: var(--accent-1); box-shadow: 0 0 0 2px var(--ring); }
textarea[readonly] { background: var(--th-bg); }

input[type="text"], input[type="number"], input[type="password"], input[type="datetime-local"], select {
  padding: 10px 16px; font-size: 14px;
  border: 1px solid var(--border-input); border-radius: var(--r);
  background: var(--surface); color: var(--text); outline: none; font-family: inherit;
  transition: all .2s cubic-bezier(.4,0,.2,1);
}
input::placeholder { color: var(--text-dim); }
input[type="text"]:focus, input[type="number"]:focus, input[type="password"]:focus, select:focus {
  border-color: var(--accent-1); box-shadow: 0 0 0 2px var(--ring);
}
label.inline { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-soft); cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent-1); width: 16px; height: 16px; }

button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--r); border: 1px solid var(--border-input);
  background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 500; font-family: inherit; cursor: pointer;
  transition: all .2s cubic-bezier(0,0,.2,1);
}
button.btn:hover { background: var(--surface-hover); border-color: #64748b; }
button.btn:active { transform: scale(.98); }
button.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
button.btn.primary {
  background: linear-gradient(to right, var(--accent-1), var(--accent-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 6px -1px var(--btn-glow), 0 2px 4px -2px var(--btn-glow);
}
button.btn.primary:hover {
  background: linear-gradient(to right, var(--accent-1h), var(--accent-2h));
  box-shadow: 0 10px 15px -3px var(--btn-glow), 0 4px 6px -4px var(--btn-glow);
}
button.btn.ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
button.btn.ghost:hover { background: var(--hover); color: var(--text); }
button.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.msg { font-size: 13px; padding: 2px 0; min-height: 18px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

.field-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.result-box {
  font-family: var(--mono); font-size: 13px; background: var(--card);
  border: 1px solid var(--card-border); border-radius: var(--r-lg);
  box-shadow: var(--card-shadow); padding: 16px 20px;
  white-space: pre-wrap; word-break: break-all; overflow: auto;
}
table.kv { border-collapse: collapse; width: 100%; font-size: 14px; }
table.kv th, table.kv td {
  padding: 12px 16px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--border);
}
table.kv th { background: var(--th-bg); color: var(--th-color); font-weight: 500; border-bottom: 1px solid var(--border-strong); }
table.kv td { color: var(--text-soft); }
table.kv tr:last-child td { border-bottom: 0; }
table.kv tbody tr { transition: background-color .15s cubic-bezier(.4,0,.2,1); }
table.kv tbody tr:hover { background: var(--row-hover); }
table.kv td.mono, table.kv th.mono { font-family: var(--mono); word-break: break-all; }

/* ---------------- Diff ---------------- */
.diff-wrap {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  border: 1px solid var(--card-border); border-radius: var(--r-lg);
  box-shadow: var(--card-shadow); overflow: auto; background: var(--card);
}
.diff-col { min-width: 0; }
.diff-line { display: flex; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.diff-line .ln {
  width: 48px; flex: 0 0 48px; text-align: right; padding-right: 10px;
  color: var(--text-faint); user-select: none; background: var(--th-bg);
}
.diff-line .txt { padding: 0 12px; flex: 1; white-space: pre-wrap; word-break: break-all; }
.diff-line.add { background: rgba(52,211,153,.14); }
.diff-line.del { background: rgba(248,113,113,.14); }
.diff-line.mod { background: rgba(251,191,36,.13); }
.diff-line.empty { background: var(--th-bg); }
.diff-inline-add { background: rgba(52,211,153,.4); border-radius: 3px; }
.diff-inline-del { background: rgba(248,113,113,.4); border-radius: 3px; }
.diff-stats { display: flex; gap: 20px; font-size: 14px; align-items: center; }
.diff-stats .add { color: var(--ok); } .diff-stats .del { color: var(--danger); }

/* ---------------- Hex / Binary compare ---------------- */
.hex-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.hex-file-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hex-file-name { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.hex-legend { display: flex; gap: 16px; font-size: 12px; align-items: center; color: var(--text-dim); }
.hex-legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.hex-view { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hex-view.single { grid-template-columns: 1fr; }
.hex-panel {
  border: 1px solid var(--card-border); border-radius: var(--r-lg);
  box-shadow: var(--card-shadow); overflow: hidden; background: var(--card);
  display: flex; flex-direction: column; min-height: 0;
}
.hex-panel-head {
  padding: 12px 16px; font-family: var(--mono); font-size: 12px;
  background: var(--th-bg); border-bottom: 1px solid var(--border-strong);
  display: flex; justify-content: space-between; gap: 12px; color: var(--text-soft);
}
.hex-scroll { overflow: auto; max-height: 62vh; }
.hex-table { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; white-space: pre; }
.hex-row { display: flex; }
.hex-row:hover { background: rgba(45,212,191,.05); }
.hex-off { color: var(--accent); padding: 0 14px; user-select: none; }
.hex-bytes { padding: 0 10px; letter-spacing: .5px; }
.hex-bytes .b, .hex-ascii .b { padding: 0 1px; border-radius: 2px; }
.hex-bytes .b.editable, .hex-ascii .b.editable { cursor: text; }
.hex-ascii { padding: 0 14px; color: var(--text-dim); border-left: 1px solid var(--border); }
.byte-diff { background: rgba(248,113,113,.35); color: var(--text); }
.byte-add { background: rgba(52,211,153,.3); }
.byte-mod { background: rgba(251,191,36,.38); color: var(--text); }
.byte-sel { outline: 2px solid var(--accent); outline-offset: -1px; border-radius: 3px; }

/* ---------------- misc ---------------- */
.color-swatch { width: 48px; height: 38px; border-radius: var(--r); border: 1px solid var(--border-strong); display: inline-block; vertical-align: middle; }
.qr-out { display: flex; justify-content: center; padding: 20px; background: #fff; border-radius: var(--r-lg); border: 1px solid var(--card-border); box-shadow: var(--card-shadow); }
.hidden { display: none !important; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 9999px;
  background: var(--accent-soft); border: 0; color: var(--accent);
}
.count-badge { font-size: 12px; color: var(--text-faint); font-weight: 500; }
.preview-frame { width: 100%; min-height: 320px; border: 1px solid var(--card-border); border-radius: var(--r-lg); box-shadow: var(--card-shadow); background: #fff; }
mark { background: rgba(251,191,36,.4); color: var(--text); border-radius: 3px; padding: 0 2px; }

@media (max-width: 900px) {
  #sidebar { position: absolute; z-index: 40; height: 100%; box-shadow: 8px 0 32px rgba(0,0,0,.5); }
  .panes { grid-template-columns: 1fr; }
  .hex-view { grid-template-columns: 1fr; }
  #tool-view { padding: 20px; }
}
