:root {
  /* --- Palette Ambition THD : blanc / bleu, pas de noir, pas de jaune/orange --- */
  --bg: #FFFFFF;
  --surface: #F5F9FD;
  --surface-alt: #EAF3FB;
  --sidebar-bg: #0B4E7A;
  --sidebar-bg-alt: #0E5F93;
  --primary: #0B72B9;
  --primary-dark: #075587;
  --accent: #29C2E6;
  --text: #16222E;
  --text-muted: #5B7387;
  --border: #DCE7F0;
  --success: #159957;
  --success-bg: #E8F7EF;
  --warning: #B5750A;
  --warning-bg: #FCF1DF;
  --danger: #C23B3B;
  --danger-bg: #FBEAEA;

  --font-display: 'Sora', 'Inter', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(11, 78, 122, 0.06), 0 4px 16px rgba(11, 78, 122, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; color: var(--text); }

.shell { display: flex; min-height: 100vh; }

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-alt) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 26px; }
.brand-logo { width: 44px; height: 44px; object-fit: contain; background: #fff; border-radius: 10px; padding: 4px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title { font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11.5px; color: rgba(255,255,255,0.72); }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: none; color: rgba(255,255,255,0.82);
  font-family: var(--font-body); font-weight: 500; font-size: 14px;
  padding: 11px 12px; border-radius: var(--radius-sm); cursor: pointer;
  text-align: left; transition: background .15s ease, color .15s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: #fff; color: var(--primary-dark); font-weight: 600; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,0.14); }
.server-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 500; }
.footer-caption { display: block; margin-top: 6px; font-size: 10.5px; color: rgba(255,255,255,0.55); }

/* ===================== MAIN ===================== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px; background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 21px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.content { padding: 26px 32px 60px; max-width: 1180px; }

.tab-content { display: none; flex-direction: column; gap: 20px; }
.tab-content.active { display: flex; }

/* ===================== CARDS ===================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
}
.card-head { margin-bottom: 16px; }
.card-head h2 { font-size: 16.5px; font-weight: 700; margin-bottom: 4px; }
.muted { color: var(--text-muted); font-size: 13px; line-height: 1.5; margin: 0; }
.muted.small { font-size: 12px; margin-top: 10px; }

/* ===================== FORMS ===================== */
.form-grid { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-group { display: flex; gap: 8px; }

input[type="text"], input[type="number"], input[type="date"], input[type="password"], select {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--text);
  min-width: 168px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 114, 185, 0.14);
}
.checkbox-field { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-muted); }
.checkbox-field input { width: auto; min-width: 0; }

/* ===================== BUTTONS ===================== */
.btn {
  font-family: var(--font-body); font-weight: 600; font-size: 13.5px;
  border-radius: var(--radius-sm); padding: 10px 16px; cursor: pointer;
  border: 1px solid transparent; transition: filter .12s ease, background .12s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--primary); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-alt); border-color: var(--primary); }
.btn-sm { padding: 8px 12px; font-size: 12.5px; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { filter: brightness(0.95); }
.btn-ghost { background: transparent; color: var(--text-muted); border: none; }
.btn-ghost:hover { color: var(--text); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===================== PILLS / BADGES ===================== */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.pill-muted { background: var(--surface-alt); color: var(--text-muted); }
.pill-online { background: var(--success-bg); color: var(--success); }
.pill-offline { background: var(--danger-bg); color: var(--danger); }
.pill-charging { background: #E4F1FB; color: var(--primary); }
.pill-warn { background: var(--warning-bg); color: var(--warning); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-online { background: #3DD68C; box-shadow: 0 0 0 3px rgba(61,214,140,0.25); }
.dot-offline { background: #E27373; }
.dot-charging { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(41,194,230,0.45); }
  50% { box-shadow: 0 0 0 6px rgba(41,194,230,0); }
}

/* ===================== CHARGE POINT LIST ===================== */
.cp-list { display: flex; flex-direction: column; gap: 12px; }

.cp-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.cp-card-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.cp-card-id { font-family: var(--font-mono); font-weight: 600; font-size: 14.5px; }
.cp-card-meta { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }

.cp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 18px; margin: 12px 0; }
.metric-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 3px; }
.metric-value { font-family: var(--font-mono); font-weight: 600; font-size: 14px; color: var(--text); }
.metric-value.accent { color: var(--primary); }

.connector-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 4px 0; }

.cp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }

.load-bar-wrap { margin-top: 10px; }
.load-bar-track { height: 8px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.load-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 999px; transition: width .4s ease; }
.load-bar-caption { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }

.empty-state { text-align: center; padding: 30px 10px; color: var(--text-muted); font-size: 13px; }

/* ===================== EDIT FIELDS (borne card) ===================== */
.edit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; }
.edit-grid input, .edit-grid select { width: 100%; min-width: 0; }
.field-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 3px; display: block; }

/* ===================== RESULT BOX ===================== */
.result-box {
  margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--success-bg); border: 1px solid #BFE8D3; font-family: var(--font-mono); font-size: 12.5px;
  line-height: 1.7; white-space: pre-wrap; word-break: break-all;
}
.result-box.error { background: var(--danger-bg); border-color: #F1C3C3; color: var(--danger); }
.hidden { display: none !important; }

/* ===================== MODAL ===================== */
.modal {
  position: fixed; inset: 0; background: rgba(11, 34, 51, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-content {
  background: #fff; border-radius: var(--radius); padding: 26px 28px;
  width: 460px; max-width: 100%; max-height: 88vh; overflow-y: auto;
  position: relative; box-shadow: 0 20px 60px rgba(11,34,51,0.25);
}
.modal-close {
  position: absolute; top: 14px; right: 16px; background: var(--surface-alt); border: none;
  width: 28px; height: 28px; border-radius: 50%; font-size: 16px; color: var(--text-muted); cursor: pointer;
}
.modal-close:hover { background: var(--danger-bg); color: var(--danger); }
.modal-content h2 { margin-bottom: 16px; font-size: 17px; }

.modal-section { margin-bottom: 16px; }
.modal-section:last-child { margin-bottom: 0; }
.modal-section h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 8px; }
.modal-btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.config-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.config-key { font-family: var(--font-mono); flex: 1; color: var(--text-muted); }
.config-value { font-family: var(--font-mono); }
.config-value input { min-width: 0; width: 130px; }

/* ===================== LOG VIEWER ===================== */
.log-viewer {
  background: #0B2338; color: #CFE9F7; font-family: var(--font-mono); font-size: 12px;
  border-radius: var(--radius-sm); padding: 14px; max-height: 460px; overflow-y: auto; line-height: 1.65;
}
.log-viewer .log-line { white-space: pre-wrap; word-break: break-all; }
.log-viewer .log-line.err { color: #FF9A9A; }
.log-viewer .log-line.warn { color: #FFD98A; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 12px 16px; }
  .nav { flex-direction: row; overflow-x: auto; margin-top: 0; }
  .sidebar-footer { display: none; }
  .brand { padding: 0 12px 0 0; }
  .content { padding: 20px 16px 40px; }
  .topbar { padding: 16px; }
}

/* ===================== Compteur de charge en temps réel ===================== */
.charge-live {
  margin: 12px 0 4px;
  padding: 12px 14px;
  border-radius: var(--radius-sm, 8px);
  background: linear-gradient(90deg, #E4F1FB, #eef7f0);
  border: 1px solid var(--primary);
}
.charge-live-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.charge-live-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}
.charge-timer {
  font-family: var(--font-mono);
  font-size: 20px;
  letter-spacing: 0.5px;
}

/* ===================== Menu de groupe : lignes de bornes cliquables ===================== */
.group-cp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 8px);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  background: var(--surface);
}
.group-cp-row:hover { background: var(--surface-alt); border-color: var(--primary); }
.group-cp-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.group-cp-row-state { display: flex; gap: 6px; flex-wrap: wrap; }
.group-cp-row-arrow { color: var(--text-muted); font-size: 20px; padding: 0 2px; }

/* ===================== Assignation badge <-> bornes ===================== */
.badge-cp-assign { display: flex; flex-direction: column; gap: 8px; }
.badge-cp-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm, 8px);
  max-height: 220px;
  overflow-y: auto;
}
.badge-edit-details summary::-webkit-details-marker { display: none; }


/* Empilement des modales : le menu de groupe reste en dessous, le menu principal
   d'une borne s'ouvre par-dessus, et les modales d'action (pilotage, config,
   firmware, journaux) passent encore au-dessus. */
#groupDetailModal { z-index: 50; }
#cpDetailModal { z-index: 60; }
#controlModal, #configModal, #firmwareModal, #logsModal { z-index: 70; }
