/* Thème clair "Serene Blue" soft UI, aligné sur la palette et les ombres du site vitrine
   (Site_Vitrine/css/styles.css) — mêmes noms de variables qu'avant pour que le reste du
   fichier reste valide, seules les valeurs changent (sombre/violet -> clair/bleu soft UI). */
:root {
  --dusk-blue: #274c77;
  --steel-blue: #6096ba;
  --icy-blue: #a3cef1;

  --bg: #e3edf5;
  --surface: #ffffff;
  --surface-alt: #dbe7f0;
  --border: hsl(206 32% 85%);
  --border-strong: hsl(206 30% 72%);
  --text: #16232f;
  --text-muted: #55636d;
  --text-faint: #6b7880;

  --accent: var(--dusk-blue);
  --accent-dark: #1b3a5c;
  --accent-ink: #2f6690;
  --accent-soft: color-mix(in oklab, var(--icy-blue) 42%, white);

  --ok: #1e7a42;
  --ok-soft: color-mix(in oklab, var(--ok) 14%, white);
  --warn: #a15c00;
  --warn-soft: color-mix(in oklab, var(--warn) 14%, white);
  --danger: #c0392b;
  --danger-soft: color-mix(in oklab, var(--danger) 14%, white);

  --radius: 14px;
  --radius-lg: 20px;
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-soft: 6px 6px 12px rgba(150, 173, 196, 0.4), -6px -6px 12px rgba(255, 255, 255, 0.85);
  --shadow-soft-sm: 4px 4px 8px rgba(150, 173, 196, 0.35), -4px -4px 8px rgba(255, 255, 255, 0.85);
  --shadow-soft-hover: 8px 8px 16px rgba(150, 173, 196, 0.45), -8px -8px 16px rgba(255, 255, 255, 0.9);
  --shadow-soft-inset: inset 4px 4px 8px rgba(150, 173, 196, 0.35), inset -4px -4px 8px rgba(255, 255, 255, 0.7);
  --shadow-sm: var(--shadow-soft-sm);
  --shadow-md: 0 20px 44px -20px rgba(22, 41, 58, 0.35), 0 4px 10px -4px rgba(22, 41, 58, 0.12);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Roboto Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Buttons */

.btn {
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.3s var(--ease-soft);
}

.btn-primary {
  background-color: var(--accent);
  background-image: linear-gradient(180deg, color-mix(in oklab, var(--accent) 88%, white), transparent 65%);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 1px 2px rgba(39, 76, 119, 0.25),
    0 4px 8px -2px rgba(39, 76, 119, 0.3);
}
.btn-primary:hover {
  background-color: var(--accent-dark);
  background-image: linear-gradient(180deg, color-mix(in oklab, var(--accent-dark) 88%, white), transparent 65%);
}
.btn-primary:active { box-shadow: var(--shadow-soft-inset); }

.btn-secondary {
  background: var(--bg);
  border-color: transparent;
  color: var(--text);
  box-shadow: var(--shadow-soft-sm);
}
.btn-secondary:hover { background: var(--surface); box-shadow: var(--shadow-soft); }
.btn-secondary:active { box-shadow: var(--shadow-soft-inset); }

.btn-danger {
  background: var(--danger-soft);
  border-color: color-mix(in oklab, var(--danger) 32%, transparent);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.icon-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: none;
  background: var(--bg);
  box-shadow: var(--shadow-soft-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--surface); box-shadow: var(--shadow-soft); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn-danger:hover { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger); }

/* Cockpit shell */

.cockpit-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.cockpit-header {
  height: 60px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: none;
  box-shadow: 0 6px 16px -10px rgba(150, 173, 196, 0.5);
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.cockpit-header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.cockpit-brand {
  font-weight: 700;
  color: var(--accent);
  font-size: 1rem;
}

.line-name {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.cockpit-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-status {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
}

/* Canvas */

.canvas-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle, var(--border-strong) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
  cursor: grab;
  touch-action: none;
}
.canvas-viewport:active { cursor: grabbing; }

.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

/* Entrance animation — plays once, on the first paint of the canvas.
   The .canvas-intro class is removed shortly after (see canvas.js). */
@keyframes cockpit-card-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
@keyframes cockpit-flow-in {
  from { stroke-dashoffset: 1; }
  to   { stroke-dashoffset: 0; }
}
@keyframes cockpit-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.canvas-intro .station-card {
  opacity: 0;
  animation: cockpit-card-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
  animation-delay: calc(var(--enter-i, 0) * 90ms);
}
.canvas-intro .flow-arrow {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: cockpit-flow-in 0.55s ease both;
  animation-delay: calc(160ms + var(--enter-i, 0) * 90ms);
}
.canvas-intro #arrow-markers,
.canvas-intro #arrow-labels {
  animation: cockpit-fade-in 0.5s ease 0.55s both;
}

@media (prefers-reduced-motion: reduce) {
  .canvas-intro .station-card,
  .canvas-intro .flow-arrow,
  .canvas-intro #arrow-markers,
  .canvas-intro #arrow-labels {
    animation: none;
    opacity: 1;
    stroke-dashoffset: 0;
  }
}

/* --- Showcase mode : ghost cursor for the looping embed demo --- */
.sc-cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100000;
  pointer-events: none;
  margin: -2px 0 0 -2px;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.5));
  transition: transform 0.6s cubic-bezier(0.45, 0.05, 0.2, 1);
}
.sc-cursor svg { display: block; }
.sc-cursor-tap svg { animation: sc-tap-svg 0.24s ease; }
@keyframes sc-tap-svg {
  50% { transform: scale(0.72); }
}
.sc-ring {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: sc-ring 0.6s ease-out forwards;
}
@keyframes sc-ring {
  from { opacity: 0.75; transform: scale(0.3); }
  to { opacity: 0; transform: scale(3.4); }
}

.zoom-controls {
  position: absolute;
  bottom: 18px;
  right: 18px;
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-soft);
}

.canvas-hint {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  background: var(--accent-dark);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  z-index: 5;
  white-space: nowrap;
}
.canvas-hint[hidden] { display: none; }

#arrow-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
}

.flow-arrow {
  fill: none;
  stroke: var(--text-faint);
  stroke-width: 2;
  pointer-events: none;
}

.flow-arrow-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  cursor: pointer;
  pointer-events: stroke;
}
.flow-arrow-hit:hover + .flow-arrow {
  stroke: var(--danger);
}

.flow-arrow-head {
  fill: var(--text-faint);
}

#arrow-markers {
  position: absolute;
  top: 0;
  left: 0;
}

.arrow-delete-btn {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow: var(--shadow-soft-sm);
}
.arrow-delete-btn:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.label-leader {
  stroke: var(--text-faint);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  pointer-events: none;
}

#arrow-labels {
  position: absolute;
  top: 0;
  left: 0;
}

.arrow-label-bubble {
  position: absolute;
  transform: translate(-50%, -50%);
  max-width: 160px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  cursor: grab;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow-soft-sm);
  user-select: none;
  touch-action: none;
}
.arrow-label-bubble:active { cursor: grabbing; }

.arrow-label-bubble.arrow-label-empty {
  color: var(--text-faint);
  font-weight: 500;
  border-style: dashed;
  opacity: 0.65;
}
.arrow-label-bubble.arrow-label-empty:hover {
  opacity: 1;
  border-color: var(--accent);
  color: var(--accent);
}

.station-card {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft-sm);
  padding: 10px 12px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: box-shadow 0.3s var(--ease-soft);
}
.station-card:hover {
  box-shadow: var(--shadow-soft);
}
.station-card:active { cursor: grabbing; }

.station-card.station-connecting {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.station-connect-handle {
  position: absolute;
  right: -11px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  touch-action: none;
}
.station-connect-handle:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.station-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.station-name {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drift-badge {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
}
.drift-badge.drift-up { background: var(--warn-soft); color: var(--warn); }
.drift-badge.drift-down { background: var(--warn-soft); color: var(--warn); }

.station-today {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.today-actual { font-weight: 700; color: var(--accent); }
.today-actual.today-empty { color: var(--text-faint); font-weight: 400; }
.today-sep { color: var(--text-faint); margin: 0 4px; }
.today-target { color: var(--text-muted); }

.sparkline { width: 100%; height: 34px; display: block; }
.spark-actual { stroke: var(--accent); stroke-width: 2; }
.spark-target { stroke: var(--text-faint); stroke-width: 1.2; stroke-dasharray: 3 3; }

/* Modals */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 22px 24px;
  max-height: 86vh;
  overflow-y: auto;
}

.modal-medium { width: 460px; }
.modal-large { width: 640px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

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

.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.field-input {
  width: 100%;
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-soft-inset);
  margin-bottom: 12px;
}
.field-input:focus {
  outline: none;
  box-shadow: var(--shadow-soft-inset), 0 0 0 3px var(--accent-soft);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

/* Daily entry */

.entry-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 4px;
}

.entry-row {
  display: grid;
  grid-template-columns: 1fr auto 90px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-alt);
  border-radius: 6px;
}

.entry-row-name { font-weight: 600; font-size: 0.86rem; }
.entry-row-target { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.entry-row-input {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  width: 100%;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-soft-inset);
}
.entry-row-input:focus {
  outline: none;
  box-shadow: var(--shadow-soft-inset), 0 0 0 3px var(--accent-soft);
}

/* Station detail */

.detail-drift-banner {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  margin: 0 0 14px;
  background: var(--warn-soft);
  color: var(--warn);
}
.detail-drift-banner[hidden] { display: none; }

.detail-chart { width: 100%; height: auto; display: block; }
.chart-actual { stroke: var(--accent); stroke-width: 2; }
.chart-target { stroke: var(--text-faint); stroke-width: 1.4; stroke-dasharray: 4 4; }
.chart-dot { fill: var(--accent); }
.chart-axis-label { font-size: 9px; fill: var(--text-faint); font-family: var(--font-mono); }

.detail-subhead {
  font-size: 0.9rem;
  margin: 18px 0 8px;
}

.target-history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 140px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.target-history-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 5px 8px;
  background: var(--surface-alt);
  border-radius: 5px;
}

.detail-empty {
  color: var(--text-faint);
  font-size: 0.85rem;
}

.detail-target-form {
  display: grid;
  grid-template-columns: 1fr 100px auto;
  gap: 8px;
  align-items: end;
}
.detail-target-form .field-input { margin-bottom: 0; }

/* Admin */

.admin-params-form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
  margin-bottom: 8px;
}

.admin-param-field { min-width: 200px; }
.admin-param-field .field-input { margin-bottom: 0; }

.admin-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.admin-station-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.admin-station-row {
  display: grid;
  grid-template-columns: 24px 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface-alt);
  border-radius: 6px;
}

.admin-station-order {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-faint);
  text-align: center;
}

.admin-station-name-input {
  font-family: var(--font);
  font-size: 0.86rem;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-soft-inset);
}
.admin-station-name-input:focus {
  outline: none;
  box-shadow: var(--shadow-soft-inset), 0 0 0 3px var(--accent-soft);
}

.danger-zone {
  margin-top: 20px;
  padding: 14px 16px;
  border: 1px solid color-mix(in oklab, var(--danger) 40%, transparent);
  border-radius: var(--radius-lg);
  background: var(--danger-soft);
}

.danger-zone h3 {
  margin: 0 0 6px;
  color: var(--danger);
  font-size: 0.9rem;
}

.danger-zone p {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}
