/* =============================================================
   Chart Template Editor — tool-specific styles
   Built on the shared design system (styles.css); uses its CSS
   variables so the tool follows the site's light/dark theme.
   All rules are scoped under .cte.
   ============================================================= */

/* Theme-mode templates (no colour-style part): the editor stays fully
   available — the explanatory note below shows only for these templates. */
#editor:not(.theme-mode) #themeNote { display: none; }
.cte .theme-note {
  display: flex; gap: 10px; align-items: flex-start;
  background: color-mix(in srgb, var(--brand) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 38%, var(--border));
  border-radius: 12px; padding: 12px 15px; margin: 0 0 22px;
  font-size: 13px; color: var(--text); line-height: 1.55;
}
.cte .theme-note::before { content: "🎨"; font-size: 15px; line-height: 1.4; flex: 0 0 auto; }
.cte .theme-note p { margin: 0; max-width: 84ch; }

/* >6 colours in theme mode: only the first 6 apply reliably. */
.cte .theme-warn {
  display: flex; gap: 10px; align-items: flex-start;
  background: color-mix(in srgb, var(--office-powerpoint) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--office-powerpoint) 45%, var(--border));
  border-radius: 12px; padding: 11px 15px; margin: 12px 0 0;
  font-size: 13px; color: var(--text); line-height: 1.55;
}
.cte .theme-warn.hidden { display: none; }
.cte .theme-warn::before { content: "⚠️"; font-size: 14px; line-height: 1.45; flex: 0 0 auto; }
.cte .theme-warn p { margin: 0; max-width: 84ch; }

.cte .card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 20px;
}
.cte .section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-soft); font-weight: 600; margin: 26px 2px 12px;
}
.cte .section-title:first-child { margin-top: 0; }
.cte code {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px; font-size: .9em;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

/* ---- Drop zone ---- */
.cte .drop {
  display: block; width: 100%;
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 52px 24px; text-align: center; cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
  background: var(--bg-soft);
}
.cte .drop:hover, .cte .drop.over { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--bg-soft)); }
.cte .drop.over { transform: translateY(-1px); }
.cte .drop-icon { color: var(--text-soft); margin-bottom: 12px; }
.cte .drop:hover .drop-icon, .cte .drop.over .drop-icon { color: var(--brand); }
.cte .drop-main { font-size: 16px; color: var(--text); }
.cte .drop-sub { margin-top: 6px; color: var(--text-soft); font-size: 13px; }
.cte .drop strong { color: var(--brand); }
.cte .drop input { display: none; }
.cte .filename { margin-top: 14px; color: var(--text); font-size: 13px; word-break: break-all; }

/* ---- Template gallery ---- */
/* Toggle bar (revealing the gallery) + the chosen-template preview */
.cte .tmpl-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 16px; }
.cte .tmpl-toggle { display: inline-flex; align-items: center; gap: 8px; }
.cte .tmpl-toggle::after { content: "▾"; font-size: 11px; color: var(--text-soft); transition: transform .15s ease; }
.cte .tmpl-toggle.open::after { transform: rotate(180deg); }
.cte .tmpl-selected {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg-soft);
}
.cte .tmpl-selected .tmpl-thumb { width: 56px; height: 38px; }
.cte .tmpl-selected .tmpl-thumb.gen { padding: 4px; }
.cte .tmpl-sel-name { font-size: 13px; color: var(--text); font-weight: 500; }

.cte .tmpl-wrap { margin-top: 18px; }
.cte .tmpl-head { font-size: 13px; color: var(--text-soft); margin-bottom: 10px; }
.cte .tmpl-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.cte .tmpl-card {
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg-soft);
  padding: 8px; cursor: pointer; transition: border-color .15s ease, background .15s ease; text-align: center;
}
.cte .tmpl-card:hover { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--bg-soft)); }
.cte .tmpl-thumb {
  width: 100%; height: 96px; object-fit: contain; background: #fff;
  border-radius: 6px; border: 1px solid var(--border); display: block;
}
.cte .tmpl-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--text-soft); font-size: 12px; background: var(--bg); }
.cte .tmpl-thumb.gen { display: flex; align-items: center; justify-content: center; padding: 6px; }
.cte .tmpl-thumb.gen svg { width: 100%; height: 100%; }
.cte .tmpl-name { margin-top: 8px; font-size: 12px; color: var(--text); word-break: break-word; line-height: 1.3; }

/* ---- Colour rows ---- */
.cte .row {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg-soft); margin-bottom: 10px;
}
.cte .idx { width: 24px; text-align: center; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.cte select, .cte .hex, .cte input[type=number], .cte input[type=text] {
  font: inherit; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 8px;
}
/* The shared design system sets a global `select,input { width:100% }` for
   .field forms. The editor's inline controls (the RGB/Theme kind picker, the
   element-row dropdowns, transform-type pickers) must size to content instead,
   or they fill the row and push the swatch + buttons into overflow. */
.cte select { width: auto; max-width: 100%; }
.cte select:focus, .cte .hex:focus, .cte input[type=number]:focus, .cte input[type=text]:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
}
.cte .kind { flex: 0 0 auto; }
.cte .control { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }

/* custom theme dropdown with colour thumbnails */
.cte .cdd { position: relative; flex: 1; min-width: 0; }
.cte .cdd-btn {
  width: 100%; display: flex; align-items: center; gap: 8px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 8px; cursor: pointer; font: inherit; text-align: left;
}
.cte .cdd-btn:hover { border-color: var(--brand); }
.cte .cdd-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cte .cdd-caret { color: var(--text-soft); font-size: 12px; flex: 0 0 auto; }
.cte .cdd-menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 9px; padding: 6px;
  box-shadow: var(--shadow-lg); max-height: 300px; overflow: auto;
}
.cte .cdd-opt { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px; cursor: pointer; }
.cte .cdd-opt:hover { background: var(--bg-soft); }
.cte .cdd-opt.sel { background: color-mix(in srgb, var(--brand) 14%, transparent); }
.cte .cdd-opt .cdd-name { font-size: 14px; }
.cte .cdd-sw { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(0,0,0,.18); flex: 0 0 auto; }
.cte .swatch {
  width: 42px; height: 42px; border-radius: 8px; border: 1px solid var(--border);
  padding: 0; cursor: pointer; background: none; flex: 0 0 auto;
}
.cte .swatch::-webkit-color-swatch-wrapper { padding: 3px; }
.cte .swatch::-webkit-color-swatch { border: none; border-radius: 6px; }
.cte .swatch-ro { width: 42px; height: 42px; border-radius: 8px; border: 1px solid var(--border); flex: 0 0 auto; }
.cte .hex { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; width: 104px; text-transform: uppercase; }
.cte .mini {
  background: transparent; border: 1px solid var(--border); color: var(--text-soft);
  width: 30px; height: 30px; border-radius: 7px; cursor: pointer; font-size: 15px; line-height: 1; flex: 0 0 auto;
}
.cte .mini:hover { border-color: var(--brand); color: var(--text); }
.cte .mini.del:hover { border-color: var(--office-powerpoint); color: var(--office-powerpoint); }

/* ---- Variations ---- */
.cte .variation { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-soft); padding: 12px 12px 8px; margin-bottom: 10px; }
.cte .variation.locked { border-style: dashed; opacity: .9; }
.cte .vhead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cte .vtitle { font-weight: 600; font-size: 14px; }
.cte .vlock { font-size: 12px; color: var(--text-soft); }
.cte .vspacer { flex: 1; }
.cte .tf { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cte .tf-type { flex: 0 0 auto; }
.cte .tf-val { width: 96px; text-align: right; }
.cte .pct { color: var(--text-soft); font-size: 13px; }
.cte .none { color: var(--text-soft); font-size: 13px; margin-bottom: 8px; }
.cte .addtf { font-size: 13px; background: transparent; border: 1px dashed var(--border); color: var(--text-soft); padding: 6px 10px; border-radius: 7px; cursor: pointer; }
.cte .addtf:hover { border-color: var(--brand); color: var(--text); }

/* ---- Buttons / actions ---- */
.cte .actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.cte .footerbar { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 18px; }
.cte .footerbar-sep { flex: 1; }
.cte button.primary {
  background: var(--brand-grad); color: #fff; border: none; padding: 11px 18px;
  border-radius: 9px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow);
  transition: box-shadow .15s ease, transform .12s ease;
}
.cte button.primary:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.cte button.ghost { background: var(--bg-elev); border: 1px solid var(--border); color: var(--text); padding: 11px 16px; border-radius: 9px; cursor: pointer; }
.cte button.ghost:hover { border-color: var(--brand); background: var(--bg-soft); }
.cte button:disabled { opacity: .4; cursor: not-allowed; }


/* ---- Chart elements ---- */
.cte .elem-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.cte .elem-label { width: 130px; flex: 0 0 auto; font-size: 14px; }
.cte .elem-row select { min-width: 150px; }
.cte .elem-cur { color: var(--text-soft); font-size: 12px; }
.cte .elem-check { display: flex; align-items: flex-start; gap: 9px; margin: 14px 2px 0; font-size: 14px; color: var(--text); cursor: pointer; }
.cte .elem-check input { width: 16px; height: 16px; margin-top: 1px; flex: 0 0 auto; }
.cte .tf-fmt {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-soft); margin-bottom: 8px;
}
.cte .tf-en { display: flex; align-items: center; gap: 8px; width: 190px; flex: 0 0 auto; font-size: 14px; cursor: pointer; }
.cte .tf-en input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.cte .tf-font { flex: 1; min-width: 120px; }
.cte .tf-size { width: 70px; }
.cte .tf-fmt input:disabled, .cte .tf-fmt select:disabled { opacity: .45; }
.cte .tf-unit { color: var(--text-soft); font-size: 13px; margin-left: -4px; }

/* ---- Help / hints / messages ---- */
.cte .hint { color: var(--text-soft); font-size: 13px; margin: 12px 2px 0; }
.cte details.help { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-soft); padding: 0 14px; margin: 12px 0 4px; }
.cte details.help summary {
  cursor: pointer; padding: 11px 0; color: var(--brand); font-size: 13px; font-weight: 600;
  list-style: none; user-select: none;
}
.cte details.help summary::-webkit-details-marker { display: none; }
.cte details.help summary::before { content: "\25B8\00a0\00a0"; display: inline-block; transition: transform .15s; }
.cte details.help[open] summary::before { transform: rotate(90deg); }
.cte details.help[open] summary { border-bottom: 1px solid var(--border); }
.cte details.help .body { font-size: 13px; color: var(--text-soft); padding: 6px 0 14px; }
.cte details.help .body p { margin: 8px 0; }
.cte details.help .body ul { margin: 8px 0; padding-left: 20px; }
.cte details.help .body li { margin: 3px 0; }
.cte details.help .body strong { color: var(--text); }
.cte details.help .body em { color: var(--text); font-style: normal; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.cte .msg { margin-top: 14px; font-size: 14px; min-height: 18px; }
.cte .msg.err { color: var(--office-powerpoint); }
.cte .msg.ok { color: var(--office-excel); }
.cte .cte-caption { color: var(--text-soft); font-size: 12px; text-align: center; margin-top: 8px; }
