/* ============================================
   Audioguide Web App - Styles
   Primary Color: #7c3aed (Purple)
   ============================================ */

:root {
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --primary-light: #a78bfa;
  --bg: #fafafa;
  --text: #1f2937;
  --text-light: #6b7280;
  --white: #ffffff;
  --black: #000000;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============================================
   Loading Screen
   ============================================ */

.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
}

.loading-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: pulse 1.5s ease-in-out infinite;
}

.loading-logo img,
.loading-logo svg {
  width: 120px;
  height: 120px;
  object-fit: contain;
}

.loading-logo .loading-text {
  color: white;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 2px;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.8;
  }
}

/* ============================================
   Language Selector
   ============================================ */

.language-selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--white);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
  opacity: 0;
  transform: translateY(-10px);
  animation: titleFadeIn 0.8s ease-out forwards, titleGlow 4s ease-in-out infinite 1s;
}

@keyframes titleFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes titleGlow {
  0%, 100% {
    opacity: 1;
    text-shadow: none;
  }
  50% {
    opacity: 0.85;
    text-shadow: 0 0 20px rgba(124, 58, 237, 0.3);
  }
}

.lang-toggle {
  display: flex;
  background: var(--bg);
  border-radius: 9999px;
  padding: 4px;
  gap: 4px;
}

.lang-btn {
  padding: 8px 20px;
  border: none;
  background: transparent;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: var(--transition);
}

.lang-btn.active {
  background: var(--primary);
  color: var(--white);
}

.lang-btn:hover:not(.active) {
  background: rgba(124, 58, 237, 0.1);
  color: var(--primary);
}

/* ============================================
   Object Grid
   ============================================ */

.app-container {
  opacity: 0;
  transition: opacity 0.5s ease;
}

.app-container.visible {
  opacity: 1;
}

.object-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
}

@media (min-width: 768px) {
  .object-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px;
  }
}

@media (min-width: 1024px) {
  .object-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
  }
}

.object-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.9);
  animation: fadeInUp 0.4s ease forwards;
  box-shadow: var(--shadow);
}

.object-item:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
}

@keyframes fadeInUp {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.object-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.object-item:hover img {
  transform: scale(1.05);
}

.object-number {
  position: absolute;
  top: 0;
  left: 0;
  width: 60%;
  height: 60%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 8vw, 48px);
  font-weight: 700;
  opacity: 0.5;
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.object-number.light {
  color: var(--white);
}

.object-number.dark {
  color: var(--black);
}

/* ============================================
   Detail View
   ============================================ */

.detail-view {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--white);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.detail-view.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.detail-header {
  display: flex;
  align-items: center;
  padding: 16px;
  background: var(--white);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.back-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  margin-right: 16px;
}

.back-btn:hover {
  background: var(--primary);
  color: var(--white);
}

.back-btn svg {
  width: 24px;
  height: 24px;
}

.detail-title-group {
  flex: 1;
}

.detail-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.detail-collection {
  font-size: 14px;
  color: var(--text-light);
  margin-top: 2px;
}

.detail-content {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.detail-image-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
}

.detail-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.play-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  transition: var(--transition);
}

.play-overlay:hover {
  background: rgba(0, 0, 0, 0.4);
}

.play-btn {
  width: 80px;
  height: 80px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.4);
  transition: var(--transition);
}

.play-btn.playing {
  animation: none;
}

.play-btn:not(.playing) {
  animation: pulsePlay 2s ease-in-out infinite;
}

@keyframes pulsePlay {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 8px 32px rgba(124, 58, 237, 0.4);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(124, 58, 237, 0.6);
  }
}

.play-btn:hover {
  transform: scale(1.1);
}

.play-btn svg {
  width: 36px;
  height: 36px;
  fill: var(--white);
  margin-left: 4px;
}

.play-btn.playing svg {
  margin-left: 0;
}

/* ============================================
   Audio Player
   ============================================ */

.audio-player {
  margin-top: 24px;
  padding: 20px;
  background: var(--bg);
  border-radius: 16px;
}

.progress-container {
  position: relative;
  height: 8px;
  background: rgba(124, 58, 237, 0.2);
  border-radius: 4px;
  cursor: pointer;
  padding: 10px 0;
  background-clip: content-box;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  width: 0%;
  transition: width 0.1s linear;
}

.progress-handle {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.progress-container:hover .progress-handle {
  opacity: 1;
}

.time-display {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 14px;
  color: var(--text-light);
  font-variant-numeric: tabular-nums;
}

/* ============================================
   Description
   ============================================ */

.detail-description {
  margin-top: 24px;
  padding: 20px;
  background: var(--bg);
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
}

/* ============================================
   Empty State
   ============================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-state svg {
  width: 80px;
  height: 80px;
  color: var(--text-light);
  margin-bottom: 20px;
  opacity: 0.5;
}

.empty-state p {
  color: var(--text-light);
  font-size: 16px;
}

/* ============================================
   CMS Styles
   ============================================ */

.password-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.password-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.password-box {
  background: var(--white);
  padding: 40px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 320px;
  width: 90%;
}

.password-box h2 {
  margin-bottom: 8px;
  color: var(--text);
}

.password-box p {
  margin-bottom: 24px;
  color: var(--text-light);
  font-size: 14px;
}

.password-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--bg);
  border-radius: 8px;
  font-size: 16px;
  text-align: center;
  transition: var(--transition);
}

.password-input:focus {
  outline: none;
  border-color: var(--primary);
}

.password-input.error {
  border-color: #ef4444;
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.cms-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.cms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--bg);
}

.cms-header h1 {
  font-size: 24px;
  color: var(--text);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: white;
}

.header-buttons {
  display: flex;
  gap: 12px;
}

@media (max-width: 600px) {
  .cms-header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }

  .header-buttons {
    flex-direction: column;
  }
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-overlay.active {
  opacity: 1;
  visibility: visible;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  color: white;
  margin-top: 16px;
  font-size: 16px;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
}

.btn-secondary:hover {
  background: #e5e7eb;
}

.btn-danger {
  background: #fee2e2;
  color: #dc2626;
}

.btn-danger:hover {
  background: #fecaca;
}

.btn svg {
  width: 18px;
  height: 18px;
}

/* Object Form */
.object-form {
  background: var(--white);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  display: none;
}

.object-form.active {
  display: block;
  animation: slideDown 0.3s ease;
  position: relative;
  z-index: 100;
}

/* Overlay when form is open */
body.form-open .object-list {
  position: relative;
}

body.form-open .object-list::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 50;
  pointer-events: auto;
}

body.form-open .object-card {
  pointer-events: none;
  opacity: 0.5;
  filter: grayscale(0.3);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

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

.form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
  padding: 10px 14px;
  border: 2px solid var(--bg);
  border-radius: 8px;
  font-size: 15px;
  transition: var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.file-input-wrapper {
  position: relative;
}

.file-input-wrapper input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.file-input-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border: 2px dashed var(--primary-light);
  border-radius: 8px;
  color: var(--primary);
  font-size: 14px;
  transition: var(--transition);
}

.file-input-label:hover {
  background: rgba(124, 58, 237, 0.05);
  border-color: var(--primary);
}

.file-input-label.has-file {
  border-style: solid;
  background: rgba(124, 58, 237, 0.1);
}

.audio-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.audio-input-row .file-input-wrapper {
  flex: 1;
}

.btn-play {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-play:hover {
  background: var(--primary-dark);
}

.btn-play:disabled {
  background: var(--text-light);
  cursor: not-allowed;
}

.btn-play.playing {
  background: var(--danger);
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--bg);
}

/* Object List */
.object-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.object-card {
  display: flex;
  align-items: center;
  background: var(--white);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  cursor: grab;
}

.object-card:active {
  cursor: grabbing;
}

.object-card.dragging {
  opacity: 0.5;
  transform: scale(1.02);
}

.object-card.drag-over {
  border: 2px dashed var(--primary);
}

.drag-handle {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px;
  cursor: grab;
  opacity: 0.4;
  transition: var(--transition);
}

.drag-handle:hover {
  opacity: 1;
}

.drag-handle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

.object-card-image {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  margin: 0 12px;
}

.object-card-info {
  flex: 1;
  min-width: 0;
}

.object-card-number {
  display: inline-block;
  background: var(--primary);
  color: var(--white);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}

.object-card-title {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.object-card-collection {
  font-size: 13px;
  color: var(--text-light);
}

.object-card-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg);
  color: var(--text);
}

.icon-btn:hover {
  background: var(--primary);
  color: var(--white);
}

.icon-btn.delete:hover {
  background: #dc2626;
}

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

/* Preview */
.image-preview {
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  margin-top: 8px;
}

/* Notifications */
.notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 16px 24px;
  background: var(--text);
  color: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  transform: translateY(100px);
  opacity: 0;
  transition: var(--transition);
  z-index: 1000;
}

.notification.show {
  transform: translateY(0);
  opacity: 1;
}

.notification.success {
  background: #059669;
}

.notification.error {
  background: #dc2626;
}

/* ============================================
   Utilities
   ============================================ */

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
