/* =========================================================
   Ionik+ — Knowledge-map cell panel (ionik-cell-panel.js)
   A compact panel that grows out of the clicked square.
   Motion is fluid only: one long ease-out curve, no overshoot,
   no bounce. Load after ionik-dashboard.css.
   ========================================================= */
.cp-back {
  position: fixed; inset: 0; z-index: 8800;
  background: color-mix(in srgb, #1d160c 16%, transparent);
  opacity: 0;
  transition: opacity 420ms var(--ease-fluid, cubic-bezier(0.32, 0.72, 0, 1));
}
.cp-back.in { opacity: 1; }
.cp-back.cp-quiet { background: transparent; }

.cp-panel {
  --cpe: var(--ease-fluid, cubic-bezier(0.32, 0.72, 0, 1));
  position: fixed; z-index: 8801;
  width: min(352px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto; overscroll-behavior: contain;
  padding: 18px 18px 16px;
  border-radius: 18px;
  border: 1px solid var(--rule);
  background:
    radial-gradient(120% 70% at 100% 0%, color-mix(in srgb, var(--bg-3) 70%, transparent), transparent 60%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  box-shadow: 0 1px 0 rgba(255,255,255,0.35) inset, 0 24px 60px -18px rgba(32, 24, 12, 0.45), 0 4px 14px -6px rgba(32, 24, 12, 0.2);
  color: var(--ink);
  opacity: 0;
  transform: scale(0.86);
  filter: blur(3px);
  transition: opacity 380ms var(--cpe), transform 560ms var(--cpe), filter 420ms var(--cpe);
  isolation: isolate;
  scrollbar-width: none;
}
.cp-panel::-webkit-scrollbar { display: none; }
.cp-panel.in { opacity: 1; transform: none; filter: none; }
.cp-panel.out { opacity: 0; transform: scale(0.92); filter: blur(2px); transition-duration: 280ms, 320ms, 280ms; }

/* Phone: a short sheet rising from the bottom edge. */
.cp-panel.cp-sheet {
  left: 0 !important; right: 0; bottom: 0; top: auto !important;
  width: 100%; max-height: 82vh;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0; border-bottom: 0;
  transform: translateY(100%); filter: none;
  transition: opacity 300ms var(--cpe), transform 520ms var(--cpe);
}
.cp-panel.cp-sheet::before {
  content: ''; display: block; width: 36px; height: 4px; border-radius: 4px;
  margin: 0 auto 12px; background: var(--rule);
}
.cp-panel.cp-sheet.in { transform: none; }
.cp-panel.cp-sheet.out { transform: translateY(100%); }

/* Switching cells while open: the content dissolves across, the panel stays put. */
.cp-panel.cp-swap > *:not(.cp-blob) { animation: cp-swap 460ms var(--cpe) both; }
@keyframes cp-swap { from { opacity: 0; transform: translateY(6px); filter: blur(2px); } to { opacity: 1; transform: none; filter: none; } }

/* Slow drifting colour, tinted by nothing but the cream ground. */
.cp-blob {
  position: absolute; z-index: -1; pointer-events: none;
  width: 190px; height: 190px; right: -70px; top: -80px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, color-mix(in srgb, #8a6a3c 22%, transparent), transparent 68%);
  filter: blur(8px);
  animation: cp-drift 14s ease-in-out infinite alternate;
}
.cp-blob.b2 { width: 150px; height: 150px; left: -70px; right: auto; top: auto; bottom: -70px;
  background: radial-gradient(circle at 60% 50%, color-mix(in srgb, #5a4530 16%, transparent), transparent 70%);
  animation-duration: 18s; animation-delay: -6s; }
@keyframes cp-drift { from { transform: translate(0, 0) scale(1); } to { transform: translate(-18px, 14px) scale(1.12); } }

/* ---- head ---------------------------------------------------------------- */
.cp-head { display: flex; align-items: flex-start; gap: 11px; }
.cp-sw { width: 14px; height: 14px; margin-top: 5px; flex: none; border-radius: 4px; border: 1px solid var(--rule); background: transparent; }
.cp-sw.s1 { background: var(--p1); border-color: var(--p1); }
.cp-sw.s2 { background: var(--p2); border-color: var(--p2); }
.cp-sw.s3 { background: var(--p3); border-color: var(--p3); }
.cp-sw.s4 { background: var(--p4); border-color: var(--p4); }
.cp-sw.s5 { background: var(--p5); border-color: var(--p5); }
.cp-sw.thin { background: var(--p-thin); border-color: var(--p-thin); }
.cp-ttl { flex: 1; min-width: 0; }
.cp-ttl h3 { margin: 0; font-size: 17px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.25; }
.cp-ttl h3 b { font-weight: 650; font-variant-numeric: tabular-nums; margin-right: 2px; }
.cp-sub { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-x {
  width: 30px; height: 30px; flex: none; margin: -4px -6px 0 0;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-muted); cursor: pointer;
  transition: background 260ms var(--cpe), color 260ms var(--cpe);
}
.cp-x svg { width: 15px; height: 15px; }
.cp-x:hover { background: var(--panel-2); color: var(--ink); }

/* ---- verdict + band ---------------------------------------------------------- */
.cp-verdict { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 12px 0 10px; }
.cp-vd, .cp-band, .cp-move {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.cp-vd { background: var(--panel-2); color: var(--ink-soft); }
.cp-vd.s1 { background: color-mix(in srgb, var(--r-red) 16%, transparent); color: var(--r-red); }
.cp-vd.s2 { background: color-mix(in srgb, var(--r-amber) 18%, transparent); color: var(--r-amber); }
.cp-vd.s3, .cp-vd.s4, .cp-vd.s5 { background: color-mix(in srgb, var(--r-green) 16%, transparent); color: var(--r-green); }
.cp-band { background: var(--ink); color: var(--bg); }
.cp-band em { font-style: normal; font-weight: 500; opacity: 0.7; margin-left: 3px; }
.cp-band.thin { background: var(--panel-2); color: var(--ink-soft); }
.cp-band.none { background: transparent; border: 1px dashed var(--rule); color: var(--ink-muted); font-weight: 500; }
.cp-move svg { width: 11px; height: 11px; }
.cp-move.up { color: var(--r-green); background: color-mix(in srgb, var(--r-green) 12%, transparent); }
.cp-move.down { color: var(--r-red); background: color-mix(in srgb, var(--r-red) 11%, transparent); }
.cp-move.flat { color: var(--ink-muted); background: var(--panel); }

/* ---- band chart ---------------------------------------------------------- */
.cp-chart-wrap {
  border-radius: 12px; padding: 8px 6px 4px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  border: 1px solid var(--rule-soft);
}
.cp-chart { display: block; width: 100%; height: auto; overflow: visible; }
.cp-chart-key { margin: 6px 2px 0; font-size: 10.5px; color: var(--ink-muted); }
.cp-dot, .cp-now { cursor: help; }
.cp-z { fill: var(--ink); opacity: 0.025; }
.cp-z.z6 { fill: var(--p5); opacity: 0.26; }
.cp-z.z5 { fill: var(--p4); opacity: 0.2; }
.cp-z.z4 { fill: var(--p3); opacity: 0.18; }
.cp-z.z3 { fill: var(--p2); opacity: 0.14; }
.cp-z.z2 { fill: var(--p1); opacity: 0.1; }
.cp-z.z1 { fill: var(--p1); opacity: 0.05; }
.cp-zl { font-size: 9px; font-weight: 600; fill: var(--ink-muted); letter-spacing: 0.02em; }
.cp-typ { stroke: var(--ink-faint); stroke-width: 1; stroke-dasharray: 3 3; }
.cp-typl { font-size: 8.5px; fill: var(--ink-faint); }
.cp-ax { font-size: 8.5px; fill: var(--ink-faint); }
.cp-none { font-size: 11px; fill: var(--ink-muted); text-anchor: middle; }
.cp-area { fill: color-mix(in srgb, var(--ink) 7%, transparent); opacity: 0; animation: cp-fade 900ms var(--cpe) 260ms forwards; }
.cp-line {
  fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  animation: cp-draw 1100ms var(--cpe) 120ms forwards;
}
.cp-dot { fill: var(--bg); stroke: var(--ink-muted); stroke-width: 1.2; opacity: 0; animation: cp-fade 600ms var(--cpe) forwards; animation-delay: calc(200ms + var(--i) * 70ms); }
.cp-now { fill: var(--ink); opacity: 0; animation: cp-fade 500ms var(--cpe) 900ms forwards; }
.cp-now-ring { fill: none; stroke: var(--ink); stroke-width: 1; opacity: 0; transform-box: fill-box; transform-origin: center;
  animation: cp-breathe 2.8s ease-in-out 1.2s infinite; }
@keyframes cp-draw { to { stroke-dashoffset: 0; } }
@keyframes cp-fade { to { opacity: 1; } }
@keyframes cp-breathe { 0%, 100% { opacity: 0; transform: scale(0.7); } 50% { opacity: 0.35; transform: scale(1.15); } }

/* ---- tiles ---------------------------------------------------------------- */
.cp-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 10px; }
.cp-tile {
  padding: 9px 10px; border-radius: 11px;
  background: var(--panel); border: 1px solid var(--rule-soft);
  opacity: 0; animation: cp-rise 560ms var(--cpe) forwards; animation-delay: calc(140ms + var(--i) * 60ms);
}
.cp-tile .k { display: block; font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); font-weight: 600; }
.cp-tile b { display: block; font-size: 19px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.cp-tile b small { font-size: 12px; font-weight: 500; color: var(--ink-muted); }
.cp-tile .s { display: block; font-size: 10px; color: var(--ink-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes cp-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.cp-history { margin-top: 12px; border: 1px solid var(--rule-soft); border-radius: 10px; background: var(--panel); }
.cp-history summary { display: flex; align-items: center; gap: 6px; padding: 10px 12px; cursor: pointer; list-style: none; font-size: 12px; font-weight: 600; }
.cp-history summary::-webkit-details-marker { display: none; }
.cp-history summary span { margin-left: auto; color: var(--ink-muted); font-size: 10.5px; font-weight: 400; }
.cp-history summary::after { content: '⌄'; color: var(--ink-muted); font-size: 16px; line-height: 1; transition: transform 180ms ease; }
.cp-history[open] summary::after { transform: rotate(180deg); }
.cp-history-list { padding: 0 9px 5px; max-height: 264px; overflow-y: auto; }
.cp-history-row { display: flex; gap: 6px; align-items: center; padding: 7px 3px; border-top: 1px solid var(--rule-soft); }
.cp-history-main { flex: 1; min-width: 0; text-decoration: none; color: var(--ink); }
.cp-history-main:hover .cp-history-q { text-decoration: underline; }
.cp-history-q { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; }
.cp-history-meta { display: block; margin-top: 2px; color: var(--ink-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.cp-history-actions { display: flex; gap: 2px; }
.cp-history-actions button { width: 27px; height: 27px; display: grid; place-items: center; flex: none; padding: 5px; border: 0; border-radius: 6px; background: transparent; color: var(--ink-muted); cursor: pointer; }
.cp-history-actions button:hover { background: var(--bg-3); color: var(--ink); }
.cp-history-actions button:disabled { opacity: .4; cursor: wait; }
.cp-history-actions svg { width: 16px; height: 16px; }
.cp-history-star.on { color: var(--r-amber) !important; }
.cp-history-heart.on { color: var(--r-red) !important; }
.cp-history-star.on svg, .cp-history-heart.on svg { fill: currentColor; }
.cp-history-empty, .cp-history-status { margin: 0; padding: 7px 4px; color: var(--ink-muted); font-size: 11px; }
.cp-history-status:empty { display: none; }

/* ---- actions ---------------------------------------------------------------- */
.cp-acts { display: flex; gap: 8px; margin-top: 14px; }
.cp-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--bg); color: var(--ink);
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background 300ms var(--cpe), border-color 300ms var(--cpe), transform 300ms var(--cpe), box-shadow 300ms var(--cpe);
}
.cp-btn svg { width: 15px; height: 15px; flex: none; }
.cp-btn small { font-weight: 500; font-size: 10.5px; opacity: 0.75; }
.cp-btn { white-space: nowrap; }
.cp-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px -8px rgba(32, 24, 12, 0.35); }
.cp-btn:active { transform: translateY(0); }
.cp-btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.cp-btn.diag { border: 1.5px dashed var(--idg-line, #8a9bc4); color: var(--idg, #4f6496); background: var(--idg-soft, rgba(79,100,150,0.12)); }
.cp-btn.diag:hover { border-color: var(--idg, #4f6496); }
.cp-panel.cp-nudge { animation: cp-glow 900ms var(--cpe); }
@keyframes cp-glow { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--idg, #4f6496) 40%, transparent), 0 24px 60px -18px rgba(32,24,12,0.45); }
                     100% { box-shadow: 0 0 0 14px transparent, 0 24px 60px -18px rgba(32,24,12,0.45); } }

/* The square that opened the panel stays marked while it is open. */
.db-cell, .db-mini i { transition: transform 320ms var(--ease-fluid, ease), box-shadow 320ms var(--ease-fluid, ease); }
.db-cell.cp-sel, .db-mini i.cp-sel {
  outline: 2px solid var(--ink); outline-offset: 2px;
  transform: scale(1.22); position: relative; z-index: 3;
  box-shadow: 0 6px 14px -6px rgba(32, 24, 12, 0.5);
}

@media (prefers-reduced-motion: reduce) {
  .cp-panel, .cp-back, .cp-panel > *, .cp-tile, .cp-line, .cp-dot, .cp-now, .cp-area, .cp-blob, .cp-now-ring {
    transition-duration: 1ms !important; animation: none !important; opacity: 1; filter: none; stroke-dashoffset: 0;
  }
  .cp-now-ring { opacity: 0 !important; }
}
