:root {
  --accent: #ec5a13;
  --accent-hover: #d44d0b;
  --accent-soft: #fdeee6;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #1b1f27;
  --muted: #6b7280;
  --green: #12805c;
  --green-soft: #e3f5ee;
  --blue: #2563eb;
  --blue-soft: #e6eefe;
  --amber: #a15c00;
  --amber-soft: #fff3d6;
  --red: #c8283a;
  --red-soft: #fde8ea;
  --gray-soft: #eef0f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .18);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #ff6e2b;
    --accent-hover: #ff8246;
    --accent-soft: #3a2116;
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #1e2229;
    --border: #2b3039;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --green: #4fd1a1;
    --green-soft: #173229;
    --blue: #7aa7ff;
    --blue-soft: #1a2640;
    --amber: #ffc25c;
    --amber-soft: #3a2d12;
    --red: #ff7a88;
    --red-soft: #3c1b20;
    --gray-soft: #262a32;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
h2 { font-size: 1.1rem; margin: 0; }
code { background: var(--gray-soft); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-weight: 400; font-size: .82rem; }
[hidden] { display: none !important; }

/* Icônes */
i[data-icon] { display: inline-flex; width: 18px; height: 18px; flex: none; }
i[data-icon] svg { width: 100%; height: 100%; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  position: relative;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .session-chip:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 1px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.secondary { background: var(--surface); border-color: var(--border); }
.btn.secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--gray-soft); }
.btn.danger { color: var(--red); }
.btn.small { height: 32px; padding: 0 10px; font-size: .85rem; }
.btn.icon-only { width: 38px; padding: 0; }
.btn.icon-only.small { width: 32px; }
.btn.warn { background: var(--amber); color: #fff; }
.badge-count {
  position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: #fff; font-size: .7rem; line-height: 18px;
}

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M10 17a6 6 0 1 0 2-4.5M10 9v4h4' stroke='white' stroke-width='2.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.topbar-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.session-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px;
  border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2);
  font-size: .82rem; font-weight: 600; cursor: pointer; min-width: 0; white-space: nowrap;
}
.session-chip > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.session-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.session-chip.ok .dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.session-chip.ko { border-color: var(--red); color: var(--red); }
.session-chip.ko .dot { background: var(--red); }

/* Bandeau d'action requise */
.action-banner {
  position: sticky; top: 57px; z-index: 15;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--amber-soft); color: var(--text);
  border-bottom: 1px solid color-mix(in srgb, var(--amber) 40%, transparent);
}
.action-banner .icon-wrap { color: var(--amber); display: flex; }
.action-banner .msg { flex: 1; min-width: 240px; }
.action-banner .msg strong { display: block; }
.action-banner .btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* Mise en page */
.layout { display: grid; grid-template-columns: 1fr 360px; min-height: calc(100vh - 57px); }
.content { padding: 22px 24px 60px; min-width: 0; }
.activity {
  border-left: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 57px; height: calc(100vh - 57px); display: flex; flex-direction: column;
}
.activity-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.activity-list { overflow-y: auto; padding: 0 12px 16px; flex: 1; }
.only-mobile { display: none; }

/* Statistiques */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.6rem; font-weight: 800; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: .8rem; }

/* Barre d'outils */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search {
  flex: 1; min-width: 200px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; height: 38px;
  color: var(--muted);
}
.search input { border: 0; outline: 0; background: transparent; flex: 1; height: 100%; color: var(--text); }
.segmented { display: flex; background: var(--gray-soft); border-radius: 10px; padding: 3px; gap: 2px; overflow-x: auto; }
.segmented button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: .85rem; color: var(--muted); white-space: nowrap;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button span { opacity: .6; margin-left: 4px; }

/* Cartes */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
  transition: box-shadow .15s, transform .15s;
}
.card:hover { box-shadow: 0 8px 24px rgba(16, 24, 40, .12); }
.card-media {
  position: relative; aspect-ratio: 4 / 3; background: var(--surface-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-media i[data-icon] { width: 40px; height: 40px; opacity: .4; }
.card-media .status { position: absolute; top: 10px; left: 10px; }
.card-media .photo-count {
  position: absolute; bottom: 10px; right: 10px; background: rgba(0, 0, 0, .6); color: #fff;
  font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; display: flex; gap: 4px; align-items: center;
}
.card-media .photo-count i[data-icon] { width: 13px; height: 13px; opacity: 1; }
.card-body { padding: 12px 14px 4px; flex: 1; }
.card-title { font-weight: 700; margin: 0 0 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-price { color: var(--accent); font-weight: 800; font-size: 1.05rem; }
.card-meta { color: var(--muted); font-size: .82rem; margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.card-meta .row { display: flex; align-items: center; gap: 6px; }
.card-meta i[data-icon] { width: 14px; height: 14px; }
.card-error { margin-top: 8px; font-size: .8rem; color: var(--red); background: var(--red-soft); padding: 6px 8px; border-radius: 8px; }
.card-progress { margin-top: 8px; font-size: .82rem; display: flex; gap: 8px; align-items: center; color: var(--blue); }
.card-progress.waiting { color: var(--amber); }
.card-actions { display: flex; gap: 6px; padding: 10px 14px 14px; align-items: center; }
.card-actions .btn.grow { flex: 1; }

.status {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px;
  font-size: .75rem; font-weight: 700; background: var(--gray-soft); color: var(--muted);
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.online { background: var(--green-soft); color: var(--green); }
.status.busy { background: var(--blue-soft); color: var(--blue); }
.status.error { background: var(--red-soft); color: var(--red); }
.status.offline { background: var(--amber-soft); color: var(--amber); }
.status.waiting { background: var(--amber-soft); color: var(--amber); }
.status.done { background: var(--green-soft); color: var(--green); }

/* Menu contextuel */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 30; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 6px; display: flex; flex-direction: column;
}
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 0; background: transparent;
  border-radius: 8px; text-align: left; cursor: pointer; font-size: .9rem; color: var(--text); text-decoration: none;
}
.menu button:hover, .menu a:hover { background: var(--gray-soft); }
.menu .danger { color: var(--red); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* État vide */
.empty {
  grid-column: 1 / -1; text-align: center; padding: 60px 20px; border: 2px dashed var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.empty .big-icon { width: 64px; height: 64px; border-radius: 18px; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.empty .big-icon i[data-icon] { width: 30px; height: 30px; }
.empty h3 { margin: 6px 0; }
.empty p { color: var(--muted); max-width: 440px; margin: 0 auto 16px; }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Activité */
.job { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface-2); }
.job.waiting_user { border-color: var(--amber); background: var(--amber-soft); }
.job-head { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.job-icon { width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; background: var(--gray-soft); flex: none; }
.job-icon i[data-icon] { width: 16px; height: 16px; }
.job-main { flex: 1; min-width: 0; }
.job-title { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-sub { font-size: .78rem; color: var(--muted); }
.job-msg { font-size: .82rem; margin-top: 8px; }
.job-btns { display: flex; gap: 6px; margin-top: 8px; }
.job-log {
  margin: 8px 0 0; padding: 8px; background: var(--surface); border-radius: 8px; border: 1px solid var(--border);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; max-height: 220px; overflow: auto;
}
.activity-empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: .9rem; }

.spinner {
  width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Fenêtres modales */
.modal {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
}
.modal::backdrop { background: rgba(10, 14, 22, .55); backdrop-filter: blur(2px); }
.modal[open] { display: flex; flex-direction: column; animation: pop .16s ease-out; }
.modal > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.modal-lg { width: min(1040px, calc(100vw - 24px)); }
.modal-sm { width: min(420px, calc(100vw - 24px)); }
.modal-full { width: calc(100vw - 32px); height: calc(100vh - 32px); max-width: none; max-height: none; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { display: flex; align-items: center; gap: 8px; }
.modal-head > .btn:last-child { margin-left: auto; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-body h2 { margin-bottom: 6px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.form-error { color: var(--red); font-size: .85rem; margin-right: auto; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* Éditeur */
.editor-body { display: grid; grid-template-columns: 340px 1fr; gap: 22px; }
.editor-fields { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-weight: 600; font-size: .88rem; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.field-row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
.field input, .field textarea, .attr-row input {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.field input:focus, .field textarea:focus, .attr-row input:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.field textarea { resize: vertical; min-height: 140px; }
.field input.invalid { border-color: var(--red); }
.counter { color: var(--muted); font-weight: 500; font-size: .8rem; }
.counter.over { color: var(--red); }
.input-suffix { position: relative; display: flex; }
.input-suffix input { padding-right: 70px; }
.input-suffix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .85rem; pointer-events: none; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.photo {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2);
  border: 2px solid transparent; cursor: grab;
}
.photo.cover { border-color: var(--accent); }
.photo.dragging { opacity: .4; }
.photo.drop-target { border-color: var(--blue); border-style: dashed; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.photo .cover-tag { position: absolute; left: 6px; bottom: 6px; background: var(--accent); color: #fff; font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.photo .remove {
  position: absolute; top: 5px; right: 5px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .65); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
}
.photo .remove i[data-icon] { width: 14px; height: 14px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 22px 12px; text-align: center;
  border: 2px dashed var(--border); border-radius: 12px; cursor: pointer; color: var(--muted); transition: all .15s;
}
.dropzone strong { color: var(--text); }
.dropzone span { font-size: .8rem; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone i[data-icon] { width: 28px; height: 28px; }

.attributes { border: 1px solid var(--border); border-radius: 12px; padding: 0 12px; }
.attributes summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 11px 0; font-weight: 600; font-size: .9rem; }
.attributes summary::-webkit-details-marker { display: none; }
.attributes summary i[data-icon] { transition: transform .15s; }
.attributes[open] summary i[data-icon] { transform: rotate(180deg); }
.attributes[open] { padding-bottom: 12px; }
.attributes > .hint { margin: 0 0 10px; }
.attr-row { display: grid; grid-template-columns: 1fr 1fr 32px; gap: 8px; margin-bottom: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 99px; padding: 6px 12px;
  font-size: .85rem; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Réglages */
.switch-row { display: flex; justify-content: space-between; gap: 16px; align-items: center; cursor: pointer; }
.switch-row small { display: block; color: var(--muted); font-size: .82rem; }
.switch {
  appearance: none; width: 44px; height: 26px; border-radius: 99px; background: var(--border); position: relative;
  cursor: pointer; flex: none; transition: background .15s;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: var(--shadow); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

/* Vue navigateur */
.viewer-actions { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 0; }
.viewer-actions .msg { font-size: .85rem; color: var(--amber); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1; background: #000; display: flex; min-height: 0; }
.viewer-body iframe { border: 0; width: 100%; height: 100%; }
.viewer-body .viewer-off { margin: auto; color: #ccc; text-align: center; max-width: 480px; padding: 20px; }

/* Notifications */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: .9rem; font-weight: 500; animation: pop .2s ease-out; max-width: calc(100vw - 32px);
}
.toast.error { background: var(--red); color: #fff; }

/* Responsive */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .activity {
    position: fixed; right: 0; top: 0; bottom: 0; height: 100vh; width: min(380px, 100vw); z-index: 40;
    transform: translateX(100%); transition: transform .2s; box-shadow: var(--shadow-lg);
  }
  .activity.open { transform: none; }
  .only-mobile { display: inline-flex; }
}
@media (min-width: 1101px) {
  #btnActivity { display: none; }
}
@media (max-width: 860px) {
  .editor-body { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .brand-name { display: none; }
  .icon-only-mobile span, #btnNew span { display: none; }
  .icon-only-mobile, #btnNew { width: 38px; padding: 0; }
  .content { padding: 14px 12px 60px; }
  .field-row { grid-template-columns: 1fr; }
  .toolbar .btn span { display: none; }
  .modal-full { width: 100vw; height: 100vh; border-radius: 0; }
}

/* Connexion */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; }
.login-error { margin: 0; color: var(--red); font-size: .9rem; }
