/* ── Theme ──────────────────────────────────────────────── */
:root {
  --primary:    #8b5cf6;
  --secondary:  #7c3aed;
  --grad:       linear-gradient(135deg, #8b5cf6, #7c3aed);
  --bg:         #0f0f14;
  --bg-card:    #1e1e28;
  --bg-surface: #18181f;
  --text:       #e8e8f0;
  --text-muted: #a0a0b8;
  --text-faint: #636380;
  --border:        rgba(255,255,255,.07);
  --border-medium: rgba(255,255,255,.12);
  --radius:    14px;
  --radius-sm:  8px;
  --font: system-ui, -apple-system, sans-serif;
  --panel-w: 340px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.6; }
a    { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; border: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── Header ─────────────────────────────────────────────── */
.site-header { background: rgba(15,15,20,.92); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.header-inner { max-width: 1280px; margin: 0 auto; padding: 0 20px; height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.logo { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.logo-icon { width: 32px; height: 32px; flex-shrink: 0; }
.logo-text { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.main-nav { display: flex; align-items: center; gap: 4px; }
.nav-link { padding: 6px 12px; border-radius: var(--radius-sm); font-size: .88rem; font-weight: 500; color: var(--text-muted); transition: color .15s, background .15s; }
.nav-link:hover, .nav-link.active { color: var(--text); background: rgba(255,255,255,.06); }
@media (max-width: 540px) { .main-nav { display: none; } }

/* ── Page layout ─────────────────────────────────────────── */
.page-wrap { max-width: 1280px; margin: 0 auto; padding: 22px 20px 80px; }
.ad-slot { background: var(--bg-surface); border: 1px dashed var(--border-medium); border-radius: var(--radius-sm); min-height: 90px; display: flex; align-items: center; justify-content: center; margin: 14px 0; color: var(--text-faint); font-size: .78rem; }

/* ── Hero ───────────────────────────────────────────────── */
.tool-hero { text-align: center; padding: 16px 0 22px; }
.tool-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 13px; border-radius: 20px; background: rgba(139,92,246,.12); color: var(--primary); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 12px; }
.tool-title { font-size: clamp(1.7rem,4vw,2.4rem); font-weight: 800; line-height: 1.2; margin-bottom: 10px; }
.gradient-title { background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.tool-subtitle { font-size: .97rem; color: var(--text-muted); max-width: 560px; margin: 0 auto; }

/* ── Builder layout ─────────────────────────────────────── */
.builder { display: flex; gap: 20px; align-items: flex-start; }

/* Left panel */
.config-panel { width: var(--panel-w); flex-shrink: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: sticky; top: 82px; max-height: calc(100vh - 100px); display: flex; flex-direction: column; }

/* Panel tabs */
.panel-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.panel-tab { flex: 1; padding: 12px 8px; text-align: center; font-size: .84rem; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: color .15s, background .15s; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.panel-tab.on { color: var(--primary); border-bottom-color: var(--primary); background: rgba(139,92,246,.05); }
.panel-tab:hover:not(.on) { color: var(--text); background: rgba(255,255,255,.04); }

/* Panel body */
.panel-body { overflow-y: auto; flex: 1; padding: 16px; }
.panel-body::-webkit-scrollbar { width: 5px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border-medium); border-radius: 3px; }

/* ── Section headings inside panel ─────────────────────── */
.sec-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); margin: 16px 0 8px; }
.sec-label:first-child { margin-top: 0; }

/* ── Chart type grid ────────────────────────────────────── */
.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.type-btn { padding: 10px 6px 8px; border-radius: 8px; background: var(--bg-surface); border: 2px solid var(--border); text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.type-btn:hover { border-color: var(--border-medium); background: rgba(255,255,255,.04); }
.type-btn.on { border-color: var(--primary); background: rgba(139,92,246,.08); }
.type-btn-icon { font-size: 1.3rem; line-height: 1; margin-bottom: 4px; }
.type-btn-name { font-size: .74rem; font-weight: 600; color: var(--text-muted); }
.type-btn.on .type-btn-name { color: var(--primary); }
.type-btn-hint { font-size: .65rem; color: var(--text-faint); margin-top: 1px; }

/* ── Data inputs ─────────────────────────────────────────── */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field-hint { font-size: .72rem; color: var(--text-faint); margin-top: 4px; }
.inp { width: 100%; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--border-medium); background: var(--bg-surface); color: var(--text); font-size: .87rem; transition: border-color .15s; }
.inp:focus { outline: none; border-color: var(--primary); }
.inp::placeholder { color: var(--text-faint); }
textarea.inp { resize: vertical; min-height: 68px; font-family: 'SF Mono','Cascadia Code',monospace; font-size: .82rem; line-height: 1.5; }

/* ── Dataset cards ──────────────────────────────────────── */
.dataset-list { display: flex; flex-direction: column; gap: 10px; }
.dataset-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 9px; padding: 12px; }
.ds-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.ds-color-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); flex-shrink: 0; cursor: pointer; }
.ds-label-inp { flex: 1; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text); font-size: .84rem; font-weight: 600; }
.ds-label-inp:focus { outline: none; border-color: var(--primary); }
.ds-remove { width: 22px; height: 22px; border-radius: 5px; background: rgba(248,113,113,.08); color: #f87171; font-size: .9rem; display: flex; align-items: center; justify-content: center; transition: background .15s; flex-shrink: 0; }
.ds-remove:hover { background: rgba(248,113,113,.18); }
.btn-add-ds { width: 100%; padding: 8px; border-radius: 7px; border: 1px dashed var(--border-medium); background: transparent; color: var(--text-muted); font-size: .83rem; font-weight: 600; transition: border-color .15s, color .15s, background .15s; margin-top: 4px; }
.btn-add-ds:hover { border-color: var(--primary); color: var(--primary); background: rgba(139,92,246,.05); }

/* ── Palette swatches ───────────────────────────────────── */
.palette-row { display: flex; gap: 8px; flex-wrap: wrap; }
.palette-chip { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }
.palette-swatches { display: flex; border-radius: 5px; overflow: hidden; border: 2px solid transparent; transition: border-color .15s; }
.palette-chip.on .palette-swatches { border-color: var(--primary); }
.swatch { width: 14px; height: 22px; }
.palette-chip-label { font-size: .68rem; color: var(--text-faint); }
.palette-chip.on .palette-chip-label { color: var(--primary); }

/* ── Toggle row ─────────────────────────────────────────── */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-size: .85rem; color: var(--text-muted); }
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track { position: absolute; inset: 0; border-radius: 10px; background: rgba(255,255,255,.1); cursor: pointer; transition: background .2s; }
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle-track::after { content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .2s; }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }

/* ── Aspect ratio chips ─────────────────────────────────── */
.ar-chips { display: flex; gap: 6px; }
.ar-chip { padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border-medium); background: var(--bg-surface); color: var(--text-muted); font-size: .81rem; font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s, color .15s; }
.ar-chip.on { border-color: var(--primary); background: rgba(139,92,246,.1); color: var(--primary); }

/* ── Right panel: preview ───────────────────────────────── */
.preview-panel { flex: 1; min-width: 0; }
.preview-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 14px; }
.preview-canvas-wrap { position: relative; }
.preview-canvas-wrap canvas { display: block; width: 100% !important; border-radius: 6px; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.preview-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.ar-row { display: flex; gap: 6px; }

/* ── Download section ───────────────────────────────────── */
.dl-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.dl-title { font-size: .9rem; font-weight: 700; margin-bottom: 12px; }
.dl-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.btn-dl { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px; border-radius: 9px; background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-muted); font-size: .78rem; font-weight: 600; transition: border-color .15s, background .15s, color .15s; }
.btn-dl:hover { border-color: var(--primary); background: rgba(139,92,246,.07); color: var(--primary); }
.btn-dl-icon { font-size: 1.4rem; }
.btn-dl-ext { font-size: .72rem; font-weight: 800; letter-spacing: .04em; }
.btn-dl-desc { font-size: .68rem; color: var(--text-faint); text-align: center; }

/* ── Error banner ───────────────────────────────────────── */
.error-banner { background: rgba(248,113,113,.08); border: 1px solid rgba(248,113,113,.25); border-radius: var(--radius-sm); padding: 10px 14px; font-size: .85rem; color: #f87171; margin-bottom: 12px; }

/* ── FAQ ──────────────────────────────────────────────────── */
.faq-section { margin-top: 40px; max-width: 760px; }
.faq-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 14px; }
.faq-item { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 7px; overflow: hidden; }
.faq-q { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; cursor: pointer; font-weight: 600; font-size: .9rem; user-select: none; }
.faq-q svg { width: 17px; height: 17px; color: var(--text-muted); transition: transform .2s; flex-shrink: 0; }
.faq-item.open .faq-q svg { transform: rotate(180deg); }
.faq-a { display: none; padding: 0 16px 14px; font-size: .86rem; color: var(--text-muted); line-height: 1.7; }
.faq-item.open .faq-a { display: block; }

/* ── Toast ──────────────────────────────────────────────── */
#toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(14px); background: #1e1430; color: #c4b5fd; border: 1px solid rgba(196,181,253,.2); padding: 10px 22px; border-radius: 24px; font-size: .87rem; font-weight: 600; pointer-events: none; opacity: 0; transition: opacity .25s, transform .25s; z-index: 999; white-space: nowrap; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 860px) {
  :root { --panel-w: 100%; }
  .builder { flex-direction: column; }
  .config-panel { width: 100%; position: static; max-height: none; }
  .dl-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .type-grid { grid-template-columns: repeat(3, 1fr); }
  .dl-grid   { grid-template-columns: repeat(2, 1fr); }
}
