@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;600&family=Inter:wght@300;400;600;700&family=Outfit:wght@500;700;800&display=swap');

:root {
  --bg-dark: #0b0f19;
  --panel-bg: #131b2e;
  --pcb-green: #064e3b;
  --pcb-surface: #042f2e;
  --accent-cyan: #06b6d4;
  --accent-blue: #3b82f6;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --accent-green: #10b981;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #1e293b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header Navbar */
.app-header {
  background: rgba(19, 27, 46, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.4rem;
  font-weight: 800;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-title span.badge {
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid var(--accent-cyan);
  color: var(--accent-cyan);
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  -webkit-text-fill-color: var(--accent-cyan);
}

.nav-tabs {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.btn-manual-nav {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: white;
  border: none;
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 0 15px rgba(37, 99, 235, 0.4);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-manual-nav:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(56, 189, 248, 0.6);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: var(--accent-blue);
  color: white;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

/* Main Grid Layout */
.main-container {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  flex: 1;
}

@media (max-width: 1200px) {
  .main-container {
    grid-template-columns: 1fr;
  }
}

/* Card Containers */
.card-panel {
  background: var(--panel-bg);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 1.25rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

/* Simulator Canvas Frame */
.viewport-frame {
  position: relative;
  background: #090d16;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

canvas#gateCanvas {
  display: block;
  width: 100%;
  height: 360px;
}

/* Interactive Overlay Buttons on Viewport */
.viewport-controls {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  background: rgba(15, 23, 42, 0.8);
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.btn-ctrl {
  background: #1e293b;
  border: 1px solid #334155;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.btn-ctrl:hover {
  background: #334155;
  border-color: var(--accent-cyan);
}

.btn-ctrl.btn-danger {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--accent-red);
  color: #fca5a5;
}

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

.btn-ctrl.btn-warning {
  background: rgba(245, 158, 11, 0.2);
  border-color: var(--accent-amber);
  color: #fde047;
}

.btn-ctrl.btn-warning.active {
  background: var(--accent-amber);
  color: black;
}

/* PCB Layout representation */
.pcb-board {
  background: radial-gradient(circle at center, #064e3b 0%, #042f2e 100%);
  border: 4px solid #0f5132;
  border-radius: 12px;
  padding: 1.25rem;
  position: relative;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.6), 0 0 15px rgba(6, 78, 59, 0.4);
}

.pcb-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  color: #a7f3d0;
  font-family: 'Fira Code', monospace;
  font-size: 0.85rem;
}

/* Afficheur 7-Segments Physique Réel CAME (Ultra-épuré) */
.lcd-physical-frame {
  background: #09170e;
  border: 4px solid #14532d;
  border-radius: 8px;
  padding: 0.8rem 1.2rem;
  box-shadow: inset 0 0 15px rgba(0,0,0,0.9), 0 4px 12px rgba(0,0,0,0.5);
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.3s ease;
}

.lcd-physical-frame.power-off {
  background: #0f172a;
  border-color: #1e293b;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
}

.lcd-bevel {
  background: #022c22;
  border: 2px solid #064e3b;
  border-radius: 6px;
  padding: 0.6rem 2rem;
  width: 100%;
  text-align: center;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.8);
}

.lcd-physical-frame.power-off .lcd-bevel {
  background: #020617;
  border-color: #0f172a;
}

.lcd-digit-code {
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 2.2rem;
  font-weight: 800;
  color: #4ade80;
  text-shadow: 0 0 12px rgba(74, 222, 128, 0.8), 0 0 25px rgba(74, 222, 128, 0.4);
  letter-spacing: 4px;
}

.lcd-physical-frame.power-off .lcd-digit-code {
  color: #1e293b;
  text-shadow: none;
}

/* Carte de Légende Explicative Pédagogique (Sous l'écran) */
.lcd-helper-card {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 0.8rem 1rem;
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.lcd-helper-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #cbd5e1;
}

.lcd-helper-label {
  color: #94a3b8;
  font-size: 0.78rem;
}

.lcd-helper-code {
  color: #fde047;
  font-weight: 700;
}

.lcd-helper-val {
  color: #38bdf8;
  font-weight: 700;
}

.lcd-helper-index {
  font-size: 0.7rem;
  color: #64748b;
  margin-left: 0.5rem;
}

.lcd-helper-status {
  color: #4ade80;
  font-weight: 600;
}

/* Terminal Blocks (Borniers) & Drag and Drop Styles */
.terminal-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.terminal-block {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.75rem;
}

.terminal-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: #94a3b8;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.terminal-node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  margin-bottom: 0.35rem;
  cursor: grab;
  user-select: none;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.terminal-node.has-wire {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.4);
}

.terminal-node:active {
  cursor: grabbing;
}

.terminal-node:hover {
  background: rgba(6, 182, 212, 0.2);
  border-color: var(--accent-cyan);
}

.terminal-node.dragging {
  opacity: 0.5;
  outline: 2px dashed var(--accent-amber);
}

.terminal-node.drag-over {
  background: rgba(16, 185, 129, 0.4) !important;
  border-color: #10b981 !important;
  transform: scale(1.03);
}

.terminal-node.selected {
  outline: 2px solid var(--accent-cyan);
  background: rgba(6, 182, 212, 0.3);
}

.terminal-label {
  font-size: 0.82rem;
  font-weight: 700;
}

.screw-head {
  width: 20px;
  height: 20px;
  background: #334155;
  color: #94a3b8;
  border-radius: 50%;
  border: 1px solid #475569;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  flex-shrink: 0;
}

.terminal-node.has-wire .screw-head,
.screw-head.has-wire {
  background: #ef4444;
  color: #ffffff;
  border-color: #dc2626;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

.screw-head:hover {
  transform: scale(1.2);
  background: #dc2626;
  color: #ffffff;
  border-color: #b91c1c;
}

.screw-head::after {
  content: '−';
}

/* Wires list view */
.wires-list {
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  max-height: 180px;
  overflow-y: auto;
}

.wire-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  font-family: 'Fira Code', monospace;
}

.wire-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.5rem;
}

.btn-remove-wire {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-weight: bold;
}

/* Log Panel */
.logs-console {
  background: #050811;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 0.75rem;
  font-family: 'Fira Code', monospace;
  font-size: 0.78rem;
  height: 140px;
  overflow-y: auto;
  color: #a7f3d0;
}

.log-entry {
  margin-bottom: 0.25rem;
  line-height: 1.3;
}

/* Exercise Cards */
.exercise-box {
  background: #0f172a;
  border: 1px solid var(--accent-cyan);
  border-radius: 8px;
  padding: 1rem;
}

.ex-title {
  font-weight: 700;
  color: var(--accent-cyan);
  font-size: 1rem;
  margin-bottom: 0.4rem;
}

.ex-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  border: none;
  color: white;
  font-weight: 700;
  padding: 0.675rem 1.25rem;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  transition: transform 0.1s, box-shadow 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(6, 182, 212, 0.4);
}

/* Modal Notice Technique CAME ZL65 */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: #0f172a;
  border: 1px solid #38bdf8;
  border-radius: 12px;
  width: 90%;
  max-width: 900px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(56, 189, 248, 0.3);
  overflow: hidden;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  background: #1e293b;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.5rem;
  font-weight: bold;
  cursor: pointer;
}

.btn-close-modal:hover {
  color: white;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.manual-quick-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #94a3b8;
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.manual-quick-btn:hover {
  color: white;
  border-color: #38bdf8;
}

.manual-quick-btn.active {
  background: #0284c7;
  color: white;
  border-color: #38bdf8;
}

.manual-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.manual-table th, .manual-table td {
  border: 1px solid #1e293b;
  padding: 0.6rem 0.8rem;
  text-align: left;
}

.manual-table th {
  background: #1e293b;
  color: #38bdf8;
}

.manual-table tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

/* Modal de Raccordement Rapide de Bornes */
.quick-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(2, 6, 23, 0.8);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.quick-modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.quick-modal-content {
  background: #0f172a;
  border: 2px solid #38bdf8;
  border-radius: 12px;
  width: 92%;
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 25px rgba(56, 189, 248, 0.25);
  overflow: hidden;
  animation: modalPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from { transform: scale(0.9) translateY(20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.quick-modal-header {
  background: #1e293b;
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #334155;
}

.quick-modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quick-modal-body {
  padding: 1.2rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.quick-device-group {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 0.8rem;
}

.quick-device-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #fde047;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid rgba(253, 224, 71, 0.2);
  padding-bottom: 0.3rem;
  display: flex;
  justify-content: space-between;
}

.quick-term-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.6rem;
}

.quick-term-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: white;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s ease;
  text-align: left;
}

.quick-term-btn:hover {
  background: #0284c7;
  border-color: #38bdf8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.quick-term-btn.connected {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
}

/* Style spécifique pour la liste déroulante des exercices à 5 lignes avec défilement */
select[size] {
  height: 160px !important;
  overflow-y: auto !important;
  scrollbar-width: thin;
  scrollbar-color: #0284c7 #0f172a;
}

select[size] option {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

select[size] option:hover {
  background: #1e293b !important;
  color: #38bdf8 !important;
}

select[size] option:checked {
  background: linear-gradient(135deg, #0284c7, #2563eb) !important;
  color: #ffffff !important;
  font-weight: 700;
}

