/**
 * Simple Voice Reader - Frontend Stylesheet
 * Sleek, glassmorphic layout, fully responsive and RTL-supportive.
 */

:root {
  --svr-font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Main widget container wrapper - fixed placement */
.svr-widget-container {
  position: fixed;
  z-index: 99999;
  font-family: var(--svr-font-family);
  direction: rtl;
  text-align: right;
  box-sizing: border-box;
}

.svr-widget-container * {
  box-sizing: border-box;
}

/* Position mapping classes */
.svr-pos-left {
  bottom: var(--svr-offset-y, 24px);
  left: var(--svr-offset-x, 24px);
}
.svr-pos-right {
  bottom: var(--svr-offset-y, 24px);
  right: var(--svr-offset-x, 24px);
}

/* Floating action button */
.svr-floating-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--svr-size, 52px);
  height: var(--svr-size, 52px);
  background-color: var(--svr-bg-color, #111111);
  color: var(--svr-icon-color, #ffffff);
  border: none;
  border-radius: var(--svr-border-radius, 50%);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease, background-color 0.2s ease;
  padding: 0;
  margin: 0;
}

/* If label is displayed on the floating button */
.svr-floating-button.svr-has-label {
  width: auto;
  min-width: var(--svr-size, 52px);
  padding: 0 18px;
  gap: 8px;
}

.svr-floating-button:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}

.svr-floating-button:active {
  transform: scale(0.96);
}

/* Focus visibility for accessibility */
.svr-floating-button:focus-visible,
.svr-panel-close-btn:focus-visible,
.svr-action-btn:focus-visible,
.svr-ctrl-btn:focus-visible {
  outline: 3px solid #6366f1;
  outline-offset: 3px;
}

/* SVG icons within the button */
.svr-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
  display: block;
  flex-shrink: 0;
}

.svr-btn-text {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

/* Reader Panel - Premium glassmorphism card */
.svr-panel {
  position: absolute;
  width: 380px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.12), 0 5px 15px rgba(0, 0, 0, 0.06);
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: scale(0.92) translateY(10px);
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
  z-index: 100000;
}

/* Panel open state */
.svr-panel.svr-panel-open {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transform: scale(1) translateY(0);
}

/* Position alignment relative to the container */
.svr-pos-left .svr-panel {
  bottom: calc(var(--svr-size, 52px) + 14px);
  left: 0;
  transform-origin: bottom left;
}
.svr-pos-right .svr-panel {
  bottom: calc(var(--svr-size, 52px) + 14px);
  right: 0;
  transform-origin: bottom right;
}

/* Header style inside the panel */
.svr-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  padding-bottom: 12px;
}

.svr-panel-title {
  font-size: 18px;
  font-weight: 700;
  color: #1f2937;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.svr-panel-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 18px;
  background-color: var(--svr-bg-color, #111111);
  border-radius: 2px;
}

/* Panel Close Button */
.svr-panel-close-btn {
  background: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
  padding: 0;
}

.svr-panel-close-btn:hover {
  background-color: rgba(0, 0, 0, 0.05);
  color: #111111;
}

/* Panel Options/Actions list */
.svr-panel-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Main action button styles (Read Article, Read Menu, etc.) */
.svr-action-btn {
  width: 100%;
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #374151;
  text-align: right;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 12px;
}

.svr-action-btn .svr-btn-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  opacity: 0.7;
}

.svr-action-btn:hover {
  background: var(--svr-bg-color, #111111);
  color: var(--svr-icon-color, #ffffff);
  border-color: var(--svr-bg-color, #111111);
  transform: translateY(-1px);
}

.svr-action-btn:active {
  transform: translateY(1px);
}

/* Controls section (Stop, Resume, Replay) */
.svr-panel-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.svr-ctrl-btn {
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 13px;
  font-weight: 600;
  color: #4b5563;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.svr-ctrl-btn .svr-btn-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.svr-ctrl-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #111111;
  border-color: rgba(0, 0, 0, 0.12);
}

.svr-ctrl-btn.svr-btn-stop:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fca5a5;
}

/* Disabled states for playback controls */
.svr-ctrl-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* Speed segment selector settings */
.svr-panel-settings {
  margin-top: 8px;
  padding: 4px 0;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.svr-setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.svr-setting-label {
  font-size: 13px;
  font-weight: 600;
  color: #4b5563;
}

.svr-speed-options {
  display: flex;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 8px;
  padding: 2px;
}

.svr-speed-btn {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #4b5563;
  cursor: pointer;
  transition: all 0.2s ease;
}

.svr-speed-btn:hover {
  color: #111111;
}

.svr-speed-btn.svr-active {
  background: var(--svr-bg-color, #111111);
  color: var(--svr-icon-color, #ffffff);
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Footer Status Bar styling */
.svr-panel-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.svr-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #9ca3af; /* Gray ready state */
  display: inline-block;
  transition: background-color 0.3s ease;
}

.svr-status-dot.svr-status-speaking {
  background-color: #10b981; /* Green reading state */
  animation: svrPulse 1.8s infinite ease-in-out;
}

.svr-status-dot.svr-status-paused {
  background-color: #f59e0b; /* Orange paused state */
  animation: svrPulsePaused 1.8s infinite ease-in-out;
}

.svr-status-dot.svr-status-error {
  background-color: #ef4444; /* Red error state */
}

.svr-status-text {
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
}

@keyframes svrPulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

@keyframes svrPulsePaused {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 6px rgba(245, 158, 11, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
  }
}

/* Inline button styles */
.svr-inline-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  font-family: var(--svr-font-family, inherit);
  margin: 4px;
}

.svr-inline-button:hover {
  background-color: var(--svr-bg-color, #111111);
  color: var(--svr-icon-color, #ffffff);
  border-color: var(--svr-bg-color, #111111);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}

.svr-inline-button:active {
  transform: translateY(1px);
}

/* Interactive area selection styles */
body.svr-select-mode * {
  cursor: crosshair !important;
}

.svr-hover-target {
  outline: 3px solid var(--svr-bg-color, #111111) !important;
  outline-offset: 2px !important;
  transition: outline 0.1s ease !important;
}

/* Panel Readable Sections List styles */
.svr-panel-sections-wrap {
  margin-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  padding-top: 14px;
}

.svr-sections-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #4b5563;
  margin-bottom: 8px;
}

.svr-sections-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 140px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Custom scrollbar for sections list */
.svr-sections-list::-webkit-scrollbar {
  width: 4px;
}
.svr-sections-list::-webkit-scrollbar-track {
  background: transparent;
}
.svr-sections-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 2px;
}

.svr-section-item-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  background-color: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: 8px;
  color: #1f2937;
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.svr-section-item-btn:hover {
  background-color: var(--svr-bg-color, #111111);
  color: var(--svr-icon-color, #ffffff);
  border-color: var(--svr-bg-color, #111111);
}

.svr-section-item-btn::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  background-color: currentColor;
  border-radius: 50%;
  margin-left: 8px;
  flex-shrink: 0;
}

/* RESPONSIVE DESIGN */
@media (max-width: 768px) {
  /* Positioning shifts for mobile based on settings */
  .svr-pos-left {
    bottom: var(--svr-mobile-offset-y, 16px);
    left: var(--svr-mobile-offset-x, 16px);
  }
  .svr-pos-right {
    bottom: var(--svr-mobile-offset-y, 16px);
    right: var(--svr-mobile-offset-x, 16px);
  }

  /* Full screen-ish mobile panel */
  .svr-widget-container .svr-panel {
    position: fixed;
    width: calc(100% - 32px);
    left: 16px !important;
    right: 16px !important;
    bottom: 16px !important;
    top: auto !important;
    transform-origin: bottom center !important;
    transform: scale(0.95) translateY(20px);
    border-radius: 16px;
    z-index: 100001;
  }

  .svr-widget-container .svr-panel.svr-panel-open {
    transform: scale(1) translateY(0);
  }
}
