/**
 * CalculatHub — floating-calc.css  (V14 — Draggable FAB)
 * Floating Quick-Calc: Bottom-Right FAB, Non-Modal, No Body Blur
 * 10-Color Neon Glassmorphism System
 * Drag: cursor feedback + panel stays in sync via JS applyPos()
 */

/* ── 10-Color Neon Custom Properties ── */
:root {
  --qc-neon-1:  #1A5BB9; /* business   – deep blue   */
  --qc-neon-2:  #FF9100; /* date-time  – orange      */
  --qc-neon-3:  #A855F7; /* education  – violet      */
  --qc-neon-4:  #22C55E; /* engineering– green       */
  --qc-neon-5:  #EC4899; /* finance    – pink        */
  --qc-neon-6:  #06B6D4; /* fitness    – cyan        */
  --qc-neon-7:  #EAB308; /* health     – amber       */
  --qc-neon-8:  #EF4444; /* lifestyle  – red         */
  --qc-neon-9:  #84CC16; /* math       – lime        */
  --qc-neon-10: #D946EF; /* science    – fuchsia     */

  /* Active FAB/panel neon color – cycles via JS class */
  --qc-neon:    var(--qc-neon-6);
}

/* ── FAB Wrapper: Fixed Bottom-Right ── */
.ch-quick-calc {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  /* CRITICAL: never block page clicks */
  pointer-events: none;
}

/* Re-enable pointer events only on interactive children */
.ch-quick-calc__fab,
.ch-quick-calc__panel.active {
  pointer-events: auto;
}

/* ── FAB Button ── */
.ch-quick-calc__fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--qc-neon), color-mix(in srgb, var(--qc-neon) 60%, #000));
  border: 2px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 24px color-mix(in srgb, var(--qc-neon) 50%, transparent),
    0 0 0 0 color-mix(in srgb, var(--qc-neon) 40%, transparent);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.25s ease;
  position: relative;
  overflow: hidden;
  pointer-events: auto;
  min-width: 56px;
  min-height: 56px;
  /* Indicate draggability */
  cursor: grab;
  touch-action: none; /* prevent scroll hijack on mobile drag */
}

.ch-quick-calc__fab:hover {
  transform: scale(1.1) translateY(-2px);
  box-shadow:
    0 8px 32px color-mix(in srgb, var(--qc-neon) 60%, transparent),
    0 0 0 8px color-mix(in srgb, var(--qc-neon) 12%, transparent);
}

/* Neon Pulse Anim — FAB only, not body */
@keyframes chFabPulse {
  0%, 100% { box-shadow: 0 4px 24px color-mix(in srgb, var(--qc-neon) 50%, transparent), 0 0 0 0 color-mix(in srgb, var(--qc-neon) 40%, transparent); }
  50%       { box-shadow: 0 4px 24px color-mix(in srgb, var(--qc-neon) 50%, transparent), 0 0 0 10px color-mix(in srgb, var(--qc-neon) 0%, transparent); }
}
.ch-mesh-pulse { animation: chFabPulse 2.4s ease-in-out infinite; }

/* FAB Icon transition */
.ch-quick-calc__fab i {
  transition: transform 0.3s ease, opacity 0.2s ease;
}
.ch-quick-calc__fab[aria-expanded="true"] i {
  transform: rotate(90deg);
}

/* FAB Ripple */
.ch-fab-ripple {
  position: absolute;
  width: 10px;
  height: 10px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  animation: chFabRipple 0.7s ease-out forwards;
  pointer-events: none;
}
@keyframes chFabRipple {
  to { transform: scale(14); opacity: 0; }
}

/* ── Panel: Bottom-Right, NOT centered, NOT a modal ── */
.ch-quick-calc__panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 320px;
  max-height: 580px;
  /* INVISIBLE state — NOT blocking clicks */
  opacity: 0;
  transform: translateY(20px) scale(0.97);
  pointer-events: none;
  visibility: hidden;
  transition:
    opacity 0.3s ease,
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    visibility 0s linear 0.3s;
  z-index: 9998;
  /* NO backdrop on the whole page — only on this panel */
}

.ch-quick-calc__panel.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
  transition:
    opacity 0.3s ease,
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    visibility 0s linear 0s;
}

/* ── Glassmorphic Panel Shell ── */
.ch-qc-glass-outer {
  background: linear-gradient(
    135deg,
    rgba(13, 27, 46, 0.82),
    rgba(5, 15, 30, 0.88)
  );
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1.5px solid color-mix(in srgb, var(--qc-neon) 40%, rgba(255,255,255,0.08));
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 0 40px color-mix(in srgb, var(--qc-neon) 12%, transparent);
  position: relative;
}

[data-theme="light"] .ch-qc-glass-outer {
  background: linear-gradient(135deg, rgba(255,255,255,0.88), rgba(240,245,255,0.9));
  border-color: color-mix(in srgb, var(--qc-neon) 35%, rgba(0,0,0,0.08));
  box-shadow: 0 8px 40px rgba(0,0,0,0.18), 0 0 40px color-mix(in srgb, var(--qc-neon) 10%, transparent);
}

.ch-qc-glass-inner {
  position: relative;
  padding: 10px 14px 14px;
}

/* ── Floating Math Background Symbols ── */
.ch-qc-math-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;
  z-index: 0;
}
.ch-qc-math-bg span {
  position: absolute;
  font-size: var(--s, 1rem);
  color: var(--c, #fff);
  opacity: 0.09;
  font-weight: 700;
  animation: chQcDrift 6s ease-in-out infinite alternate;
  animation-delay: calc(var(--dx, 0px) * 0.1s);
}
@keyframes chQcDrift {
  0%   { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(var(--dx, 8px), var(--dy, -8px)) rotate(12deg); }
}
@media (prefers-reduced-motion: reduce) {
  .ch-qc-math-bg span { animation: none; }
}

/* ── Close (X) Button ── */
.ch-qc-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  /* MOBILE TOUCH TARGET: minimum 44×44px */
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--ch-text, #e2e8f0);
  font-size: 1rem;
  /* Center icon perfectly */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.ch-qc-close:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: #EF4444;
  color: #EF4444;
}

/* ── Display / OLED Screen ── */
.ch-quick-calc__display {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 14px 14px 10px;
  margin: 10px 0 12px;
  min-height: 72px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}
.ch-oled-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--qc-neon) 6%, transparent) 0%,
    transparent 60%
  );
  pointer-events: none;
}

.ch-quick-calc__expr {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.35);
  min-height: 18px;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-quick-calc__result {
  font-size: 1.9rem;
  font-weight: 800;
  color: #fff;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.2;
  letter-spacing: -0.5px;
  text-shadow: 0 0 20px color-mix(in srgb, var(--qc-neon) 60%, transparent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.2s ease;
}

/* Copy button inside display */
.ch-qc-copy {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.3);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color 0.2s ease, background 0.2s ease;
  z-index: 2;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ch-qc-copy:hover {
  color: var(--qc-neon);
  background: rgba(255, 255, 255, 0.06);
}

/* Sparkle */
.ch-sparkle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--qc-neon);
  pointer-events: none;
  animation: chSparkle 0.6s ease-out forwards;
  transform: translate(-50%, -50%);
}
@keyframes chSparkle {
  0%   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--tx, 0px)), calc(-50% + var(--ty, 0px))) scale(0); opacity: 0; }
}

/* ── Keypad Grid ── */
.ch-quick-calc__btns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  position: relative;
  z-index: 1;
}

.ch-quick-calc__btn {
  height: 46px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ch-text, #e2e8f0);
  font-size: 1rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, border-color 0.15s ease;
  position: relative;
  overflow: hidden;
  /* MOBILE: ensure tap target */
  min-height: 44px;
}
.ch-quick-calc__btn:hover {
  background: rgba(255, 255, 255, 0.13);
  transform: scale(0.97);
}
.ch-quick-calc__btn:active {
  transform: scale(0.93);
}

/* Operator keys — neon tint */
.ch-quick-calc__btn.op {
  color: var(--qc-neon);
  background: color-mix(in srgb, var(--qc-neon) 10%, rgba(255,255,255,0.04));
  border-color: color-mix(in srgb, var(--qc-neon) 25%, transparent);
}
.ch-quick-calc__btn.op:hover {
  background: color-mix(in srgb, var(--qc-neon) 22%, rgba(0,0,0,0.3));
}

/* Clear key */
.ch-quick-calc__btn.clear {
  color: #EF4444;
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
}
.ch-quick-calc__btn.clear:hover {
  background: rgba(239, 68, 68, 0.22);
}

/* Equals key */
.ch-quick-calc__btn.equals {
  background: linear-gradient(135deg, var(--qc-neon), color-mix(in srgb, var(--qc-neon) 55%, #000));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 12px color-mix(in srgb, var(--qc-neon) 40%, transparent);
}
.ch-quick-calc__btn.equals:hover {
  filter: brightness(1.12);
  box-shadow: 0 4px 20px color-mix(in srgb, var(--qc-neon) 55%, transparent);
}

/* Key Ripple */
.ch-key-ripple {
  position: absolute;
  width: 8px;
  height: 8px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(1);
  animation: chKeyRipple 0.5s ease-out forwards;
  pointer-events: none;
}
@keyframes chKeyRipple {
  to { transform: translate(-50%, -50%) scale(8); opacity: 0; }
}

/* Bounce Effect */
.ch-bounce-eff:active {
  animation: chBounce 0.2s ease;
}
@keyframes chBounce {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(0.89); }
}

/* ── Extra Widgets Row ── */
.ch-qc-widgets {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  position: relative;
  z-index: 1;
}

.ch-qc-hist-btn,
.ch-qc-all-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.2s ease, color 0.2s ease;
}

.ch-qc-hist-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--ch-text, #e2e8f0);
}
.ch-qc-hist-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.ch-qc-all-btn {
  background: color-mix(in srgb, var(--qc-neon) 14%, rgba(0,0,0,0.2));
  border: 1px solid color-mix(in srgb, var(--qc-neon) 30%, transparent);
  color: var(--qc-neon);
}
.ch-qc-all-btn:hover {
  background: color-mix(in srgb, var(--qc-neon) 25%, rgba(0,0,0,0.1));
}

/* ── History Panel ── */
.ch-qc-history-panel {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 8px;
  max-height: 110px;
  overflow-y: auto;
  position: relative;
  z-index: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--qc-neon) transparent;
}
.ch-qc-history-panel ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.ch-qc-history-panel li {
  font-size: 0.74rem;
  color: rgba(255, 255, 255, 0.55);
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  transition: color 0.15s ease;
}
.ch-qc-history-panel li:hover { color: var(--qc-neon); }
.ch-qc-history-panel li:last-child { border-bottom: none; }

/* ── REMOVE OLD OVERLAY (safety rule) ── */
/* Ensures .ch-qc-overlay (legacy) never darkens background */
.ch-qc-overlay {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  background: none !important;
  backdrop-filter: none !important;
}

/* ── Mobile Responsive ── */
@media (max-width: 400px) {
  .ch-quick-calc__panel {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: 84px;
  }
  .ch-quick-calc__fab {
    right: 0;
    bottom: 0;
  }
  .ch-quick-calc {
    bottom: 16px;
    right: 12px;
  }
  .ch-quick-calc__btn { height: 44px; font-size: 0.95rem; }
}

@media (max-width: 360px) {
  .ch-quick-calc__btns { gap: 5px; }
  .ch-quick-calc__btn { font-size: 0.85rem; }
}
