:root {
  --bg: #07070E;
  --panel: #111122;
  --card2: #15162C;
  --border: #23243F;
  --border-strong: #35365C;
  --accent: #7C5CFF;
  --accent2: #A08BFF;
  --text: #F0F0FA;
  --sub: #9090B8;
  --green: #10B981;
  --red: #F04444;
  --orange: #F97316;
  --teal: #3B82F6;
  --pill-bg: #1D1B3A;
  --pill-txt: #C7BBFF;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 1px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 22px 48px rgba(0, 0, 0, 0.55), 0 6px 18px rgba(0, 0, 0, 0.35);
  --glow: 0 0 0 3px rgba(124, 92, 255, 0.28);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Inter", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2A2B4C; border-radius: 20px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #3A3B66; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
  z-index: 5;
}
.sidebar .logo {
  background: linear-gradient(135deg, var(--accent), #9370FF 60%, var(--accent2));
  color: white;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.2px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar .nav { padding: 14px 10px; display: flex; flex-direction: column; gap: 3px; }
.nav-btn {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background-color .15s ease, color .15s ease, transform .1s ease;
}
.nav-btn:hover { background: var(--card2); transform: translateX(1px); }
.nav-btn.active { background: var(--pill-bg); color: var(--pill-txt); font-weight: 700; }

.sidebar hr { border: none; border-top: 1px solid var(--border); margin: 10px 16px; }

.settings-form { padding: 0 12px; display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 10px; font-weight: 700; color: var(--sub); margin-top: 10px; letter-spacing: 0.4px; }
.settings-form input, .settings-form select {
  height: 34px;
  border: 1px solid var(--border);
  background: var(--card2);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: 12px;
  color: var(--text);
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.settings-form input:focus, .settings-form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--glow);
}
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; }
.radio-pill { display: flex; align-items: center; gap: 4px; }
.api-status { font-size: 9px; color: var(--sub); min-height: 28px; white-space: pre-line; line-height: 1.5; }
.btn-row { display: flex; gap: 6px; margin: 6px 0; }
.logout-form { margin-top: 8px; }

.sidebar-footer { margin-top: auto; text-align: center; padding: 14px; font-size: 9px; color: var(--sub); letter-spacing: 0.3px; }

.content { flex: 1; min-width: 0; }

/* Buttons */
.accent-btn {
  background: var(--accent);
  color: white;
  border: none;
  font-weight: 700;
  font-size: 12px;
  border-radius: var(--radius-sm);
  height: 38px;
  padding: 0 16px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color .15s ease, transform .08s ease, box-shadow .15s ease;
}
.accent-btn:hover { background: var(--accent2); box-shadow: var(--shadow-md), var(--glow); transform: translateY(-1px); }
.accent-btn:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.accent-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
.accent-btn.green { background: var(--green); }
.accent-btn.green:hover { background: #22D69B; }
.accent-btn.orange { background: var(--orange); }
.accent-btn.orange:hover { background: #FF9A42; }
.accent-btn.teal { background: var(--teal); }
.accent-btn.teal:hover { background: #5B9DFF; }
.accent-btn.full { width: 100%; margin-top: 14px; }

.ghost-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  height: 36px;
  padding: 0 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .08s ease;
}
.ghost-btn:hover { background: var(--card2); border-color: var(--border-strong); transform: translateY(-1px); }
.ghost-btn:active { transform: translateY(0); }
.ghost-btn.small { height: 30px; font-size: 11px; width: 100%; }

/* Cards */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.section-title { font-size: 13px; font-weight: 700; padding: 12px 16px 4px; letter-spacing: 0.1px; }

.pill {
  display: inline-block;
  background: var(--pill-bg);
  color: var(--pill-txt);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 10px;
  font-weight: 700;
  margin: 2px;
}

textarea, input[type=text], input[type=number], input[type=password] {
  border: 1px solid var(--border);
  background: var(--card2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 9px 11px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea:focus, input[type=text]:focus, input[type=number]:focus, input[type=password]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--glow);
}

/* Login */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background:
    radial-gradient(circle at 15% 15%, rgba(124, 92, 255, 0.16), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(59, 130, 246, 0.12), transparent 45%),
    var(--bg);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px;
  width: 360px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-logo { font-size: 28px; font-weight: 800; color: var(--accent2); margin-bottom: 6px; letter-spacing: 0.2px; }
.login-sub { font-size: 12px; color: var(--sub); margin-bottom: 22px; }
.login-card input { width: 100%; height: 42px; margin-top: 4px; text-align: center; letter-spacing: 2px; }
.login-error { color: var(--red); font-size: 12px; margin-top: 10px; }

/* Home */
.header-banner {
  background: linear-gradient(135deg, var(--accent), #9370FF 55%, var(--accent2));
  color: white;
  border-radius: var(--radius-lg);
  margin: 24px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.header-banner h1 { margin: 0 0 6px; font-size: 25px; letter-spacing: 0.2px; }
.header-banner p { margin: 0; font-size: 13px; opacity: 0.92; }

.quick-actions { display: flex; gap: 16px; padding: 0 24px; margin-bottom: 16px; }
.quick-card {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  display: block;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.quick-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.quick-card .icon { font-size: 27px; }
.quick-card .title { font-weight: 700; font-size: 12px; margin-top: 6px; }
.quick-card .desc { font-size: 10px; color: var(--sub); margin-top: 2px; }

.section-heading { font-size: 16px; font-weight: 700; padding: 0 24px; margin: 24px 0 10px; }

.project-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 6px 24px;
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .1s ease;
}
.project-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.project-thumb {
  width: 56px; height: 56px;
  background: var(--card2);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  font-size: 20px;
  flex-shrink: 0;
}
.project-thumb img { width: 100%; height: 100%; object-fit: cover; }
.project-info { flex: 1; min-width: 0; }
.project-info .name { font-weight: 700; font-size: 13px; }
.project-info .meta { font-size: 11px; color: var(--sub); margin-top: 2px; }
.project-actions { display: flex; gap: 6px; }

.empty-state { text-align: center; color: var(--sub); padding: 70px 20px; font-size: 14px; line-height: 1.7; }

/* New project form */
.page-title { font-size: 21px; font-weight: 700; padding: 22px 24px 6px; letter-spacing: 0.1px; }
.form-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin: 8px 24px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-col { flex: 1; min-width: 220px; }
.form-card label.title { display: block; font-weight: 700; font-size: 13px; margin-bottom: 7px; }
.form-card .hint { font-size: 10px; color: var(--sub); margin-bottom: 4px; line-height: 1.5; }
.full-width { width: 100%; }
textarea.tall { height: 150px; width: 100%; resize: vertical; }
textarea.med { height: 110px; width: 100%; resize: vertical; }
textarea.small { height: 80px; width: 100%; resize: vertical; }

.templates-row { display: flex; gap: 8px; padding: 0 24px 12px; flex-wrap: wrap; }
.template-btn {
  flex: 1;
  min-width: 90px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
  padding: 12px 4px;
  cursor: pointer;
  font-size: 10px;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.template-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--accent2); }
.template-btn .icon { font-size: 23px; }
.template-btn .name { font-weight: 700; margin-top: 5px; white-space: pre-line; }

.params-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 12px 0; }
.count-lbl { font-weight: 700; color: var(--accent2); font-size: 12px; margin-top: 6px; }
.cost-lbl { color: var(--sub); font-size: 11px; margin-top: 4px; }

.char-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px;
  margin-bottom: 6px;
  transition: border-color .15s ease;
}
.char-row:hover { border-color: var(--border-strong); }
.char-thumb {
  width: 52px; height: 52px; border-radius: var(--radius-sm);
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; font-size: 22px; flex-shrink: 0;
}
.char-thumb img { width: 100%; height: 100%; object-fit: cover; }
.char-fields { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.char-fields input { height: 30px; font-size: 11px; }
.char-btns { display: flex; flex-direction: column; gap: 4px; }

/* Tabs (editor) */
.editor-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 22px;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}
.editor-header .title { font-weight: 700; font-size: 15px; letter-spacing: 0.1px; }
.editor-header .meta { font-size: 11px; color: var(--sub); }
.editor-header .spacer { flex: 1; }

.tabs-bar { display: flex; gap: 4px; padding: 12px 22px 0; background: var(--panel); border-bottom: 1px solid var(--border); }
.tab-btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--sub);
  position: relative;
  top: 1px;
  transition: color .15s ease, background-color .15s ease;
}
.tab-btn:hover { color: var(--text); background: var(--card2); }
.tab-btn.active {
  background: var(--bg);
  color: var(--accent2);
  font-weight: 700;
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--bg);
}
.tab-panel { display: none; padding: 18px 24px; }
.tab-panel.active { display: block; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.split .card { padding: 14px; display: flex; flex-direction: column; }
.split textarea { flex: 1; min-height: 300px; }

.status-line { font-size: 11px; color: var(--sub); margin-left: 12px; }
.badge { font-weight: 700; font-size: 11px; color: var(--accent2); }

.progress-bar-outer { height: 12px; background: var(--card2); border-radius: 6px; overflow: hidden; }
.progress-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  width: 0%;
  transition: width .35s ease;
  border-radius: 6px;
}

.gen-log {
  background: #08080F;
  color: #C7CCE8;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  height: 280px;
  overflow-y: auto;
  font-family: "Cascadia Code", "Courier New", monospace;
  font-size: 11.5px;
  line-height: 1.6;
  padding: 12px 14px;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}

.gallery-toolbar {
  display: flex;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  height: 52px;
  padding: 0 16px;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}
.gallery-toolbar .title { font-weight: 700; font-size: 14px; }
.gallery-toolbar .spacer { flex: 1; }
.gallery-nav { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.gallery-sel-row { display: flex; align-items: center; gap: 6px; padding: 4px 0; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 10px 0;
}
.gallery-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .1s ease;
}
.gallery-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.gallery-card.failed { border-color: #5C2A3A; background: #23121A; }
.gallery-card .img-wrap { border-radius: var(--radius-sm); overflow: hidden; }
.gallery-card img {
  max-width: 100%;
  display: block;
  border-radius: var(--radius-sm);
  cursor: zoom-in;
  transition: transform .25s ease;
}
.gallery-card .img-wrap:hover img { transform: scale(1.035); }
.gallery-card .top-row { display: flex; justify-content: flex-end; }
.gallery-card .num-badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  margin: 6px 0;
}
.gallery-card.failed .num-badge { background: var(--red); }
.gallery-card .words { font-size: 9px; color: var(--sub); margin: 2px 0 10px; line-height: 1.5; }
.gallery-card .btn-row { display: flex; gap: 4px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-weight: 600;
  font-size: 12.5px;
  padding: 12px 22px;
  border-radius: var(--radius-md);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
  z-index: 999;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.variant-grid { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.variant-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px; width: 220px; text-align: center; box-shadow: var(--shadow-sm); }
.variant-card img { max-width: 100%; border-radius: var(--radius-sm); }

/* Lightbox (agrandissement image galerie) */
.lightbox-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: zoom-out;
  padding: 40px;
}
.lightbox-overlay.show { display: flex; }
.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  cursor: default;
}
.lightbox-close {
  position: fixed;
  top: 20px;
  right: 26px;
  background: rgba(255,255,255,0.10);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  transition: background-color .15s ease;
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .params-grid { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
}
