/* ══════════════════════════════════════════════════════════════
   ToolBoxesAi Community — Plug & Play Extension
   Glassmorphism UI • Responsive • Zero Dependencies
   Drop this file + toolboxes-community.js into any project.
   ══════════════════════════════════════════════════════════════ */

/* ── Design Tokens (inherits host if available, else defaults) ── */
.tbc-ext {
  --tbc-primary: var(--primary, #0891B2);
  --tbc-secondary: var(--secondary, #7C3AED);
  --tbc-bg: var(--bg, #F8FAFC);
  --tbc-surface: var(--surface, #FFFFFF);
  --tbc-on-bg: var(--on-bg, #0F172A);
  --tbc-on-surface: var(--on-surface-variant, #475569);
  --tbc-outline: var(--outline, #CBD5E1);
  --tbc-outline-variant: var(--outline-variant, #E2E8F0);
  --tbc-success: var(--success, #16A34A);
  --tbc-error: var(--error, #DC2626);
  --tbc-glass: rgba(255,255,255,0.82);
  --tbc-glass-border: rgba(203,213,225,0.35);
  --tbc-gradient: linear-gradient(135deg, var(--tbc-primary), var(--tbc-secondary));
  --tbc-shadow: 0 8px 32px rgba(15,23,42,0.10);
  --tbc-shadow-lg: 0 20px 60px rgba(15,23,42,0.15);
  --tbc-radius: 16px;
  --tbc-radius-sm: 10px;
  --tbc-transition: 0.3s cubic-bezier(0.4,0,0.2,1);
  --tbc-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  font-family: var(--tbc-font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════════
   VOTE BAR (Left edge, always visible)
   ══════════════════════════════════════════ */
.tbc-vote-bar {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 3px;
  background: var(--tbc-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--tbc-glass-border);
  border-left: none;
  border-radius: 0 var(--tbc-radius-sm) var(--tbc-radius-sm) 0;
  box-shadow: var(--tbc-shadow);
  transition: opacity var(--tbc-transition), transform var(--tbc-transition);
}

.tbc-vote-bar.tbc-hidden {
  opacity: 0;
  transform: translateY(-50%) translateX(-100%);
  pointer-events: none;
}

.tbc-vote-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  transition: all var(--tbc-transition);
  position: relative;
  color: var(--tbc-on-surface);
}

.tbc-vote-btn:hover {
  background: var(--tbc-outline-variant);
}

.tbc-vote-btn svg {
  width: 15px;
  height: 15px;
  transition: transform 0.2s ease, color 0.2s ease;
}

.tbc-vote-btn:active svg {
  transform: scale(1.25);
}

.tbc-vote-btn--like.tbc-voted {
  color: var(--tbc-success);
}

.tbc-vote-btn--dislike.tbc-voted {
  color: var(--tbc-error);
}

.tbc-vote-count {
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--tbc-on-surface);
  text-align: center;
  min-width: 16px;
  line-height: 1;
  padding: 1px 0;
  user-select: none;
}

.tbc-vote-divider {
  width: 14px;
  height: 1px;
  background: var(--tbc-outline-variant);
  margin: 2px 0;
}

/* ══════════════════════════════════════════
   COMMUNITY BUBBLE (Draggable)
   ══════════════════════════════════════════ */
.tbc-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--tbc-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  box-shadow: 0 6px 24px rgba(8,145,178,0.35), 0 0 0 0 rgba(8,145,178,0.3);
  transition: box-shadow var(--tbc-transition), transform 0.2s ease;
  user-select: none;
  touch-action: none;
  animation: tbc-bubble-pulse 3s ease-in-out infinite;
}

.tbc-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 32px rgba(8,145,178,0.45);
}

.tbc-bubble:active {
  cursor: grabbing;
  animation: none;
}

.tbc-bubble svg {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.tbc-bubble__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--tbc-error);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transform: scale(0);
  transition: all 0.25s ease;
}

.tbc-bubble__badge.tbc-visible {
  opacity: 1;
  transform: scale(1);
}

@keyframes tbc-bubble-pulse {
  0%, 100% { box-shadow: 0 6px 24px rgba(8,145,178,0.35), 0 0 0 0 rgba(8,145,178,0.3); }
  50% { box-shadow: 0 6px 24px rgba(8,145,178,0.35), 0 0 0 10px rgba(8,145,178,0); }
}

/* ══════════════════════════════════════════
   COMMUNITY PANEL (Expandable from bubble)
   ══════════════════════════════════════════ */
.tbc-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  z-index: 10000;
  width: 380px;
  height: 500px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--tbc-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--tbc-glass-border);
  border-radius: var(--tbc-radius);
  box-shadow: var(--tbc-shadow-lg);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.tbc-panel.tbc-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Panel Header */
.tbc-panel__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--tbc-outline-variant);
  flex-shrink: 0;
}

.tbc-panel__header-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--tbc-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.tbc-panel__header-icon svg {
  width: 16px;
  height: 16px;
}

.tbc-panel__header-text {
  flex: 1;
}

.tbc-panel__header-text h3 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--tbc-on-bg);
  margin: 0;
}

.tbc-panel__header-text p {
  font-size: 0.7rem;
  color: var(--tbc-on-surface);
  margin: 0;
}

.tbc-panel__close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--tbc-outline-variant);
  color: var(--tbc-on-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--tbc-transition);
  flex-shrink: 0;
}

.tbc-panel__close:hover {
  background: var(--tbc-outline);
}

.tbc-panel__close svg {
  width: 14px;
  height: 14px;
}

/* Messages container */
.tbc-panel__messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Custom thin scrollbar for messages */
.tbc-panel__messages::-webkit-scrollbar { width: 4px; }
.tbc-panel__messages::-webkit-scrollbar-track { background: transparent; }
.tbc-panel__messages::-webkit-scrollbar-thumb {
  background: var(--tbc-outline);
  border-radius: 4px;
}
.tbc-panel__messages::-webkit-scrollbar-thumb:hover {
  background: var(--tbc-on-surface);
}

/* Empty state */
.tbc-panel__empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--tbc-on-surface);
}

.tbc-panel__empty-icon {
  font-size: 2rem;
  margin-bottom: 8px;
  opacity: 0.5;
}

.tbc-panel__empty p {
  font-size: 0.8rem;
  margin: 0;
}

/* Single message card */
.tbc-msg {
  padding: 12px 14px;
  background: var(--tbc-surface);
  border: 1px solid var(--tbc-outline-variant);
  border-radius: var(--tbc-radius-sm);
  animation: tbc-msg-in 0.3s ease;
}

@keyframes tbc-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.tbc-msg__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.tbc-msg__author {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--tbc-primary);
}

.tbc-msg__time {
  font-size: 0.65rem;
  color: var(--tbc-outline);
}

.tbc-msg__body {
  font-size: 0.813rem;
  color: var(--tbc-on-bg);
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Compose area */
.tbc-panel__compose {
  padding: 12px 18px 16px;
  border-top: 1px solid var(--tbc-outline-variant);
  flex-shrink: 0;
}

.tbc-panel__compose-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.tbc-panel__input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tbc-panel__name-input,
.tbc-panel__msg-input {
  width: 100%;
  border: 1px solid var(--tbc-outline-variant);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.813rem;
  font-family: var(--tbc-font);
  color: var(--tbc-on-bg);
  background: var(--tbc-surface);
  outline: none;
  transition: border-color var(--tbc-transition);
  resize: none;
}

.tbc-panel__name-input:focus,
.tbc-panel__msg-input:focus {
  border-color: var(--tbc-primary);
}

.tbc-panel__msg-input {
  min-height: 38px;
  max-height: 80px;
  field-sizing: content;
}

.tbc-panel__send-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--tbc-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow var(--tbc-transition);
  flex-shrink: 0;
}

.tbc-panel__send-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 4px 16px rgba(8,145,178,0.3);
}

.tbc-panel__send-btn:active {
  transform: scale(0.95);
}

.tbc-panel__send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.tbc-panel__send-btn svg {
  width: 18px;
  height: 18px;
}

.tbc-panel__limit {
  font-size: 0.65rem;
  color: var(--tbc-outline);
  padding-top: 6px;
  text-align: center;
}

/* Status / toast feedback */
.tbc-toast {
  position: fixed;
  bottom: 148px;
  right: 24px;
  z-index: 10001;
  padding: 10px 18px;
  border-radius: var(--tbc-radius-sm);
  background: var(--tbc-on-bg);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 500;
  font-family: var(--tbc-font);
  box-shadow: var(--tbc-shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s ease;
  pointer-events: none;
}

.tbc-toast.tbc-toast--show {
  opacity: 1;
  transform: translateY(0);
}

.tbc-toast.tbc-toast--error {
  background: var(--tbc-error);
}

.tbc-toast.tbc-toast--success {
  background: var(--tbc-success);
}

/* Loading spinner */
.tbc-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--tbc-outline-variant);
  border-top-color: var(--tbc-primary);
  border-radius: 50%;
  animation: tbc-spin 0.6s linear infinite;
  margin: 0 auto;
}

@keyframes tbc-spin {
  to { transform: rotate(360deg); }
}

/* ══════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════ */
@media (max-width: 480px) {
  .tbc-panel {
    right: 8px;
    left: 8px;
    bottom: 76px;
    width: auto;
    height: 75vh;
    max-height: calc(100vh - 100px);
  }

  .tbc-bubble {
    width: 46px;
    height: 46px;
    bottom: 16px;
    right: 16px;
  }

  .tbc-bubble svg {
    width: 20px;
    height: 20px;
  }

  .tbc-vote-bar {
    padding: 3px 2px;
  }

  .tbc-vote-btn {
    width: 24px;
    height: 24px;
  }

  .tbc-vote-btn svg {
    width: 13px;
    height: 13px;
  }

  .tbc-vote-count {
    font-size: 0.5rem;
  }

  .tbc-toast {
    right: 8px;
    left: 8px;
    bottom: 130px;
    text-align: center;
  }
}

@media (max-width: 360px) {
  .tbc-panel {
    height: 70vh;
    max-height: calc(100vh - 90px);
  }
}
