/* =========================================================================
   Vega Theme Studio — clean Material-style UI, light-blue accent.
   ========================================================================= */

:root {
  --accent: #1a73e8;
  --accent-hover: #1666c7;
  --accent-soft: rgba(26, 115, 232, 0.10);
  --accent-ink: #ffffff;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --line: #e6e8eb;
  --line-strong: #d4d7dc;
  --ink: #1f2328;
  --ink-2: #3c4149;
  --muted: #6b7280;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-2: 0 1px 2px rgba(16, 24, 40, 0.06), 0 10px 28px -14px rgba(16, 24, 40, 0.22);
  --shadow-modal: 0 24px 60px -20px rgba(16, 24, 40, 0.35);

  --font-ui: "IBM Plex Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --sidebar-w: 340px;
}

[data-theme="dark"] {
  --accent: #5b9bf3;
  --accent-hover: #7cb0f6;
  --accent-soft: rgba(91, 155, 243, 0.16);
  --accent-ink: #0b1220;

  --bg: #111315;
  --surface: #1b1d20;
  --surface-2: #23262a;
  --line: #2b2e33;
  --line-strong: #3a3e44;
  --ink: #e8eaed;
  --ink-2: #c2c6cd;
  --muted: #8b9098;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 32px -18px rgba(0, 0, 0, 0.7);
  --shadow-modal: 0 30px 70px -25px rgba(0, 0, 0, 0.75);
}

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

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(1200px 400px at 80% -180px, var(--accent-soft), transparent 70%);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  overflow: hidden;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* ------------------------------------------------------------- top bar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  flex: none; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-title { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; line-height: 1; }
.brand-title em { font-style: normal; color: var(--accent); }
.brand-sub {
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
@media (max-width: 860px) { .brand-sub { display: none; } }

.top-actions { display: flex; align-items: center; gap: 9px; }
.action-divider { width: 1px; height: 24px; background: var(--line-strong); margin: 0 2px; }

.btn {
  font-family: var(--font-ui); font-size: 13px; font-weight: 600;
  padding: 9px 15px; border-radius: var(--r-sm); border: 1px solid transparent;
  cursor: pointer; transition: transform .1s ease, background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-accent { background: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 6px -1px var(--accent-soft); }
.btn-accent:hover { background: var(--accent-hover); }

.icon-btn {
  width: 38px; height: 38px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); cursor: pointer; font-size: 16px;
  display: grid; place-items: center; transition: border-color .15s, background .15s, color .15s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
#site-toggle .ic-moon { display: none; }
[data-theme="dark"] #site-toggle .ic-sun { display: none; }
[data-theme="dark"] #site-toggle .ic-moon { display: block; }

/* --------------------------------------------------------------- body --- */
.body { display: flex; flex: 1; min-height: 0; }

/* ------------------------------------------------------------ sidebar --- */
.sidebar {
  width: var(--sidebar-w); flex: none;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column;
}
.sidebar-section { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sticky-search { position: sticky; top: 0; z-index: 5; background: var(--surface); }
.sb-title {
  margin: 0 0 12px; font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
}

.presets { display: flex; flex-wrap: wrap; gap: 7px; }
.preset-chip {
  font-family: var(--font-ui); font-size: 12px; font-weight: 500;
  padding: 6px 11px; border-radius: 100px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  transition: all .14s ease;
}
.preset-chip:hover { border-color: var(--accent); color: var(--accent); }
.preset-chip.active {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}

.search-wrap { position: relative; display: flex; align-items: center; }
.search-ic { position: absolute; left: 11px; color: var(--muted); font-size: 15px; pointer-events: none; }
#search {
  width: 100%; padding: 9px 12px 9px 32px; font-family: var(--font-ui); font-size: 13px;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink);
}
#search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.hint { margin: 9px 2px 0; font-size: 11px; color: var(--muted); line-height: 1.4; }

.groups { flex: 1; }

/* groups / accordion */
.group { border-bottom: 1px solid var(--line); }
.group-head {
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: 14px 18px; background: none; border: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 13.5px; font-weight: 600; color: var(--ink);
  text-align: left;
}
.group-head:hover { background: var(--surface-2); }
.group-icon {
  width: 24px; height: 24px; flex: none; display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 13px; color: var(--accent);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface);
}
.group-name { flex: 1; }
.group-count {
  font-family: var(--font-mono); font-size: 10px; color: var(--accent-ink);
  background: var(--accent); min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 100px; display: grid; place-items: center;
}
.group-count:empty { display: none; }
.group-caret { color: var(--muted); transition: transform .2s ease; font-size: 16px; }
.group.open .group-caret { transform: rotate(90deg); }

.group-body { display: none; padding: 4px 18px 16px; }
.group.open .group-body { display: block; }

/* control rows */
.ctrl-row { padding: 9px 0; border-top: 1px solid var(--line); }
.ctrl-row:first-child { border-top: none; }
.ctrl-head { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; }
.ctrl-label { font-size: 12.5px; color: var(--muted); transition: color .15s; }
.ctrl-row.enabled .ctrl-label { color: var(--ink); font-weight: 500; }

/* enable switch */
.enable-switch { position: relative; width: 30px; height: 17px; flex: none; cursor: pointer; }
.enable-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.enable-track { position: absolute; inset: 0; border-radius: 100px; background: var(--line-strong); transition: background .18s; }
.enable-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.enable-switch input:checked + .enable-track { background: var(--accent); }
.enable-switch input:checked + .enable-track::after { transform: translateX(13px); }

/* control inputs (dimmed until enabled) */
.ctrl-input { display: flex; align-items: center; gap: 8px; opacity: .42; transition: opacity .15s; }
.ctrl-row.enabled .ctrl-input { opacity: 1; }

.c-color { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: none; cursor: pointer; }
.c-color::-webkit-color-swatch-wrapper { padding: 2px; }
.c-color::-webkit-color-swatch { border: none; border-radius: 4px; }
.c-hex {
  flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 12px;
  padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--ink);
}
.c-none { width: 28px; height: 28px; flex: none; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 13px; }
.c-none.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.c-range { flex: 1; min-width: 0; accent-color: var(--accent); height: 4px; }
.c-num { width: 58px; flex: none; font-family: var(--font-mono); font-size: 12px; padding: 6px 6px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink); text-align: right; }

.c-select { flex: 1; min-width: 0; font-family: var(--font-ui); font-size: 12.5px; padding: 7px 8px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink); cursor: pointer; }

.c-switch { position: relative; width: 38px; height: 21px; cursor: pointer; }
.c-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.c-switch-track { position: absolute; inset: 0; border-radius: 100px; background: var(--line-strong); transition: background .18s; }
.c-switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.c-switch input:checked + .c-switch-track { background: var(--accent); }
.c-switch input:checked + .c-switch-track::after { transform: translateX(17px); }

.c-palette { display: flex; flex-wrap: wrap; gap: 6px; }
.pal-swatch { position: relative; }
.pal-swatch input { width: 30px; height: 28px; padding: 0; border: 1px solid var(--line-strong); border-radius: var(--r-sm); cursor: pointer; background: none; }
.pal-swatch input::-webkit-color-swatch-wrapper { padding: 2px; }
.pal-swatch input::-webkit-color-swatch { border: none; border-radius: 4px; }
.pal-rm { position: absolute; top: -6px; right: -6px; width: 15px; height: 15px; border-radius: 50%; border: none; background: var(--ink); color: var(--surface); font-size: 10px; line-height: 1; cursor: pointer; display: none; place-items: center; }
.pal-swatch:hover .pal-rm { display: grid; }
.pal-add { width: 30px; height: 28px; border: 1px dashed var(--line-strong); border-radius: var(--r-sm); background: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.pal-add:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------- main --- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.tabs { display: flex; gap: 2px; padding: 12px 22px 0; overflow-x: auto; border-bottom: 1px solid var(--line); flex: none; background: var(--surface); }
.tab {
  font-family: var(--font-ui); font-size: 13px; font-weight: 500; white-space: nowrap;
  padding: 9px 15px; border: none; background: none; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .14s, border-color .14s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* custom-spec panel */
.custom-panel { padding: 16px 22px 0; flex: none; }
.custom-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.custom-label { font-size: 12.5px; color: var(--muted); }
#custom-spec {
  width: 100%; min-height: 120px; resize: vertical; font-family: var(--font-mono); font-size: 12px; line-height: 1.5;
  padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); tab-size: 2;
}
#custom-spec:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.custom-msg { display: block; min-height: 16px; margin-top: 6px; font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.custom-msg.err { color: #d93025; }
.custom-msg.ok { color: var(--accent); }

.canvas { flex: 1; min-height: 0; padding: 28px; overflow: auto; display: flex; flex-direction: column; align-items: center; }
.chart-card {
  width: 100%; max-width: 900px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 26px;
  box-shadow: var(--shadow-2); position: relative; min-height: 360px;
  display: flex; align-items: center; justify-content: center;
}
.chart-render { width: 100%; }
.chart-loading, .chart-error { font-family: var(--font-mono); font-size: 12px; color: var(--muted); text-align: center; }
.chart-error code { color: #d93025; }
.canvas-foot { margin: 18px 0 0; font-size: 12px; color: var(--muted); max-width: 900px; }

#vg-tooltip-element { font-family: var(--font-mono) !important; font-size: 11px !important; }

/* --------------------------------------------------------------- modal --- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.modal.open { display: flex; }
.modal-card { width: 100%; max-width: 720px; max-height: 84vh; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-modal); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }

.export-tabs { display: flex; gap: 4px; padding: 12px 20px 0; }
.export-tab { font-family: var(--font-mono); font-size: 11.5px; padding: 7px 12px; cursor: pointer; border: 1px solid var(--line-strong); border-bottom: none; background: var(--surface-2); color: var(--muted); border-radius: var(--r-sm) var(--r-sm) 0 0; }
.export-tab.active { color: var(--accent); border-color: var(--line-strong); background: var(--surface); font-weight: 500; }
.export-pre { margin: 0; padding: 18px 20px; overflow: auto; flex: 1; background: var(--surface-2); border-top: 1px solid var(--line); }
.export-pre code { font-family: var(--font-mono); font-size: 12px; line-height: 1.55; white-space: pre; color: var(--ink-2); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }

/* show-theme mode hides the export-only chrome */
.modal-card.mode-show .export-tabs,
.modal-card.mode-show #download-btn { display: none; }

/* import modal */
.import-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.import-help { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.import-help code { font-family: var(--font-mono); font-size: 11.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
#import-spec { width: 100%; min-height: 200px; resize: vertical; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--r-md); background: var(--surface-2); color: var(--ink); }
#import-spec:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.import-msg { min-height: 16px; font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.import-msg.err { color: #d93025; }
.import-msg.ok { color: var(--accent); }

/* scrollbars */
.sidebar::-webkit-scrollbar, .canvas::-webkit-scrollbar, .export-pre::-webkit-scrollbar, .tabs::-webkit-scrollbar { width: 9px; height: 9px; }
.sidebar::-webkit-scrollbar-thumb, .canvas::-webkit-scrollbar-thumb, .export-pre::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 100px; border: 2px solid var(--surface); }

@media (max-width: 880px) {
  body { overflow: auto; }
  .app { height: auto; }
  .body { flex-direction: column; }
  .sidebar { width: 100%; max-height: none; }
  .sticky-search { position: static; }
}
