/* Base styles */
:root {
  --bg-color: #f8f9fa; /* Light gray */
  --text-color: #495057; /* Darker gray */
  --primary-color: #71a7d6; /* Low-saturation light blue */
  --primary-darker: #5b7ba8;
  --secondary-color: #e9ecef; /* Lighter gray */
  --accent-color-1: #f4a261; /* Morandi orange-ish */
  --accent-color-2: #e76f51; /* Morandi red-ish */
  --border-color: #dee2e6;
  --error-color: #dc3545;
  --success-color: #28a745;
  --shadow-color: rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  margin: 0;
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  line-height: 1.6;
}

header, footer {
  background-color: var(--secondary-color);
  padding: 0.8rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  border-radius: 0 0 12px 12px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap; /* Allow wrapping on smaller screens */
  box-shadow: 0 2px 6px var(--shadow-color);
  padding: 0.8rem 1.5rem;
}

header h1 {
  margin: 0;
  color: var(--primary-darker);
  font-size: 1.8rem;
  flex: 1;
  text-align: left;
}

header p {
  margin: 0;
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
}

#user-info {
  font-size: 0.9em;
  background-color: rgba(255, 255, 255, 0.8);
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  box-shadow: 0 1px 3px var(--shadow-color);
  flex: 1;
  text-align: right;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: nowrap;
}

main {
  flex-grow: 1;
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

section {
  background-color: #fff;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 3px 8px var(--shadow-color);
}

h2 {
  color: var(--primary-darker);
  margin-top: 0;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

/* Forms & Buttons */
input[type="number"], input[type="file"] {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  margin-right: 0.5rem;
  font-size: 1rem;
  transition: border-color 0.2s ease-in-out;
}

input[type="number"]:focus, input[type="file"]:focus {
  outline: none;
  border-color: var(--primary-color);
}

button {
  padding: 0.6rem 1.2rem;
  background-color: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background-color 0.2s ease-in-out, transform 0.1s ease, box-shadow 0.2s ease-in-out;
  box-shadow: 0 2px 4px var(--shadow-color);
}

button:hover {
  background-color: var(--primary-darker);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

button:hover {
  background-color: var(--primary-darker);
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  background-color: var(--secondary-color);
  color: #aaa;
  cursor: not-allowed;
}

#logout-button {
    background-color: var(--accent-color-2);
    margin-left: 0.5rem;
}
#logout-button:hover {
    background-color: #c75a41;
}

#revoke-all-votes-button {
    background-color: var(--accent-color-1);
    margin-left: 0.5rem;
}
#revoke-all-votes-button:hover {
    background-color: #d8894a;
}

/* Login Section */
#login-section {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 90%;
  max-width: 500px;
  margin: 0 auto;
}

#login-section h2 {
  margin-bottom: 1.5rem;
}

#login-section p {
  margin-bottom: 1.2rem;
  font-size: 0.95rem;
}

#login-section input[type="number"], #login-section input[type="text"], #login-section input[type="password"] {
  width: 100%;
  margin-bottom: 1.2rem;
  padding: 0.7rem;
  border-radius: 8px;
}

#login-section button {
  width: 100%;
  margin-top: 0.8rem;
  margin-bottom: 1.2rem;
  padding: 0.7rem 1.4rem;
  border-radius: 24px;
}

#admin-login-toggle {
  margin-top: 1.2rem;
}

#admin-login-section {
  width: 100%;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

#admin-login-section h3 {
  margin-top: 0;
  margin-bottom: 1.2rem;
  font-size: 1.1rem;
}

/* Gallery Section */
#gallery-controls {
  margin-bottom: 2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1rem;
}

#gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.gallery-item {
  background-color: var(--secondary-color);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 3px 8px var(--shadow-color);
  transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

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

.gallery-item img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9; /* Enforce 16:9 aspect ratio */
  object-fit: cover; /* Crop image to fit */
  background-color: #eee; /* Placeholder bg */
}

.image-info {
  padding: 1rem;
  font-size: 0.9em;
}

.image-info p {
  margin: 0.5rem 0;
}

.image-info button, .image-info a {
    margin: 0.3rem 0.5rem;
    font-size: 0.85em;
    padding: 0.4rem 0.8rem;
}

a.download-button {
    display: inline-block;
    text-decoration: none;
    background-color: var(--accent-color-1);
    color: #fff;
    border-radius: 28px;
    transition: background-color 0.2s ease-in-out;
}

a.download-button:hover {
    background-color: #d8894a;
}

/* Upload Section */
#upload-section {
  /* Styles specific to upload if needed */
}

/* Cropping Modal Styles */
.modal {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.modal-content {
  background-color: #fff;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  max-width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
}

.img-container {
  margin-bottom: 1rem;
  max-height: 60vh; /* Limit image container height */
  overflow: hidden; /* Hide parts of image outside container */
}

/* Cropper.js requires the image to be display: block */
#image-to-crop {
  display: block;
  /* Set max-width to prevent Cropper.js issues on large images */
  max-width: 100%;
}

.modal-actions {
    margin-top: 1.5rem;
}

.modal-actions button {
    margin: 0 0.8rem;
    padding: 0.6rem 1.2rem;
}

#cancel-crop-button {
    background-color: var(--text-color);
}
#cancel-crop-button:hover {
    background-color: #6c757d;
}

/* Utility classes */
.hidden {
  display: none !important; /* Use important to override potential conflicts */
}

.error-message {
  color: var(--error-color);
  font-size: 0.9em;
  margin-top: 0.5rem;
}

.status-message {
  color: var(--success-color);
  font-size: 0.9em;
  margin-top: 0.5rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  header {
    padding: 0.8rem;
    flex-direction: column;
    align-items: center;
  }
  header h1 {
      margin-bottom: 0.3rem;
      font-size: 1.5rem;
  }
  header p {
      font-size: 0.8rem;
  }
  #user-info {
      margin-top: 0.3rem;
      padding: 0.3rem 0.6rem;
      font-size: 0.8em;
  }
  main {
    padding: 1rem;
  }
  section {
    padding: 1.2rem;
    margin-bottom: 1.2rem;
  }
  #gallery-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.2rem;
  }
  input[type="number"], input[type="file"], button {
      width: 100%;
      margin-bottom: 0.8rem;
      box-sizing: border-box;
      font-size: 0.9rem;
  }
  input[type="number"], input[type="file"] {
      margin-right: 0;
      padding: 0.6rem;
  }
button {
  padding: 0.7rem 1.4rem;
  background-color: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 28px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background-color 0.2s ease-in-out, transform 0.1s ease, box-shadow 0.2s ease-in-out;
  box-shadow: 0 2px 4px var(--shadow-color);
}
}
