*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  margin: 0;
}

/* THEME: DARK (par défaut) */
body.theme-dark {
  --bg-main: #020617;
  --bg-elevated: #020617;
  --bg-card: #020617;
  --border-subtle: rgba(148, 163, 184, 0.35);
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --accent-1: #06b6d4;
  --accent-2: #22c55e;
  --accent-3: #f97316;
  --danger: #ef4444;
  --sidebar-border: rgba(15, 23, 42, 0.85);
  --shadow-strong: rgba(15, 23, 42, 0.85);
}

/* THEME: LIGHT */
body.theme-light {
  --bg-main: #f3f4f6;
  --bg-elevated: #e5e7eb;
  --bg-card: #ffffff;
  --border-subtle: rgba(148, 163, 184, 0.5);
  --text-main: #111827;
  --text-muted: #6b7280;
  --accent-1: #06b6d4;
  --accent-2: #16a34a;
  --accent-3: #f97316;
  --danger: #b91c1c;
  --sidebar-border: rgba(209, 213, 219, 0.9);
  --shadow-strong: rgba(15, 23, 42, 0.15);
}

body.theme-dark {
  background: radial-gradient(circle at top left, #111827, #020617);
  color: var(--text-main);
}

body.theme-light {
  background: #f3f4f6;
  color: var(--text-main);
}

/* LAYOUT */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */

.sidebar {
  width: 260px;
  padding: 20px 16px;
 background: var(--bg-elevated);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.brand-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-name {
  font-weight: 600;
  font-size: 1.05rem;
}

.brand-tagline {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  padding: 10px 10px;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: #0b1220;
  color: var(--text-main);
}

.nav-item-active {
  background: #0b1220;
  color: var(--text-main);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.badge-env {
  border-radius: 999px;
  padding: 4px 10px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.badge-small {
  opacity: 0.7;
}

/* MAIN */

.main {
  flex: 1;
  padding: 20px 24px 32px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.6rem;
}

.topbar-subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar-time {
  padding-left: 12px;
  border-left: 1px solid rgba(148, 163, 184, 0.4);
}

/* HEALTH */

.health-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #020617;
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.health-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #6b7280;
}

.health-ok {
  background: var(--accent-2);
}

.health-bad {
  background: var(--danger);
}

/* VIEWS */

.view {
  display: none;
}

.view-active {
  display: block;
}

/* CARDS */

.card {
  background: var(--bg-card);
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  padding: 16px 18px;
  box-shadow: 0 20px 40px var(--shadow-strong);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.card-header h2 {
  margin: 0;
  font-size: 0.98rem;
  color: var(--text-main);
}

.card-caption {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
}

/* GRID HELPERS */

.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.grid-2-main {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr);
  gap: 14px;
}

.details-layout {
  margin-bottom: 16px;
}

/* STAT CARDS */

.stat-card {
  position: relative;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
}

.stat-foot {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* HIGHLIGHTS */

.highlight-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.highlight-list li {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.highlight-badge {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  margin-right: 6px;
}

/* TABLES */

.table-wrapper {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(30, 41, 59, 0.8);
}

th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: rgba(15, 23, 42, 0.9);
}

.table-footer {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sparkline {
  width: 80px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
}

.sparkline svg {
  width: 100%;
  height: 100%;
}

.sparkline-up {
  color: var(--accent-2); /* vert */
}

.sparkline-down {
  color: var(--danger); /* rouge */
}


/* MODELS HEADER */

.models-header {
  align-items: center;
}

.models-controls {
  display: flex;
  gap: 8px;
}

.models-controls input,
.models-controls select {
  background: #020617;
  border-radius: 9px;
  border: 1px solid rgba(51, 65, 85, 0.9);
  padding: 6px 10px;
  color: var(--text-main);
  font-size: 0.85rem;
}

.models-controls input::placeholder {
  color: #6b7280;
}

/* DETAILS */

.details-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.details-stats {
  margin-top: 6px;
}

.mini-stat {
  background: #020617;
  border-radius: 10px;
  border: 1px solid rgba(51, 65, 85, 0.9);
  padding: 10px 12px;
}

.mini-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.mini-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.mini-foot {
  margin-top: 3px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.details-overview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.6);
}

body.theme-light .details-overview {
  background: rgba(243, 244, 246, 0.9);
}

.details-thumb {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.details-overview-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.details-overview-name {
  font-weight: 600;
  font-size: 0.98rem;
}

.details-overview-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.details-overview-side {
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.details-overview-side-value {
  font-weight: 500;
  color: var(--text-main);
}

/* Sur mobile, on empile */
@media (max-width: 640px) {
  .details-overview {
    flex-direction: column;
    align-items: flex-start;
  }

  .details-overview-side {
    text-align: left;
    width: 100%;
  }
}


.details-meta-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.details-meta-list > div {
  display: flex;
  justify-content: space-between;
}

.meta-label {
  opacity: 0.7;
}

/* OTHER */

.chart-card {
  padding-bottom: 20px;
}

.hint {
  opacity: 0.7;
}

/* RESPONSIVE */

@media (max-width: 960px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-right: none;
    border-bottom: 1px solid rgba(15, 23, 42, 0.85);
  }

  .nav {
    flex-direction: row;
  }

  .main {
    padding: 16px;
  }

  .grid-2-main {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .models-controls {
    flex-direction: column;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .topbar-right {
    padding-top: 4px;
    border-top: 1px solid rgba(30, 41, 59, 0.9);
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .topbar-time {
    border-left: none;
    padding-left: 0;
  }
}

.nav-item {
  /* ... tes styles existants ... */
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 100%;
  height: 100%;
  stroke: var(--text-muted);
  fill: none;
}

.nav-item.nav-item-active .nav-icon svg {
  stroke: var(--accent-1);
}

.nav-item:hover .nav-icon svg {
  stroke: var(--text-main);
}

/* Theme toggle */

.theme-toggle {
  margin-left: 8px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  padding: 4px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}

.theme-toggle:hover {
  background: rgba(148, 163, 184, 0.12);
}

.theme-toggle-label {
  color: var(--text-muted);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  stroke: var(--text-muted);
  fill: none;
}

/* Icônes visibles selon le thème */
.theme-icon-sun {
  display: none;
}

body.theme-light .theme-icon-sun {
  display: block;
}
body.theme-light .theme-icon-moon {
  display: none;
}

body.theme-dark .theme-icon-sun {
  display: none;
}
body.theme-dark .theme-icon-moon {
  display: block;
}

.range-toggle {
  display: inline-flex;
  background: var(--bg-elevated);
  border-radius: 999px;
  padding: 2px;
  border: 1px solid var(--border-subtle);
  gap: 2px;
}

.range-toggle button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
}

.range-toggle button:hover {
  background: rgba(148, 163, 184, 0.18);
  color: var(--text-main);
}

.range-toggle button.active {
  background: var(--accent-1);
  color: white;
}

.source-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.source-toggle .source-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.7;
}

.source-toggle button {
  border: 0;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  background: rgba(148, 163, 184, 0.15);
  color: inherit;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.source-toggle button.active {
  background: rgba(59, 130, 246, 0.25);
}

.source-toggle button:disabled {
  opacity: 0.4;
  cursor: default;
}
