/* =========================================================================
   Planning Studio — feuille de style
   1) Habillage de l'outil (topbar, panneau, scène)
   2) Design du canevas (.pl-*) — le planning exporté
   ========================================================================= */

:root {
  --bg-0: #0c0e14;
  --bg-1: #12151d;
  --bg-2: #181c26;
  --bg-3: #212636;
  --line: #2b3142;
  --text: #e7ebf3;
  --muted: #99a2b8;
  --brand: #7c5cff;
  --brand-2: #22d3ee;
  --danger: #ef4767;
  --ok: #22c55e;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: 'Poppins', 'Montserrat', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg-0);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 26px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 16px; letter-spacing: 0.2px; }
.brand-text small { color: var(--muted); font-size: 11px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.tb-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; }
.tb-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.tb-btn:hover { background: #2a3145; }
.tb-btn:active { transform: translateY(1px); }
.tb-btn:disabled { opacity: 0.4; cursor: default; }
.tb-btn--primary {
  background: linear-gradient(180deg, var(--brand), #6039ff);
  border-color: #6039ff;
  font-weight: 600;
}
.tb-btn--primary:hover { filter: brightness(1.08); background: linear-gradient(180deg, var(--brand), #6039ff); }

/* ---------- Auth / cloud ---------- */
.auth-area { display: flex; align-items: center; gap: 8px; }
.tb-btn--discord { background: linear-gradient(180deg, #5865f2, #4752c4); border-color: #4752c4; font-weight: 600; }
.tb-btn--discord:hover { filter: brightness(1.08); background: linear-gradient(180deg, #5865f2, #4752c4); }
.user-chip { display: inline-flex; align-items: center; gap: 7px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px 3px 3px; }
.user-chip img { width: 24px; height: 24px; border-radius: 50%; display: block; }
.user-chip .uname { font-size: 12.5px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thumb-del {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 6px; border: none;
  background: rgba(0, 0, 0, 0.6); color: #fff; cursor: pointer; font-size: 11px; line-height: 1;
  display: none; align-items: center; justify-content: center;
}
.thumb:hover .thumb-del { display: inline-flex; }
.thumb-del:hover { background: var(--danger); }

.planning-list { display: flex; flex-direction: column; gap: 8px; }
.planning-row { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg-2); }
.planning-row.active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.planning-meta { flex: 1; min-width: 0; }
.planning-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cloud-flash {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease; z-index: 60; font-size: 13px;
}
.cloud-flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Workspace ---------- */
.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 0;
}

/* ---------- Panneau de contrôles ---------- */
.panel {
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 12px 12px 60px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-3) transparent;
}
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 20px; border: 3px solid var(--bg-1); }

.ctl-section { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: var(--bg-2); overflow: hidden; }
.ctl-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 12px 14px; cursor: pointer; user-select: none;
  font-weight: 600; font-size: 13.5px;
}
.ctl-head:hover { background: #1c2130; }
.ctl-head .ctl-ico { color: var(--muted); font-size: 12px; transition: transform 0.2s ease; }
.ctl-section.collapsed .ctl-body { display: none; }
.ctl-section.collapsed .ctl-ico { transform: rotate(-90deg); }
.ctl-body { padding: 6px 14px 14px; display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field-row { display: flex; align-items: center; gap: 8px; }
.field-row .field { flex: 1; }

input[type='text'],
input[type='number'],
textarea,
select {
  width: 100%;
  background: var(--bg-0);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  outline: none;
}
input[type='text']:focus, textarea:focus, select:focus, input[type='number']:focus {
  border-color: var(--brand);
}
textarea { resize: vertical; min-height: 44px; }
select { cursor: pointer; }

/* Range */
input[type='range'] { width: 100%; accent-color: var(--brand); }

/* Color input */
.color {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 9px; padding: 4px 8px 4px 4px;
  background: var(--bg-0);
}
.color input[type='color'] {
  width: 30px; height: 30px; border: none; background: none; padding: 0; border-radius: 6px; cursor: pointer;
}
.color .hex { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 62px; }

/* Segmented control */
.seg { display: flex; background: var(--bg-0); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; appearance: none; border: none; background: transparent; color: var(--muted);
  padding: 7px 8px; border-radius: 7px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.seg button.active { background: var(--brand); color: #fff; font-weight: 600; }

/* Chips (emojis, badges, backgrounds) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg-0); color: var(--text);
  border-radius: 8px; padding: 6px 8px; cursor: pointer; font-size: 15px; line-height: 1;
  min-width: 34px; text-align: center;
}
.chip.small { font-size: 11px; padding: 5px 8px; }
.chip.active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }

/* Template & background thumbnails */
.thumb-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.thumb {
  position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  cursor: pointer; aspect-ratio: 16 / 9; background: #000;
}
.thumb.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.thumb .thumb-label {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px;
  font-size: 11px; font-weight: 600; color: #fff; background: linear-gradient(0deg, rgba(0,0,0,0.75), transparent);
}

/* Days editor */
.day-list { display: flex; flex-direction: column; gap: 8px; }
.day-item { border: 1px solid var(--line); border-radius: 10px; background: var(--bg-0); overflow: hidden; }
.day-item-head {
  display: flex; align-items: center; gap: 6px; padding: 8px 8px;
}
.day-item-head .drag { cursor: grab; color: var(--muted); font-size: 14px; padding: 0 2px; }
.day-item-head input.day-name { flex: 1; font-weight: 600; }
.day-item-body { padding: 0 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.day-item.collapsed .day-item-body { display: none; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 13px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-3); }
.icon-btn.danger:hover { background: var(--danger); border-color: var(--danger); }
.day-item.dragging { opacity: 0.5; }
.day-item.dragover { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; }

.btn-add {
  appearance: none; border: 1px dashed var(--line); background: transparent; color: var(--muted);
  border-radius: 10px; padding: 10px; cursor: pointer; font: inherit; font-size: 13px; width: 100%;
}
.btn-add:hover { border-color: var(--brand); color: var(--text); }

.btn-reset-sizes {
  appearance: none; border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 8px; padding: 6px 8px; cursor: pointer; font: inherit; font-size: 11.5px; width: 100%;
}
.btn-reset-sizes:hover { color: var(--text); border-color: var(--brand); }

.hint { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

/* ---------- Scène / aperçu ---------- */
.stage-wrap {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 0; min-height: 0;
  background:
    radial-gradient(60% 60% at 50% 0%, rgba(124, 92, 255, 0.08), transparent 70%),
    var(--bg-0);
  padding: 20px;
}
.stage {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.stage-scaler { transform-origin: top left; position: absolute; }
.stage-hint { position: absolute; bottom: 8px; font-size: 11px; color: var(--muted); }

/* =========================================================================
   2) DESIGN DU CANEVAS (.pl-*) — c'est ce qui est exporté.
   Les tailles sont appliquées en px par render.js (déjà multipliées par
   le facteur d'échelle du format). Les couleurs/polices viennent de variables.
   ========================================================================= */
.canvas {
  position: relative;
  overflow: hidden;
  background: #05050f;
  font-family: 'Montserrat', sans-serif;
  --accent: #ff5db1;
  --accent2: #57e0d4;
}
.pl-bg, .pl-overlay, .pl-starfield {
  position: absolute; inset: 0; pointer-events: none;
}
.pl-bg { background-size: cover; background-position: center; }
.pl-starfield { width: 100%; height: 100%; }
.pl-overlay { background: #000; }

.pl-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  z-index: 2;
}

/* En-tête */
.pl-header { text-align: center; }
.pl-title {
  font-family: var(--title-font, 'Anton');
  color: var(--title-color, #fff);
  line-height: 0.98;
  margin: 0;
  text-transform: none;
}
.pl-subtitle {
  font-family: var(--subtitle-font, 'Baloo 2');
  color: var(--subtitle-color, #57e0d4);
  margin: 0;
}

/* Cartes (jours) */
.pl-cards { display: flex; flex: 1 1 auto; }
.pl-cards--row { flex-direction: row; align-items: stretch; }
.pl-cards--col { flex-direction: column; align-items: stretch; justify-content: center; }
.pl-cards--grid { flex-flow: row wrap; align-content: center; justify-content: center; }

.pl-card { flex: 1 1 0; display: flex; min-width: 0; }
.pl-cards--col .pl-card { flex: 0 0 auto; }
.pl-cards--grid .pl-card { flex: 1 1 40%; }

.pl-card-frame {
  position: relative;
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  border: var(--card-border, 2px solid rgba(255,255,255,0.5));
  border-radius: var(--card-radius, 10px);
  background: var(--card-fill, rgba(0,0,0,0.28));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.pl-card-frame::before {
  /* liseré intérieur façon "double cadre" comme l'exemple */
  content: '';
  position: absolute; inset: 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: inherit; pointer-events: none;
}
.pl-badge {
  position: absolute; top: 0; left: 50%; transform: translate(-50%, -50%);
  font-family: 'Montserrat', sans-serif; font-weight: 700; color: #fff;
  border-radius: 999px; white-space: nowrap; z-index: 3;
}
.pl-day {
  font-family: var(--day-font, 'Great Vibes');
  color: var(--day-color, #fff);
  line-height: 1;
  text-align: center;
}
.pl-emoji { line-height: 1; }
.pl-activity {
  font-family: var(--body-font, 'Montserrat');
  color: var(--body-color, #dbe4ff);
  text-transform: uppercase;
  text-align: center;
  font-weight: 600;
}
.pl-time {
  font-family: var(--body-font, 'Montserrat');
  color: var(--time-color, #fff);
  text-align: center;
}
.pl-corner { position: absolute; color: color-mix(in srgb, #fff 85%, transparent); opacity: 0.85; }

/* Pied de page */
.pl-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.pl-footer-text {
  font-family: var(--footer-font, 'Baloo 2');
  color: var(--footer-color, #4bc5e8);
  flex: 1;
}
.pl-channel {
  display: inline-flex; align-items: center; gap: 0.35em;
  font-family: 'Montserrat', sans-serif; font-weight: 700; color: #fff; white-space: nowrap;
}
.pl-channel svg { display: block; }

/* ---------- Modal export ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(2, 4, 10, 0.7);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal-overlay[hidden] { display: none; }
.modal { width: min(460px, 100%); background: var(--bg-1); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-close { appearance: none; border: none; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.export-actions { display: flex; gap: 10px; }
.export-actions .tb-btn { flex: 1; justify-content: center; text-align: center; padding: 12px; }
.export-status { font-size: 12px; color: var(--muted); min-height: 16px; }

/* Export : masque les couches de fond pour un PNG transparent. */
.export-transparent .pl-bg,
.export-transparent .pl-overlay,
.export-transparent .pl-starfield { display: none !important; }

/* ---------- Responsive ---------- */
.mobile-tabs { display: none; }
@media (max-width: 900px) {
  body { overflow: auto; }
  .workspace { grid-template-columns: 1fr; }
  .panel { max-height: none; border-right: none; border-bottom: 1px solid var(--line); }
  .stage-wrap { min-height: 60vh; }
}
