/* Water Connect — App Styles */
@import url('tokens.css');
@import url('dashboard-home.css');

/* ===== FONTS ===== */
@font-face {
  font-family: 'Sofia Pro';
  src: url('../fonts/SofiaPro-Regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Sofia Pro';
  src: url('../fonts/SofiaPro-Bold.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Sofia Pro';
  src: url('../fonts/SofiaPro-ExtraLight.woff2') format('woff2');
  font-weight: 200; font-style: normal; font-display: swap;
}

/* ===== RESET BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: 'Sofia Pro', 'Inter', system-ui, sans-serif;
  background: var(--wt-surface);
  color: var(--wt-text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--wt-surface2); }
::-webkit-scrollbar-thumb { background: var(--wt-border2); border-radius: 3px; }

/* ===== LAYOUT APP ===== */
.app-wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, rgba(26, 42, 107, 0.98) 0%, rgba(13, 27, 75, 0.99) 100%);
  border-right: 1px solid var(--wt-border);
  box-shadow: 4px 0 32px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.28s ease, box-shadow 0.28s ease;
}

.sidebar-brand {
  padding: 20px var(--sidebar-pad) 18px;
  border-bottom: 1px solid var(--wt-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.sidebar-brand-link {
  display: block;
  line-height: 0;
  border-radius: var(--wt-radius-sm);
  outline: none;
}

.sidebar-brand-link:focus-visible {
  box-shadow: 0 0 0 2px var(--wt-surface), 0 0 0 4px var(--wt-accent);
}

.sidebar-brand-img {
  height: 80px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  object-position: left center;
}

.sidebar-brand-tag {
  font-size: 0.68rem;
  font-weight: 200;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #fffff9;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0 16px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.wt-nav-section {
  padding-bottom: 8px;
}

.wt-nav-heading {
  font-size: 0.62rem;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #fffff9;
  padding: 14px var(--sidebar-pad) 8px;
}

.wt-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 var(--sidebar-pad);
  padding: 10px 12px;
  min-height: 44px;
  color: var(--wt-text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--wt-radius-sm);
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  border: 1px solid transparent;
}

.wt-nav-item:hover {
  color: var(--wt-text);
  background: rgba(59, 158, 232, 0.1);
  border-color: rgba(59, 158, 232, 0.12);
}

.wt-nav-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(59, 158, 232, 0.45);
}

.wt-nav-item.active {
  color: var(--wt-text);
  background: rgba(59, 158, 232, 0.16);
  border-color: rgba(59, 158, 232, 0.22);
  box-shadow: inset 3px 0 0 var(--wt-accent);
}

.wt-nav-item-external .wt-nav-external {
  margin-left: auto;
  font-size: 0.7rem;
  opacity: 0.55;
  color: #fffff9;
}

.wt-nav-ico {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.15);
  color: var(--wt-accent);
}

.wt-nav-item.active .wt-nav-ico {
  background: rgba(59, 158, 232, 0.2);
  color: var(--wt-accent);
}

.wt-nav-label {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.wt-nav-badge {
  margin-left: auto;
  flex-shrink: 0;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--wt-danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
}

.sidebar-user {
  margin-top: auto;
  padding: 14px var(--sidebar-pad);
  border-top: 1px solid var(--wt-border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.12);
}

.sidebar-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--wt-accent), var(--wt-primary));
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-meta {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--wt-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.7rem;
  color: #fffff9;
  margin-top: 2px;
}

.sidebar-user-out {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--wt-text-muted);
  transition: var(--trans);
}

.sidebar-user-out:hover {
  color: var(--wt-danger);
  background: rgba(226, 75, 74, 0.1);
}

.sidebar-user-out:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(226, 75, 74, 0.45);
}

/* Voile mobile derrière la sidebar */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 95;
  background: rgba(5, 10, 30, 0.55);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s ease, visibility 0.28s;
}

.sidebar.open ~ .sidebar-backdrop {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

@media (min-width: 769px) {
  .sidebar-backdrop { display: none; }
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: rgba(26,42,107,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--wt-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 90;
  gap: 16px;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--wt-text);
  flex: 1;
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-content { padding: 24px; flex: 1; }

/* ===== MOTIF VAGUE SVG DÉCORATIF ===== */
.wt-wave-bg {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'%3E%3Cpath fill='%233B9EE8' fill-opacity='1' d='M0,192L48,176C96,160,192,128,288,133.3C384,139,480,181,576,186.7C672,192,768,160,864,144C960,128,1056,128,1152,144C1248,160,1344,192,1392,208L1440,224L1440,320L0,320Z'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: bottom;
  background-size: 1440px 320px;
}

/* ===== CARDS ===== */
.wt-card {
  background: var(--wt-surface2);
  border: 1px solid var(--wt-border);
  border-radius: var(--wt-radius-md);
  padding: 20px;
  box-shadow: var(--wt-shadow);
  position: relative;
  overflow: hidden;
  transition: var(--trans);
}

.wt-card:hover { border-color: var(--wt-border2); box-shadow: var(--wt-shadow-lg); }

.wt-card-title {
  font-size: .65rem;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #fffff9;
  margin-bottom: 8px;
}

.wt-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--wt-text);
  line-height: 1;
}

.wt-card-unit {
  font-size: .75rem;
  color: var(--wt-text-muted);
  margin-left: 4px;
}

/* Sparkline placeholder */
.sparkline-wrap { height: 40px; margin-top: 12px; }

/* ===== KPI GRID ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* ===== STATUS BADGES ===== */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
}

.badge-status.ok      { background: rgba(29,158,117,.15); color: var(--wt-success); border: 1px solid rgba(29,158,117,.3); }
.badge-status.warning { background: rgba(239,159,39,.15); color: var(--wt-warning); border: 1px solid rgba(239,159,39,.3); }
.badge-status.danger  { background: rgba(226,75,74,.15);  color: var(--wt-danger);  border: 1px solid rgba(226,75,74,.3); }

.badge-status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ===== JAUGES SVG ===== */
.gauge-wrap { display: flex; flex-direction: column; align-items: center; }
.gauge-label {
  font-size: .7rem;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--wt-text-muted);
  margin-top: 6px;
}
.gauge-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--wt-text);
  text-anchor: middle;
}

/* ===== TOGGLE SWITCH ===== */
.wt-toggle { display: flex; align-items: center; gap: 12px; }
.wt-toggle input[type="checkbox"] { display: none; }
.wt-toggle-track {
  width: 48px; height: 26px;
  background: var(--wt-surface3);
  border: 1px solid var(--wt-border2);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: var(--trans);
}
.wt-toggle-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fffff9;
  transition: var(--trans);
}
.wt-toggle input:checked + .wt-toggle-track {
  background: rgba(29,158,117,.2);
  border-color: var(--wt-success);
}
.wt-toggle input:checked + .wt-toggle-track::after {
  left: 23px;
  background: var(--wt-success);
  box-shadow: 0 0 8px rgba(29,158,117,.5);
}

/* Pulse CSS pour composants actifs */
@keyframes pulse-dot {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .6; transform: scale(1.4); }
}
.pulse { animation: pulse-dot 2s ease-in-out infinite; }

/* ===== ALERTS PANEL ===== */
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border-radius: var(--wt-radius-sm);
  margin-bottom: 8px;
  font-size: .85rem;
}
.alert-item.warning { background: rgba(239,159,39,.1); border: 1px solid rgba(239,159,39,.2); }
.alert-item.critical { background: rgba(226,75,74,.1); border: 1px solid rgba(226,75,74,.2); }
.alert-item.info { background: rgba(59,158,232,.1); border: 1px solid var(--wt-border); }

/* ===== SLIDER RANGE ===== */
.wt-range { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; background: var(--wt-surface3); border-radius: 3px; outline: none; }
.wt-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--wt-accent);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(59,158,232,.5);
}

/* ===== FORMS ===== */
.wt-input, .wt-select {
  background: var(--wt-surface3);
  border: 1px solid var(--wt-border2);
  border-radius: var(--wt-radius-sm);
  color: var(--wt-text);
  padding: 10px 14px;
  font-family: inherit;
  font-size: .9rem;
  width: 100%;
  transition: var(--trans);
}
.wt-input:focus, .wt-select:focus {
  outline: none;
  border-color: var(--wt-accent);
  box-shadow: 0 0 0 3px rgba(59,158,232,.15);
}

/* ===== BUTTONS ===== */
.btn-wt {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--wt-radius-sm);
  border: none;
  font-family: inherit;
  font-weight: 700;
  font-size: .875rem;
  cursor: pointer;
  transition: var(--trans);
}
.btn-wt-primary { background: var(--wt-accent); color: #fff; }
.btn-wt-primary:hover { background: #5ab0f0; box-shadow: var(--wt-glow); }
.btn-wt-outline {
  background: transparent;
  color: var(--wt-accent);
  border: 1px solid var(--wt-accent);
}
.btn-wt-outline:hover { background: rgba(59,158,232,.1); }
.btn-wt-danger { background: var(--wt-danger); color: #fff; }
.btn-wt-success { background: var(--wt-success); color: #fff; }

/* ===== TABLES ===== */
.wt-table { width: 100%; border-collapse: collapse; }
.wt-table th {
  font-size: .65rem;
  font-weight: 200;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: #fffff9;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--wt-border);
}
.wt-table td {
  padding: 10px 12px;
  font-size: .875rem;
  color: var(--wt-text);
  border-bottom: 1px solid rgba(59,158,232,.05);
}
.wt-table tr:hover td { background: rgba(59,158,232,.04); }

/* ===== PROGRESS BARS (BIB) ===== */
.bib-gauge {
  position: relative;
  height: 120px;
  width: 32px;
  background: var(--wt-surface3);
  border-radius: 4px;
  border: 1px solid var(--wt-border2);
  overflow: hidden;
  margin: 0 auto;
}
.bib-fill {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(to top, var(--wt-accent), rgba(59,158,232,.5));
  border-radius: 0 0 3px 3px;
  transition: height .8s ease;
}
.bib-fill.warning { background: linear-gradient(to top, var(--wt-warning), rgba(239,159,39,.5)); }
.bib-fill.danger  { background: linear-gradient(to top, var(--wt-danger),  rgba(226,75,74,.5)); }

/* ===== TOAST ===== */
.wt-toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wt-toast {
  background: var(--wt-surface2);
  border: 1px solid var(--wt-border2);
  border-radius: var(--wt-radius-sm);
  padding: 12px 20px;
  min-width: 280px;
  box-shadow: var(--wt-shadow-lg);
  font-size: .875rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in .3s ease;
}
@keyframes toast-in { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }
.wt-toast.success { border-left: 3px solid var(--wt-success); }
.wt-toast.error   { border-left: 3px solid var(--wt-danger); }
.wt-toast.warning { border-left: 3px solid var(--wt-warning); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45);
  }
  .main-content { margin-left: 0; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 16px; }
}

/* ===== BOOTSTRAP MODALS (fix interaction / overlays) =====
   Certains overlays (sidebar/backdrop/toasts) peuvent capturer les clics
   selon le contexte. On force les modals au-dessus. */
.modal { z-index: 2100; pointer-events: auto; }
.modal-backdrop { z-index: 2090; }
.modal-content { pointer-events: auto; }
