:root {
  --bg:          #0f1623;
  --bg-card:     #1a2235;
  --bg-input:    #111827;
  --bg-hover:    #232f45;
  --accent:      #6366f1;
  --accent-h:    #4f46e5;
  --accent-dim:  rgba(99,102,241,0.15);
  --text:        #f1f5f9;
  --text-muted:  #7c8fa6;
  --border:      #2a3a52;
  --border-l:    #3d5270;
  --green:       #22c55e;
  --yellow:      #f59e0b;
  --red:         #ef4444;
  --shadow:      0 2px 12px rgba(0,0,0,.35);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.5);
  --radius:      8px;
  --radius-lg:   12px;
}

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

html {
  font-size: 14px;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
}

#app { display: contents; }

.app-view {
  display: none;
  flex-direction: column;
  height: 100%;
}
.app-view.active { display: flex; }

/* ─── Header ─── */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(99,102,241,.2);
  display: flex;
  align-items: stretch;
  gap: 20px;
  min-height: 52px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-top-row {
  display: contents;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  padding: 12px 0;
  min-width: 0;
}

.header-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.app-version {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  letter-spacing: .3px;
  flex-shrink: 0;
}

#app-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Tabs ─── */
.tabs-wrap {
  flex: 1;
  display: flex;
  align-items: stretch;
  position: relative;
  min-width: 0;
}

.tabs {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  padding: 12px 16px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Badge compteur dans les onglets */
.tab-btn[data-count]:not([data-count=""])::after {
  content: attr(data-count);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  line-height: 1;
  transition: background .15s, color .15s;
}
.tab-btn.active[data-count]:not([data-count=""])::after {
  background: var(--accent);
  color: #fff;
}

/* ─── Header actions ─── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-actions button,
.btn-import {
  background: transparent;
  border: 1px solid var(--border-l);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: inherit;
}

.header-actions button:hover,
.btn-import:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-dim);
}

#import-file,
#import-all-file { display: none; }

/* ─── Back button ─── */
.btn-back {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 5px 12px 5px 0;
  margin-right: 12px;
  border-right: 1px solid var(--border-l);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  transition: color .15s;
  font-family: inherit;
  white-space: nowrap;
}
.btn-back:hover { color: var(--accent); }

/* ─── Main ─── */
main {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  padding: 32px 28px 80px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.tab-panel        { display: none; }
.tab-panel.active {
  display: block;
  animation: fadeUp .18s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Typography ─── */
h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .7px;
  margin-bottom: 16px;
  margin-top: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
}
h2:first-child { margin-top: 0; }

.badge {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: none;
  letter-spacing: 0;
}

.hint {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
  line-height: 1.5;
}

/* ─── Boutons ─── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary:hover  { background: var(--accent-h); box-shadow: 0 0 0 3px var(--accent-dim); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-l);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.btn-secondary:hover  { border-color: var(--accent); color: var(--text); background: var(--accent-dim); }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 5px;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, color .15s, background .15s;
  font-family: inherit;
  flex-shrink: 0;
}
.btn-icon:hover           { border-color: var(--accent); color: var(--text); background: var(--accent-dim); }
.btn-icon:disabled        { opacity: .3; cursor: default; pointer-events: none; }

.btn-icon.remove-player:hover,
.btn-icon.remove-case:hover,
.btn-icon.remove-gage:hover {
  border-color: var(--red);
  color: var(--red);
  background: rgba(239,68,68,.1);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(239,68,68,.3);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  font-family: inherit;
}
.btn-danger:hover { background: rgba(239,68,68,.1); border-color: var(--red); }

/* ─── Form elements ─── */
.form-group { margin-bottom: 20px; }

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: .6px;
}

.label-checkbox {
  text-transform: none !important;
  letter-spacing: 0 !important;
  display: flex !important;
  align-items: center;
  gap: 9px;
  color: var(--text) !important;
  cursor: pointer;
  font-size: 13px !important;
  font-weight: 500 !important;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  background: var(--bg-input);
  border: 1px solid var(--border-l);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  width: 100%;
  font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.form-group input[type="text"]:focus,
.form-group input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin-top: 4px;
}

.form-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.form-row .form-group { flex: 1; min-width: 100px; }

.form-actions {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ─── Error / status ─── */
.error-msg {
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.5;
}

.warn-banner {
  background: rgba(245,158,11,.08);
  border: 1px solid rgba(245,158,11,.3);
  color: #fcd34d;
  padding: 10px 16px;
  border-radius: var(--radius);
  margin: 12px 0;
  font-size: 13px;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 56px 24px;
  border: 1px dashed var(--border-l);
  border-radius: var(--radius-lg);
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.8;
}
.empty-state .empty-icon {
  font-size: 32px;
  display: block;
  margin-bottom: 12px;
  opacity: .6;
}
.empty-state strong {
  color: var(--text);
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

/* ─── Projects list ─── */
.projects-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.projects-search {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.projects-search input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-l);
  color: var(--text);
  padding: 9px 14px 9px 36px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.projects-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.projects-search::before {
  content: '⌕';
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
  pointer-events: none;
  line-height: 1;
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.project-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--card-accent, var(--accent));
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color .15s, box-shadow .15s, transform .15s;
  cursor: default;
}
.project-card:hover {
  border-color: var(--border-l);
  border-left-color: var(--card-accent, var(--accent));
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.project-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.project-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  min-width: 0;
  line-height: 1.3;
  word-break: break-word;
}

.project-card-actions {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.project-card-actions .proj-delete {
  margin-left: 8px;
  color: var(--red);
  border-color: rgba(239,68,68,.3);
}

.project-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.project-card-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.project-card-meta .sep { color: var(--border-l); }
.project-card-meta .meta-chip {
  background: var(--bg-hover);
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
}

.proj-open {
  align-self: stretch;
  margin-top: 4px;
  justify-content: center;
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn .15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-l);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .18s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-box h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* ─── Tablette + mobile paysage (641–1024px) ─── */
@media (max-width: 1024px) {
  header {
    display: flex;
    flex-direction: column;
    padding: 0;
    gap: 0;
    min-height: auto;
  }

  .header-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    min-height: 52px;
  }

  .header-left {
    padding: 0;
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }

  #app-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    min-width: 0;
    flex: 1;
  }

  .tabs-wrap {
    width: 100%;
    border-top: 1px solid var(--border);
  }

  /* Indicateur de scroll à droite */
  .tabs-wrap::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 48px;
    background: linear-gradient(to right, transparent, var(--bg-card));
    pointer-events: none;
  }

  .tabs {
    flex: none;
    width: 100%;
    gap: 0;
  }

  main {
    padding: 24px 20px 80px;
  }
}

/* ─── Mobile (≤ 640px) ─── */
@media (max-width: 640px) {
  html { font-size: 15px; }

  /* padding-top retiré — body ne scroll plus, le header est toujours en haut */

  header {
    display: flex;
    flex-direction: column;
    padding: 0;
    gap: 0;
    min-height: auto;
  }

  .header-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    min-height: 48px;
  }

  .header-left {
    min-width: 0;
    font-size: 14px;
    padding: 0;
    flex: 1;
    overflow: hidden;
  }

  #app-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    min-width: 0;
    flex: 1;
  }

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

  .header-actions button,
  .header-actions .btn-import {
    font-size: 11px;
    padding: 5px 8px;
  }

  .tabs {
    flex-direction: row;
    flex: none;
    width: 100%;
    gap: 0;
  }

  .tab-btn {
    padding: 10px 14px 9px;
    font-size: 13px;
    flex-shrink: 0;
    white-space: nowrap;
  }

  main {
    padding: 16px 14px 80px;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

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

  .btn-primary, .btn-danger {
    padding: 11px 18px;
    font-size: 14px;
    min-height: 44px;
  }

  .btn-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .empty-state { padding: 40px 16px; }

  /* Projects mobile */
  .projects-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 20px;
  }
  .projects-search { min-width: 0; }
  #btn-new-project { width: 100%; min-height: 44px; font-size: 14px; justify-content: center; }
  .projects-grid { grid-template-columns: 1fr; }

  .modal-box { padding: 20px; }
  .modal-actions { flex-direction: column; }
  .modal-actions button { width: 100%; min-height: 44px; font-size: 14px; justify-content: center; }

  .btn-back { font-size: 11px; padding: 4px 8px 4px 0; margin-right: 8px; }

  /* Version badge cachée dans l'éditeur (le titre a besoin de la place),
     mais conservée dans la vue Projets où il y a de la place */
  #view-editor header .app-version { display: none; }

  /* Cacher Exporter/Importer sur mobile pour libérer de la place */
  #btn-export, label[for="import-file"], #import-file, #import-all-file { display: none; }
}

/* ─── Share modal ─── */
.share-modal { max-width: 300px; }

.share-qr {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  background: #1a2235;
  border-radius: var(--radius);
  padding: 12px;
  min-height: 244px;
  align-items: center;
}
.share-qr img,
.share-qr canvas { display: block; border-radius: 4px; }

.share-qr-msg {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 16px;
  display: block;
}

@media (max-height: 500px) {
  .share-qr {
    min-height: auto;
    padding: 6px;
  }
  .share-qr canvas,
  .share-qr img {
    width: 140px !important;
    height: 140px !important;
  }
}

.btn-scan-qr {
  width: 100%;
  justify-content: center;
  margin-bottom: 10px;
}

.share-import-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.share-import-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-l);
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
  transition: border-color .15s;
}
.share-import-input::placeholder { color: var(--text-muted); }
.share-import-input:focus { outline: none; border-color: var(--accent); }
.share-import-input.share-import-error { border-color: var(--red); }

.share-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.share-url-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-l);
  color: var(--text-muted);
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 11px;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Scanner QR (overlay plein écran) ─── */
.qr-scanner-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.qr-scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}

.qr-scanner-frame {
  position: relative;
  z-index: 1;
  width: min(260px, 70vw);
  height: min(260px, 70vw);
  border: 2px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.55);
}

.qr-scanner-frame::before,
.qr-scanner-frame::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--accent);
  border-style: solid;
}
.qr-scanner-frame::before {
  top: -2px; left: -2px;
  border-width: 3px 0 0 3px;
  border-radius: 10px 0 0 0;
}
.qr-scanner-frame::after {
  bottom: -2px; right: -2px;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 10px 0;
}

.qr-scanner-hint {
  position: relative;
  z-index: 1;
  color: #fff;
  font-size: 13px;
  margin-top: 24px;
  text-align: center;
  padding: 0 16px;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}

.qr-scanner-cancel {
  position: relative;
  z-index: 1;
  margin-top: 20px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  padding: 10px 28px;
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.qr-scanner-cancel:active { background: rgba(255,255,255,.22); }

.qr-scanner-error {
  position: relative;
  z-index: 1;
  color: #fecaca;
  font-size: 13px;
  text-align: center;
  padding: 16px;
  max-width: 280px;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #14532d;
  border: 1px solid var(--green);
  color: #dcfce7;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.toast.toast-error {
  background: #450a0a;
  border-color: var(--red);
  color: #fecaca;
}
.toast.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
