/* =============================================================
   crypto-tools shared chrome
   Sidebar + top-bar + ⌘K palette. Load AFTER theme.css.

   Every accent color pulls from --ct-accent / --ct-accent-soft /
   --ct-accent-ghost, so per-tool palettes (body.theme-amber|cyan|red)
   automatically re-tint the active nav item, cmdk hover, and row
   hover without any per-theme selectors in this file.

   The ONE exception: palette pico backgrounds (.p-poly, .p-bybit,
   .p-hash, .p-bitget) are literal per-tool accents, because the
   palette shows every tool side-by-side regardless of current page.
   ============================================================= */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

/* Smooth cross-fade when navigating between tools. Chromium + Safari 18+
   animate; Firefox falls back to instant nav. The sidebar is identical
   across pages, so giving it its own transition name makes it render as
   a stable shared element — no visible repaint on the left column. */
@view-transition { navigation: auto; }
aside.ct-sidebar { view-transition-name: ct-sidebar; }

body {
  background: var(--ct-bg);
  color: var(--ct-text);
  font-family: var(--ct-font-body);
  display: grid;
  grid-template-columns: 56px 1fr;
  min-height: 100vh;
}
body.sidebar-open { grid-template-columns: 240px 1fr; }

/* ============ Sidebar ============ */
aside.ct-sidebar {
  background: #05050c;
  border-right: 1px solid var(--ct-border);
  display: flex;
  flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow: hidden;
  /* Pin line-height so the sidebar doesn't change row-height depending on
     the host tool's body rules (e.g. bybit-analyzer sets body { line-height: 1.4 }). */
  line-height: 1.2;
}
.ct-sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  height: 48px;
  border-bottom: 1px solid var(--ct-border);
  flex-shrink: 0;
}
.ct-sidebar .brand-mark {
  width: 26px; height: 26px; flex-shrink: 0;
  background: var(--ct-accent); color: var(--ct-accent-text);
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--ct-font-display); font-weight: 800; font-size: 14px;
}
.ct-sidebar .brand-name {
  font-family: var(--ct-font-display);
  font-weight: 800; font-size: 15px; letter-spacing: -0.5px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .15s;
  color: var(--ct-text);
}
body.sidebar-open .ct-sidebar .brand-name { opacity: 1; }

.ct-sidebar .nav-label {
  padding: 12px 16px 4px;
  font-family: var(--ct-font-mono);
  font-size: 9px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ct-text-dim);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .15s;
  min-height: 24px;
}
body.sidebar-open .ct-sidebar .nav-label { opacity: 1; }

.ct-sidebar nav a {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  text-decoration: none;
  color: var(--ct-text-muted);
  font-size: 13px;
  border-left: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s, background .15s;
}
.ct-sidebar nav a:hover { color: var(--ct-text); background: rgba(255,255,255,0.02); }
/* Active tool — matched by body[data-tool] → nav a[data-tool-id]. Keeps the
   sidebar purely server-rendered; no JS needed for active-state paint. */
body[data-tool="overview"]        .ct-sidebar nav a[data-tool-id="overview"],
body[data-tool="bybit-analyzer"]  .ct-sidebar nav a[data-tool-id="bybit-analyzer"],
body[data-tool="bybit-funding"]   .ct-sidebar nav a[data-tool-id="bybit-funding"],
body[data-tool="polytracker"]     .ct-sidebar nav a[data-tool-id="polytracker"],
body[data-tool="hashdivehelper"]  .ct-sidebar nav a[data-tool-id="hashdivehelper"],
body[data-tool="bitget-scamscan"] .ct-sidebar nav a[data-tool-id="bitget-scamscan"] {
  color: var(--ct-text);
  border-left-color: var(--ct-accent);
  background: var(--ct-accent-ghost);
}
.ct-sidebar nav a svg { width: 16px; height: 16px; stroke-width: 1.8; flex-shrink: 0; }
.ct-sidebar nav a .label {
  opacity: 0;
  transition: opacity .15s;
}
body.sidebar-open .ct-sidebar nav a .label { opacity: 1; }
.ct-sidebar nav a .kbd {
  font-family: var(--ct-font-mono);
  font-size: 10px;
  color: var(--ct-text-faint);
  padding: 1px 6px;
  border: 1px solid var(--ct-border-strong);
  border-radius: 3px;
  opacity: 0;
  transition: opacity .15s;
}
body.sidebar-open .ct-sidebar nav a .kbd { opacity: 1; }

.ct-sidebar .sidebar-toggle {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--ct-border);
  display: flex; align-items: center; gap: 12px;
  font-family: var(--ct-font-mono);
  font-size: 11px;
  color: var(--ct-text-dim);
  background: none; border: 0; cursor: pointer;
  white-space: nowrap;
}
.ct-sidebar .sidebar-toggle:hover { color: var(--ct-text); }
.ct-sidebar .sidebar-toggle svg { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.8; }
.ct-sidebar .sidebar-toggle .label { opacity: 0; transition: opacity .15s; }
body.sidebar-open .ct-sidebar .sidebar-toggle .label { opacity: 1; }
.ct-sidebar .sidebar-toggle kbd {
  font-family: var(--ct-font-mono); font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--ct-border-strong);
  border-radius: 3px;
  color: inherit;
}

/* ============ Main ============ */
main.ct-main { overflow-x: hidden; min-width: 0; }

/* ============ Top bar ============ */
.ct-topbar {
  position: sticky; top: 0; z-index: 20;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: rgba(8, 8, 16, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--ct-border);
  font-family: var(--ct-font-mono);
  font-size: 12px;
}
.ct-topbar .crumbs { color: var(--ct-text-dim); }
.ct-topbar .crumbs b {
  color: var(--ct-text);
  font-weight: 500;
  font-family: var(--ct-font-body);
  letter-spacing: -0.2px;
}
.ct-topbar .cmdk {
  display: inline-flex; align-items: center; gap: 10px;
  min-width: 280px;
  padding: 6px 12px;
  background: var(--ct-bg-input);
  border: 1px solid var(--ct-border-strong);
  border-radius: 6px;
  color: var(--ct-text-dim);
  cursor: pointer;
  transition: border-color .15s, color .15s;
  margin-left: auto;
}
.ct-topbar .cmdk:hover { border-color: var(--ct-accent); color: var(--ct-text); }
.ct-topbar .cmdk svg { width: 14px; height: 14px; stroke-width: 2; }
.ct-topbar .cmdk .placeholder { flex: 1; font-family: var(--ct-font-body); font-size: 13px; text-align: left; }
.ct-topbar .cmdk kbd {
  font-family: var(--ct-font-mono);
  font-size: 10px;
  padding: 1px 6px;
  border: 1px solid var(--ct-border-strong);
  border-radius: 3px;
  color: var(--ct-text-faint);
}

/* Generic mono button used for tool-specific top-bar actions */
.ct-topbar .btn-mono {
  font-family: var(--ct-font-mono); font-size: 11px;
  padding: 6px 12px; border-radius: 5px;
  background: var(--ct-bg-input); border: 1px solid var(--ct-border-strong);
  color: var(--ct-text-muted); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  transition: color .15s, border-color .15s, background .15s;
}
.ct-topbar .btn-mono:hover { color: var(--ct-text); border-color: var(--ct-accent); }
.ct-topbar .btn-mono.primary {
  background: var(--ct-accent); color: var(--ct-accent-text); border-color: var(--ct-accent);
}
.ct-topbar .btn-mono.primary:hover { background: var(--ct-accent-hover); border-color: var(--ct-accent-hover); color: var(--ct-accent-text); }

.ct-topbar .live {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ct-text-dim);
}
.ct-topbar .live .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ct-positive);
  box-shadow: 0 0 6px var(--ct-positive);
}

/* Mobile hamburger — hidden on desktop */
.ct-topbar .hamburger {
  display: none;
  background: transparent;
  border: 0;
  color: var(--ct-text);
  padding: 6px;
  cursor: pointer;
}
.ct-topbar .hamburger svg { width: 20px; height: 20px; stroke-width: 2; }

/* ============ ⌘K palette overlay ============ */
.ct-palette-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  z-index: 100;
}
.ct-palette-backdrop.open { display: flex; }
.ct-palette {
  width: 100%;
  max-width: 560px;
  background: var(--ct-bg-elevated);
  border: 1px solid var(--ct-border-strong);
  border-radius: 12px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.ct-palette-search {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--ct-border);
}
.ct-palette-search svg { width: 16px; height: 16px; color: var(--ct-text-dim); }
.ct-palette-search input {
  flex: 1; background: transparent; border: 0; outline: 0;
  color: var(--ct-text); font-size: 15px;
  font-family: var(--ct-font-body);
}
.ct-palette-search input::placeholder { color: var(--ct-text-dim); }
.ct-palette-search kbd {
  font-family: var(--ct-font-mono); font-size: 10px;
  padding: 3px 8px;
  border: 1px solid var(--ct-border-strong);
  border-radius: 4px;
  color: var(--ct-text-dim);
}
.ct-palette-body { overflow-y: auto; flex: 1; }
.ct-palette-section {
  font-family: var(--ct-font-mono);
  font-size: 10px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--ct-text-dim);
  padding: 12px 18px 4px;
}
.ct-palette-entry {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 18px;
  text-decoration: none; color: inherit; cursor: pointer;
}
.ct-palette-entry:hover,
.ct-palette-entry.is-selected { background: var(--ct-accent-ghost); }
.ct-palette-entry .pico {
  width: 24px; height: 24px;
  border-radius: 5px;
  background: var(--ct-accent-soft);
  color: var(--ct-accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ct-palette-entry .pico svg { width: 13px; height: 13px; stroke-width: 2; }
.ct-palette-entry .title { font-size: 13px; color: var(--ct-text); }
.ct-palette-entry .sub {
  font-family: var(--ct-font-mono); font-size: 11px;
  color: var(--ct-text-dim); margin-top: 2px;
}
.ct-palette-entry .hotkey {
  font-family: var(--ct-font-mono); font-size: 10px;
  padding: 2px 7px;
  border: 1px solid var(--ct-border-strong);
  border-radius: 4px;
  color: var(--ct-text-dim);
}

/* Per-tool pico tints — literal because the palette shows all tools
   at once regardless of current page. */
.ct-palette-entry .pico.p-poly   { background: rgba(124, 58, 237, 0.15); color: var(--ct-accent-poly); }
.ct-palette-entry .pico.p-bybit  { background: rgba(247, 166, 0,  0.15); color: var(--ct-accent-bybit); }
.ct-palette-entry .pico.p-hash   { background: rgba(6,   182, 212, 0.15); color: var(--ct-accent-hash); }
.ct-palette-entry .pico.p-bitget { background: rgba(239, 68,  68,  0.15); color: var(--ct-accent-bitget); }

.ct-palette-foot {
  display: flex; justify-content: space-between;
  padding: 10px 18px;
  border-top: 1px solid var(--ct-border);
  font-family: var(--ct-font-mono); font-size: 10px;
  color: var(--ct-text-dim);
  background: rgba(0, 0, 0, 0.25);
}
.ct-palette-foot kbd {
  display: inline-block;
  padding: 1px 6px; margin: 0 2px;
  border: 1px solid var(--ct-border-strong);
  border-radius: 3px;
  color: var(--ct-text-muted);
}

/* ============ Mobile ============ */
@media (max-width: 768px) {
  body,
  body.sidebar-open { grid-template-columns: 1fr; }

  aside.ct-sidebar {
    position: fixed; left: 0; top: 0;
    width: 260px; height: 100vh;
    transform: translateX(-100%);
    transition: transform .2s;
    z-index: 200;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.5);
  }
  body.sidebar-open aside.ct-sidebar { transform: translateX(0); }

  /* Labels always visible in mobile drawer — no collapsed state. */
  aside.ct-sidebar .brand-name,
  aside.ct-sidebar .nav-label,
  aside.ct-sidebar nav a .label,
  aside.ct-sidebar nav a .kbd { opacity: 1 !important; }
  aside.ct-sidebar .sidebar-toggle { display: none; }

  /* Backdrop for mobile drawer */
  body.sidebar-open::before {
    content: '';
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 150;
  }

  .ct-topbar .hamburger { display: inline-flex; align-items: center; justify-content: center; }

  .ct-topbar {
    height: 48px;
    padding: 0 12px;
    gap: 10px;
  }
  .ct-topbar .crumbs { font-size: 12px; }
  .ct-topbar .cmdk {
    min-width: 0;
    width: 36px; height: 32px;
    padding: 0;
    justify-content: center;
    margin-left: auto;
  }
  .ct-topbar .cmdk .placeholder,
  .ct-topbar .cmdk kbd { display: none; }
  .ct-topbar .live span:not(.dot) { display: none; }
  .ct-topbar .btn-mono { padding: 6px 10px; font-size: 10px; }
  .ct-topbar .btn-mono:not(.primary) { display: none; }

  /* Palette: fullscreen sheet on phone */
  .ct-palette-backdrop { padding-top: 0; align-items: stretch; }
  .ct-palette { max-width: 100%; border-radius: 0; height: 100vh; }
}
