:root {
  --bg: #0f1115; --panel: #161a22; --text: #e8eaf0;
  --muted: #9aa4b2; --accent: #5b8cff; --ok: #3ddc97; --warn: #ffb020; --err: #ff5c6c;
  --border: #202532;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin:0; height:100%; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial; }
.app-header { display:flex; align-items:center; justify-content:space-between; padding:12px 16px; border-bottom:1px solid var(--border); background:#0f1119; }
.brand { font-weight: 700; }
.badge { background: #1f2633; color: var(--text); padding: 3px 8px; border-radius: 20px; margin-left: 6px; font-size: 12px; }
.runner-badge { margin-left:8px; color:#a6b1ff; font-size:12px; }
.auth button, .auth a { margin-left:8px; }
#loginForm { display: flex; gap: 8px; align-items: center; }
#loginForm input { padding: 6px 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 4px; }
.hidden { display:none!important; }
.layout { display:flex; height: calc(100vh - 58px); }
.left, .right { padding:12px; }
.left { flex: 1.4; border-right:1px solid var(--border); display:flex; flex-direction:column; gap:12px; }
.right { flex: 1; display:flex; flex-direction:column; gap:12px; }
.toolbar { display:flex; gap:8px; align-items:center; }
button { background:#1e2432; color:var(--text); border:1px solid var(--border); border-radius:8px; padding:8px 12px; cursor:pointer; }
button.primary { background: var(--accent); color:#0b0e17; border:none; }
button.secondary { background:#1a1f2b; }
button:disabled { opacity:0.5; cursor:not-allowed; }
.editor { flex:1; min-height: 280px; background: #0c0f14; border:1px solid var(--border); border-radius: var(--radius); }
.console { background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); }
.console-header { padding:8px 12px; border-bottom:1px solid var(--border); color: var(--muted); }
.console-out { margin:0; padding:12px; font-family: var(--mono); color:#b9dbff; white-space:pre-wrap; }
.panel-header, .panel-subheader { font-weight:600; display:flex; justify-content:space-between; align-items:center; margin-bottom:8px; }
.exercise-select { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; font-size: 12px; }
.panel-body { background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); padding:12px; min-height:160px; }
.tests { list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:6px; }
.searchbar { display:flex; gap:8px; }
.searchbar input { flex:1; padding:8px; border-radius:8px; border:1px solid var(--border); background:#0c0f14; color:var(--text); }
.results { margin-top:8px; display:flex; flex-direction:column; gap:8px; }
.result a { color:#9ec1ff; text-decoration:none; }
.message-display { flex:1; border:1px solid var(--border); border-radius: var(--radius); background: var(--panel); min-height: 280px; padding: 16px; overflow-y: auto; }
.message-content { line-height: 1.6; }
.message-content h1, .message-content h2, .message-content h3 { color: var(--accent); margin-top: 0; }
.message-content p { margin: 16px 0; }
.message-content a { color: var(--accent); text-decoration: none; }
.message-content a:hover { text-decoration: underline; }
.message-content iframe { width: 100%; border: 1px solid var(--border); border-radius: 8px; margin: 16px 0; }
.message-content img { max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0; }
.message-content code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-family: var(--mono); }
.message-content pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow-x: auto; font-family: var(--mono); }
.message-timestamp { color: var(--muted); font-size: 12px; margin-bottom: 16px; }
.toast { position:fixed; bottom:16px; right:16px; background:#1f2633; color:#fff; padding:10px 14px; border-radius:8px; border:1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.muted { color: var(--muted); font-size:12px; }
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { display:none; }
.slider { position:absolute; cursor:pointer; inset:0; background:#333; border-radius:30px; }
.slider:before { content:""; position:absolute; height:22px; width:22px; left:3px; top:3px; background:white; border-radius:50%; transition:.2s; }
input:checked + .slider { background: var(--accent); }
input:checked + .slider:before { transform: translateX(22px); }
.admin-layout { padding:16px; display:grid; gap:16px; grid-template-columns: repeat(auto-fit,minmax(260px,1fr)); }
.card { background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); padding:12px; display:grid; gap:8px; }
.dashboard { grid-column: 1 / -1; }
.stats { display:grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap:12px; margin-top:12px; }
.stat-card { background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); padding:16px; text-align:center; }
.stat-number { font-size:24px; font-weight:bold; color: var(--accent); }
.stat-label { font-size:12px; color: var(--muted); margin-top:4px; }

/* Modal de connexion */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: 400px; width: 90%; }
.modal h2 { margin-top: 0; color: var(--accent); }
.form { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.form input { padding: 10px 12px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 6px; font-size: 14px; }
.form input:focus { outline: none; border-color: var(--accent); }
.form-buttons { display: flex; gap: 8px; }
.form-buttons button { flex: 1; }
.error { background: #2a1f1f; border: 1px solid var(--err); color: var(--err); padding: 8px 12px; border-radius: 4px; font-size: 12px; }

/* Admin simple */
.admin-simple { padding: 20px; max-width: 600px; margin: 0 auto; }
.admin-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.admin-card h2 { margin-top: 0; color: var(--accent); }
.admin-card p { color: var(--muted); margin-bottom: 24px; }
.mode-controls { display: flex; flex-direction: column; gap: 12px; margin: 20px 0; }
.mode-option { display: flex; align-items: flex-start; gap: 12px; }
.mode-option input[type="radio"] { margin-top: 4px; }
.mode-label { cursor: pointer; flex: 1; }
.mode-label strong { display: block; font-size: 16px; margin-bottom: 4px; }
.mode-label span { color: var(--muted); font-size: 14px; }
.current-mode { margin-top: 20px; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; text-align: center; }

/* Formulaire exercices */
.exercise-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-weight: 600; color: var(--text); }
.form-group input, .form-group textarea { padding: 10px 12px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 6px; font-size: 14px; font-family: inherit; resize: vertical; }
.form-group input:focus, .form-group textarea:focus { outline: none; border-color: var(--accent); }
.status { padding: 12px; border-radius: 6px; margin-top: 16px; text-align: center; }
.status.success { background: #1a2f1a; border: 1px solid var(--ok); color: var(--ok); }
.status.error { background: #2a1f1f; border: 1px solid var(--err); color: var(--err); }
.exercises-list { display: flex; flex-direction: column; gap: 12px; }
.exercise-item { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.exercise-info { flex: 1; }
.exercise-item h3 { margin: 0 0 8px 0; color: var(--accent); }
.exercise-item p { margin: 0; color: var(--muted); }
.delete-btn { background: var(--err); color: white; border: none; border-radius: 4px; padding: 6px 12px; cursor: pointer; font-size: 12px; white-space: nowrap; }
.delete-btn:hover { background: #ff4757; }
.loading { text-align: center; color: var(--muted); padding: 20px; }
.form-group select { padding: 10px 12px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: 6px; font-size: 14px; }
.form-group select:focus { outline: none; border-color: var(--accent); }
.exercise-preview { margin-top: 16px; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.exercise-preview h4 { margin: 0 0 8px 0; color: var(--accent); }

/* Cacher les boutons et ajuster l'affichage en mode recherche */
body[data-mode="recherche"] .toolbar {
  display: none;
}

body[data-mode="recherche"] .console {
  background: var(--panel);
  border: 1px solid var(--border);
}

body[data-mode="recherche"] .console-out {
  color: var(--muted);
  font-style: italic;
}

/* Popup Mode Recherche Glassmorphism */
.search-mode-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, rgba(15, 17, 21, 0.85), rgba(22, 26, 34, 0.75));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  animation: fadeInGlass 0.5s ease-out;
}

@keyframes fadeInGlass {
  from { opacity: 0; backdrop-filter: blur(0px); }
  to { opacity: 1; backdrop-filter: blur(20px); }
}

.glass-container {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 20px;
  padding: 0;
  max-width: 90vw;
  max-height: 85vh;
  width: 100%;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  overflow: scroll;
  display: flex;
  flex-direction: column;
}

.glass-header {
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.2), rgba(91, 140, 255, 0.1));
  padding: 30px 40px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.glass-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.mode-badge {
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.3), rgba(91, 140, 255, 0.2));
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 14px;
  font-weight: 500;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.glass-content {
  flex: 1;
  padding: 40px;
 
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup-message-display {
  width: 100%;
  max-width: 800px;
  text-align: center;
}

.popup-message-display .loading {
  color: rgba(255, 255, 255, 0.7);
  font-size: 18px;
  font-style: italic;
}

.popup-message-display .message-content {
  color: white;
  line-height: 1.8;
  font-size: 16px;
}

.popup-message-display .message-content h1,
.popup-message-display .message-content h2,
.popup-message-display .message-content h3 {
  color: rgba(91, 140, 255, 0.9);
  margin: 32px 0 16px 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.popup-message-display .message-content h1 {
  font-size: 32px;
}

.popup-message-display .message-content h2 {
  font-size: 26px;
}

.popup-message-display .message-content h3 {
  font-size: 22px;
}

.popup-message-display .message-content p {
  margin: 20px 0;
  color: rgba(255, 255, 255, 0.9);
}

.popup-message-display .message-content iframe {
  border-radius: 15px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  margin: 32px 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  max-width: 100%;
  height: 400px;
}

.popup-message-display .message-content img {
  border-radius: 15px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.popup-message-display .message-content a {
  color: rgba(91, 140, 255, 0.9);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-bottom-color 0.3s ease;
}

.popup-message-display .message-content a:hover {
  border-bottom-color: rgba(91, 140, 255, 0.9);
}

.popup-message-display .message-content code {
  background: rgba(0, 0, 0, 0.3);
  color: rgba(255, 255, 255, 0.9);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.popup-message-display .message-content pre {
  background: rgba(0, 0, 0, 0.3);
  color: rgba(255, 255, 255, 0.9);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin: 24px 0;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
}

.popup-message-display .message-timestamp {
  color: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  margin-bottom: 24px;
  font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
  .search-mode-popup {
    padding: 20px;
  }
  
  .glass-header {
    padding: 20px 24px;
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
  
  .glass-header h1 {
    font-size: 24px;
  }
  
  .glass-content {
    padding: 24px;
  }
  
  .popup-message-display .message-content iframe {
    height: 250px;
  }
}

/* Dashboard Styles */
.dashboard-layout {
  padding: 20px;
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
  max-width: 1400px;
  margin: 0 auto;
}

.dashboard-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.dashboard-card h2 {
  margin: 0 0 20px 0;
  color: var(--accent);
  font-size: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}

.stat-item {
  background: var(--bg);
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  text-align: center;
}

.stat-number {
  font-size: 32px;
  font-weight: bold;
  color: var(--accent);
  margin-bottom: 8px;
}

.stat-label {
  color: var(--muted);
  font-size: 14px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  align-items: end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.filter-group select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  font-size: 14px;
}

.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.submissions-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.submission-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: start;
}

.submission-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.submission-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.submission-exercise {
  font-weight: 600;
  color: var(--accent);
  font-size: 16px;
}

.submission-student {
  color: var(--text);
  font-size: 14px;
}

.submission-date {
  color: var(--muted);
  font-size: 12px;
  margin-left: auto;
}

.submission-content {
  margin-top: 12px;
}

.submission-description {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 12px;
  background: var(--panel);
  padding: 12px;
  border-radius: 6px;
  border-left: 4px solid var(--accent);
}

.code-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.code-preview-header {
  background: var(--panel);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.code-preview-content {
  padding: 16px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.5;
}

.submission-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-expand {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-expand:hover {
  background: #4a7cff;
}

.btn-reveliatus {
  background: linear-gradient(135deg, #330066, #1a0033);
  color: #ff3366;
  border: 1px solid #ff3366;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: bold;
  box-shadow: 0 0 10px rgba(255, 51, 102, 0.3);
  transition: all 0.3s ease;
}

.btn-reveliatus:hover {
  background: linear-gradient(135deg, #4d0099, #260040);
  box-shadow: 0 0 20px rgba(255, 51, 102, 0.6);
  transform: scale(1.05);
}

.btn-liberate {
  background: linear-gradient(135deg, #0d5a3d, #1a8b5a);
  color: #ffffff;
  border: 1px solid #3ddc97;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: bold;
  box-shadow: 0 0 10px rgba(61, 220, 151, 0.3);
  transition: all 0.3s ease;
}

.btn-liberate:hover {
  background: linear-gradient(135deg, #1a8b5a, #26a86e);
  box-shadow: 0 0 20px rgba(61, 220, 151, 0.6);
  transform: scale(1.05);
}

.btn-expand.expanded {
  background: var(--muted);
}

.submission-item.expanded .code-preview-content {
  max-height: none;
}

/* Styles anti-triche dans le dashboard */
.submission-item.suspicious {
  border-left: 4px solid var(--err);
  background: linear-gradient(135deg, rgba(255, 92, 108, 0.05), rgba(255, 92, 108, 0.02));
}

.cheat-indicator {
  position: relative;
  background: var(--err);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: help;
  white-space: nowrap;
}

.cheat-indicator:hover .cheat-tooltip {
  opacity: 1;
  visibility: visible;
}

.cheat-tooltip {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

.cheat-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.9);
}

.anti-cheat-info {
  background: rgba(255, 92, 108, 0.1);
  border: 1px solid rgba(255, 92, 108, 0.3);
  border-radius: 8px;
  padding: 16px;
  margin: 12px 0;
}

.anti-cheat-header {
  font-weight: 600;
  color: var(--err);
  margin-bottom: 12px;
  font-size: 14px;
}

.anti-cheat-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.anti-cheat-stats .stat {
  background: rgba(255, 92, 108, 0.15);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text);
  border: 1px solid rgba(255, 92, 108, 0.2);
}

.last-copied {
  margin-top: 12px;
}

.last-copied strong {
  color: var(--err);
  font-size: 13px;
}

.copied-text {
  background: var(--bg);
  border: 1px solid rgba(255, 92, 108, 0.3);
  border-radius: 6px;
  padding: 12px;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  max-height: 150px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 768px) {
  .dashboard-layout {
    padding: 16px;
  }
  
  .filters-grid {
    grid-template-columns: 1fr;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .submission-item {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .submission-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .submission-date {
    margin-left: 0;
  }
}

/* Navigation des exercices en mode individuel */
.exercise-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 12px;
}

.nav-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

.nav-btn:hover:not(:disabled) {
  background: #4a7cff;
  transform: translateY(-1px);
}

.nav-btn:disabled {
  background: var(--muted);
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.nav-indicator {
  font-weight: 600;
  color: var(--text);
  font-size: 16px;
  padding: 0 16px;
}

.mode-indicator {
  background: var(--accent);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  margin-left: 12px;
}

/* Responsive navigation */
@media (max-width: 768px) {
  .exercise-navigation {
    flex-direction: column;
    gap: 12px;
  }
  
  .nav-btn {
    width: 100%;
    min-width: auto;
  }
}

@media (max-width: 1100px) { .layout { flex-direction: column; } .left{ border-right:none; } }