/* Mobile-first CSS for ArtPick */
/* Base styles */
:root {
  --primary-color: #2563eb;
  --secondary-color: #64748b;
  --danger-color: #dc2626;
  --background: #ffffff;
  --text-color: #1e293b;
  --border-color: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text-color);
  background: var(--background);
  line-height: 1.6;
  padding: 0;
  margin: 0;
}

h1 {
  font-size: 1.75rem;
  margin-bottom: 1rem;
  font-weight: 700;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

/* Voting Container - Mobile First */
.voting-container {
  max-width: 100vw;
  min-height: 100vh;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  overflow-x: hidden;
}

.voting-header {
  text-align: center;
  margin-bottom: 1rem;
  padding: 0.5rem;
  width: 100%;
}

.voting-header h1 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.instruction {
  color: var(--secondary-color);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.progress-status {
  margin-top: 1rem;
  padding: 1rem;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.progress-status.completed {
  background: #dcfce7;
  border: 2px solid #22c55e;
  color: #166534;
  font-weight: 500;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.remaining {
  color: var(--primary-color);
}

.progress-bar-voting {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill-voting {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), #22c55e);
  transition: width 0.3s ease;
}

.results-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: #166534;
  text-decoration: underline;
  font-weight: 600;
}

.voting-pair {
  width: 100%;
  max-width: 1200px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.image-choice-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  max-height: calc(100vh - 200px);
  align-items: center;
}

.vote-form {
  width: 100%;
  margin: 0;
}

.image-choice {
  background: none;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  transition: all 0.2s ease;
  overflow: hidden;
  max-height: calc(100vh - 220px);
}

.image-choice:hover {
  border-color: var(--primary-color);
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

.image-choice:active {
  transform: scale(0.98);
}

.image-wrapper {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 224px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  position: relative;
}

.voting-image {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 224px);
  object-fit: contain;
  display: block;
}

.image-placeholder {
  padding: 2rem;
  text-align: center;
  color: var(--secondary-color);
}

.voting-footer {
  margin-top: 2rem;
  text-align: center;
  color: var(--secondary-color);
  font-size: 0.875rem;
}

.completion-message,
.no-images {
  text-align: center;
  padding: 2rem;
}

/* Results Container */
.results-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.results-header {
  text-align: center;
  margin-bottom: 2rem;
  padding: 2rem 1rem;
}

.intro-text {
  font-size: 1.125rem;
  color: var(--secondary-color);
  margin: 1rem 0;
}

.voting-status {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  margin-top: 1rem;
  display: inline-block;
}

.voting-status.open {
  background: #dcfce7;
  color: #166534;
}

.voting-status.closed {
  background: #fee2e2;
  color: #991b1b;
}

.vote-link {
  color: inherit;
  text-decoration: underline;
}

.favorites-prompt {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 2px solid #f59e0b;
  border-radius: 8px;
  padding: 1rem 1.5rem;
  margin: 1rem 0;
  text-align: center;
}

.favorites-prompt p {
  margin: 0;
  font-size: 1.1rem;
}

.favorites-prompt-link {
  color: #d97706;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s ease;
}

.favorites-prompt-link:hover {
  color: #b45309;
  text-decoration: underline;
}

.ranking-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.ranking-item {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  gap: 1rem;
  align-items: center;
}

.rank-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
  min-width: 3rem;
  text-align: center;
}

.image-container {
  flex-shrink: 0;
  width: 80px;
  height: 142px;
  overflow: hidden;
  border-radius: 4px;
  background: #f8fafc;
}

.result-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-info {
  flex: 1;
}

.image-info h3 {
  margin-bottom: 0.25rem;
}

.image-info p {
  font-size: 0.875rem;
  color: var(--secondary-color);
  margin: 0.125rem 0;
}

.full-ranking {
  margin: 2rem 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
}

.full-ranking summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.5rem;
  list-style-position: outside;
}

.full-ranking summary:hover {
  color: var(--primary-color);
}

.ranking-list {
  margin-top: 1rem;
}

.ranking-row {
  display: grid;
  grid-template-columns: 40px 60px 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.ranking-row:last-child {
  border-bottom: none;
}

.image-thumb {
  width: 60px;
  height: 106px;
  overflow: hidden;
  border-radius: 4px;
  background: #f8fafc;
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.position {
  font-weight: 600;
  text-align: center;
}

.share-section {
  margin: 3rem 0;
  padding: 2rem;
  background: #f8fafc;
  border-radius: 8px;
}

.share-section h2 {
  text-align: center;
  margin-bottom: 1.5rem;
}

.social-share {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.share-button {
  display: block;
  padding: 0.75rem 1.5rem;
  background: var(--primary-color);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  text-align: center;
  font-weight: 500;
  transition: all 0.2s;
}

.share-button:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
}

.share-button.twitter {
  background: #1da1f2;
}

.share-button.linkedin {
  background: #0077b5;
}

.email-invite {
  margin-top: 2rem;
}

.email-invite h3 {
  margin-bottom: 1rem;
  text-align: center;
}

/* Forms */
.form-group {
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label {
  font-weight: 500;
  color: var(--text-color);
}

.form-input,
.form-checkbox {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 1rem;
  width: 100%;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-help {
  font-size: 0.875rem;
  color: var(--secondary-color);
  margin-top: 0.25rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

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

.btn-primary:hover {
  background: #1d4ed8;
}

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

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

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

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

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* Admin Styles */
.admin-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.admin-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border-color);
  overflow-x: auto;
  flex-wrap: nowrap;
}

.nav-link {
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: var(--secondary-color);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.2s;
}

.nav-link:hover {
  color: var(--primary-color);
}

.nav-link.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.dashboard-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.stat-card h3 {
  font-size: 0.875rem;
  color: var(--secondary-color);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
}

.dashboard-section {
  margin: 2rem 0;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  overflow-x: auto;
  display: block;
}

.admin-table thead {
  background: #f8fafc;
}

.admin-table th,
.admin-table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.admin-table th {
  font-weight: 600;
  color: var(--text-color);
}

.admin-table tr:hover {
  background: #f8fafc;
}

.url-cell input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.75rem;
  background: white;
}

.admin-actions {
  margin: 1.5rem 0;
}

.images-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.admin-image-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.image-preview {
  width: 100%;
  max-width: 200px;
  margin: 0 auto;
  height: 355px;
  overflow: hidden;
  border-radius: 4px;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-preview .placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--secondary-color);
}

.image-details {
  flex: 1;
}

.image-details h3 {
  margin-bottom: 0.5rem;
}

.image-details p {
  color: var(--secondary-color);
  font-size: 0.875rem;
  margin: 0.25rem 0;
}

.image-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-container {
  max-width: 600px;
  margin: 2rem auto;
  padding: 2rem;
  background: #f8fafc;
  border-radius: 8px;
}

.error-messages {
  background: #fee2e2;
  border: 1px solid #fecaca;
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  color: #991b1b;
}

.error-messages h3 {
  margin-bottom: 0.5rem;
}

.error-messages ul {
  list-style-position: inside;
  margin-left: 0;
}

.current-image {
  margin-top: 1rem;
  padding: 1rem;
  background: white;
  border-radius: 4px;
}

/* Tablet and up (≥ 640px) */
@media (min-width: 640px) {
  .voting-container {
    padding: 1.5rem;
  }

  .voting-header h1 {
    font-size: 1.75rem;
  }

  .instruction {
    font-size: 1rem;
  }

  .image-choice-container {
    grid-template-columns: 1fr 1fr;
    max-height: calc(100vh - 180px);
  }

  .image-choice {
    max-height: calc(100vh - 200px);
  }

  .image-wrapper {
    max-height: calc(100vh - 204px);
  }

  .voting-image {
    max-height: calc(100vh - 204px);
  }

  .ranking-grid {
    grid-template-columns: 1fr;
  }

  .social-share {
    flex-direction: row;
    justify-content: center;
  }

  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-table {
    display: table;
  }

  .images-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop (≥ 1024px) */
@media (min-width: 1024px) {
  .voting-header h1 {
    font-size: 2rem;
  }

  .voting-header {
    margin-bottom: 1.5rem;
  }

  .ranking-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .images-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .admin-image-card {
    flex-direction: row;
  }

  .image-preview {
    max-width: 150px;
    margin: 0;
  }
}

/* Authentication Pages */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
}

.auth-header {
  padding: 2rem;
  background: white;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
}

.auth-header h1 {
  margin-bottom: 0.5rem;
  color: var(--text-color);
}

.auth-header p {
  color: var(--secondary-color);
  font-size: 0.875rem;
  margin: 0;
}

.auth-form {
  padding: 2rem;
}

.auth-footer {
  padding: 1rem 2rem 2rem;
  text-align: center;
}

.auth-link {
  color: var(--primary-color);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}

.auth-link:hover {
  text-decoration: underline;
}

.btn-block {
  width: 100%;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* Bulk Upload */
.bulk-upload-container {
  margin: 2rem 0;
  padding: 2rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 2px dashed var(--border-color);
}

.bulk-upload-container h3 {
  margin-bottom: 1rem;
}

.file-drop-zone {
  padding: 3rem;
  text-align: center;
  background: white;
  border: 2px dashed var(--primary-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.file-drop-zone:hover {
  background: #f8fafc;
  border-color: #1d4ed8;
}

.file-drop-zone.dragging {
  background: #dbeafe;
  border-color: #1d4ed8;
}

.file-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.file-preview-item {
  position: relative;
  aspect-ratio: 9/16;
  border-radius: 4px;
  overflow: hidden;
  background: #f8fafc;
}

.file-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--danger-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-preview-remove:hover {
  background: #b91c1c;
}

.upload-progress {
  margin-top: 1rem;
  padding: 1rem;
  background: white;
  border-radius: 6px;
}

.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary-color);
  transition: width 0.3s ease;
}

/* Favorites Selection Page */
.favorites-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.favorites-header {
  text-align: center;
  margin-bottom: 2rem;
}

.favorites-header h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.favorites-header .instruction {
  color: var(--secondary-color);
  margin-bottom: 1rem;
}

.selection-counter {
  display: inline-block;
  background: linear-gradient(135deg, var(--primary-color), #22c55e);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 24px;
  font-weight: 600;
  font-size: 1.1rem;
}

.favorites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (max-width: 768px) {
  .favorites-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
  }
}

.favorite-item {
  position: relative;
  transition: transform 0.2s ease;
}

.favorite-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.favorite-item.selected {
  transform: scale(0.98);
}

.favorite-checkbox {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.favorite-label {
  display: block;
  cursor: pointer;
  border: 3px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: white;
  transition: all 0.2s ease;
}

.favorite-label:hover {
  border-color: var(--primary-color);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.favorite-checkbox:checked + .favorite-label {
  border-color: var(--primary-color);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.favorite-image-wrapper {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #f8fafc;
  overflow: hidden;
}

.favorite-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.selection-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 32px;
  height: 32px;
  background: var(--primary-color);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
  opacity: 0;
  transform: scale(0);
  transition: all 0.2s ease;
}

.favorite-checkbox:checked ~ .favorite-label .selection-badge {
  opacity: 1;
  transform: scale(1);
}

.image-info {
  padding: 0.75rem;
  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.image-info h3 {
  font-size: 0.9rem;
  margin: 0;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-rank {
  font-size: 0.85rem;
  color: var(--secondary-color);
  font-weight: 500;
  margin-left: 0.5rem;
}

.favorites-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 2rem;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: 12px;
}

.favorites-actions .btn {
  min-width: 200px;
}

@media (max-width: 768px) {
  .favorites-actions .btn {
    min-width: 100%;
  }
}

/* Top Favorites Section in Results */
.top-favorites {
  margin: 3rem 0;
  padding: 2rem;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-radius: 12px;
}

.top-favorites h2 {
  text-align: center;
  margin-bottom: 2rem;
  color: var(--text-color);
}

.favorites-ranking {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .favorites-ranking {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
  }
}

.favorites-item {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease;
}

.favorites-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.fav-rank-number {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  z-index: 1;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.fav-image-container {
  position: relative;
  aspect-ratio: 9 / 16;
  background: #f8fafc;
}

.fav-result-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.fav-info {
  padding: 1rem;
}

.fav-info h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.fav-count {
  color: #d97706;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.elo-ref {
  font-size: 0.85rem;
  color: var(--secondary-color);
}

.favorite-count {
  color: #d97706;
  font-weight: 600;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
