/* ============ Consent modal + edit-mode builder ============ */

/* ---- Modal scaffold ---- */
.ap-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 20px;
  background: color-mix(in srgb, #0b0d18 70%, transparent);
  animation: ap-fade-in .2s var(--ap-ease) both;
}
.ap-modal {
  width: min(560px, 100%); max-height: 92vh; overflow: auto;
  background: var(--ap-surface); border-radius: var(--ap-radius-lg);
  box-shadow: var(--ap-shadow-lg); border: 1px solid var(--ap-border);
  animation: ap-pop .28s var(--ap-ease) both;
}
.ap-modal__banner { padding: 26px 28px 18px; color: #fff; background: var(--ap-grad); position: relative; overflow: hidden; }
.ap-modal__banner::after { content: ""; position: absolute; inset: 0; background: radial-gradient(120% 160% at 90% -10%, rgba(255,255,255,.3), transparent 60%); }
.ap-modal__brand { display: flex; align-items: center; justify-content: center; gap: 12px; position: relative; z-index: 1; }
.ap-modal__brand svg, .ap-modal__brand img { height: 34px; }
.ap-modal__brandname { font-family: var(--ap-font-head); font-weight: 800; font-size: 22px; letter-spacing: .02em; }
.ap-modal__title { margin: 16px 0 0; font-size: var(--ap-fs-xl); position: relative; z-index: 1; text-align: center; }
.ap-modal__body { padding: 22px 28px; }
.ap-modal__foot { padding: 16px 28px 24px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.ap-trust { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--ap-radius); background: color-mix(in srgb, var(--ap-accent) 12%, var(--ap-surface)); border: 1px solid color-mix(in srgb, var(--ap-accent) 28%, transparent); margin-bottom: 16px; }
.ap-trust svg { width: 24px; height: 24px; flex: none; color: var(--ap-accent); }
.ap-trust strong { display: block; margin-bottom: 2px; }
.ap-consent-list { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ap-consent-list li { display: flex; gap: 10px; font-size: var(--ap-fs-sm); color: var(--ap-text-soft); }
.ap-consent-list svg { width: 18px; height: 18px; flex: none; color: var(--ap-primary); margin-top: 1px; }
.ap-fineprint { font-size: var(--ap-fs-xs); color: var(--ap-text-mute); margin-top: 14px; }

/* ---- Edit-mode shell ---- */
.ap-root.is-editing { --ap-pad: 22px; }
.ap-editbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px clamp(12px, 3vw, 24px);
  background: var(--ap-chrome); color: #fff;
  box-shadow: var(--ap-shadow);
}
.ap-editbar__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.ap-editbar__brand svg { height: 22px; }
.ap-editbar__tag { font-size: var(--ap-fs-xs); padding: 3px 9px; border-radius: 999px; background: color-mix(in srgb, #fff 16%, transparent); font-weight: 700; letter-spacing: .03em; }
.ap-editbar .ap-btn { --bg: color-mix(in srgb, #fff 12%, transparent); --fg: #fff; border-color: color-mix(in srgb,#fff 18%, transparent); }
.ap-editbar .ap-btn--primary { --bg: #fff; --fg: var(--ap-chrome); border-color: transparent; }

/* highlight editable regions while editing */
.is-editing .ap-editable { position: relative; outline: 1.5px dashed transparent; outline-offset: 4px; border-radius: 8px; transition: outline-color .15s, background .15s; }
.is-editing .ap-editable:hover { outline-color: color-mix(in srgb, var(--ap-primary) 60%, transparent); background: color-mix(in srgb, var(--ap-primary) 5%, transparent); cursor: pointer; }
.is-editing .ap-editable > .ap-edit-tag { position: absolute; top: -10px; left: 8px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: #fff; background: var(--ap-primary); padding: 2px 7px; border-radius: 6px; opacity: 0; transition: opacity .15s; pointer-events: none; }
.is-editing .ap-editable:hover > .ap-edit-tag { opacity: 1; }

/* ---- Side panel (drawer) ---- */
.ap-drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(420px, 100vw); z-index: 80; background: var(--ap-surface); border-left: 1px solid var(--ap-border); box-shadow: var(--ap-shadow-lg); display: flex; flex-direction: column; transform: translateX(100%); transition: transform .32s var(--ap-ease); }
.ap-drawer.is-open { transform: none; }
.ap-drawer__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--ap-border); }
.ap-drawer__title { font-weight: 800; font-size: var(--ap-fs-lg); }
.ap-drawer__body { flex: 1; overflow: auto; padding: 18px; }
.ap-drawer__foot { padding: 14px 18px; border-top: 1px solid var(--ap-border); display: flex; gap: 10px; }

.ap-divider { height: 1px; background: var(--ap-border); margin: 18px 0; border: 0; }
.ap-subhead { font-size: var(--ap-fs-xs); font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--ap-text-mute); margin: 4px 0 10px; }

/* swatch palette picker */
.ap-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.ap-swatch { width: 30px; height: 30px; border-radius: 9px; border: 2px solid transparent; cursor: pointer; box-shadow: var(--ap-shadow-sm); transition: transform .12s; position: relative; }
.ap-swatch:hover { transform: scale(1.08); }
.ap-swatch.is-active { border-color: var(--ap-text); }
.ap-palette-card { appearance: none; -webkit-appearance: none; background: var(--ap-surface); color: var(--ap-text); font: inherit; display: flex; gap: 4px; padding: 8px; border-radius: 12px; border: 2px solid var(--ap-border); cursor: pointer; transition: border-color .15s, transform .12s; align-items: center; }
.ap-palette-card:hover { transform: translateY(-2px); }
.ap-palette-card.is-active { border-color: var(--ap-primary); }
.ap-palette-card__dots { display: flex; gap: 3px; }
.ap-palette-card__dot { width: 16px; height: 16px; border-radius: 5px; }
.ap-palette-card__name { font-size: var(--ap-fs-xs); font-weight: 700; }

/* chart type picker grid */
.ap-typegrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ap-typecell { appearance: none; -webkit-appearance: none; color: var(--ap-text); font: inherit; display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 4px; border-radius: 12px; border: 1.5px solid var(--ap-border); background: var(--ap-surface); cursor: pointer; transition: all .14s var(--ap-ease); }
.ap-typecell svg { width: 26px; height: 26px; color: var(--ap-text-soft); }
.ap-typecell span { font-size: 10px; font-weight: 700; color: var(--ap-text-soft); text-align: center; line-height: 1.1; }
.ap-typecell:hover { border-color: var(--ap-primary); transform: translateY(-2px); }
.ap-typecell.is-active { border-color: var(--ap-primary); background: color-mix(in srgb, var(--ap-primary) 12%, var(--ap-surface)); }
.ap-typecell.is-active svg, .ap-typecell.is-active span { color: var(--ap-primary); }
.ap-typecell.is-recommended::after { content: "★"; position: absolute; }
.ap-typecell[disabled] { opacity: .32; pointer-events: none; }
.ap-typecell { position: relative; }
.ap-typecell .ap-rec-star { position: absolute; top: 4px; right: 5px; color: var(--ap-warn); font-size: 11px; }

/* column pill multi-select */
.ap-collist { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow: auto; padding: 2px; }
.ap-colpill { appearance: none; -webkit-appearance: none; background: var(--ap-surface); color: var(--ap-text); font: inherit; font-size: var(--ap-fs-sm); display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--ap-border); cursor: pointer; transition: all .12s; }
.ap-colpill:hover { border-color: var(--ap-primary); }
.ap-colpill.is-on { background: color-mix(in srgb, var(--ap-primary) 12%, var(--ap-surface)); border-color: var(--ap-primary); color: var(--ap-primary); font-weight: 600; }
.ap-coltype { margin-left: auto; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 2px 6px; border-radius: 5px; background: var(--ap-bg-soft); color: var(--ap-text-mute); }

/* live preview box inside drawer */
.ap-preview { border: 1px dashed var(--ap-border); border-radius: var(--ap-radius); padding: 10px; background: var(--ap-surface-2); }
.ap-preview__chart { width: 100%; height: 220px; }

/* drag handle / add buttons on blocks */
.is-editing .ap-block { position: relative; }
.ap-block__tools { position: absolute; top: 8px; right: 8px; display: none; gap: 4px; z-index: 5; }
.is-editing .ap-block:hover .ap-block__tools { display: flex; }
.ap-block__tools .ap-btn { box-shadow: var(--ap-shadow); }
.ap-drag-handle { cursor: grab; }
.ap-sortable-ghost { opacity: .4; }
.ap-sortable-chosen { box-shadow: var(--ap-shadow-lg); }
/* Reset <button> defaults so transparent shows in dark mode. */
.ap-addblock { appearance: none; -webkit-appearance: none; background: transparent; font: inherit; font-weight: 700;
  display: grid; place-items: center; min-height: 120px; border: 2px dashed var(--ap-border); border-radius: var(--ap-radius); color: var(--ap-text-mute); cursor: pointer; gap: 6px; transition: all .15s; text-align: left; }
.ap-addblock:hover { border-color: var(--ap-primary); color: var(--ap-primary); background: color-mix(in srgb, var(--ap-primary) 8%, transparent); }
.ap-addblock:focus-visible { outline: none; box-shadow: var(--ap-ring); }

/* "Add a block" chooser: a menu row with a gradient icon badge + title/description. */
.ap-addtile { appearance: none; -webkit-appearance: none; font: inherit; width: 100%; text-align: left;
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--ap-border); background: var(--ap-surface); color: var(--ap-text); cursor: pointer;
  transition: border-color .15s var(--ap-ease), background .15s var(--ap-ease), transform .12s var(--ap-ease), box-shadow .15s var(--ap-ease); }
.ap-addtile:hover { border-color: var(--ap-primary); background: color-mix(in srgb, var(--ap-primary) 8%, var(--ap-surface)); transform: translateY(-1px); box-shadow: var(--ap-shadow-sm); }
.ap-addtile:focus-visible { outline: none; box-shadow: var(--ap-ring); }
.ap-addtile__icon { flex: none; width: 46px; height: 46px; border-radius: 13px; background: var(--ap-grad); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 16px color-mix(in srgb, var(--ap-primary) 30%, transparent); }
.ap-addtile__icon svg { width: 23px; height: 23px; }
.ap-addtile__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ap-addtile__title { font-weight: 700; font-size: var(--ap-fs-md); color: var(--ap-text); }
.ap-addtile__desc { font-size: var(--ap-fs-xs); color: var(--ap-text-mute); }

/* tab editor row */
.ap-tabedit { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--ap-border); border-radius: 10px; margin-bottom: 8px; background: var(--ap-surface); }
.ap-tabedit input { border: none; background: none; flex: 1; font: inherit; font-weight: 600; }
.ap-tabedit input:focus { outline: none; }
.ap-tab-grip { cursor: grab; color: var(--ap-text-mute); display: inline-flex; flex: none; touch-action: none; }
.ap-tab-grip:active { cursor: grabbing; }
.ap-tab-grip svg { width: 16px; height: 16px; }

/* Info (i) button + popover */
.ap-info-wrap { position: relative; display: inline-flex; margin-left: 6px; vertical-align: middle; }
.ap-info-btn { width: 15px; height: 15px; padding: 0; border: none; border-radius: 50%; background: var(--ap-text-mute); color: #fff; font: italic 700 10px/1 Georgia, serif; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.ap-info-btn:hover { background: var(--ap-primary); }
.ap-info-pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 90; display: none; min-width: 230px; max-width: 290px; background: var(--ap-surface); border: 1px solid var(--ap-border); border-radius: 10px; box-shadow: var(--ap-shadow-lg); padding: 10px 12px; font: 400 12px/1.5 var(--ap-font-body); color: var(--ap-text-soft); text-transform: none; letter-spacing: 0; }
.ap-info-pop.is-open { display: block; }
.ap-info-pop code { background: var(--ap-bg-soft); padding: 1px 5px; border-radius: 4px; font-size: 11px; color: var(--ap-primary); }

/* toast */
.ap-toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 120; background: var(--ap-chrome); color: #fff; padding: 11px 18px; border-radius: 999px; font-weight: 600; font-size: var(--ap-fs-sm); box-shadow: var(--ap-shadow-lg); opacity: 0; transition: all .3s var(--ap-ease); display: flex; align-items: center; gap: 9px; }
.ap-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.ap-toast svg { width: 18px; height: 18px; }
.ap-toast--ok { background: #14a06f; }
.ap-toast--err { background: var(--ap-series-5); }

@media (max-width: 520px) { .ap-typegrid { grid-template-columns: repeat(3,1fr); } }
