:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card2: #263449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --border: #334155;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  padding: 24px 32px;
  background: linear-gradient(135deg, #0f172a, #1e293b);
  border-bottom: 1px solid var(--border);
}

header h1 { margin: 0 0 4px; font-size: 1.6rem; }
header p { margin: 0; color: var(--muted); }

main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.card h2 { margin: 0 0 12px; font-size: 1.1rem; }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 800px) { .row { grid-template-columns: 1fr; } }

.grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 10px;
}
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } }

input, select {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  font-size: 0.95rem;
  width: 100%;
}

button {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
button.approve { background: var(--green); }
button.danger { background: var(--red); color: white; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.hidden { display: none !important; }
.error { color: var(--red); margin-top: 10px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}
.badge.LOW, .badge.approved, .badge.published { background: #14532d; color: var(--green); }
.badge.MEDIUM, .badge.scheduled, .badge.pending_validation { background: #713f12; color: var(--amber); }
.badge.HIGH, .badge.failed { background: #7f1d1d; color: var(--red); }
.badge.draft, .badge.generated, .badge.cancelled { background: #334155; color: var(--muted); }

.preview-box {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  white-space: pre-wrap;
  font-size: 0.95rem;
}
.preview-meta { color: var(--muted); font-size: 0.85rem; margin: 8px 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.post-item, .cal-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--card2);
}
.post-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.post-text { white-space: pre-wrap; font-size: 0.9rem; margin: 8px 0; color: #cbd5e1; }
.post-meta { color: var(--muted); font-size: 0.8rem; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.kpi { background: var(--card2); border-radius: 8px; padding: 10px; text-align: center; }
.kpi .num { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.kpi .lbl { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }

ul { margin: 8px 0; padding-left: 18px; color: #cbd5e1; }

/* ----------------------------- Connexion ----------------------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 8px; }
.login-card h1 { margin: 0 0 4px; font-size: 1.35rem; }
.login-card label { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.login-card button { margin-top: 12px; }
.small { font-size: 0.8rem; }
.muted { color: var(--muted); }
code { background: var(--card2); padding: 1px 5px; border-radius: 5px; font-size: 0.85em; }

/* ----------------------------- En-tête & navigation ----------------------------- */
.header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.header-user { display: flex; align-items: center; gap: 10px; }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 7px 13px;
}
.tab:hover { filter: none; border-color: var(--accent); color: var(--text); }
.tab.active { background: var(--accent); color: #0f172a; border-color: var(--accent); }

/* ----------------------------- Formulaires ----------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  align-items: end;
}
.form-grid + .form-grid { margin-top: 10px; }
textarea {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--text);
  font-size: 0.95rem;
  width: 100%;
  font-family: inherit;
  resize: vertical;
}
input[type="file"] { padding: 8px; }
label { font-size: 0.85rem; color: var(--muted); }

.chips-field { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 12px; margin: 12px 0 0; }
.chips-field legend { color: var(--muted); font-size: 0.8rem; padding: 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.chip input { width: auto; }
.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.9rem; }
.checkbox input { width: auto; }

button.small { padding: 4px 10px; font-size: 0.78rem; }

/* ----------------------------- Médias ----------------------------- */
.media-grid { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.media-item { margin: 0; background: var(--card2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; width: 170px; }
.media-item figcaption { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.thumb { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; background: #0b1220; }
.media-grid img.thumb { width: 100%; }

/* ----------------------------- Tableaux ----------------------------- */
.table-scroll { overflow-x: auto; margin-top: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:hover td { background: rgba(56, 189, 248, 0.06); }

/* ----------------------------- Modale ----------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal-card { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 8px; }
.modal-card form { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.modal-card form label { margin-top: 4px; }

/* ----------------------------- Statuts supplémentaires ----------------------------- */
.badge.rejected { background: #7f1d1d; color: var(--red); }
.badge.partially_published { background: #713f12; color: var(--amber); }

/* ----------------------------- Dictée vocale ----------------------------- */
.voice-block { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.voice-field { position: relative; display: flex; align-items: center; }
.voice-field input { padding-right: 56px; }

.mic-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
}
.mic-btn svg { pointer-events: none; }
.mic-btn:hover { filter: none; color: var(--text); border-color: var(--border); }
.mic-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mic-btn.listening {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  animation: mic-pulse 1.2s ease-in-out infinite;
}

.voice-status { min-height: 1.1em; }
.voice-status:empty { min-height: 0; }

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .mic-btn.listening { animation: none; }
}

/* ----------------------------- Canaux & aides ----------------------------- */
.chip { flex-wrap: wrap; }
.chip-state {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
}
.chip-state.live { color: var(--green); border-color: var(--green); }

.hint { color: var(--amber); font-size: 0.8rem; margin-top: 8px; }

/* ------------------------------------------------------------------ */
/* Accessibilité : labels visibles des champs                          */
/* ------------------------------------------------------------------ */

.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted, #6b7280);
  margin-bottom: 0.25rem;
}

/* Contour de focus bien visible pour la navigation clavier. */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* La modale bloque le défilement de la page en arrière-plan. */
.modal-backdrop:not(.hidden) {
  overflow-y: auto;
}

/* ------------------------------------------------------------------ */
/* Connexion des canaux (onglet Marques)                               */
/* ------------------------------------------------------------------ */

.channel-block {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border, #e5e7eb);
}

.channel-rows {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.channel-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.channel-name {
  min-width: 8.5rem;
  font-weight: 600;
}

.channel-actions {
  display: inline-flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-left: auto;
}

button.small {
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
}
