:root {
  --border-color: #444;
  --background-color: #1a1a1a;
  --text-color: #f0f0f0;
  --primary-color: #007bff;
  --secondary-color: #333;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  overflow: hidden;
}

/* --- Initial Loading State --- */
.global-loader {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

body.is-loading .app-container,
body.is-loading .login-overlay {
  display: none;
}

.global-loader {
  display: none;
}

/* --- Main App Container --- */
/* By default, the main app is hidden */
.app-container {
  display: none;
  width: 100%;
  height: 100%; /* FIX #1: Ensure it takes full height when displayed */
}
/* We will show it with JS if the user is authenticated */
.app-container.visible {
  display: flex;
}

/* --- Columns --- */
.controls-column {
  width: 550px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid var(--border-color);
}

.result-column {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

header h1 {
  margin: 0;
}

.control-section h2 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 1.1em;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 5px;
}

/* --- Layout Reorganization --- */
.upload-section {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.bottom-controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* --- Image Upload & Fitting --- */
.image-upload-box {
  flex-grow: 1;
  width: 100%;
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background-color: var(--secondary-color);
  cursor: pointer;
}
.image-upload-box span {
  font-size: 40px;
  color: #555;
}
.image-upload-box .preview-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

/* --- Pose and View Options --- */
.options-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.option-title {
  font-weight: bold;
  color: #aaa;
}
.options-group input[type="radio"] {
  display: none;
}
.options-group input[type="radio"] + label {
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--secondary-color);
  cursor: pointer;
  transition: all 0.2s ease-in-out;
}
.options-group input[type="radio"]:checked + label {
  background-color: var(--primary-color);
  color: white;
  box-shadow: 0 0 10px var(--primary-color);
}

/* --- Clothing Gallery Styling --- */
.clothing-gallery-container {
  width: 100%;
  overflow-x: auto;
}
.clothing-gallery {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  padding-bottom: 10px;
}
.clothing-item {
  flex-shrink: 0;
  width: 100px;
  height: 100px;
  border: 5px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  overflow: hidden;
  background: #fff;
  box-sizing: border-box;
}
.clothing-item.selected {
  border-color: var(--primary-color);
  box-shadow: 0 0 15px var(--primary-color);
}
.clothing-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* --- Try On Button --- */
#tryOnBtn {
  padding: 15px;
  font-size: 18px;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s;
}
#tryOnBtn:hover {
  background-color: #0056b3;
}

/* --- Result Panel & Fitting --- */
.image-preview-large {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background-color: var(--secondary-color);
}
.preview-image-large {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: none;
}
.placeholder-text {
  color: #555;
  font-size: 1.2em;
}
.loader {
  border: 5px solid #f3f3f3;
  border-top: 5px solid var(--primary-color);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* --- Login Overlay Styles --- */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease-in-out;
}

/* JS will use this to hide the overlay */
.login-overlay.hidden {
  display: none;
}

.login-box {
  background-color: var(--secondary-color);
  padding: 40px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  text-align: center;
  width: 350px;
}
.login-box h1 {
  margin-top: 0;
}
#loginForm {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
#loginForm input,
#loginForm button {
  padding: 12px;
  border-radius: 5px;
  border: 1px solid var(--border-color);
  background-color: #444;
  color: var(--text-color);
  font-size: 16px;
}
#loginForm button {
  background-color: var(--primary-color);
  border: none;
  cursor: pointer;
  font-weight: bold;
}
.login-error {
  color: #ff5c5c;
  min-height: 20px;
  margin: 0;
}
