/* ============================================================
   AVICOME — Feuille de style principale v3
   Police : Outfit (Google Fonts, chargée dans index.html)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg: #f0f5f1;
  --surface: #ffffff;
  --surface-2: #eef7ef;
  --surface-3: #f7faf7;
  --text: #0c1a10;
  --muted: #536b5c;
  --primary: #0d6b45;
  --primary-2: #0f8050;
  --primary-3: #0a5438;
  --primary-light: #dff3e8;
  --primary-xlight: #f0faf3;
  --danger: #b42318;
  --danger-light: #fef3f2;
  --warning: #92540a;
  --warning-light: #fffbeb;
  --success: #027a48;
  --success-light: #ecfdf3;
  --border: #cde2d4;
  --border-strong: #a8cdb8;
  --shadow-xs: 0 1px 2px rgba(15,50,30,.05);
  --shadow-sm: 0 1px 6px rgba(15,50,30,.07);
  --shadow: 0 4px 20px rgba(15,50,30,.09);
  --shadow-lg: 0 12px 40px rgba(15,50,30,.13);
  --shadow-xl: 0 20px 60px rgba(15,50,30,.17);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --sidebar-width: 272px;
  --transition: .18s ease;
}

/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: none; background: none; }
img { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---- Layout ---- */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
}

/* ---- Sidebar ---- */
.sidebar {
  background: linear-gradient(170deg, #04281a 0%, #0a5236 55%, #0d6b45 100%);
  color: #fff;
  padding: 18px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform var(--transition);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.brand-logo {
  width: 44px; height: 44px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.22);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.brand h1 { font-size: 17px; margin: 0; letter-spacing: -.02em; font-weight: 700; }
.brand p { margin: 2px 0 0; opacity: .65; font-size: 11px; font-weight: 400; }

.nav { display: grid; gap: 2px; }
.nav button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: rgba(255,255,255,.75);
  padding: 9px 12px;
  border-radius: 11px;
  transition: var(--transition);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.nav button:hover { background: rgba(255,255,255,.09); color: #fff; transform: translateX(2px); }
.nav button.active {
  background: rgba(255,255,255,.14);
  color: #fff;
  border-color: rgba(255,255,255,.18);
  font-weight: 600;
}
.nav button.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: #6ee7a2;
  border-radius: 0 3px 3px 0;
}
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  animation: badge-pop .3s ease;
}
@keyframes badge-pop { 0% { transform: scale(0); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.1);
  display: grid;
  gap: 8px;
  color: rgba(255,255,255,.65);
  font-size: 12px;
}
.sync-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  padding: 7px 10px;
  background: rgba(255,255,255,.07);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.08);
}
.sync-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #6ee7a2;
  flex-shrink: 0;
  transition: background .3s;
}
.sync-dot.saving { background: #fbbf24; animation: pulse .8s infinite; }
.sync-dot.error { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(.85); } }

.template-link {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  background: rgba(255,255,255,.09);
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.template-link:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ---- Mobile header ---- */
.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--primary-3);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}
.menu-toggle { display: flex; flex-direction: column; gap: 5px; padding: 4px; }
.menu-toggle span {
  display: block;
  width: 22px; height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: var(--transition);
}
.menu-toggle.active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.active span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.menu-toggle.active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.mobile-title { font-size: 15px; font-weight: 700; letter-spacing: .02em; }
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
  transition: opacity var(--transition);
  backdrop-filter: blur(2px);
}

/* ---- Main content ---- */
.main { padding: 24px; min-width: 0; display: flex; flex-direction: column; gap: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.03em; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.actions, .table-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Buttons ---- */
.btn {
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-weight: 600;
  font-size: 13.5px;
  box-shadow: 0 2px 8px rgba(13,107,69,.22);
  transition: var(--transition);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: -.01em;
}
.btn:hover { background: var(--primary-2); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(13,107,69,.3); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn.secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.btn.secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn.danger { background: var(--danger); color: #fff; box-shadow: 0 2px 8px rgba(180,35,24,.22); }
.btn.danger:hover { background: #9b1e14; }
.icon-btn { gap: 5px; }
.file-label { position: relative; overflow: hidden; cursor: pointer; display: inline-flex; align-items: center; }
.file-label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

/* ---- Views ---- */
.view { display: none; }
.view.active { display: block; animation: fadeInUp .22s ease; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.hidden { display: none !important; }

/* ---- Cards & Panels ---- */
.profile-card, .panel, .kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.profile-card {
  padding: 20px 24px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  overflow: hidden;
  position: relative;
}
.profile-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 180px; height: 100%;
  background: linear-gradient(135deg, transparent 0%, var(--primary-xlight) 100%);
  pointer-events: none;
}
.profile-card h3 { margin: 4px 0 6px; font-size: 21px; font-weight: 700; }
.profile-card p { margin: 0; color: var(--muted); font-size: 13.5px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; color: var(--primary) !important; font-size: 10.5px; font-weight: 700; margin: 0 0 2px; }

/* ---- KPI Grid ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi-card {
  padding: 16px 18px;
  transition: var(--transition);
  cursor: default;
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  opacity: 0;
  transition: opacity var(--transition);
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.kpi-card:hover::before { opacity: 1; }
.kpi-card span { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; }
.kpi-card strong { display: block; margin-top: 6px; font-size: 24px; font-weight: 800; letter-spacing: -.03em; }
.kpi-card small { display: block; margin-top: 6px; color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.kpi-card.kpi-alert strong { color: var(--danger); }
.kpi-card.kpi-warning strong { color: var(--warning); }
.kpi-card.kpi-success strong { color: var(--success); }

/* ---- Dashboard grid ---- */
.dashboard-grid { display: grid; grid-template-columns: 1.4fr .6fr; gap: 18px; }
.panel { padding: 18px 20px; margin-bottom: 18px; }
.panel:last-child { margin-bottom: 0; }
.panel-header { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.panel-header.wrap { align-items: flex-start; }
.panel h3 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--muted); margin: 3px 0 0; font-size: 13px; }
.tag { color: var(--primary); background: var(--primary-light); padding: 4px 10px; border-radius: 999px; font-size: 10.5px; font-weight: 700; white-space: nowrap; }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 11.5px; color: var(--primary); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.field.required label::after { content: ' *'; color: var(--danger); }
.field input, .field select, .field textarea, .table-actions input[type="search"] {
  width: 100%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:hover, .field select:hover { border-color: var(--border-strong); }
.field input:focus, .field select:focus, .field textarea:focus, .table-actions input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13,107,69,.1);
}
.field input.error, .field select.error { border-color: var(--danger); }
.field textarea { min-height: 88px; resize: vertical; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 4px; }
.computed-preview {
  display: flex; gap: 12px; flex-wrap: wrap; grid-column: 1 / -1;
  background: var(--primary-xlight);
  border: 1.5px solid var(--primary-light);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.computed-item { font-size: 13px; }
.computed-item span { color: var(--muted); }
.computed-item strong { color: var(--primary); font-size: 15px; margin-left: 4px; font-weight: 700; }

/* ---- Table ---- */
.table-actions input[type="search"] { min-width: 220px; border-radius: 10px; }
.table-wrap { overflow: auto; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 860px; background: var(--surface); font-size: 13px; }
th, td { padding: 10px 13px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--primary-xlight); }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.row-actions button {
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  transition: var(--transition);
}
.row-actions button:hover { background: var(--surface-2); }
.row-actions .delete { color: var(--danger); }
.row-actions .delete:hover { background: var(--danger-light); border-color: #fec9c5; }
.table-footer {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-3);
  border-radius: 0 0 12px 12px;
}

/* ---- Empty state ---- */
.empty-state { display: grid; gap: 6px; padding: 40px 24px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--text); font-size: 15px; font-weight: 600; }
.empty-state span { font-size: 13px; }

/* ---- Analysis & Alerts ---- */
.analysis-list, .alerts-list { display: grid; gap: 10px; }
.analysis-item, .alert-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface);
  transition: var(--transition);
}
.analysis-item:hover { box-shadow: var(--shadow-sm); transform: translateX(2px); }
.analysis-item header { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.analysis-item header strong { font-size: 14px; font-weight: 700; }
.analysis-item div { font-size: 12.5px; color: var(--muted); }
.bar-line { display: grid; gap: 5px; margin-top: 8px; }
.bar-track { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; width: var(--w,0%); background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 999px; transition: width .5s ease; }
.alert-item { position: relative; padding-left: 16px; }
.alert-item::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; border-radius: 12px 0 0 12px; }
.alert-item.danger { border-color: #fec9c5; background: #fff7f6; }
.alert-item.danger::before { background: var(--danger); }
.alert-item.warning { border-color: #fcd88a; background: var(--warning-light); }
.alert-item.warning::before { background: #f59e0b; }
.alert-item.ok { border-color: #a6e9bc; background: var(--success-light); }
.alert-item.ok::before { background: var(--success); }
.alert-item strong { display: block; margin-bottom: 3px; font-size: 13px; font-weight: 700; }
.alert-item span { font-size: 12px; color: var(--muted); line-height: 1.4; }

/* ---- Chart ---- */
.chart-panel { margin-bottom: 18px; }
.chart-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 8px;
}
#layRateChart { display: block; width: 100%; min-height: 300px; }
.chart-meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; }
.chart-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.chart-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); display: inline-block; flex-shrink: 0; }

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
  max-width: 360px;
}
.toast {
  background: #12231a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 8px 28px rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp .25s cubic-bezier(.34,1.56,.64,1);
  pointer-events: all;
  border: 1px solid rgba(255,255,255,.07);
}
.toast.success { border-left: 3px solid #6ee7a2; }
.toast.error { border-left: 3px solid #f87171; }
.toast.warning { border-left: 3px solid #fbbf24; }
.toast .toast-close { margin-left: auto; opacity: .5; font-size: 16px; padding: 0 2px; transition: opacity .15s; }
.toast .toast-close:hover { opacity: 1; }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px) scale(.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes slideDown { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(16px); } }
.toast.hiding { animation: slideDown .2s ease forwards; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn .15s ease;
  backdrop-filter: blur(4px);
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 26px 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-xl);
  animation: modalIn .2s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal h3 { margin: 0 0 10px; font-size: 18px; font-weight: 700; }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  :root { --sidebar-width: 240px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 280px; transform: translateX(-100%); z-index: 100; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-xl); }
  .sidebar-overlay { display: block; opacity: 0; pointer-events: none; }
  .sidebar-overlay.visible { opacity: 1; pointer-events: all; }
  .mobile-header { display: flex; }
  .main { padding: 16px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar .actions { justify-content: flex-end; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .profile-card { flex-direction: column; align-items: stretch; }
  .table-actions { flex-wrap: wrap; }
  .table-actions input[type="search"] { min-width: 100%; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .chart-badge { font-size: 11px; padding: 4px 9px; }
  .toast-container { bottom: 12px; right: 12px; left: 12px; max-width: 100%; }
  .toast { max-width: 100%; }
  .topbar h2 { font-size: 20px; }
}

/* ---- Print ---- */
@media print {
  .sidebar, .mobile-header, .actions, .table-actions, .btn,
  .row-actions, .toast-container, .modal-backdrop, #syncStatus { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .panel, .profile-card, .kpi-card { box-shadow: none; border: 1px solid #ccc; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  body { font-size: 11px; }
}