/* =====================================================================
   APPLI CHAI VR 2 - css/index.css
   Styles specifiques a la page Schema chai (index.html).
   Design "sobre + onglets" (mockup-2). Layout 2 colonnes
   (stage + panneau lateral) sur desktop, single-column avec panneau
   en bas sur tablette/mobile (<= 900px).
   Extrait du <style> inline de index.html (CSP : style-src 'self'
   interdit toute balise <style> inline et tout attribut style="...").
   ===================================================================== */

.chai-page {
  max-width: 1480px;
  margin: 0 auto;
  padding: var(--space-4);
}
@media (min-width: 768px) {
  .chai-page { padding: var(--space-5); }
}
@media (min-width: 1024px) {
  .chai-page { padding: var(--space-6); }
}

/* Header de page sobre */
.chai-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--c-border);
}
.chai-page-header h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: 1.75rem;
  margin: 0;
  letter-spacing: -0.01em;
}
.chai-page-header .subtitle {
  color: var(--c-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* Layout 2 colonnes : main + panneau */
.chai-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--space-5);
  align-items: flex-start;
}
@media (max-width: 1024px) {
  .chai-layout { grid-template-columns: minmax(0, 1fr) 320px; gap: var(--space-4); }
}
@media (max-width: 900px) {
  .chai-layout { grid-template-columns: 1fr; }
}

/* Toolbar */
.chai-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: 0;
}
.chai-zones-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1 1 auto;
  border-bottom: 1px solid var(--c-border);
  align-items: flex-end;
  margin-bottom: -1px;
}
.zone-tab {
  padding: 10px 18px;
  background: transparent;
  border: none;
  color: var(--c-muted);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  font-family: inherit;
}
.zone-tab:hover { color: var(--c-text); }
.zone-tab.active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
  font-weight: 600;
}
.chai-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding-bottom: 6px;
}
.chai-edit-actions { display: none; gap: var(--space-2); flex-wrap: wrap; padding-bottom: 6px; }
.chai-edit-actions.is-active { display: flex; }

/* Stage */
.chai-stage-wrapper {
  position: relative;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-top: none;
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  touch-action: pan-x pan-y;
  padding: var(--space-4) var(--space-3);
  min-height: 380px;
}
.chai-stage {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-select: none;
}
.chai-stage.is-edit { cursor: grab; }
.chai-stage.is-edit .cuve { cursor: grab; }
.chai-stage.is-edit .cuve.is-dragging { cursor: grabbing; }

/* Cuves */
.cuve {
  transition: opacity 120ms ease, transform 150ms ease;
  cursor: pointer;
}
.cuve:hover { transform: translateY(-2px); }
.chai-stage.is-edit .cuve:hover { transform: none; }
.cuve.state-retiree { opacity: 0.4; }
.cuve .cuve-bg-circle { fill: #d6d2cb; }
.cuve .cuve-fill { transition: y 120ms ease, height 120ms ease; }
.cuve .cuve-border {
  fill: none;
  stroke: #1c1c1c;
  stroke-width: 1.5;
  transition: stroke 150ms ease, stroke-width 150ms ease;
}
.cuve.is-selected .cuve-border {
  stroke: var(--c-primary);
  stroke-width: 3;
  filter: drop-shadow(0 0 0.5px rgba(139, 0, 0, 0.5));
}
.cuve.state-maintenance .cuve-border {
  stroke: #c47b1f;
  stroke-width: 3;
  stroke-dasharray: 5 4;
}
.cuve.state-retiree .cuve-border {
  stroke: #888;
  stroke-width: 2;
}
.cuve .cuve-numero {
  /* Numero positionne AU-DESSUS du rond (bug 9, 2026-05-07).
     Couleur fixe sur le fond de la zone, plus de stroke. */
  font-weight: 700;
  font-size: 18px;
  text-anchor: middle;
  dominant-baseline: alphabetic;
  fill: #1c1c1c;
  pointer-events: none;
}
.cuve .cuve-volume,
.cuve .cuve-vin {
  text-anchor: middle;
  pointer-events: none;
  fill: #2a2a2a;
}
.cuve .cuve-volume {
  font-size: 12px;
  font-weight: 600;
}
.cuve .cuve-vin {
  font-size: 11px;
  fill: #555;
}
.cuve .cuve-icon {
  pointer-events: none;
  font-size: 16px;
  text-anchor: middle;
  dominant-baseline: central;
}

/* Grille */
.chai-grid line { stroke: #ece6dc; stroke-width: 1; }
.chai-grid.is-hidden { display: none; }

/* Slider de zoom */
.chai-zoom {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: var(--space-1);
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 4px;
  box-shadow: var(--shadow-sm);
  z-index: 4;
}
.chai-zoom button {
  width: 32px; height: 32px;
  border: 1px solid var(--c-border);
  background: var(--c-card);
  border-radius: var(--radius-sm);
  font-weight: 700;
}

/* Panneau lateral (integre au layout, sticky) */
aside.cuve-side-panel {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: var(--space-5) var(--space-4);
  box-shadow: var(--shadow-sm);
  position: sticky;
  /* --header-h-actual : hauteur REELLE du header (mise a jour par nav.js).
     Indispensable pour que le panneau s'aligne sous le header meme quand
     ce dernier wrap sur 2 lignes. Cf styles.css. */
  top: calc(var(--header-h-actual) + var(--space-3));
  align-self: flex-start;
  max-height: calc(100vh - var(--header-h-actual) - var(--space-5));
  overflow-y: auto;
}
@media (max-width: 900px) {
  aside.cuve-side-panel {
    position: static;
    max-height: none;
    margin-top: var(--space-3);
  }
}

.panel-empty {
  text-align: center;
  padding: var(--space-6) var(--space-3);
  color: var(--c-muted);
}
.panel-empty .icon {
  font-size: 36px;
  opacity: 0.3;
  margin-bottom: 8px;
  line-height: 1;
}

.panel-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-4);
  border-bottom: 2px solid var(--c-border);
  flex-wrap: wrap;
}
.panel-header h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  margin: 0;
  color: var(--c-primary);
  font-weight: 600;
}

.panel-vin-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: #faf6ee;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
}
.panel-vin-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
  flex: 0 0 auto;
  background: #cccccc;
}
.panel-vin-info {
  min-width: 0;
  flex: 1 1 auto;
}
.panel-vin-info .name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--c-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.panel-vin-info .meta {
  font-size: 0.8rem;
  color: var(--c-muted);
}
.panel-vin-info.is-empty { color: var(--c-muted); }

.panel-volume-section { margin-bottom: var(--space-4); }
.panel-volume-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-muted);
  margin: 0 0 var(--space-2) 0;
  font-weight: 600;
}
.panel-gauge {
  height: 28px;
  background: #ece8e1;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--c-border);
}
.panel-gauge-bar {
  height: 100%;
  background: var(--c-primary);
  transition: width 200ms ease;
}
.panel-gauge-label {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: #fff;
  font-weight: 600;
  font-size: 0.82rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.panel-gauge-pct {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: #1c1c1c;
  font-size: 0.78rem;
  font-weight: 600;
}

dl.panel-details {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-3);
}
dl.panel-details dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-muted);
  margin: 0;
  grid-column: span 1;
}
dl.panel-details dd {
  margin: 2px 0 0 0;
  font-weight: 600;
  font-size: 0.9rem;
  grid-column: span 1;
}
dl.panel-details .full {
  grid-column: 1 / -1;
}

.panel-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--c-border);
  flex-wrap: wrap;
}
.panel-actions .btn { flex: 1 1 auto; text-align: center; min-width: 120px; }

/* Legende compactee sous le stage */
.chai-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding: var(--space-3);
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}
.chai-legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.chai-legend-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid #1c1c1c;
  flex: 0 0 auto;
}
/* Variantes de swatch (ex-inline style="..." ; CSP-compliant). */
.chai-legend-swatch.swatch-empty { background: #d6d2cb; }
.chai-legend-swatch.swatch-partial { background: linear-gradient(0deg, #7a0024 60%, #d6d2cb 60%); }
.chai-legend-swatch.swatch-full { background: #7a0024; }
.chai-legend-swatch.swatch-maintenance { border-style: dashed; border-color: #c47b1f; }
.chai-legend-swatch.swatch-retiree { opacity: 0.4; }

@media (max-width: 600px) {
  .chai-toolbar { flex-direction: column; align-items: stretch; }
  .chai-zones-tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .zone-tab { white-space: nowrap; }
  .chai-actions, .chai-edit-actions.is-active { padding-bottom: 0; }
}
