:root {
  /* Light Theme */
  --bg-color: #f4f4f9;
  --text-color: #333;
  --card-bg: #fff;
  --card-border: #ddd;
  --accent-color: #007bff;
  --accent-hover: #0056b3;
  --secondary-color: #6c757d;
  --danger-color: #dc3545;
  --border-radius: 8px;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  --nav-height: 60px;
}

[data-theme="dark"] {
  /* Dark Theme */
  --bg-color: #121212;
  --text-color: #e0e0e0;
  --card-bg: #1e1e1e;
  --card-border: #333;
  --accent-color: #bb86fc;
  --accent-hover: #9b65de;
  --secondary-color: #a0a0a0;
  --danger-color: #cf6679;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color 0.3s, color 0.3s;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  height: var(--nav-height);
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.logo {
  font-weight: bold;
  font-size: 1.2rem;
  color: var(--accent-color);
}

.header-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--border-radius);
  padding: 8px 16px;
  font-size: 0.9rem;
  transition: background-color 0.2s;
}

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

.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.btn-secondary {
  background-color: transparent;
  border: 1px solid var(--secondary-color);
  color: var(--text-color);
}

.btn-secondary:hover {
  background-color: rgba(128, 128, 128, 0.1);
}

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

.btn-icon {
  padding: 8px;
  background: transparent;
  color: var(--text-color);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

main {
  flex: 1;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.grid-layout {
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  gap: 20px;
  height: calc(100vh - var(--nav-height) - 240px); /* Adjust for gallery height */
  min-height: 500px;
}

.card {
  background-color: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  padding: 15px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

h2 {
  font-size: 1rem;
  margin-bottom: 15px;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 10px;
  color: var(--accent-color);
}

.input-group {
  margin-bottom: 15px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.85rem;
  color: var(--secondary-color);
}

input[type="text"],
input[type="number"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: inherit;
}

input[type="range"] {
  width: 100%;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-color);
  border-radius: var(--border-radius);
  margin-bottom: 15px;
  position: relative;
  overflow: hidden;
}

.preview-area img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: opacity 0.3s;
}

.placeholder {
  color: var(--secondary-color);
  text-align: center;
}

.status-bar {
  text-align: center;
  margin-top: 10px;
  font-size: 0.9rem;
  min-height: 1.2rem;
}

.progress-bar-container {
  width: 100%;
  height: 4px;
  background-color: var(--card-border);
  margin-top: 5px;
  border-radius: 2px;
  overflow: hidden;
  display: none;
}

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

.gallery-section {
  height: 200px;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
}

.gallery-grid {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 0;
  flex: 1;
}

.gallery-item {
  min-width: 150px;
  height: 150px;
  border-radius: var(--border-radius);
  overflow: hidden;
  position: relative;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  background-color: var(--card-bg);
}

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

.gallery-item:hover .gallery-overlay {
  opacity: 1;
}

.gallery-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  gap: 5px;
}

.gallery-overlay button {
  padding: 5px;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
}

.gallery-overlay button:hover {
  background: rgba(255, 255, 255, 0.4);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.8);
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: var(--card-bg);
  margin: auto;
  padding: 20px;
  border: 1px solid var(--card-border);
  width: 90%;
  max-width: 1000px;
  max-height: 90vh;
  border-radius: var(--border-radius);
  display: flex;
  gap: 20px;
  position: relative;
}

.modal-image {
  flex: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border-radius: 4px;
}

.modal-image img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
}

.modal-details {
  flex: 1;
  overflow-y: auto;
}

.close-modal {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 28px;
  font-weight: bold;
  color: var(--text-color);
  cursor: pointer;
  z-index: 10;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background-color: var(--card-bg);
  color: var(--text-color);
  padding: 12px 20px;
  border-radius: var(--border-radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  border-left: 4px solid var(--accent-color);
  animation: slideIn 0.3s ease;
  max-width: 300px;
}

.toast.error {
  border-left-color: var(--danger-color);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 900px) {
  .grid-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
  }

  .card {
    height: auto;
    max-height: 500px;
  }

  .modal-content {
    flex-direction: column;
  }

  .modal-image {
    height: 300px;
  }
}
