:root {
  color-scheme: dark;
  --ink: #edf7f5;
  --muted: #8ba3ad;
  --accent: #29c2a3;
  --accent-soft: rgba(41, 194, 163, 0.13);
  --sidebar: #071a2d;
  --panel: #0b2237;
  --line: rgba(154, 190, 199, 0.14);
  --surface: #eaf0f1;
  --control: rgba(255, 255, 255, 0.055);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--sidebar);
  color: var(--ink);
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100%;
}

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 24px 22px 20px;
}

.brand-mark {
  position: relative;
  width: 39px;
  height: 39px;
  flex: 0 0 auto;
  border: 1px solid rgba(41, 194, 163, 0.45);
  border-radius: 11px;
  background: var(--accent-soft);
}

.brand-mark span {
  position: absolute;
  width: 7px;
  height: 7px;
  border: 2px solid var(--accent);
  border-radius: 2px;
}

.brand-mark span:nth-child(1) { left: 8px; top: 8px; }
.brand-mark span:nth-child(2) { right: 8px; top: 8px; }
.brand-mark span:nth-child(3) { left: 15px; bottom: 7px; }

.brand p, .brand h1 { margin: 0; }
.brand p {
  margin-bottom: 2px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.brand h1 { font-size: 1.05rem; font-weight: 650; }

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 16px 16px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--control);
}

.search:focus-within { border-color: rgba(41, 194, 163, 0.55); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 17px; color: var(--muted); fill: none; stroke: currentColor; stroke-width: 1.8; }
.search input { width: 100%; min-width: 0; height: 42px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 0.9rem; }
.search input::placeholder { color: #6f8993; }
kbd { display: inline-flex; min-width: 21px; height: 21px; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.12); border-radius: 5px; background: rgba(255,255,255,.055); color: #9db0b7; font: 0.72rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }

.chart-nav { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 16px; scrollbar-width: thin; scrollbar-color: #294355 transparent; }
.nav-item {
  display: grid;
  width: 100%;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 11px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.045); }
.nav-item.active { background: var(--accent-soft); }
.nav-index {
  display: flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}
.nav-item.active .nav-index { border-color: rgba(41,194,163,.5); background: rgba(41,194,163,.1); color: var(--accent); }
.nav-copy strong { display: block; color: #dce9e9; font-size: 0.88rem; font-weight: 600; line-height: 1.35; }
.nav-copy small { display: block; margin-top: 3px; color: #708b95; font-size: 0.75rem; line-height: 1.3; }
.nav-empty { padding: 28px 16px; color: var(--muted); font-size: .9rem; text-align: center; }

.shortcut-note { display: flex; justify-content: space-between; gap: 10px; padding: 13px 17px; border-top: 1px solid var(--line); color: #78909a; font-size: .72rem; }
.shortcut-note span { display: flex; align-items: center; gap: 4px; }

.main-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; background: var(--panel); }
.topbar { display: flex; height: 76px; flex: 0 0 auto; align-items: center; gap: 14px; padding: 0 22px; border-bottom: 1px solid var(--line); }
.title-block { min-width: 0; flex: 1; }
.title-block p, .title-block h2 { overflow: hidden; margin: 0; text-overflow: ellipsis; white-space: nowrap; }
.title-block p { margin-bottom: 3px; color: var(--accent); font-size: .72rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.title-block h2 { font-size: 1.05rem; font-weight: 620; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.chart-count { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }

.icon-button, .text-button, .fit-button, .zoom-value { border: 1px solid var(--line); border-radius: 8px; background: var(--control); cursor: pointer; }
.icon-button { display: inline-flex; width: 38px; height: 38px; align-items: center; justify-content: center; padding: 0; }
.icon-button:hover, .text-button:hover, .fit-button:hover, .zoom-value:hover { border-color: rgba(41,194,163,.4); background: var(--accent-soft); }
.icon-button:focus-visible, .text-button:focus-visible, .fit-button:focus-visible, .zoom-value:focus-visible, .nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-button svg, .text-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.menu-button, .sidebar-close { display: none; }

.viewer-wrap { display: flex; min-height: 0; flex: 1; flex-direction: column; padding: 12px; }
.viewer-toolbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; height: 48px; flex: 0 0 auto; padding: 0 4px 10px; }
.text-button { display: inline-flex; width: max-content; height: 36px; align-items: center; gap: 7px; padding: 0 12px; font-size: .82rem; }
.text-button:last-child { justify-self: end; }
.text-button:disabled { opacity: .35; cursor: default; }
.zoom-controls { display: flex; align-items: center; gap: 6px; }
.zoom-controls .icon-button { width: 34px; height: 34px; }
.zoom-value, .fit-button { height: 34px; padding: 0 10px; color: #cbdadc; font-size: .78rem; font-variant-numeric: tabular-nums; }
.zoom-value { width: 62px; }

.viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
  flex: 1;
  overflow: auto;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  background-color: var(--surface);
  background-image: radial-gradient(#b8c5c7 0.75px, transparent 0.75px);
  background-size: 18px 18px;
  cursor: grab;
  overscroll-behavior: contain;
}
.viewer.dragging { cursor: grabbing; user-select: none; }
.viewer:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.canvas { display: flex; width: max-content; min-width: 100%; min-height: 100%; align-items: flex-start; justify-content: center; padding: 42px; }
.canvas img { display: block; max-width: none; height: auto; filter: drop-shadow(0 12px 24px rgba(9, 30, 40, .14)); transition: opacity .18s ease; }
.canvas img.loading-image { opacity: 0; }
.loading { position: absolute; z-index: 2; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--surface); color: #50666c; font-size: .9rem; }
.loading span { width: 18px; height: 18px; border: 2px solid #b7c8ca; border-top-color: #148b77; border-radius: 50%; animation: spin .7s linear infinite; }
.loading[hidden] { display: none; }
@keyframes spin { to { transform: rotate(1turn); } }

.scrim { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(88vw, 320px); box-shadow: 18px 0 55px rgba(0,0,0,.35); transform: translateX(-102%); transition: transform .22s ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .scrim { position: fixed; z-index: 15; inset: 0; display: block; background: rgba(2,10,18,.68); opacity: 0; pointer-events: none; transition: opacity .22s ease; }
  body.sidebar-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-button, .sidebar-close { display: inline-flex; }
  .sidebar-close { margin-left: auto; }
  .main-panel { height: 100%; }
  .canvas { padding: 24px; }
}

@media (max-width: 560px) {
  .topbar { height: 68px; padding: 0 12px; }
  .top-actions .icon-button { display: none; }
  .viewer-wrap { padding: 8px; }
  .viewer-toolbar { grid-template-columns: 38px 1fr 38px; gap: 5px; }
  .text-button { width: 38px; padding: 0; justify-content: center; }
  .text-button span { display: none; }
  .text-button:last-child { justify-self: auto; }
  .zoom-controls { justify-content: center; }
  .zoom-controls .icon-button { display: none; }
  .canvas { padding: 16px; }
  .shortcut-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
