/* ===== Theme Variables ===== */
:root,
[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-input: #1a1a1a;
  --bg-hover: #2a2a2a;
  --border: #2a2a2a;
  --border-hover: #444;
  --text: #e0e0e0;
  --text-dim: #aaa;
  --text-muted: #777;
  --text-subtle: #555;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-text: #fff;
  --green: #34d399;
  --green-bg: rgba(34, 197, 94, 0.15);
  --green-border: rgba(34, 197, 94, 0.3);
  --green-text: #86efac;
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.15);
  --red-border: rgba(239, 68, 68, 0.3);
  --red-text: #fca5a5;
  --yellow-bg: rgba(234, 179, 8, 0.15);
  --yellow-border: rgba(234, 179, 8, 0.3);
  --yellow-text: #fde68a;
  --stat-accent: #3b82f6;
  --stat-highlight: #34d399;
  --nav-bg: #1a1a1a;
  --footer-text: #555;
  --badge-active-bg: rgba(34, 197, 94, 0.2);
  --badge-inactive-bg: rgba(239, 68, 68, 0.2);
  --code-bg: #1a1a1a;
  --file-btn-bg: #2a2a2a;
  --file-btn-text: #ccc;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --bg-card: #fff;
  --bg-input: #fff;
  --bg-hover: #f0f0f0;
  --border: #e0e0e0;
  --border-hover: #ccc;
  --text: #222;
  --text-dim: #555;
  --text-muted: #888;
  --text-subtle: #aaa;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #fff;
  --green: #16a34a;
  --green-bg: rgba(22, 163, 74, 0.1);
  --green-border: rgba(22, 163, 74, 0.25);
  --green-text: #15803d;
  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.08);
  --red-border: rgba(220, 38, 38, 0.25);
  --red-text: #b91c1c;
  --yellow-bg: rgba(202, 138, 4, 0.12);
  --yellow-border: rgba(202, 138, 4, 0.3);
  --yellow-text: #a16207;
  --stat-accent: #2563eb;
  --stat-highlight: #16a34a;
  --nav-bg: #fff;
  --footer-text: #aaa;
  --badge-active-bg: rgba(22, 163, 74, 0.15);
  --badge-inactive-bg: rgba(220, 38, 38, 0.1);
  --code-bg: #f0f0f0;
  --file-btn-bg: #e5e5e5;
  --file-btn-text: #333;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Navbar ===== */
.navbar {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
}

.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.5px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.nav-links a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.15s;
}

.nav-links a:hover { color: var(--text); }

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: all 0.15s;
  margin-left: 0.25rem;
}

.theme-toggle:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

/* ===== Main ===== */
.main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--footer-text);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

/* ===== Gallery ===== */
.gallery-header { margin-bottom: 2rem; }
.gallery-header h1 { font-size: 2rem; font-weight: 700; }
.gallery-subtitle { color: var(--text-muted); margin-top: 0.25rem; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.gallery-card {
  background: var(--bg-card);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.gallery-card:hover { border-color: var(--border-hover); }

.gallery-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.gallery-card-info { padding: 0.75rem 1rem; }

.prompt-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.prompt-text.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

.prompt-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 2px 0;
  margin-top: 2px;
  transition: color 0.15s;
}

.prompt-toggle:hover { color: var(--accent); }

.gallery-date {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: 0.4rem;
  display: block;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 2rem;
}

.page-btn {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.page-btn:hover { background: var(--bg-hover); color: var(--text); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ===== Forms ===== */
.form-container { max-width: 460px; margin: 0 auto; }
.form-container h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.form-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }

.auth-form, .generate-form { display: flex; flex-direction: column; gap: 1rem; }

.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label { font-size: 0.85rem; color: var(--text-dim); font-weight: 500; }

.form-group input,
.form-group textarea,
.form-group select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--accent); }

.checkbox-group { flex-direction: row; align-items: center; gap: 0.5rem; }
.checkbox-group input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

/* ===== Buttons ===== */
.btn {
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  transition: background 0.15s;
}

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

.btn-secondary { background: var(--bg-card); color: var(--text-dim); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); color: var(--text); }

.btn-danger { background: #991b1b; color: #fff; }
.btn-danger:hover { background: #7f1d1d; }

.btn-success { background: #166534; color: #fff; }
.btn-success:hover { background: #14532d; }

.btn-warning { background: #854d0e; color: #fff; }
.btn-warning:hover { background: #713f12; }

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* ===== Alerts ===== */
.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: var(--red-bg); border: 1px solid var(--red-border); color: var(--red-text); }
.alert-success { background: var(--green-bg); border: 1px solid var(--green-border); color: var(--green-text); }
.alert-warning { background: var(--yellow-bg); border: 1px solid var(--yellow-border); color: var(--yellow-text); }

/* ===== Dashboard ===== */
.dashboard h1 { margin-bottom: 1.5rem; }

.dashboard-nav { display: flex; gap: 0.75rem; margin-bottom: 2rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  text-align: center;
}

.stat-value { display: block; font-size: 2rem; font-weight: 700; color: var(--stat-accent); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.stat-card.highlight { border-color: var(--accent); }
.stat-card.highlight .stat-value { color: var(--stat-highlight); }

.change-password-section {
  max-width: 400px;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.change-password-section h2 { font-size: 1.1rem; margin-bottom: 1rem; }

/* ===== Tables ===== */
.list-section { margin-top: 2rem; }
.list-section h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }
.empty-hint { color: var(--text-subtle); font-size: 0.9rem; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 0.65rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.data-table td { color: var(--text-dim); }

.mono { font-family: 'SF Mono', 'Consolas', monospace; font-size: 0.8rem; }

.badge { padding: 0.15rem 0.5rem; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.badge-active { background: var(--badge-active-bg); color: var(--green-text); }
.badge-inactive { background: var(--badge-inactive-bg); color: var(--red-text); }

.actions-cell { display: flex; gap: 0.35rem; }

/* ===== Generate Page ===== */
.generate-page h1 { margin-bottom: 0.25rem; }

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.result-card h2 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--green); }

.result-image-wrap { border-radius: 8px; overflow: hidden; margin-bottom: 0.75rem; }
.result-image-wrap img { width: 100%; display: block; }

.gallery-status { font-size: 0.85rem; margin-top: 0.5rem; }
.status-yes { color: var(--green-text); }
.status-no { color: var(--red-text); }

.empty-state { text-align: center; padding: 3rem 0; color: var(--text-subtle); }
.empty-state a { color: var(--accent); }

.generate-page { max-width: 700px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

input[type="file"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  width: 100%;
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  background: var(--file-btn-bg);
  color: var(--file-btn-text);
  border: none;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  margin-right: 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
}

code {
  background: var(--code-bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 0.85em;
  word-break: break-all;
}

.text-error { color: var(--red-text); }
.text-success { color: var(--green-text); }

/* ===== Loading Overlay ===== */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.loading-overlay.active {
  display: flex;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
}

.loading-hint {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85rem;
}

/* ===== Label Hint (info tooltip) ===== */
.label-hint {
  cursor: help;
  font-style: normal;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-left: 2px;
}

/* ===== Lightbox ===== */
.gallery-card img {
  cursor: pointer;
}

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.lightbox.active {
  display: flex;
}

.lightbox img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 1.25rem;
  right: 1.5rem;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s;
  line-height: 1;
}

.lightbox-close:hover { opacity: 1; }

.lightbox-info {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  margin-top: 1rem;
  max-width: 70vw;
  text-align: center;
  line-height: 1.5;
}

/* Badge for pending tasks */
.badge-pending {
  background: var(--yellow-bg);
  color: var(--yellow-text);
}

/* Image management total hint */
.total-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  align-self: center;
  margin-left: auto;
}

/* ===== Mobile ===== */
@media (max-width: 640px) {
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .nav-inner { flex-direction: column; height: auto; padding: 0.75rem 0; gap: 0.5rem; }
}
