/**
 * Copy Toolbar Styles - Optimized for Mobile & Desktop
 * Modern, responsive design with smooth interactions
 */

/* ==================== CSS Variables ==================== */
:root {
  --toolbar-bg: rgba(255, 255, 255, 0.95);
  --toolbar-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --toolbar-border: rgba(0, 0, 0, 0.06);
  --button-hover-bg: #f8f9fa;
  --button-active-bg: #e9ecef;
  --success-bg: #d1f4dd;
  --success-color: #0d6832;
  --success-icon: #16a34a;
  --primary-color: #16a34a;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
  --toast-bg: #1f2937;
  --toast-success-bg: #16a34a;
  --toast-error-bg: #dc2626;
}

/* ==================== Main Toolbar ==================== */
.copy-toolbar {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: 20px;
  box-shadow: var(--toolbar-shadow), 0 0 0 1px var(--toolbar-border);
  padding: 20px;
  min-width: 220px;
  max-width: 260px;
  z-index: 1000;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: transform, box-shadow;
}

.copy-toolbar:hover {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--toolbar-border);
  transform: translateY(-50%) scale(1.02);
}

.copy-toolbar-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-toolbar-title::before {
  content: '⚡';
  font-size: 14px;
}

/* ==================== Tool Buttons ==================== */
.tool-button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
  text-align: left;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  position: relative;
  overflow: hidden;
}

/* Primary buttons (main actions) */
.tool-button.primary {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(22, 163, 74, 0.2);
  padding: 16px 18px;
  font-size: 15px;
}

.tool-button.primary:hover {
  background: linear-gradient(135deg, #15803d 0%, #166534 100%);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
  transform: translateY(-2px);
}

.tool-button.primary .icon {
  font-size: 20px;
}

/* Secondary buttons (more options) */
.tool-button.secondary {
  font-size: 13px;
  padding: 12px 14px;
  color: var(--text-secondary);
  background: var(--button-hover-bg);
}

.tool-button.secondary .icon {
  font-size: 16px;
  opacity: 0.7;
}

/* More toggle button */
.tool-button.more-toggle {
  border: 2px dashed var(--border-color);
  color: var(--text-secondary);
  justify-content: space-between;
  margin-top: 8px;
}

.tool-button.more-toggle .arrow {
  font-size: 12px;
  transition: transform 0.3s;
}

.tool-button.more-toggle[aria-expanded="true"] .arrow {
  transform: rotate(180deg);
}

/* More options container */
.more-options {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-color);
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tool-button:last-child {
  margin-bottom: 0;
}

/* Ripple effect */
.tool-button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(22, 163, 74, 0.1);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.tool-button:active::before {
  width: 300px;
  height: 300px;
}

.tool-button .icon {
  font-size: 18px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.25s;
}

.tool-button:hover {
  background: var(--button-hover-bg);
  transform: translateX(-4px);
}

.tool-button:hover .icon {
  transform: scale(1.15);
}

.tool-button:active {
  background: var(--button-active-bg);
  transform: translateX(-4px) scale(0.98);
}

.tool-button.success {
  background: var(--success-bg);
  color: var(--success-color);
  font-weight: 600;
  animation: successPulse 0.4s ease;
}

.tool-button.success .icon {
  color: var(--success-icon);
  animation: successBounce 0.5s ease;
}

@keyframes successPulse {
  0%, 100% { transform: translateX(-4px) scale(1); }
  50% { transform: translateX(-4px) scale(1.05); }
}

@keyframes successBounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

/* ==================== Format Options ==================== */
.format-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 2px solid var(--border-color);
}

.format-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.format-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.format-option {
  padding: 8px 10px;
  border: 2px solid var(--border-color);
  background: white;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-secondary);
  text-align: center;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.format-option .format-label {
  font-size: 11px;
  font-weight: 700;
}

.format-option .format-preview {
  font-size: 10px;
  opacity: 0.6;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.format-option::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(22, 163, 74, 0.1), transparent);
  transition: left 0.5s;
}

.format-option:hover::before {
  left: 100%;
}

.format-option:hover {
  border-color: var(--primary-color);
  background: #f0fdf4;
  color: var(--text-primary);
  transform: translateY(-2px);
}

.format-option.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
  font-weight: 700;
  transform: scale(1.05);
}

.format-option:active {
  transform: scale(0.95);
}

/* ==================== Toast Notifications ==================== */
.copy-toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10000;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.copy-toast {
  background: var(--toast-bg);
  color: white;
  padding: 14px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateX(120px) scale(0.9);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-size: 14px;
  font-weight: 500;
  max-width: 320px;
  word-wrap: break-word;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.copy-toast::before {
  content: '✓';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
  font-weight: bold;
}

.copy-toast.show {
  opacity: 1;
  transform: translateX(0) scale(1);
}

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

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

.copy-toast-error::before {
  content: '✗';
}

/* ==================== Mobile Optimizations ==================== */
@media (max-width: 768px) {
  .copy-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    /* Default to collapsed state */
    transform: translateY(calc(100% - 56px));
    border-radius: 24px 24px 0 0;
    max-width: 100%;
    padding: 16px 20px 24px;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-height: 65vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    cursor: pointer;
  }

  /* Drag handle - more prominent when collapsed */
  .copy-toolbar::before {
    content: '';
    display: block;
    width: 48px;
    height: 5px;
    background: #9ca3af;
    border-radius: 3px;
    margin: 0 auto 16px;
    transition: background 0.2s;
  }

  .copy-toolbar:active::before {
    background: #6b7280;
  }

  /* Add visual hint when collapsed */
  .copy-toolbar::after {
    content: '⚡ Quick Tools';
    display: block;
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    opacity: 1;
    transition: opacity 0.2s;
    pointer-events: none;
  }

  /* Expanded state */
  .copy-toolbar.expanded {
    transform: translateY(0);
    cursor: default;
  }

  .copy-toolbar.expanded::after {
    opacity: 0;
  }

  /* Legacy collapsed class support */
  .copy-toolbar.collapsed {
    transform: translateY(calc(100% - 56px));
  }

  /* Larger touch targets */
  .tool-button {
    padding: 16px 18px;
    font-size: 16px;
    margin-bottom: 10px;
    min-height: 56px; /* WCAG AAA touch target */
    border-radius: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .copy-toolbar.expanded .tool-button {
    opacity: 1;
    pointer-events: auto;
  }

  .tool-button .icon {
    font-size: 20px;
    width: 28px;
    height: 28px;
  }

  .tool-button:hover {
    transform: none; /* Remove hover transform on mobile */
  }

  .tool-button:active {
    transform: scale(0.97);
    background: var(--button-active-bg);
  }

  .copy-toolbar-title {
    font-size: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    opacity: 0;
    transition: opacity 0.2s;
  }

  .copy-toolbar.expanded .copy-toolbar-title {
    opacity: 1;
  }

  /* Format section hidden when collapsed */
  .format-section {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .copy-toolbar.expanded .format-section {
    opacity: 1;
    pointer-events: auto;
  }

  /* Format options - stack vertically on small screens */
  .format-options {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .format-option {
    padding: 12px 16px;
    font-size: 14px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Toast positioning */
  .copy-toast-container {
    left: 16px;
    right: 16px;
    top: 16px;
    width: auto;
    align-items: stretch;
  }

  .copy-toast {
    transform: translateY(-80px) scale(0.9);
    max-width: 100%;
    padding: 16px 18px;
    font-size: 15px;
  }

  .copy-toast.show {
    transform: translateY(0) scale(1);
  }

  /* Safe area for iPhone notch */
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    .copy-toolbar {
      padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
  }
}

/* ==================== Tablet Optimizations ==================== */
@media (max-width: 1024px) and (min-width: 769px) {
  .copy-toolbar {
    /* Move toolbar to bottom on tablet to avoid overlapping content */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    /* Default to collapsed state */
    transform: translateY(calc(100% - 56px));
    border-radius: 24px 24px 0 0;
    max-width: 100%;
    padding: 16px 20px 24px;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    cursor: pointer;
  }

  /* Drag handle */
  .copy-toolbar::before {
    content: '';
    display: block;
    width: 48px;
    height: 5px;
    background: #9ca3af;
    border-radius: 3px;
    margin: 0 auto 16px;
    transition: background 0.2s;
  }

  .copy-toolbar:active::before {
    background: #6b7280;
  }

  /* Visual hint when collapsed */
  .copy-toolbar::after {
    content: '⚡ Quick Tools';
    display: block;
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    opacity: 1;
    transition: opacity 0.2s;
    pointer-events: none;
  }

  /* Expanded state */
  .copy-toolbar.expanded {
    transform: translateY(0);
    cursor: default;
  }

  .copy-toolbar.expanded::after {
    opacity: 0;
  }

  /* Legacy collapsed class support */
  .copy-toolbar.collapsed {
    transform: translateY(calc(100% - 56px));
  }

  .tool-button {
    padding: 14px 16px;
    font-size: 15px;
    min-height: 52px;
    margin-bottom: 10px;
    border-radius: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .copy-toolbar.expanded .tool-button {
    opacity: 1;
    pointer-events: auto;
  }

  .tool-button .icon {
    font-size: 19px;
    width: 26px;
    height: 26px;
  }

  .tool-button:hover {
    transform: none;
  }

  .tool-button:active {
    transform: scale(0.97);
    background: var(--button-active-bg);
  }

  .copy-toolbar-title {
    font-size: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    opacity: 0;
    transition: opacity 0.2s;
  }

  .copy-toolbar.expanded .copy-toolbar-title {
    opacity: 1;
  }

  /* Format section hidden when collapsed */
  .format-section {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }

  .copy-toolbar.expanded .format-section {
    opacity: 1;
    pointer-events: auto;
  }

  /* Format options */
  .format-options {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .format-option {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Scrollbar styling */
  .copy-toolbar::-webkit-scrollbar {
    width: 6px;
  }

  .copy-toolbar::-webkit-scrollbar-track {
    background: transparent;
  }

  .copy-toolbar::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
  }

  .copy-toolbar::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
  }
}

/* ==================== Small Mobile (≤375px) ==================== */
@media (max-width: 375px) {
  .copy-toolbar {
    padding: 12px 16px 20px;
  }

  .tool-button {
    padding: 14px 16px;
    font-size: 15px;
  }

  .copy-toolbar-title {
    font-size: 11px;
  }
}

/* ==================== Landscape Mobile ==================== */
@media (max-height: 500px) and (orientation: landscape) {
  .copy-toolbar {
    max-height: 85vh;
    padding: 12px 20px 16px;
  }

  .tool-button {
    padding: 10px 14px;
    min-height: 44px;
    margin-bottom: 6px;
  }

  .format-section {
    margin-top: 12px;
    padding-top: 12px;
  }
}

/* ==================== Dark Mode Support ==================== */
@media (prefers-color-scheme: dark) {
  :root {
    --toolbar-bg: rgba(31, 41, 55, 0.95);
    --toolbar-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --toolbar-border: rgba(255, 255, 255, 0.1);
    --button-hover-bg: rgba(55, 65, 81, 0.8);
    --button-active-bg: rgba(75, 85, 99, 0.8);
    --success-bg: rgba(22, 163, 74, 0.2);
    --success-color: #86efac;
    --success-icon: #22c55e;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --border-color: #374151;
  }

  .copy-toolbar::before {
    background: #6b7280;
  }

  .format-option {
    background: rgba(55, 65, 81, 0.5);
    color: #d1d5db;
  }

  .format-option:hover {
    background: rgba(22, 163, 74, 0.2);
    border-color: var(--primary-color);
  }

  .format-option.active {
    background: var(--primary-color);
    color: white;
  }
}

/* ==================== High Contrast Mode ==================== */
@media (prefers-contrast: high) {
  .copy-toolbar {
    background: white;
    border: 3px solid #000;
  }

  .tool-button {
    border: 2px solid transparent;
  }

  .tool-button:hover {
    background: #000;
    color: white;
    border-color: #000;
  }

  .tool-button.success {
    background: #0f5132;
    color: white;
    border-color: #0f5132;
  }

  .format-option {
    border-width: 3px;
  }
}

/* ==================== Reduced Motion ==================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .copy-toolbar,
  .tool-button,
  .copy-toast,
  .format-option {
    transition: none;
  }
}

/* ==================== Print Styles ==================== */
@media print {
  .copy-toolbar,
  .copy-toast-container {
    display: none !important;
  }
}

/* ==================== Keyboard Focus ==================== */
.tool-button:focus-visible,
.format-option:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(22, 163, 74, 0.1);
}

/* ==================== Scrollbar Styling (Mobile) ==================== */
@media (max-width: 768px) {
  .copy-toolbar::-webkit-scrollbar {
    width: 6px;
  }

  .copy-toolbar::-webkit-scrollbar-track {
    background: transparent;
  }

  .copy-toolbar::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
  }

  .copy-toolbar::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
  }
}

/* ==================== Smooth Scroll ==================== */
.copy-toolbar {
  scroll-behavior: smooth;
}

/* ==================== Loading State ==================== */
.tool-button.loading {
  pointer-events: none;
  opacity: 0.6;
}

.tool-button.loading .icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ==================== First-Time Hint ==================== */
.copy-tools-hint {
  position: fixed;
  z-index: 10001;
  opacity: 0;
  transform: scale(0.9);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: auto;
}

.copy-tools-hint.show {
  opacity: 1;
  transform: scale(1);
}

.hint-content {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  color: white;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(22, 163, 74, 0.3);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  max-width: 280px;
  position: relative;
  animation: bounce 2s ease infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.hint-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.hint-text {
  flex: 1;
}

.hint-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.2s;
}

.hint-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Arrow pointer */
.hint-content::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border: 8px solid transparent;
}

@media (min-width: 1025px) {
  /* Desktop: arrow points right */
  .hint-content::after {
    right: -16px;
    top: 50%;
    transform: translateY(-50%);
    border-left-color: #15803d;
  }
}

@media (max-width: 1024px) {
  /* Mobile/Tablet: arrow points down */
  .hint-content::after {
    bottom: -16px;
    left: 50%;
    transform: translateX(-50%);
    border-top-color: #15803d;
  }

  .hint-content {
    animation: none; /* Disable bounce on mobile */
  }
}

/* ==================== Improved Mobile Messaging ==================== */
@media (max-width: 1024px) {
  /* Better visual hint when collapsed */
  .copy-toolbar::after {
    content: '👆 Tap to open Copy & Share tools';
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
  }

  /* Add subtle pulse animation to attract attention */
  .copy-toolbar::before {
    animation: pulse 2s ease-in-out infinite;
  }

  @keyframes pulse {
    0%, 100% {
      background: #9ca3af;
      transform: scaleX(1);
    }
    50% {
      background: #6b7280;
      transform: scaleX(1.1);
    }
  }

  /* Primary buttons more prominent on mobile */
  .tool-button.primary {
    padding: 18px 20px;
    font-size: 16px;
    box-shadow: 0 3px 10px rgba(22, 163, 74, 0.25);
  }

  .tool-button.primary .icon {
    font-size: 22px;
  }

  /* Hide more options animations when not expanded */
  .copy-toolbar:not(.expanded) .more-options {
    display: none;
  }

  .copy-toolbar:not(.expanded) .more-toggle {
    opacity: 0;
    pointer-events: none;
  }

  .copy-toolbar.expanded .more-toggle {
    opacity: 1;
    pointer-events: auto;
  }
}
