/* =============================================
   Stories System - Estilos Otimizados
   ============================================= */

/* =============================================
   Variáveis
   ============================================= */
:root {
  --story-primary: #00636d;
  --story-gradient: linear-gradient(135deg, #004953, #00636d);
  --story-bg-dark: rgba(21, 31, 40, 0.95);
  --story-bg-light: rgba(255, 255, 255, 0.95);
  --story-text-dark: #ffffff;
  --story-text-light: #151f28;
  --story-border-radius: 12px;
  --story-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --story-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* =============================================
   Carrossel de Stories (Desktop)
   ============================================= */
.stories-desktop {
  display: flex;
  gap: 12px;
  padding: 16px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--story-primary) transparent;
  -webkit-overflow-scrolling: touch;
}

/* Tornar sticky em telas maiores para ficar fixo abaixo do header */
@media (min-width: 769px) {
  .stories-desktop {
    position: sticky;
    top: 72px; /* ajuste conforme altura do header */
    background: transparent;
    z-index: 40;
  }
}

.stories-desktop::-webkit-scrollbar {
  height: 6px;
}

.stories-desktop::-webkit-scrollbar-track {
  background: transparent;
}

.stories-desktop::-webkit-scrollbar-thumb {
  background: var(--story-primary);
  border-radius: 3px;
}

/* =============================================
   Story Cards
   ============================================= */
.story-card {
  position: relative;
  min-width: 100px;
  width: 100px;
  height: 160px;
  border-radius: var(--story-border-radius);
  overflow: hidden;
  cursor: pointer;
  transition: var(--story-transition);
  box-shadow: var(--story-shadow);
  flex-shrink: 0;
}

.story-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.story-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--story-transition);
}

.story-card:hover img {
  transform: scale(1.05);
}

.story-card .username {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  color: white;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Story Create Card */
.story-create {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--story-gradient);
  color: white;
  font-size: 48px;
  font-weight: 300;
  border: 2px dashed rgba(255, 255, 255, 0.5);
}

.story-create:hover {
  border-color: rgba(255, 255, 255, 0.8);
  background: linear-gradient(135deg, #005560, #007a89);
}

/* Story Count Badge */
.story-count-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--story-primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

/* =============================================
   Stories Inline Break (Mobile)
   ============================================= */
.stories-inline-break {
  display: flex;
  gap: 10px;
  padding: 16px 0;
  margin: 16px 0;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.stories-inline-break .story-card {
  scroll-snap-align: start;
}

.story-card-small {
  min-width: 80px;
  width: 80px;
  height: 120px;
}

/* =============================================
   Story Viewer Modal
   ============================================= */
.story-viewer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.95);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.story-viewer .stage {
  position: relative;
  width: 100%;
  max-width: 500px;
  height: 90vh;
  background: #000;
  border-radius: var(--story-border-radius);
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* =============================================
   Story Header
   ============================================= */
.story-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
  z-index: 100;
}

.story-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.story-profile-pic {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid white;
  object-fit: cover;
}

.story-username {
  color: white;
  font-weight: 600;
  font-size: 14px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.close-viewer-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 24px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  transition: var(--story-transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-viewer-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

/* =============================================
   Progress Bars
   ============================================= */
.story-progress {
  position: absolute;
  top: 60px;
  left: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  z-index: 100;
}

.story-progress .bar {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.story-progress .bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: var(--progress, 0%);
  background: white;
  border-radius: 2px;
  transition: width linear;
}

/* =============================================
   Content Container
   ============================================= */
.story-content-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.story-content-container img,
.story-content-container video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* =============================================
   Story Controls
   ============================================= */
.story-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: 16px;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
  z-index: 100;
}

.story-controls input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 14px;
  outline: none;
  transition: var(--story-transition);
}

.story-controls input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.story-controls input:focus {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

.story-control-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 20px;
  background: var(--story-primary);
  color: white;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: var(--story-transition);
}

.story-control-btn:hover {
  background: #007a89;
  transform: scale(1.05);
}

/* =============================================
   Navigation Areas
   ============================================= */
.story-navigation {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  z-index: 50;
  pointer-events: none;
}

.nav-area {
  flex: 1;
  pointer-events: all;
  cursor: pointer;
}

.nav-prev {
  cursor: w-resize;
}

.nav-next {
  cursor: e-resize;
}

/* =============================================
   Story Editor Modal
   ============================================= */
.story-editor-modal .story-editor-stage {
  padding: 24px;
  background: var(--story-bg-dark);
  max-height: 90vh;
  overflow-y: auto;
}

.story-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.story-editor-header h3 {
  color: white;
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.close-editor-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  font-size: 28px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  transition: var(--story-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.close-editor-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: rotate(90deg);
}

/* =============================================
   Editor Form
   ============================================= */
.story-editor-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.media-input-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.media-buttons-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.story-btn {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: var(--story-transition);
  white-space: nowrap;
}

.story-btn-camera,
.story-btn-video,
.story-btn-gallery {
  background: var(--story-gradient);
  color: white;
}

.story-btn-camera:hover,
.story-btn-video:hover,
.story-btn-gallery:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 99, 109, 0.4);
}

.story-btn-publish {
  background: var(--story-primary);
  color: white;
  padding: 14px;
  font-size: 16px;
  margin-top: 8px;
}

.story-btn-publish:hover {
  background: #007a89;
  transform: scale(1.02);
}

/* =============================================
   Media Preview
   ============================================= */
.media-preview {
  min-height: 200px;
  max-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--story-border-radius);
  overflow: hidden;
  position: relative;
}

.media-preview:empty {
  display: none;
}

/* =============================================
   Upload Progress
   ============================================= */
.upload-progress {
  background: rgba(255, 255, 255, 0.05);
  padding: 12px;
  border-radius: 8px;
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  height: 100%;
  background: var(--story-gradient);
  border-radius: 6px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  color: white;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* =============================================
   Text Input
   ============================================= */
#storyTextInput {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: var(--story-transition);
}

#storyTextInput::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

#storyTextInput:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--story-primary);
}

/* =============================================
   Mention Suggestions
   ============================================= */
.mention-suggestions {
  position: relative;
  background: rgba(0, 0, 0, 0.9);
  border-radius: 8px;
  overflow: hidden;
  max-height: 200px;
  overflow-y: auto;
}

.mention-suggestions:empty {
  display: none;
}

.mention-suggestion-item {
  padding: 10px 14px;
  color: white;
  cursor: pointer;
  transition: var(--story-transition);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mention-suggestion-item:last-child {
  border-bottom: none;
}

.mention-suggestion-item:hover {
  background: var(--story-primary);
}

/* =============================================
   Duration Selector
   ============================================= */
.duration-selector {
  display: flex;
  align-items: center;
  gap: 12px;
}

.duration-selector label {
  color: white;
  font-weight: 600;
  font-size: 14px;
}

#storyDurationSelect {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-size: 14px;
  outline: none;
  cursor: pointer;
  transition: var(--story-transition);
}

#storyDurationSelect:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--story-primary);
}

#storyDurationSelect option {
  background: #151f28;
  color: white;
}

/* =============================================
   Notifications
   ============================================= */
.story-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 14px 20px;
  border-radius: 8px;
  color: white;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 10001;
  opacity: 0;
  transform: translateX(400px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.story-notification.show {
  opacity: 1;
  transform: translateX(0);
}

.story-notification-error {
  background: linear-gradient(135deg, #d32f2f, #f44336);
}

.story-notification-success {
  background: linear-gradient(135deg, #388e3c, #4caf50);
}

.story-notification-info {
  background: linear-gradient(135deg, #1976d2, #2196f3);
}

/* =============================================
   Responsive Design
   ============================================= */
@media (max-width: 768px) {
  .stories-desktop {
    padding: 12px;
    gap: 8px;
  }
  
  .story-card {
    min-width: 85px;
    width: 85px;
    height: 140px;
  }
  
  .story-viewer .stage {
    width: 100%;
    height: 100vh;
    max-width: none;
    border-radius: 0;
  }
  
  .story-editor-modal .story-editor-stage {
    width: 100%;
    height: 100vh;
    max-height: none;
    border-radius: 0;
  }
  
  .media-buttons-group {
    grid-template-columns: 1fr;
  }
  
  .story-notification {
    right: 10px;
    left: 10px;
    width: auto;
  }
}

/* =============================================
   Theme Support
   ============================================= */
.theme-light .story-editor-modal .story-editor-stage {
  background: var(--story-bg-light);
}

.theme-light .story-editor-header h3,
.theme-light #storyTextInput,
.theme-light .duration-selector label,
.theme-light #storyDurationSelect {
  color: var(--story-text-light);
}

.theme-light #storyTextInput,
.theme-light #storyDurationSelect {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.2);
}

.theme-light #storyTextInput::placeholder {
  color: rgba(0, 0, 0, 0.5);
}

/* =============================================
   Loading States
   ============================================= */
.story-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 16px;
  text-align: center;
}

.story-loading::after {
  content: '';
  display: block;
  width: 40px;
  height: 40px;
  margin: 10px auto 0;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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