/* ============================================================
   Testeur Python — feuille de style
   Base reprise telle quelle du template Hello World v0.1 (variables
   de couleur, système de carte, menu horizontal), complétée par les
   composants propres à cette appli (éditeur/sortie, panneau fichiers,
   quota) tout en bas du fichier.
   ============================================================ */

:root {
  --bg-page: #f0f4f8;
  --bg-card: #ffffff;
  --bg-card-alt: #f8fafc;
  --bg-accent-soft: #e7f0f9;

  --text-primary: #0b2a3c;
  --text-secondary: #335f77;
  --text-muted: #7d93a3;

  --border: #dce5ed;

  --brand: #1a5f7a;
  --brand-hover: #0f4a62;
  --brand-light: #3b8cbf;
  --brand-tint: rgba(26, 95, 122, 0.08);
  --on-brand: #ffffff;

  --danger: #b33333;
  --danger-bg: #fbeaea;
  --on-danger: #ffffff;
  --success-text: #0f6e56;
  --success-bg: #dff3e6;
}

[data-theme="dark"] {
  --bg-page: #0f1720;
  --bg-card: #16212c;
  --bg-card-alt: #1a2733;
  --bg-accent-soft: #1c2e3a;

  --text-primary: #e2e8ee;
  --text-secondary: #9fb3c2;
  --text-muted: #7f97a8;

  --border: #2a3742;

  --brand: #4a9fc0;
  --brand-hover: #6cb6d4;
  --brand-light: #4a9fc0;
  --brand-tint: rgba(74, 159, 192, 0.14);
  --on-brand: #0f1720;

  --danger: #e6716f;
  --danger-bg: #3a1f1f;
  --on-danger: #1a0a0a;
  --success-text: #7fd9a0;
  --success-bg: #1e3d2c;
}

* { box-sizing: border-box; font-family: system-ui, 'Segoe UI', Roboto, sans-serif; }

body { background: var(--bg-page); margin: 0; padding: 20px; color: var(--text-primary); }

.app {
  max-width: 640px;
  margin: 0 auto;
  background: var(--bg-card);
  border-radius: 32px;
  padding: 28px 26px 32px;
  box-shadow: 0 20px 40px rgba(0, 20, 40, 0.12);
}
.app.app-large { max-width: none; width: 97%; }

h1 { font-weight: 700; font-size: 1.5rem; margin: 0 0 18px 0; color: var(--text-primary); }

form { display: flex; flex-direction: column; gap: 14px; }
/* PIÈGE CONNU : toute classe utilitaire appliquée directement sur un
   <form> doit déclarer flex-direction elle-même (ex. .row ci-dessous),
   sinon cette règle générique l'impose silencieusement en colonne. */

fieldset { border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px 16px; margin-bottom: 16px; }
legend { padding: 0 8px; font-weight: 600; color: var(--brand); font-size: 0.85rem; }

label { font-weight: 600; font-size: 0.82rem; color: var(--text-secondary); display: block; margin-bottom: 4px; }

input[type="text"], input[type="email"], input[type="password"], textarea, select {
  width: 100%; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--border);
  font-size: 0.9rem; background: var(--bg-card-alt); color: var(--text-primary);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand-light); background: var(--bg-card); }

.field { display: flex; flex-direction: column; gap: 2px; }
.row { display: flex; flex-direction: row; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; }

.btn {
  background: var(--brand); border: 1px solid var(--brand); color: var(--on-brand);
  font-weight: 600; padding: 10px 20px; border-radius: 30px; font-size: 0.88rem;
  cursor: pointer; transition: 0.15s; text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline { background: transparent; color: var(--brand); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg-accent-soft); }
.btn-outline:disabled { opacity: .5; cursor: not-allowed; background: transparent; }
.btn-sm { padding: 5px 12px; font-size: 0.75rem; }

.alert { padding: 10px 14px; border-radius: 12px; font-size: 0.85rem; margin-bottom: 4px; }
.alert-erreur { background: var(--danger-bg); color: var(--danger); border-left: 4px solid var(--danger); }
.alert-info { background: var(--bg-accent-soft); color: var(--brand); border-left: 4px solid var(--brand-light); }

/* Menu horizontal fixe — bandeau arrondi flottant */
.topnav {
  position: sticky; top: 12px; z-index: 200;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 24px;
  box-shadow: 0 12px 28px rgba(0, 20, 40, 0.10);
  max-width: 1400px; width: 97%; margin: 12px auto 20px;
}
.topnav-inner { display: flex; align-items: center; gap: 20px; padding: 10px 16px; flex-wrap: wrap; }
.topnav-brand { font-weight: 700; font-size: 1.02rem; color: var(--brand); text-decoration: none; white-space: nowrap; flex-shrink: 0; }
.topnav-links { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; }
.topnav-link {
  padding: 8px 14px; border-radius: 10px; color: var(--text-secondary); text-decoration: none;
  font-weight: 600; font-size: 0.84rem; white-space: nowrap; transition: background 0.15s ease, color 0.15s ease;
}
.topnav-link:hover { background: var(--bg-accent-soft); color: var(--brand); }
.topnav-link.active { background: var(--brand-tint); color: var(--brand); }
.topnav-user { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topnav-who { background: var(--bg-accent-soft); padding: 6px 14px; border-radius: 30px; font-size: 0.82rem; color: var(--brand); font-weight: 600; white-space: nowrap; }

.theme-toggle {
  background: var(--bg-card-alt); border: 1px solid var(--border); border-radius: 30px;
  width: 34px; height: 34px; font-size: 1rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--bg-accent-soft); }

.pastille {
  display: inline-block; padding: 3px 12px; border-radius: 30px; font-size: 0.72rem; font-weight: 600;
  background: var(--brand); color: var(--on-brand);
}

pre.bloc-code {
  background: var(--bg-card-alt); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; overflow-x: auto; font-size: 0.8rem; line-height: 1.5;
}

kbd {
  background: var(--bg-card-alt); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; font-size: 0.78rem; font-family: ui-monospace, Consolas, monospace;
}

/* ============================================================
   Testeur Python — composants propres à cette appli
   ============================================================ */

.pytester-shell {
  display: flex;
  gap: 14px;
  height: calc(100vh - 200px);
  min-height: 480px;
}

.pytester-files {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}
.pytester-files-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px;
}
.btn-icon {
  background: var(--brand); color: var(--on-brand); border: none; border-radius: 8px;
  width: 26px; height: 26px; font-size: 1rem; line-height: 1; cursor: pointer;
}
.btn-icon:hover { background: var(--brand-hover); }

.pytester-files-list {
  list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1;
  display: flex; flex-direction: column; gap: 4px;
}
.pytester-files-list li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 6px;
  padding: 7px 9px; border-radius: 8px; cursor: pointer; font-size: 0.8rem; color: var(--text-primary);
}
.pytester-files-list li:hover { background: var(--bg-accent-soft); }
.pytester-files-list li.actif { background: var(--brand-tint); color: var(--brand); font-weight: 600; }
.pytester-files-list li .nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pytester-files-list li .taille { font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.pytester-files-list .vide { color: var(--text-muted); font-size: 0.78rem; padding: 10px 4px; text-align: center; }

.pytester-quota { margin-top: 10px; }
.pytester-quota-bar { height: 6px; border-radius: 4px; background: var(--border); overflow: hidden; }
.pytester-quota-fill { height: 100%; background: var(--brand); width: 0%; transition: width .2s; }
.pytester-quota-fill.attention { background: #d99a1f; }
.pytester-quota-fill.plein { background: var(--danger); }
.pytester-quota-texte { display: block; margin-top: 4px; font-size: 0.7rem; color: var(--text-muted); text-align: right; }

.pytester-main { flex: 1; display: flex; flex-direction: column; min-width: 0; gap: 10px; }

.pytester-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pytester-nomfichier {
  flex: 1; min-width: 160px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-card-alt); color: var(--text-primary); font-size: 0.85rem;
  font-family: ui-monospace, Consolas, monospace;
}
.pytester-nomfichier:focus { outline: none; border-color: var(--brand-light); background: var(--bg-card); }
.pytester-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pytester-panels { flex: 1; display: flex; gap: 10px; min-height: 0; }
.pytester-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.panel-label { font-size: 12px; color: var(--text-muted); padding: 4px 8px; letter-spacing: 1px; text-transform: uppercase; }

.editor-wrapper { flex: 1; border: 2px solid var(--border); border-radius: 12px; overflow: hidden; }
.output-wrapper {
  flex: 1; border: 2px solid var(--border); border-radius: 12px; background: var(--bg-card-alt);
  padding: 14px; overflow: auto; font-family: 'Consolas', 'Courier New', monospace;
  font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; color: var(--text-primary);
}
.output-wrapper .stdout { color: var(--success-text); }
.output-wrapper .stderr { color: var(--danger); }
.output-wrapper .info { color: var(--brand-light); }
.output-wrapper img { max-width: 100%; border-radius: 8px; margin: 8px 0; display: block; border: 1px solid var(--border); }

.status-bar { display: flex; justify-content: space-between; padding: 6px 4px; font-size: 0.76rem; color: var(--text-muted); }
.CodeMirror { height: 100% !important; font-size: 14px; font-family: 'Consolas', 'Courier New', monospace !important; }

@media (max-width: 900px) {
  .pytester-shell { flex-direction: column; height: auto; }
  .pytester-files { width: auto; }
  .pytester-panels { flex-direction: column; }
  .editor-wrapper, .output-wrapper { min-height: 320px; }
}
