/* Basic Reset & Globals */
:root {
  --background-color: #f8f9fa;
  --surface-color-rgba: 255, 255, 255; /* For glass effect */
  --primary-color: #dc4325;
  --primary-color-alt: #dc4326;
  --primary-color-hover: #e46146;
  --text-color: #212529;
  --text-muted-color: #6c757d;
  --border-color-light: rgba(255, 255, 255, 0.4);
  --border-color-dark: rgba(0, 0, 0, 0.1);
  --shadow-color-rgba: 100, 100, 111;
  --font-family: 'Inter', sans-serif;
  --error-color: #d90429;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--background-color);
  color: var(--text-color);
  line-height: 1.6;
  /* Add a subtle gradient background for the glass effect to be more visible */
  background-image: linear-gradient(120deg, #fdfbfb 0%, #ebedee 100%);
}

.hidden {
    display: none !important;
}

/* Auth Container */
#auth-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

/* App Container */
#root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 2rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}

.header-content {
    text-align: left;
    flex-grow: 1;
}

header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(45deg, var(--primary-color), var(--primary-color-alt));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-fill-color: transparent;
  text-align: center;
}

header p {
    color: var(--text-muted-color);
    max-width: 600px;
    margin: 0.5rem auto 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: rgba(var(--surface-color-rgba), 0.65);
    border-radius: 12px;
    border: 1px solid var(--border-color-light);
    margin-left: auto;
}

.user-info span {
    font-weight: 500;
    color: var(--text-muted-color);
}

#sign-out-button {
    background: none;
    border: 1px solid var(--border-color-dark);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    color: var(--primary-color);
    transition: all 0.2s ease;
}

#sign-out-button:hover {
    background-color: rgba(220, 67, 37, 0.1);
    border-color: var(--primary-color);
}

/* API Key Section */
.api-key-section {
    background: rgba(var(--surface-color-rgba), 0.5);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    margin-bottom: 2rem;
    border: 1px solid var(--border-color-light);
    box-shadow: 0 2px 10px rgba(var(--shadow-color-rgba), 0.05);
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.api-key-section label {
    font-weight: 600;
    color: var(--text-color);
    white-space: nowrap;
}

.api-key-section input {
    flex-grow: 1;
    min-width: 250px; /* Ensures input is not too small when wrapping */
}


/* Main Content Layout */
main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  flex: 1;
  min-height: 0; /* Prevents flexbox overflow issues */
}

/* Liquid Glass Panels */
.controls-panel, .results-panel {
  background: rgba(var(--surface-color-rgba), 0.65);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px); /* For Safari */
  border-radius: 16px;
  border: 1px solid var(--border-color-light);
  box-shadow: 0 4px 20px rgba(var(--shadow-color-rgba), 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Contains children */
}
.controls-panel {
    padding: 1.5rem;
}

.form-content {
    overflow-y: auto; /* Make form scrollable */
    padding-right: 10px; /* For scrollbar */
    margin-right: -10px;
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color-dark);
  margin-bottom: 1rem;
  flex-shrink: 0;
  overflow-x: auto; /* Allow horizontal scrolling */
}

/* Subtle scrollbar for tabs */
.tabs::-webkit-scrollbar {
  height: 6px;
}
.tabs::-webkit-scrollbar-track {
  background: transparent;
}
.tabs::-webkit-scrollbar-thumb {
  background-color: var(--border-color-dark);
  border-radius: 10px;
}


.tab-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-muted-color);
  font-size: 1rem;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease-in-out;
  white-space: nowrap;
}

.tab-button svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

.tab-button.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    color: var(--text-muted-color);
    font-size: 0.9rem;
    font-weight: 500;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Form Elements */
.form-description {
    color: var(--text-muted-color);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    text-align: center;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-muted-color);
}

select,
textarea, 
input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-color-dark);
  background-color: rgba(255, 255, 255, 0.4);
  color: var(--text-color);
  font-family: var(--font-family);
  font-size: 1rem;
  transition: all 0.2s ease;
}

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 12px;
}

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

select:focus,
textarea:focus, 
input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(220, 67, 37, 0.2);
  background-color: rgba(255, 255, 255, 0.7);
}

/* Form Validation States */
.has-error {
  border-color: var(--error-color) !important;
}

select:focus.has-error,
textarea:focus.has-error, 
input[type="text"]:focus.has-error,
input[type="password"]:focus.has-error {
  border-color: var(--error-color) !important;
  box-shadow: 0 0 0 3px rgba(217, 4, 41, 0.2) !important;
}

.error-text {
  color: var(--error-color);
  font-size: 0.85rem;
  margin-top: 0.4rem;
}


/* Dynamic Field */
.dynamic-field-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.dynamic-field-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.dynamic-field-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: rgba(255, 255, 255, 0.3);
    padding: 0.5rem 0.5rem 0.5rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border-color-dark);
}

.dynamic-field-item span {
    flex-grow: 1;
    padding-right: 0.5rem;
    word-break: break-word;
}

.delete-item-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: 50%;
    color: var(--text-muted-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s, background-color 0.2s;
    flex-shrink: 0;
}

.delete-item-btn:hover {
    color: var(--error-color);
    background-color: rgba(217, 4, 41, 0.1);
}

.add-item-group {
    display: flex;
    gap: 0.5rem;
}

.add-item-input {
    flex-grow: 1;
    width: 100%; /* For flex calculation */
}

.add-item-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 1.25rem;
    background-color: #e9ecef;
    color: var(--text-color);
    border: 1px solid var(--border-color-dark);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-weight: 500;
}

.add-item-btn svg {
    width: 16px;
    height: 16px;
}

.add-item-btn:hover {
    background-color: #dee2e6;
}

/* Generate Button */
.generate-button {
  width: 100%;
  padding: 0.8rem;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: auto; /* Pushes button to bottom */
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background-image: linear-gradient(to right, var(--primary-color) 0%, var(--primary-color-alt) 100%);
  box-shadow: 0 2px 8px rgba(220, 67, 37, 0.3);
}

.generate-button svg {
    width: 18px;
    height: 18px;
}

.generate-button:hover:not(:disabled) {
  box-shadow: 0 4px 12px rgba(220, 67, 37, 0.4);
  transform: translateY(-2px);
}

.generate-button:disabled {
  background-image: none;
  background-color: #adb5bd;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
  color: #e9ecef;
}

/* File Upload & Image Preview */
.file-upload-container input[type="file"] {
    background-color: #e9ecef;
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
}
.file-upload-container input[type="file"]::file-selector-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
}

.image-preview {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem;
    background-color: rgba(255, 255, 255, 0.4);
    border-radius: 8px;
}
.image-preview img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
}
.image-preview span {
    flex: 1;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.remove-image-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: 50%;
    color: var(--text-muted-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s, background-color 0.2s;
}
.remove-image-btn:hover {
    color: var(--error-color);
    background-color: rgba(217, 4, 41, 0.1);
}


/* Results Panel */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.5rem 0.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color-dark);
    flex-shrink: 0;
}

.results-header .tabs {
    margin-bottom: 0;
    border-bottom: none;
}

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

.action-button {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background-color: rgba(255,255,255,0.2);
    color: var(--text-color);
    border: 1px solid var(--border-color-dark);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-weight: 500;
    font-size: 0.9rem;
}

.action-button:hover:not(:disabled) {
    background-color: rgba(255,255,255,0.5);
}

.action-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-button svg {
    width: 14px;
    height: 14px;
}

.output-content-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    overflow: hidden;
}

.json-error-message {
    background-color: rgba(217, 4, 41, 0.1);
    color: var(--error-color);
    padding: 0.75rem;
    border-radius: 8px 8px 0 0;
    border: 1px solid var(--error-color);
    border-bottom: none;
    font-size: 0.9rem;
    font-family: 'Courier New', Courier, monospace;
    white-space: pre-wrap;
    word-break: break-all;
}

.output-editor {
    flex-grow: 1;
    width: 100%;
    resize: none;
    border: 1px solid var(--border-color-dark);
    border-radius: 8px;
    padding: 1rem;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95rem;
    line-height: 1.5;
    background-color: rgba(255, 255, 255, 0.4);
    color: var(--text-color);
    transition: all 0.2s ease;
}

.output-editor:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(220, 67, 37, 0.2);
}

.output-editor.has-error {
    border-color: var(--error-color);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}
.output-editor:focus.has-error {
  box-shadow: 0 0 0 3px rgba(217, 4, 41, 0.2) !important;
}

.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted-color);
  text-align: center;
  padding: 1rem;
}

.placeholder.error-message {
    color: var(--error-color);
    font-weight: 500;
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem 0 1rem;
  color: var(--text-muted-color);
  font-size: 0.9rem;
}

footer a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 600;
}

footer a:hover {
  text-decoration: underline;
}


/* Loaders */
.loader {
    border: 4px solid var(--border-color-dark);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

.loader-small {
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-top: 3px solid white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    max-height: none;
  }
  
  header {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }

  .user-info {
    margin-left: 0;
  }
}

@media (max-width: 600px) {
  #root {
    padding: 1rem;
  }

  header h1 {
    font-size: 2rem;
  }
  
  .results-header {
      flex-direction: column;
      align-items: stretch;
      gap: 0.5rem;
      padding: 0.5rem;
  }
  .results-actions {
      justify-content: space-around;
  }

  .tab-button {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  .tab-button span {
    display: none; /* Hide text on very small screens, show only icon */
  }

  .tab-button {
    padding: 0.75rem;
  }
}