* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  background: #f4f6f8;
  color: #2c3e50;
}

header {
  background: #2c3e50;
  color: #ecf0f1;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
header h1 { font-size: 1.1rem; font-weight: 600; }
.hint { font-size: 0.8rem; color: #bdc3c7; margin-left: auto; }

.toolbar { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.btn {
  padding: 0.4rem 0.8rem;
  border: none;
  background: #34495e;
  color: #ecf0f1;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.85rem;
  display: inline-block;
  user-select: none;
  font-family: inherit;
}
.btn:hover { background: #4a6278; }
.btn.primary { background: #27ae60; }
.btn.primary:hover { background: #2ecc71; }
.btn.active { background: #e67e22; }
.btn.danger, .danger { background: #c0392b; color: white; }
.btn.danger:hover { background: #e74c3c; }

.layout { flex: 1; display: flex; min-height: 0; }

#basemap-select {
  background: #34495e;
  color: #ecf0f1;
  border: none;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
#basemap-select:hover { background: #4a6278; }

#profile-panel {
  height: 200px;
  background: white;
  border-top: 1px solid #bdc3c7;
  display: flex;
  flex-direction: column;
  transition: height 0.2s ease;
  flex-shrink: 0;
}
#profile-panel.collapsed { height: 30px; }
#profile-panel.collapsed #profile-body { display: none; }

.profile-header {
  background: #34495e;
  color: #ecf0f1;
  padding: 0.3rem 0.8rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}
.profile-header h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
#profile-hint {
  font-size: 0.75rem;
  color: #bdc3c7;
  flex: 1;
}
#profile-toggle {
  background: transparent;
  border: none;
  color: #ecf0f1;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.1rem 0.4rem;
  transition: transform 0.2s;
}
#profile-panel.collapsed #profile-toggle { transform: rotate(180deg); }

#profile-body {
  flex: 1;
  min-height: 0;
  padding: 0.4rem 0.6rem;
  position: relative;
}
#profile-chart { width: 100% !important; height: 100% !important; }

#sidebar {
  width: 320px;
  background: #ecf0f1;
  padding: 0.8rem;
  overflow-y: auto;
  border-right: 1px solid #bdc3c7;
}
#sidebar section { margin-bottom: 1.2rem; }
#sidebar h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #7f8c8d;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid #bdc3c7;
  padding-bottom: 0.2rem;
}
#sidebar label {
  display: block;
  font-size: 0.7rem;
  color: #7f8c8d;
  margin-top: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
#sidebar input, #sidebar textarea {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid #bdc3c7;
  border-radius: 3px;
  font-size: 0.85rem;
  font-family: inherit;
  background: white;
}
#sidebar input:focus, #sidebar textarea:focus {
  outline: none;
  border-color: #3498db;
}

#sidebar ul { list-style: none; }
#sidebar li {
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  border-radius: 3px;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 2px;
}
#sidebar li:hover { background: #d5dbdb; }
#sidebar li.selected { background: #3498db; color: white; }
#sidebar li .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sidebar li button {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.3rem;
  line-height: 1;
}
#sidebar li button:hover { color: #e74c3c; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 0.4rem; vertical-align: middle; }

.row { display: flex; gap: 0.4rem; margin-top: 0.6rem; }
.row button {
  flex: 1;
  padding: 0.4rem;
  border: 1px solid #bdc3c7;
  background: white;
  cursor: pointer;
  border-radius: 3px;
  font-size: 0.8rem;
  font-family: inherit;
}
.row button:hover { background: #d5dbdb; }
.row button.danger { background: #c0392b; color: white; border-color: #c0392b; }
.row button.danger:hover { background: #e74c3c; }

#stats-content { font-size: 0.85rem; line-height: 1.6; }
#stats-content b { color: #2c3e50; }

#map { flex: 1; }

.help-list { list-style: disc; padding-left: 1.2rem; font-size: 0.8rem; color: #34495e; }
.help-list li { padding: 0.15rem 0; cursor: default; display: list-item; margin-bottom: 0; }
.help-list li:hover { background: transparent; }

#dropzone {
  position: fixed;
  inset: 0;
  background: rgba(52, 152, 219, 0.85);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  z-index: 10000;
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.leaflet-container { background: #cde1f5; }

body.placing .leaflet-container,
body.placing .leaflet-interactive { cursor: crosshair !important; }
.hint.placing { color: #f1c40f; font-weight: 600; }

#help-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.modal-card {
  position: relative;
  background: white;
  border-radius: 6px;
  max-width: 820px;
  width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.modal-head {
  background: #2c3e50;
  color: #ecf0f1;
  padding: 0.7rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.modal-head h2 { font-size: 1rem; font-weight: 600; }
#help-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.6rem;
  cursor: pointer;
  padding: 0 0.5rem;
  line-height: 1;
}
#help-close:hover { color: #e74c3c; }

.modal-body {
  padding: 1.2rem 1.6rem;
  overflow-y: auto;
  line-height: 1.55;
  color: #2c3e50;
}
.modal-body h3 {
  font-size: 0.95rem;
  margin-top: 1.4rem;
  margin-bottom: 0.4rem;
  color: #2c3e50;
  border-bottom: 1px solid #ecf0f1;
  padding-bottom: 0.25rem;
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body p { margin: 0.4rem 0; }
.modal-body ul, .modal-body ol { padding-left: 1.6rem; margin: 0.3rem 0 0.6rem; }
.modal-body li { margin-bottom: 0.25rem; }
.modal-body kbd {
  background: #ecf0f1;
  border: 1px solid #bdc3c7;
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0.05rem 0.4rem;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.82em;
  color: #2c3e50;
}
.modal-body code {
  background: #ecf0f1;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-size: 0.88em;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
}
.modal-body table {
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.88rem;
  width: 100%;
}
.modal-body th, .modal-body td {
  border: 1px solid #d5dbdb;
  padding: 0.3rem 0.6rem;
  text-align: left;
  vertical-align: top;
}
.modal-body th { background: #ecf0f1; font-weight: 600; }
.modal-body .tip {
  background: #fef9e7;
  border-left: 3px solid #f1c40f;
  padding: 0.5rem 0.8rem;
  margin: 0.6rem 0;
  font-size: 0.9rem;
  border-radius: 0 3px 3px 0;
}
.modal-body .warn {
  background: #fdeaea;
  border-left: 3px solid #e74c3c;
  padding: 0.5rem 0.8rem;
  margin: 0.6rem 0;
  font-size: 0.9rem;
  border-radius: 0 3px 3px 0;
}

/* ===== Page de connexion ===== */
body.login-page {
  background: linear-gradient(135deg, #2c3e50, #4a6278);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  height: 100vh;
  padding: 1rem;
}
.login-card {
  background: white;
  padding: 2rem 2.2rem;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 360px;
}
.login-card h1 { font-size: 1.4rem; color: #2c3e50; margin-bottom: 0.2rem; }
.login-sub { color: #7f8c8d; font-size: 0.85rem; margin-bottom: 1.4rem; }
.login-card label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #7f8c8d;
  margin-top: 0.8rem;
  margin-bottom: 0.2rem;
}
.login-card input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid #bdc3c7;
  border-radius: 4px;
  font-size: 0.95rem;
  font-family: inherit;
}
.login-card input:focus { outline: none; border-color: #3498db; }
.login-card button[type="submit"] {
  width: 100%;
  margin-top: 1.2rem;
  padding: 0.6rem;
  background: #27ae60;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
}
.login-card button[type="submit"]:hover:not(:disabled) { background: #2ecc71; }
.login-card button[type="submit"]:disabled { background: #95a5a6; cursor: wait; }
.login-error {
  margin-top: 0.8rem;
  padding: 0.5rem 0.7rem;
  background: #fdeaea;
  border-left: 3px solid #c0392b;
  color: #c0392b;
  font-size: 0.85rem;
  border-radius: 0 3px 3px 0;
}
.login-footer { margin-top: 1.4rem; font-size: 0.75rem; color: #95a5a6; text-align: center; }

/* ===== Barre utilisateur dans le header ===== */
#user-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.5rem;
  font-size: 0.85rem;
  color: #ecf0f1;
}
.user-info b { color: white; }
.user-info small { color: #bdc3c7; }
.btn-logout { background: #7f8c8d; }
.btn-logout:hover { background: #95a5a6; }

/* ===== Admin panel ===== */
#admin-section { background: #fdf6e3; border-radius: 4px; padding: 0.6rem; }
#admin-section h2 { color: #b7950b; border-color: #f7dc6f; }
.admin-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0.4rem;
  background: white;
  border-radius: 3px;
  margin-bottom: 3px;
  font-size: 0.85rem;
}
.admin-user button {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.admin-user button:disabled { opacity: 0.3; cursor: not-allowed; }
#admin-new-user-form {
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px dashed #f7dc6f;
}
