/*
 * Mise en page commune aux versions V1 « Épuré » et V2 « Néon ».
 * Règle : aucune couleur, police ou rayon en dur ici — uniquement des variables définies dans
 * themes/tokens-v1.css et themes/tokens-v2.css (sauf la barre de présentation et le Mode SFD, hors produit).
 */

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2 { font-family: var(--font-display); font-weight: var(--display-weight); margin: 0 0 8px; line-height: 1.2; letter-spacing: var(--display-tracking); }
h1 { font-size: 26px; }
h2 { font-size: 15px; }

button, input, select { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.muted { color: var(--text-muted); font-weight: normal; }

/* ---------- En-tête ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid var(--header-border);
  backdrop-filter: var(--surface-blur);
}

.brand { font-family: var(--font-display); font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--accent); font-size: 20px; text-shadow: var(--accent-glow); }
.header-session { display: flex; align-items: center; gap: 12px; font-size: 14px; min-width: 0; }
.session-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-chip { padding: 3px 10px; border-radius: 999px; background: var(--chip-bg); color: var(--chip-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.app-main { max-width: 1240px; margin: 0 auto; padding: 24px 16px 120px; }

/* ---------- Panneaux et formulaires ---------- */

.panel {
  max-width: 560px;
  margin: 32px auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: var(--surface-blur);
}
.panel-wide { max-width: 820px; }

.lead { color: var(--text-muted); margin: 0 0 24px; }
.eyebrow { color: var(--text-muted); margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.hint { color: var(--text-muted); font-size: 13px; margin: 8px 0 0; }
.hint + .field { margin-top: 20px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-muted); }

input, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.stories-editor { border-top: 1px solid var(--border); padding-top: 20px; }
.stories-head { display: flex; align-items: baseline; justify-content: space-between; }
.stories-rows { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; max-height: 460px; overflow-y: auto; padding-right: 4px; }
.story-row { display: grid; grid-template-columns: 20px 140px 1fr 36px minmax(36px, auto); gap: 8px; align-items: center; padding: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-input); }
.story-row.is-dragging { opacity: .4; }
.story-row.is-drop { border-color: var(--accent-text); }
.story-row.is-estimated { border-color: var(--accent-text); }
.story-row.is-estimated .key { color: var(--text-muted); }
.row-est { font-size: 13px; font-weight: 700; color: var(--accent-text); white-space: nowrap; padding: 0 4px; }
.drag-handle { cursor: grab; color: var(--text-muted); text-align: center; user-select: none; }
.story-row .key { font-family: var(--font-mono); text-transform: uppercase; }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-input);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--danger); }
.row-jira { display: flex; align-items: center; justify-content: center; color: var(--accent-text); text-decoration: none; font-weight: 700; }
.row-jira:hover { color: var(--accent-text); }

.form-error { color: var(--danger); min-height: 1.5em; margin: 8px 0 0; font-weight: 600; }

.actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform .1s, filter .15s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; box-shadow: none; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary-bg); color: var(--primary-contrast); box-shadow: var(--primary-glow); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.copy-row { display: flex; gap: 8px; }
.copy-row input { font-family: var(--font-mono); font-size: 13px; }

.success-mark {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--primary-bg);
  color: var(--primary-contrast);
  box-shadow: var(--primary-glow);
  font-size: 24px;
  margin: 0 0 16px;
}

/* ---------- Table de vote ---------- */

.story-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: var(--surface-blur);
  margin-bottom: 20px;
}
.story-info { flex: 1; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-width: 0; }
.story-counter { font-size: 13px; color: var(--text-muted); }
.story-title { font-family: var(--font-display); font-size: 18px; font-weight: 600; }

.fac-only { display: none; }
.is-facilitator .fac-only { display: inline-flex; }

.table-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.story-panel h2 { margin: 0 0 8px; }
.panel-desc { font-size: 14px; line-height: 1.5; color: var(--text-muted); margin: 0 0 12px; white-space: pre-line; }
.panel-jira { font-size: 13px; font-weight: 600; color: var(--accent-text); text-decoration: none; }
.panel-jira:hover { text-decoration: underline; }

.table-zone { position: relative; aspect-ratio: 16 / 10; min-height: 360px; margin: 12px 0 28px; }

.poker-table {
  position: absolute;
  inset: var(--table-inset);
  display: grid;
  place-items: center;
  background: var(--table-bg);
  border: var(--table-rim);
  border-radius: var(--table-radius);
  box-shadow: var(--table-shadow);
  color: var(--table-text);
}

.table-status { text-align: center; padding: 8px; }
.table-status p { margin: 0; }
.status-big { font-family: var(--font-display); font-size: 46px; font-weight: var(--number-weight); line-height: 1.1; }
.status-big .unit { font-size: 20px; margin-left: 4px; opacity: .7; }
.status-sub { font-size: 14px; opacity: .85; }
.status-hint { font-size: 12px; opacity: .65; margin-top: 4px !important; }
.status-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--table-accent); }
.status-label.warn { color: var(--table-warn); }
.jira-line { margin-top: 10px !important; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--table-chip); display: inline-block; }
.jira-line.ok { color: var(--table-accent); }
.jira-line.err { color: var(--table-warn); }
.jira-line .link-btn { margin-left: 6px; }
.jira-line .btn-validate { padding: 6px 14px; font-size: 13px; }
.jira-line:has(.btn-validate) { background: transparent; padding: 0; }

.seats { position: absolute; inset: 0; pointer-events: none; }
.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: left .3s, top .3s;
}
.seat-name {
  font-size: 13px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--seat-name-bg);
  color: var(--seat-name-text);
  white-space: nowrap;
}
.seat.is-me .seat-name { background: var(--primary-bg); color: var(--primary-contrast); }

.pcard {
  width: var(--seat-card-w);
  height: calc(var(--seat-card-w) * 1.4);
  display: grid;
  place-items: center;
  border-radius: var(--card-radius);
  font-family: var(--font-display);
  font-weight: var(--number-weight);
  font-size: 20px;
}
.pcard .unit { font-size: 11px; margin-left: 1px; opacity: .6; }
.pcard.is-empty { border: 2px dashed var(--slot-border); }
.pcard.is-back { background: var(--card-back); border: var(--card-back-border); box-shadow: var(--card-shadow); }
.pcard.is-face { background: var(--card-bg); color: var(--card-text); border: var(--card-border); box-shadow: var(--card-shadow); }
.pcard.flip { animation: flip var(--flip-duration) ease-out; }

@keyframes flip {
  0% { transform: perspective(400px) rotateY(90deg); filter: brightness(var(--flip-flash)); }
  100% { transform: perspective(400px) rotateY(0); filter: brightness(1); }
}

.side { display: flex; flex-direction: column; gap: 16px; }
.side-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: var(--surface-blur);
  padding: 16px;
}
.progress { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; }
.progress-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent-text); transition: width .3s; }
.progress-label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.final-value { font-family: var(--font-display); font-size: 40px; font-weight: 700; color: var(--accent-text); margin: 4px 0; }
.final-value.is-none { color: var(--text-muted); }
.final-state { font-size: 13px; color: var(--text-muted); margin: 0; }
.participants, .backlog { list-style: none; margin: 8px 0 0; padding: 0; }
.backlog { position: relative; max-height: 340px; overflow-y: auto; }
.participants li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.participants li:last-child { border-bottom: 0; }
.participants li.is-me .p-name { font-weight: 700; }
.p-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crown { color: var(--accent); }
.bot { color: var(--text-muted); }

.tag { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-muted); white-space: nowrap; }
.tag-ok { background: var(--success-soft); color: var(--success); }
.tag-value { background: var(--primary-bg); color: var(--primary-contrast); font-weight: 700; min-width: 36px; text-align: center; }

.backlog li > div, .backlog li > button {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto 18px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: var(--radius-input);
}
.backlog li > button { border: 0; background: none; text-align: left; cursor: pointer; }
.backlog li > button:hover { background: var(--surface-2); }
.backlog li.is-current > * { background: var(--current-bg); box-shadow: inset 3px 0 0 var(--accent); }
.backlog li.is-done { opacity: .7; }
.b-key { font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: var(--accent-text); }
.b-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.est { font-weight: 700; min-width: 28px; text-align: right; font-size: 13px; }
.est-none { color: var(--text-muted); font-weight: 400; }
.jira { font-size: 12px; width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; }
.jira-ok { background: var(--success-soft); color: var(--success); }
.jira-err { background: var(--danger); color: var(--primary-contrast); }
.jira-pending { color: var(--text-muted); }

/* ---------- Main de cartes ---------- */

.hand-zone {
  position: sticky;
  bottom: 0;
  margin-top: 16px;
  padding: 12px 0 20px;
  background: var(--hand-bg);
  text-align: center;
}
.hand-hint { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); }
.hand { display: flex; justify-content: center; gap: var(--hand-gap); flex-wrap: wrap; }
.card {
  width: var(--card-w);
  height: calc(var(--card-w) * 1.4);
  border-radius: var(--card-radius);
  background: var(--card-bg);
  color: var(--card-text);
  border: var(--card-border);
  box-shadow: var(--card-shadow);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: var(--number-weight);
  cursor: pointer;
  transform-origin: 50% 140%;
  transform: rotate(calc(var(--i) * var(--fan-angle)));
  transition: transform .15s ease, box-shadow .15s ease;
}
.card .unit { font-size: 12px; margin-left: 1px; opacity: .6; }
.card:hover { transform: rotate(calc(var(--i) * var(--fan-angle))) translateY(var(--hover-lift)); }
.card.is-selected {
  transform: rotate(calc(var(--i) * var(--fan-angle))) translateY(-16px);
  background: var(--primary-bg);
  color: var(--primary-contrast);
  border-color: transparent;
  box-shadow: var(--card-selected-shadow);
}

/* ---------- Barre de présentation (hors produit) ---------- */

.proto-bar {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 50;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border-radius: 10px;
  background: rgba(20, 20, 30, .82);
  color: #fff;
  font: 12px/1 system-ui, sans-serif;
  opacity: .55;
  transition: opacity .2s;
}
.proto-bar:hover, .proto-bar:focus-within { opacity: 1; }
.proto-bar button, .proto-bar a {
  border: 0;
  padding: 6px 10px;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  text-align: left;
}
.proto-bar button:hover, .proto-bar a:hover { background: rgba(255, 255, 255, .15); }
.proto-bar button:disabled { opacity: .4; cursor: default; }
.proto-bar .is-active { background: #fff !important; color: #111 !important; }
.seg { display: flex; border: 1px solid rgba(255, 255, 255, .25); border-radius: 7px; }
.demo-panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  min-width: 220px;
  border-radius: 10px;
  background: rgba(20, 20, 30, .95);
}
.demo-panel label { display: flex; gap: 8px; align-items: center; }
.demo-panel input { width: auto; }
.demo-panel a[aria-disabled] { opacity: .4; pointer-events: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg-solid);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mode SFD (hors produit, identique dans les deux versions) ---------- */

.sfd-layer { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.sfd-outline { position: fixed; border: 2px dashed #d6177a; border-radius: 4px; background: rgba(214, 23, 122, .05); }
.sfd-badge, .sfd-screen {
  position: fixed;
  pointer-events: auto;
  padding: 2px 6px;
  border: 0;
  border-radius: 4px;
  background: #d6177a;
  color: #fff;
  font: 700 11px/1.3 ui-monospace, Consolas, monospace;
  cursor: pointer;
  white-space: nowrap;
}
.sfd-screen { top: 64px; right: 16px; padding: 6px 10px; font-size: 13px; background: #8a0f4f; }
.sfd-pop {
  position: fixed;
  z-index: 55;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
  border-top: 4px solid #d6177a;
  font: 13px/1.45 system-ui, sans-serif;
}
.sfd-item + .sfd-item { margin-top: 10px; padding-top: 10px; border-top: 1px solid #eee; }
.sfd-item strong { color: #d6177a; font-family: ui-monospace, Consolas, monospace; }
.sfd-item p { margin: 4px 0 0; color: #555; }

/* Mode Repères (touche R) : repères d'interface data-ui, pour cibler une MOD */
.sfd-outline.is-ui { border-color: #1d6fe0; background: rgba(29, 111, 224, .05); }
.sfd-badge.is-ui { background: #1d6fe0; }
.sfd-screen.is-ui { background: #0f3f86; }
.ui-item strong { color: #1d6fe0; }
.ui-copy {
  margin-top: 10px;
  padding: 6px 12px;
  border: 0;
  border-radius: 6px;
  background: #1d6fe0;
  color: #fff;
  font: 600 13px/1.3 system-ui, sans-serif;
  cursor: pointer;
}

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  .table-layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .story-panel { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .table-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  html:root { --fan-angle: 0deg; --card-w: 48px; --seat-card-w: 36px; }
  .app-header { padding: 10px 16px; }
  .panel { padding: 20px; margin: 12px auto; }
  .story-row { grid-template-columns: 16px 1fr 32px minmax(32px, auto); }
  .story-row .title { grid-column: 2 / -1; grid-row: 2; }
  .stories-rows { gap: 18px; }
  .story-bar { flex-wrap: wrap; }
  .story-info { flex-basis: 100%; }
  .story-bar .btn { width: 100%; }
  .screen-table:not([hidden]) { display: flex; flex-direction: column; }
  .table-layout { display: contents; }
  .table-zone { aspect-ratio: 1 / 1; min-height: 300px; }
  .hand-zone { position: static; order: 2; margin-top: 0; }
  .side, .story-panel { order: 3; }
  .status-big { font-size: 34px; }
  .seat-name { font-size: 11px; padding: 1px 6px; }
  .header-session .session-name { display: none; }
}
