:root {
  --ink-950: #071620;
  --ink-900: #0b2233;
  --ink-800: #123249;
  --ink-700: #1a4560;
  --ink-600: #285a7a;
  --line: #1e3d54;
  --paper: #f6f8f7;
  --paper-dim: #eef2f1;

  --teal-500: #17a598;
  --teal-400: #2ec4b6;
  --teal-300: #7fe0d5;
  --coral: #ff8c69;
  --amber: #f0a93a;
  --danger: #e35d5d;
  --ok: #3fb98a;

  --font-display: 'Fraunces', serif;
  --font-body: 'Manrope', system-ui, sans-serif;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-1: 0 1px 2px rgba(7, 22, 32, 0.06), 0 8px 24px rgba(7, 22, 32, 0.06);
  --shadow-2: 0 20px 60px rgba(7, 22, 32, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink-900);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 272px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: linear-gradient(180deg, var(--ink-950), var(--ink-900) 60%, var(--ink-800));
  color: #dfeef0;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 28px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: radial-gradient(circle at 30% 30%, var(--teal-300), var(--teal-500) 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-950);
  font-size: 18px;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-family: var(--font-display); font-size: 19px; letter-spacing: 0.2px; }
.brand-text span { font-size: 11.5px; color: #8fb4bd; letter-spacing: 0.3px; }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }

.nav-item {
  all: unset;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: #b9d2d7;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-ico { font-size: 15px; width: 18px; text-align: center; opacity: 0.85; }

.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active {
  background: rgba(46, 196, 182, 0.16);
  color: #eafffb;
  box-shadow: inset 3px 0 0 var(--teal-400);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-footer label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: #7fa2ab; }

#structure-select {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: #eafffb;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13.5px;
}

/* ---------- Content ---------- */

.content { padding: 40px 48px 60px; max-width: 1180px; }

.view { display: none; }
.view.active { display: block; animation: fade 0.25s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 28px;
}

.header-actions { display: flex; gap: 10px; align-items: center; }

.view-header h1 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink-950);
}

.subtitle { margin: 0; color: var(--ink-600); font-size: 14px; }

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  border: none;
  border-radius: 999px;
  padding: 11px 20px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--teal-400), var(--teal-500));
  color: #05201d;
  box-shadow: 0 8px 20px rgba(23, 165, 152, 0.28);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(23, 165, 152, 0.36); }

.btn-ghost {
  background: transparent;
  color: var(--ink-700);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--paper-dim); }

.btn-sm { padding: 8px 14px; font-size: 12.5px; }

/* ---------- Stat cards ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 30px;
}

.stat-card {
  background: #fff;
  border: 1px solid #e6ebe9;
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-1);
}

.stat-card .value { font-family: var(--font-display); font-size: 30px; color: var(--ink-950); }
.stat-card .label { font-size: 12.5px; color: var(--ink-600); margin-top: 2px; }
.stat-card.accent { background: linear-gradient(135deg, #0e3a4f, #123249); color: #fff; border: none; }
.stat-card.accent .value { color: var(--teal-300); }
.stat-card.accent .label { color: #a9c7cd; }

/* ---------- Panels ---------- */

.panels { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }

.panel {
  background: #fff;
  border: 1px solid #e6ebe9;
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-1);
}

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-header h2 { font-size: 15.5px; margin: 0; font-family: var(--font-display); font-weight: 600; }

.tag {
  background: var(--paper-dim);
  color: var(--ink-700);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.alert-list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }

.alert-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--paper-dim);
  font-size: 13px;
}

.alert-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.alert-dot.depassee { background: var(--danger); }
.alert-dot.proche { background: var(--amber); }

.alert-row .meta { color: var(--ink-600); font-size: 12px; margin-left: auto; text-align: right; }

.empty-inline { color: var(--ink-600); font-size: 13px; padding: 10px 2px; }

.repartition-list { display: flex; flex-direction: column; gap: 10px; }

.repartition-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.repartition-row .name { width: 140px; color: var(--ink-800); }
.repartition-bar-track { flex: 1; height: 8px; background: var(--paper-dim); border-radius: 6px; overflow: hidden; }
.repartition-bar-fill { height: 100%; background: linear-gradient(90deg, var(--teal-400), var(--teal-500)); border-radius: 6px; }
.repartition-row .count { width: 24px; text-align: right; font-weight: 700; color: var(--ink-900); }

/* ---------- Toolbar / filters ---------- */

.toolbar { display: flex; gap: 10px; margin-bottom: 18px; }

.toolbar input, .toolbar select,
select, input[type="text"], input[type="date"], input[type="number"], input[type="email"], textarea {
  font-family: var(--font-body);
  border: 1px solid #dbe3e1;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  background: #fff;
  color: var(--ink-900);
}

.toolbar input[type="search"] { flex: 1; }
.toolbar select { min-width: 170px; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal-400);
  box-shadow: 0 0 0 3px rgba(46, 196, 182, 0.15);
}

/* ---------- Tables ---------- */

.table-wrap {
  background: #fff;
  border: 1px solid #e6ebe9;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-600);
  padding: 14px 18px;
  border-bottom: 1px solid #e6ebe9;
  background: var(--paper-dim);
}

tbody td { padding: 13px 18px; border-bottom: 1px solid #f0f3f2; color: var(--ink-900); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfcfb; cursor: pointer; }

.empty-state { padding: 34px 18px; text-align: center; color: var(--ink-600); font-size: 13.5px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }

.pill-disponible { background: #e6f7f1; color: #16805c; }
.pill-disponible::before { background: var(--ok); }
.pill-en_service { background: #e8f1fb; color: #2263ad; }
.pill-en_service::before { background: #4a90d9; }
.pill-maintenance { background: #fff3e0; color: #b5750d; }
.pill-maintenance::before { background: var(--amber); }
.pill-hors_service { background: #fbe8e8; color: #b93c3c; }
.pill-hors_service::before { background: var(--danger); }
.pill-perdu { background: #f1eef4; color: #6b5d7d; }
.pill-perdu::before { background: #8b7aa3; }

.type-badge {
  font-size: 12px;
  color: var(--ink-700);
  background: var(--paper-dim);
  padding: 3px 9px;
  border-radius: 6px;
}

.row-action {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-600);
  font-size: 16px;
  text-decoration: none;
}

.check-inline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-700); }

/* ---------- Structures cards ---------- */

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

.structure-card {
  background: #fff;
  border: 1px solid #e6ebe9;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-1);
}

.structure-card h3 { margin: 0 0 6px; font-family: var(--font-display); font-size: 17px; }
.structure-card p { margin: 2px 0; font-size: 13px; color: var(--ink-600); }
.structure-card .count { margin-top: 12px; font-size: 12.5px; color: var(--teal-500); font-weight: 700; }

/* ---------- Modals ---------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 22, 32, 0.5);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: #fff;
  border-radius: 18px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-2);
  padding: 26px 28px 22px;
}

.modal-wide { max-width: 680px; }

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h2 { font-family: var(--font-display); font-size: 20px; margin: 0; }

.modal-close { background: none; border: none; font-size: 22px; color: var(--ink-600); cursor: pointer; line-height: 1; }

.modal-header-actions { display: flex; align-items: center; gap: 14px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-700); }
.field textarea { resize: vertical; font-family: var(--font-body); }

.form-section {
  margin: 6px 0 16px;
  padding: 16px 16px 2px;
  background: var(--paper-dim);
  border-radius: var(--radius-sm);
}
.form-section h3 { margin: 0 0 12px; font-size: 13px; color: var(--ink-700); text-transform: uppercase; letter-spacing: 0.4px; }

.modal-footer { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.spacer { flex: 1; }

/* ---------- Fiche tabs ---------- */

.fiche-tabs { display: flex; gap: 4px; border-bottom: 1px solid #e6ebe9; margin-bottom: 16px; }
.fiche-tab {
  all: unset; cursor: pointer; padding: 9px 4px; margin-right: 18px;
  font-size: 13.5px; color: var(--ink-600); border-bottom: 2px solid transparent;
}
.fiche-tab.active { color: var(--ink-950); border-bottom-color: var(--teal-500); font-weight: 700; }

.fiche-panel { display: none; }
.fiche-panel.active { display: block; }

.inline-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 120px; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; }

.timeline li {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--paper-dim);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.timeline .t-main strong { display: block; color: var(--ink-950); font-size: 13.5px; }
.timeline .t-date { color: var(--ink-600); font-size: 12px; white-space: nowrap; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink-950);
  color: #eafffb;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  box-shadow: var(--shadow-2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #5a1f1f; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .content { padding: 24px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .panels { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
