:root {
  /* Color Palette */
  --bg-page: #101014;
  --bg-sidebar: #18181c;
  --bg-header: #1c1c22;
  --bg-surface: #25252b;
  --bg-input: #2f2f36;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #3f3f46;

  /* Block Colors (Vibrant & Gradient-ready) */
  --color-sequence: #3b82f6;
  --color-speak: #f59e0b;
  --color-pub: #10b981;
  --color-musique: #8b5cf6;
  --color-autre: #ef4444;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --radius: 8px;
}

/* Global */
html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

* {
  box-sizing: border-box;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-page);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #52525b;
}

/* Header */
header {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  gap: 16px;
}


.logo {
  display: flex;
  align-items: center;
}

.logo img {
  height: 32px;
  width: auto;
}

h1 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-main);
  flex: 1;
}

.header-stats {
  display: flex;
  gap: 24px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-family: monospace;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  gap: 20px;
  flex-wrap: wrap;
}

.show-inputs {
  display: flex;
  gap: 16px;
  flex: 1;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.input-group input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  min-width: 120px;
}

.input-group input:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

#showName {
  min-width: 250px;
}

/* Controls & Buttons */
.controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  font-size: 0.9rem;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #3f3f46;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid transparent;
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: none;
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
}

.btn-icon:hover {
  background: #3f3f46;
}

/* Dropdown */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background-color: var(--bg-surface);
  min-width: 180px;
  box-shadow: var(--shadow-md);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  z-index: 50;
  margin-top: 4px;
  padding: 4px;
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown-content button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-main);
  padding: 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 4px;
}

.dropdown-content button:hover {
  background: #3f3f46;
}

/* Main Layout */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Palette Sidebar */
#palette {
  width: 200px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
  overflow-y: auto;
}

.palette-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.palette-header h3 {
  margin: 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: var(--text-muted);
}

.palette-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.block {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: white;
  cursor: grab;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid transparent;
  transition: transform 0.1s;
}

.block:active {
  cursor: grabbing;
  transform: scale(0.98);
}

/* Block colors in palette */
.block.sequence {
  border-color: var(--color-sequence);
}

.block.speak {
  border-color: var(--color-speak);
}

.block.pub {
  border-color: var(--color-pub);
}

.block.musique {
  border-color: var(--color-musique);
}

.block.autre {
  border-color: var(--color-autre);
}

/* Conductor Area */
#conductor-wrapper {
  flex: 1;
  background: #09090b;
  /* Darker than page bg */
  overflow-y: auto;
  padding: 20px;
}

#conductor {
  max-width: 900px;
  margin: 0 auto;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 100px;
}

#conductor.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: 12px;
}

.conductor-empty-msg {
  color: var(--text-muted);
  font-size: 1.1rem;
  pointer-events: none;
  user-select: none;
}

/* Conductor Blocks */
.block-item,
.placeholder {
  display: grid;
  grid-template-columns: 32px 80px 70px 1fr 60px;
  /* Handle Time Dur Content Actions */
  gap: 12px;
  align-items: start;
  background: var(--bg-surface);
  padding: 12px;
  border-radius: var(--radius);
  border-left: 4px solid var(--text-muted);
  /* Default fallback */
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.placeholder {
  background: transparent;
  border: 2px dashed var(--border) !important;
  box-shadow: none;
}

/* Drag Handle */
.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.2rem;
  height: 100%;
  padding-top: 4px;
}

.drag-handle:active {
  cursor: grabbing;
}

/* Time */
.time-display {
  font-family: monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  padding-top: 6px;
}

/* Duration */
.duration-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.label-duration {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.duration-input {
  background: var(--bg-input);
  border: 1px solid transparent;
  color: var(--text-main);
  border-radius: 4px;
  padding: 4px;
  width: 100%;
  text-align: center;
  font-family: monospace;
  font-size: 0.95rem;
}

.duration-input:focus {
  outline: 2px solid var(--primary);
  background: #000;
}

/* Content */
.content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-main);
  padding: 4px;
  border-radius: 4px;
  border: 1px solid transparent;
}

.title:hover {
  background: var(--bg-input);
}

.title:focus {
  background: var(--bg-input);
  outline: 2px solid var(--primary);
  border-color: transparent;
}

/* Description always visible as requested */
.description-input {
  /* Make it look like an input field or just visible box */
  background: rgba(255, 255, 255, 0.05);
  /* Subtle bg */
  border: 1px solid transparent;
  /* No border by default */
  color: var(--text-muted);
  resize: none;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s;
  min-height: 2.4em;
  /* Ensure some height */
  margin-top: 4px;
}

.description-input::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.description-input:hover,
.description-input:focus {
  background: var(--bg-input);
  color: var(--text-main);
}

.description-input:focus {
  outline: none;
  border-color: var(--border);
}

/* Item Actions */
.item-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.btn-mini {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 1.1rem;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-mini:hover {
  background: var(--bg-input);
  color: var(--text-main);
}

/* Specific colors for actions */
.btn-mini.duplicate:hover {
  color: var(--primary);
}

.btn-mini.delete:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.hidden {
  display: none !important;
}

/* --- Collaboration Features --- */

/* Connection Status in Header */
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--danger);
  /* Offline/Default */
  transition: background-color 0.3s;
}

.status-dot.connected {
  background-color: var(--success);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
}

.status-dot.connecting {
  background-color: var(--color-speak);
  animation: pulse 1.5s infinite;
}

.status-dot.offline {
  background-color: var(--danger);
}

@keyframes pulse {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }

  100% {
    opacity: 1;
  }
}

.peer-count {
  font-weight: 600;
  color: var(--text-main);
}

/* Locked Block Styles */
.block-item.locked {
  border: 2px solid var(--danger) !important;
  /* Red border overrides type color */
  position: relative;
  /* Visual feedback */
}

/* Padlock Icon */
.padlock-icon {
  position: absolute;
  top: -10px;
  right: -10px;
  font-size: 1.2rem;
  z-index: 10;
  background: var(--bg-surface);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* User Badge */
.lock-badge {
  position: absolute;
  top: -10px;
  right: 20px;
  /* Left of padlock */
  background: var(--danger);
  color: white;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  pointer-events: none;
  z-index: 9;
}

/* Disable inputs visually when locked */
.block-item.locked .title,
.block-item.locked .description-input,
.block-item.locked .duration-input {
  pointer-events: none;
  opacity: 0.7;
  background: rgba(0, 0, 0, 0.1);
}

.modal-content {
  background: var(--bg-surface);
  padding: 24px;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.modal-content h2 {
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--text-main);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.form-group input:not([type="checkbox"]),
.form-group select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: var(--radius);
  color: var(--text-main);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
}

.checkbox-group span {
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: color 0.2s;
}

.checkbox-group:hover span {
  color: var(--text-main);
}

.form-group input[type="color"] {
  height: 40px;
  padding: 2px;
  cursor: pointer;
}

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

.spacer {
  flex: 1;
}

.btn-text {
  background: transparent;
  color: var(--text-muted);
  border: none;
}

.btn-text:hover {
  color: var(--text-main);
}

/* Print Styles - Update Round 4 & 6: Layout & Pagination */
@media print {
  @page {
    margin: 1cm;
    size: A4;
  }

  html,
  body {
    background: #fff !important;
    color: #000 !important;
    height: auto !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  header,
  .top-bar,
  #palette,
  .item-actions,
  .drag-handle,
  .duration-container,
  .modal,
  .dropdown,
  #conductor::before {
    display: none !important;
  }

  .main-layout {
    display: block !important;
  }

  #conductor-wrapper {
    overflow: visible !important;
    padding: 0 !important;
    background: transparent !important;
  }

  /* Custom Print Header */
  .print-header-only {
    display: block !important;
    border-bottom: 2px solid #000;
    margin-bottom: 20px;
    padding-bottom: 10px;
  }

  .print-header-only h2 {
    margin: 0;
    font-size: 1.5rem;
  }

  .print-header-only p {
    margin: 5px 0 0;
  }

  #conductor {
    display: block !important;
    padding: 0 !important;
    border: none !important;
  }

  .block-item {
    display: flex !important;
    align-items: flex-start !important;
    padding: 8px 12px !important;

    /* Force Border Color */
    border: 1px solid #ddd !important;
    border-left-width: 8px !important;
    border-left-style: solid !important;

    /* Redundant Color Method: Box Shadow Inset */
    box-shadow: inset 8px 0 0 0 var(--item-color) !important;

    background: #fff !important;

    /* Allow breaking across pages (Round 6) */
    page-break-inside: auto !important;
    break-inside: auto !important;

    gap: 16px;
    margin-bottom: 8px !important;

    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .time-display {
    width: 60px;
    color: #000 !important;
    font-size: 1rem;
    font-weight: bold;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .print-duration {
    font-size: 0.8rem;
    font-weight: normal;
    color: #555 !important;
  }

  .content {
    flex: 1;
  }

  .title {
    font-size: 1.1rem;
    font-weight: bold;
    color: #000 !important;
    padding: 0 !important;
  }

  /* Textarea replacement via JS during print */
  .description-print-view {
    display: block !important;
    color: #333 !important;
    white-space: pre-wrap !important;
    font-size: 0.9rem !important;
    margin-top: 4px;

    /* Ensure content inside doesn't cause weird break issues */
    page-break-inside: auto !important;
  }

  /* Hide original inputs in print */
  .description-input,
  .duration-container {
    display: none !important;
  }
}

.print-header-only {
  display: none;
}

/* ============================================
   Share / Collaborate Modal
   ============================================ */

.share-modal-content {
  max-width: 480px;
  width: 100%;
}

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

.share-modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-main);
}

.share-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.share-section-title {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.share-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.share-section-title strong {
  display: block;
  font-size: 1rem;
  color: var(--text-main);
  margin-bottom: 2px;
}

.share-section-title p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.share-divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* Link display row */
.link-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.link-wrapper input[type="text"] {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--primary);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: monospace;
  font-size: 0.82rem;
  cursor: text;
  min-width: 0;
}

.link-wrapper input[type="text"]:focus {
  outline: 2px solid var(--primary);
}

.btn-copy {
  white-space: nowrap;
  flex-shrink: 0;
}

/* Notice de sécurité sous le lien de partage */
.share-notice {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ─── Toggle switch (iOS-style) ─────────────────────── */
.toggle-switch-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.toggle-track {
  width: 34px;
  height: 18px;
  border-radius: 9px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.toggle-track.active {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.toggle-track.active .toggle-thumb {
  left: 18px;
}

.toggle-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  transition: color 0.15s;
}

.toggle-switch-wrap:hover .toggle-text {
  color: var(--text-main);
}

/* ─── Menu Dropdown (Save/Load/Excel/Print) ─────────── */
.menu-dropdown {
  position: relative;
  flex-shrink: 0;
}

.menu-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
}

.menu-chevron {
  display: flex;
  align-items: center;
  opacity: 0.8;
  transition: transform 0.2s ease;
}

.menu-toggle[aria-expanded="true"] .menu-chevron {
  transform: rotate(-180deg);
}

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  z-index: 500;
  min-width: 160px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  animation: langMenuIn 0.15s ease;
}

.menu-panel button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  text-align: left;
  transition: background 0.12s;
}

.menu-panel button:hover {
  background: var(--bg-input);
}

/* ─── Language Dropdown ─────────────────────────────── */
.lang-dropdown {
  position: relative;
  flex-shrink: 0;
}

.lang-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 78px;
  justify-content: center;
  font-size: 0.85rem;
}

.lang-chevron {
  font-size: 0.6rem;
  opacity: 0.7;
  transition: transform 0.2s ease;
}

.lang-toggle[aria-expanded="true"] .lang-chevron {
  transform: rotate(180deg);
}

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  z-index: 500;
  min-width: 140px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  animation: langMenuIn 0.15s ease;
}

@keyframes langMenuIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  text-align: left;
  transition: background 0.12s;
}

.lang-option:hover {
  background: var(--bg-input);
}

.lang-option.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}