/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; font-size: 14px; height: 100vh; display: flex; flex-direction: column; overflow: hidden; background: #1a1a2e; color: #e0e0e0; }

/* Header */
#app-header {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; background: #16213e;
  border-bottom: 1px solid #0f3460; flex-shrink: 0; z-index: 1000;
}
#app-header h1 { font-size: 15px; font-weight: 600; color: #fff; white-space: nowrap; }
#year-control { display: flex; align-items: center; gap: 8px; }
#year-control label { white-space: nowrap; font-size: 13px; color: #aaa; }
#year-control strong { color: #4fc3f7; }
#year-slider { width: 140px; accent-color: #4fc3f7; cursor: pointer; }
#btn-national {
  margin-left: auto; padding: 6px 14px;
  background: #0f3460; border: 1px solid #4fc3f7; border-radius: 6px;
  color: #4fc3f7; cursor: pointer; font-size: 13px; white-space: nowrap;
  transition: background 0.2s;
}
#btn-national:hover { background: #1a4a7a; }

/* Map + panel */
#app-body { flex: 1; display: flex; overflow: hidden; position: relative; }
#map { flex: 1; }

/* Panel */
#panel {
  width: 320px; background: #16213e; border-left: 1px solid #0f3460;
  overflow-y: auto; flex-shrink: 0; position: relative;
  transition: width 0.25s ease;
}
#panel.hidden { width: 0; overflow: hidden; border: none; }
#panel-close {
  position: sticky; top: 8px; left: calc(100% - 36px);
  background: #0f3460; border: none; border-radius: 50%;
  width: 28px; height: 28px; cursor: pointer; color: #aaa;
  font-size: 14px; display: flex; align-items: center; justify-content: center;
  margin: 8px 8px 0 auto;
}
#panel-close:hover { color: #fff; }
#panel-content { padding: 8px 16px 24px; }

/* Panel content */
#panel-content h2 { font-size: 15px; color: #fff; margin-bottom: 4px; line-height: 1.3; }
.school-location { color: #888; font-size: 12px; margin-bottom: 10px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tag { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.tag-public { background: #1a4a7a; color: #4fc3f7; }
.tag-prive { background: #4a1a1a; color: #f07070; }
.tag-rep { background: #3a3a00; color: #ffd700; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.stat { background: #0f3460; border-radius: 6px; padding: 10px; text-align: center; }
.stat-value { display: block; font-size: 22px; font-weight: 700; color: #4fc3f7; }
.stat-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; }
#panel-content h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: #888; margin: 16px 0 8px; }
.levels { margin-bottom: 16px; }
.level-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.level-label { width: 70px; font-size: 12px; color: #aaa; }
.level-bar { flex: 1; background: #0f3460; border-radius: 3px; height: 6px; overflow: hidden; }
.level-bar div { height: 100%; background: #4fc3f7; border-radius: 3px; transition: width 0.4s ease; }
.level-value { width: 30px; text-align: right; font-size: 11px; color: #888; }

/* Modal */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 2000;
}
#modal-overlay.hidden { display: none; }
#modal {
  background: #16213e; border: 1px solid #0f3460; border-radius: 10px;
  padding: 24px; width: min(700px, 90vw); position: relative;
}
#modal h2 { color: #fff; margin-bottom: 16px; font-size: 16px; }
#modal-close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; color: #888; cursor: pointer; font-size: 18px;
}
#modal-close:hover { color: #fff; }

/* Loader */
.loading { color: #888; padding: 16px; text-align: center; font-size: 13px; }

/* ============================================================
   Responsive — mobile (≤ 640px)
   ============================================================ */

@media (max-width: 640px) {
  /* Header : 2 lignes */
  #app-header {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
  }
  #app-header h1 {
    order: 1;
    flex: 1;
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #btn-national {
    order: 2;
    margin-left: 0;
    padding: 5px 10px;
    font-size: 12px;
    flex-shrink: 0;
  }
  #year-control {
    order: 3;
    width: 100%;
  }
  #year-slider {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  /* Panel : bottom sheet sur mobile */
  #panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 65vh;
    overflow-y: auto;
    border-left: none;
    border-top: 1px solid #0f3460;
    border-radius: 12px 12px 0 0;
    transition: transform 0.3s ease;
    z-index: 1500;
  }
  #panel::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #4fc3f7;
    border-radius: 2px;
    margin: 10px auto 0;
    opacity: 0.4;
  }
  #panel.hidden {
    width: 100%;
    overflow-y: auto;
    transform: translateY(110%);
    border: none;
  }
  #panel-close {
    top: 16px;
  }
}
