/* =================
   GLOBAL RESET & BODY
   ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  display: flex; height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: #f5f7fa; color: #333;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 220px; background: #2f3e50;
  display: flex; flex-direction: column;
}
.sidebar h2 {
  color: #fff; text-align: center;
  padding: 20px 0; font-size: 1.2rem;
}
.sidebar nav ul { list-style: none; }
.sidebar nav a {
  display: block; text-decoration: none;
  color: #b8c7ce; padding: 12px 20px;
  transition: background 0.2s, color 0.2s;
}
.sidebar nav a:hover,
.sidebar nav a.active {
  background: #3a4a5a; color: #fff;
}

/* ===== MAIN AREA ===== */
.main {
  flex: 1; overflow-y: auto; padding: 30px;
}
.main header h1 {
  font-size: 1.6rem; margin-bottom: 25px;
}
.page-content { max-width: 800px; margin: 0 auto; }

/* ===== FORM CARD ===== */
.form-card {
  background: #fff; border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  padding: 20px 25px; margin-bottom: 30px;
}
.form-card h2 {
  font-size: 1.3rem; margin-bottom: 15px; color: #444;
}

/* ===== INPUTS ===== */
.form-card label {
  display: block; margin-bottom: 6px;
  font-weight: 500; color: #555;
}
.form-card input[type="text"],
.form-card input[type="number"],
.form-card select,
.form-card textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid #ccd0d5; border-radius: 4px;
  font-size: 1rem; margin-bottom: 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-card textarea {
  min-height: 100px; resize: vertical;
}
.form-card input:focus,
.form-card select:focus,
.form-card textarea:focus {
  border-color: #4096ee;
  box-shadow: 0 0 0 2px rgba(64,150,238,0.2);
  outline: none;
}

/* ===== UPLOAD BOX ===== */
.upload-box {
  width: 100%;
  max-width: 180px;
  min-width: 150px;
  min-height: 230px;
  max-height: 230px;
  border: 2px dashed #ccd0d5; border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  text-align: center;
  color: #888; font-size: 0.95rem;
  cursor: pointer; margin-bottom: 18px;
  background: #fff;
  transition: background 0.2s, border-color 0.2s;
}

.upload-box input[type="file"] {
  position: absolute; top:0; left:0;
  width:100%; height:100%; opacity:0; cursor:pointer;
  z-index: 2;
}

.upload-box .upload-text {
  position: absolute;
  left: 0; top: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center;
  color: #888;
  font-size: 1rem;
  z-index: 1;
  pointer-events: none;
}

.upload-box.dragover {
  background: #e3f2fd;
  border-color: #4096ee;
  color: #333;
}

/* Uploaded preview fills the box */
.upload-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
  display: block;
  background: #f9f9f9;
  z-index: 3;
}

/* ===== CLOSE BUTTON ON IMAGE PREVIEW ===== */
.upload-close-btn {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e8504c;
  color: #fff;
  border: none;
  font-size: 17px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  z-index: 10;
  opacity: 0.87;
  transition: opacity 0.2s, background 0.2s;
  outline: none;
}
.upload-close-btn:hover {
  opacity: 1;
  background: #bb2926;
}

/* ===== BUTTONS ===== */
button {
  background: #4096ee; color: #fff;
  border: none; padding: 10px 25px;
  font-size: 1rem; border-radius: 4px;
  cursor: pointer; transition: background 0.2s, box-shadow 0.2s;
}
button:hover {
  background: #357acc; box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
button:disabled {
  background: #a0b0c0; cursor: not-allowed;
}

/* ===== IMAGE RESULT ===== */
.result {
  max-width: 100%; margin-top: 20px;
  border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ===== HISTORY TABLE ===== */
.history {
  width: 100%; border-collapse: collapse;
}
.history th, .history td {
  padding: 12px 10px; border-bottom: 1px solid #e0e0e0;
  font-size: 0.94rem; text-align: left;
}
.history th {
  background: #f0f0f0; color: #555;
}

/* ===== LOGIN PAGE ===== */
.login-page {
  display: flex; justify-content: center; align-items: center;
  height: 100vh; background: #f5f7fa;
}
.login-form {
  background: #fff; padding: 30px 35px;
  border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  width: 280px; text-align: center;
}
.login-form h2 { margin-bottom: 25px; }
.login-form input {
  width: 100%; padding: 10px 12px;
  margin-bottom: 15px; border: 1px solid #ccd0d5;
  border-radius: 4px; font-size: 1rem;
}
.login-form .error {
  color: #d9534f; font-size: 0.9rem; margin-bottom: 12px;
}
.login-form button { width: 100%; }

.error {
  color: #d9534f; font-weight: 600; margin-top: 10px;
}

/* HISTORY UI */
.history-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}
.history-filters input,
.history-filters select {
  padding: 8px;
  font-size: 0.95rem;
}
.history-filters button {
  padding: 10px 18px;
  font-size: 1rem;
  border-radius: 4px;
}
.history-filters label { font-size: 0.9rem; }

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill,minmax(280px,1fr));
  gap: 20px;
}
.history-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  height: auto;
  overflow: hidden;
}
.history-thumb-small {
  width: 100%;
  height: 200px;
  object-fit: contain;
  background: #f0f0f0;
}
.history-info {
  padding: 10px 12px;
  flex: 1;
  font-size: 0.9rem;
  color: #333;
}
.history-info p { margin: 4px 0; }
.history-actions {
  display: flex;
  justify-content: space-around;
  padding: 8px;
  background: #f7f7f7;
}
.history-actions a {
  font-size: 0.85rem;
  color: #4096ee;
  text-decoration: none;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.2s;
}
.history-actions a:hover {
  background: rgba(64,150,238,0.1);
}

/* Increase the max width of the main content area */
.main .page-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* --- Text Prompt and Input Image Layout --- */
.text-prompt-container {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}
.text-prompt-container textarea {
  width: 100%;
  height: 150px;
  padding: 10px;
  font-size: 16px;
}

.upload-box .upload-text {
  text-align: center;
  font-size: 1rem;
  color: #888;
}

/* --- Settings Section (Compact layout) --- */
.settings-row {
  display: flex;
  gap: 20px;
}
.settings-row select,
.settings-row input {
  width: 32%;
  padding: 10px;
  font-size: 14px;
}
.details-summary {
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
}
hr {
  margin: 20px 0;
}

/* Responsive prompt-image-row */
.prompt-image-row {
  display: flex;
  gap: 24px;
  margin-bottom: 18px;
}
.prompt-col {
  flex: 2;
  display: flex;
  flex-direction: column;
}
.upload-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 180px;
  max-width: 300px;
}
.prompt-col textarea {
  min-height: 110px;
  resize: vertical;
}

.settings-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.settings-row > div {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.settings-row label {
  font-weight: 500;
  margin-bottom: 3px;
}

.num-output-row {
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.num-output-row label {
  font-weight: 500;
  min-width: 120px;
}

/* Responsive design for mobile */
@media (max-width: 900px) {
  .prompt-image-row {
    flex-direction: column;
    gap: 10px;
  }
  .upload-col {
    max-width: 100%;
    min-width: 100px;
  }
  .settings-row {
    flex-direction: column;
    gap: 6px;
  }
  .upload-box {
    max-width: 100%;
    min-width: 80px;
  }
}

/* Multi-result grid */
.result-container-multi {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
}
.result-thumb {
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 8px;
  background: #fafbfc;
  max-width: 220px;
  text-align: center;
}
.result-thumb img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 6px;
  display: block;
  margin: 0 auto 10px;
}
.result-actions {
  font-size: 14px;
  margin-top: 4px;
}

.prompt-image-row .prompt-col textarea,
textarea#prompt {
  min-height: 230px;
  resize: vertical;
}
