/*
 * MultiView Web — style adapté de l'application desktop MultiView
 * (base.css + layout.css + stream.css + dialogs.css), sans les fenêtres flottantes.
 */

:root {
  color-scheme: dark;

  --bg: #101217;
  --bg-elev: #15181f;
  --bg-card: #191c24;
  --bg-input: #101217;
  --border: #303541;
  --border-soft: #282c36;
  --text: #e7eaf0;
  --text-dim: #9299a8;
  --text-soft: #b6bdc9;
  --accent: #6558e8;
  --accent-hover: #776af5;
  --accent-soft: #a69cff;
  --danger: #ff5968;
  --ok: #35d07f;
  --warn: #e6b64c;
  --radius: 12px;

  font-family: Inter, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* Les règles display des composants ne doivent jamais masquer [hidden]. */
[hidden] {
  display: none !important;
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

h1,
h2,
h3,
p,
dl,
dd,
dt {
  margin: 0;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}

/* ---------- Boutons ---------- */

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 15px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition:
    background 120ms ease,
    border-color 120ms ease;
}

.primary-button {
  border-color: #7669fa;
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-hover);
}

.secondary-button {
  border-color: #383d49;
  background: #20242d;
  color: #d8dce5;
}

.secondary-button:hover {
  background: #2b303b;
}

.secondary-button.danger {
  border-color: #4d343b;
  color: #f2a6af;
}

.secondary-button.danger:hover {
  background: #3a2028;
}

.icon-button {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 1px solid #383d49;
  border-radius: 7px;
  background: transparent;
  color: #b9bfcb;
  transition:
    border-color 120ms ease,
    color 120ms ease;
}

.icon-button:hover {
  border-color: #7669fa;
  color: #c3bcff;
}

.icon-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icon-button:disabled:hover {
  border-color: #383d49;
  color: #b9bfcb;
}

.icon-button.active {
  border-color: #7669fa;
  background: rgb(101 88 232 / 28%);
  color: #d7d1ff;
}

.delete-button .icon {
  width: 17px;
  height: 17px;
}

.delete-button {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  padding: 7px;
  border: 1px solid #49343b;
  border-radius: 9px;
  background: linear-gradient(180deg, #2a1c22, #21171c);
  color: #ef9aa5;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.delete-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.delete-button:hover {
  border-color: #e35f70;
  background: #54242d;
  color: #fff;
  transform: translateY(-1px);
}

.icon {
  display: block;
  flex: none;
}

.icon-spin {
  animation: icon-spin 1s linear infinite;
}

@keyframes icon-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Structure ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-elev);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
}

.brand h1 {
  font-size: 19px;
  letter-spacing: -0.5px;
}

.brand-web {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  border: 1px solid #3c4251;
  border-radius: 6px;
  color: var(--accent-soft);
  font-size: 11px;
  font-weight: 600;
  vertical-align: 2px;
}

.brand p {
  margin-top: 3px;
  color: var(--text-dim);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* Matches the height of the "add stream" button for a coherent toolbar. */
.topbar-settings {
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 24px 28px 12px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-heading h2 {
  font-size: 17px;
  font-weight: 650;
}

.section-heading p {
  margin-top: 5px;
  color: var(--text-dim);
  font-size: 12px;
}

.stream-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 18px;
  min-width: 0;
}

/*
 * Largeur par défaut fixe : agrandir la fenêtre recalcule la grille (plus de
 * colonnes) au lieu de zoomer les vidéos. La poignée de redimensionnement
 * enregistre une taille explicite par flux ; ces tuiles ne rétrécissent plus
 * et l'espace de travail défile.
 */
.sortable-stream {
  display: block;
  flex: 0 0 440px;
  width: 440px;
  min-width: 280px;
  max-width: 100%;
}

.sortable-stream[draggable='true'] {
  cursor: grab;
}

.sortable-stream[draggable='true']:active {
  cursor: grabbing;
}

.sortable-stream.dragging {
  opacity: 0.5;
}

.footer {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  padding: 9px 20px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 12px;
}

.footer-left,
.footer-right {
  display: flex;
  align-items: center;
  gap: 9px;
}

.footer-left strong {
  color: var(--text);
}

.footer .version {
  padding: 2px 6px;
  border: 1px solid #3c4251;
  border-radius: 5px;
  color: #c6cbe0;
  font-size: 11px;
}

.footer-tech {
  color: var(--text-dim);
}

.footer-right {
  margin-left: auto;
  gap: 5px;
}

.footer-right button {
  padding: 3px 5px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
}

.footer-right button.language-active {
  color: #fff;
  font-weight: 700;
}

.kofi-link {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  color: #f0c9a6;
  font-size: 12px;
  text-decoration: none;
}

.kofi-link img {
  width: 21px;
  height: 21px;
  border-radius: 5px;
  background: #fff;
  object-fit: contain;
}

.empty-state {
  display: flex;
  min-height: 360px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  border: 1px dashed #383d49;
  border-radius: 14px;
  background: #14171d;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 20px;
  border: 1px solid #3c3a67;
  border-radius: 16px;
  background: #24213f;
  color: var(--accent-soft);
  font-size: 30px;
}

.empty-state h2 {
  font-size: 17px;
}

.empty-state p {
  max-width: 380px;
  margin: 10px 0 22px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.7;
}

.form-error {
  margin: 10px 0 0;
  font-size: 12px;
}

.modal-field input:focus {
  border-color: #7669fa;
}

/* ---------- Cartes de flux ---------- */

.stream-card {
  position: relative;
  display: flex;
  height: 100%;
  min-height: 200px;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.stream-info {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
}

.stream-details {
  flex: 1;
  min-width: 0;
}

.stream-info h3 {
  margin-bottom: 5px;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stream-info p {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-dim);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 7px;
}

.stream-status {
  display: block;
  margin-top: 7px;
  overflow-wrap: anywhere;
  color: #8f9dba;
  font-size: 11px;
}

.stream-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 5px;
}

.inline-error {
  margin-top: 5px;
  font-size: 11px;
}

.video-container {
  position: relative;
  width: 100%;
  height: auto;
  flex: none;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #050609;
}

.video-container.sized-video-container {
  height: auto;
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: auto;
}

.video-container video {
  display: block;
  width: 100%;
  height: 100%;
  background: #050609;
  object-fit: contain;
}

.video-container:fullscreen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  background: #000;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  color: #b8bfce;
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}

.player-overlay > * {
  max-width: 100%;
}

.player-overlay .overlay-action {
  pointer-events: auto;
}

.idle-overlay {
  background: rgb(5 6 9 / 65%);
}

.idle-overlay.is-offline {
  background: rgb(30 8 12 / 62%);
}

.video-symbol {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid #373b49;
  border-radius: 50%;
  color: var(--accent-soft);
  font-size: 16px;
}

.overlay-title {
  color: #dfe4ee;
  font-size: 13px;
  font-weight: 600;
}

.overlay-hint {
  max-width: 340px;
  color: #f0a7ae;
  font-size: 11px;
  line-height: 1.5;
}

.player-error {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: #ff8b96;
  font-size: 11px;
}

.overlay-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px;
  border: 1px solid #7669fa;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  pointer-events: auto;
}

.overlay-action:hover {
  background: var(--accent-hover);
}

.view-controls {
  position: absolute;
  z-index: 5;
  top: 10px;
  right: 10px;
  left: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.view-controls button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 6px;
  background: rgb(15 18 25 / 88%);
  color: #fff;
  font-size: 12px;
  pointer-events: auto;
}

.view-controls button:hover,
.view-controls button.active {
  background: rgb(65 75 95 / 96%);
}

.video-container:hover .view-controls,
.video-container:has(:focus-visible) .view-controls {
  opacity: 1;
}

.audio-controls {
  position: absolute;
  z-index: 7;
  right: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 7px;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 8px;
  background: rgb(15 17 23 / 88%);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.audio-controls .mute-button,
.audio-controls .solo-button {
  display: grid;
  place-items: center;
  padding: 3px 4px;
  border: 0;
  background: transparent;
  font-size: 14px;
}

.audio-controls .solo-button {
  border-radius: 5px;
  opacity: 0.7;
}

.audio-controls .solo-button:hover {
  opacity: 1;
}

.audio-controls .solo-button.active {
  background: rgb(139 128 255 / 30%);
  opacity: 1;
}

.audio-controls input[type='range'] {
  width: 90px;
  accent-color: #8b80ff;
  cursor: pointer;
}

.video-container:hover .audio-controls,
.video-container:has(:focus-visible) .audio-controls {
  opacity: 1;
}

.stats-panel {
  position: absolute;
  z-index: 6;
  top: 52px;
  right: 10px;
  min-width: 168px;
  padding: 8px 10px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 8px;
  background: rgb(10 12 18 / 92%);
  color: #dfe4ee;
  font-size: 11px;
  pointer-events: none;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0;
}

.stats-row dt {
  color: #9aa3b5;
}

.stats-row dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.availability-dot {
  display: inline-block;
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #818897;
  box-shadow: 0 0 0 3px rgb(129 136 151 / 12%);
}

.availability-dot.online {
  background: var(--ok);
  box-shadow:
    0 0 0 3px rgb(53 208 127 / 13%),
    0 0 9px rgb(53 208 127 / 25%);
}

.availability-dot.offline {
  background: var(--danger);
  box-shadow:
    0 0 0 3px rgb(255 89 104 / 13%),
    0 0 9px rgb(255 89 104 / 22%);
}

.availability-dot.checking {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgb(230 182 76 / 13%);
}

.resize-grip {
  position: absolute;
  z-index: 10;
  right: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: linear-gradient(
    135deg,
    transparent 0 42%,
    #747b8e 43% 49%,
    transparent 50% 60%,
    #747b8e 61% 67%,
    transparent 68%
  );
  cursor: nwse-resize;
  touch-action: none;
}

.resize-grip:hover {
  background: linear-gradient(
    135deg,
    transparent 0 42%,
    #b5adff 43% 49%,
    transparent 50% 60%,
    #b5adff 61% 67%,
    transparent 68%
  );
}

/* ---------- Dialogues ---------- */

.modal-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(5 6 9 / 72%);
  backdrop-filter: blur(2px);
}

.modal-panel {
  width: min(620px, 100%);
  max-height: 86vh;
  overflow: auto;
  padding: 18px 20px 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elev);
  box-shadow: 0 24px 60px rgb(0 0 0 / 45%);
}

.modal-panel-narrow {
  width: min(480px, 100%);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.modal-header h2 {
  font-size: 16px;
}

.modal-section {
  padding: 14px 0;
  border-top: 1px solid var(--border-soft);
}

.modal-section:first-of-type {
  border-top: 0;
}

.modal-section h3 {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 650;
}

.modal-field {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
  min-width: 0;
}

.modal-field span {
  color: var(--text-dim);
  font-size: 11px;
}

.modal-field input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #383d49;
  border-radius: 7px;
  outline: none;
  background: var(--bg-input);
  color: var(--text);
  font-size: 12px;
}

.modal-row {
  display: flex;
  gap: 12px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-message {
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.65;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.modal-hint {
  margin-top: 9px;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.5;
}

.modal-notice {
  margin-top: 10px;
  padding: 7px 9px;
  border: 1px solid #3a3f52;
  border-radius: 7px;
  background: #1d2130;
  color: #cfd6e8;
  font-size: 11px;
}

/* ---------- Responsive / accessibilité ---------- */

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 650px) {
  .footer {
    padding: 8px 10px;
  }

  .footer-left .footer-tech {
    display: none;
  }

  .footer-right {
    gap: 2px;
  }

  .workspace {
    padding: 16px 12px;
  }
}

@media (max-width: 520px) {
  .modal-row {
    flex-direction: column;
    gap: 0;
  }
}

@media (hover: none) {
  .view-controls,
  .audio-controls {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
