:root {
  --sidebar-width: 240px;
  --sidebar-bg: #1a1d21;
  --sidebar-hover: #2c2f35;
  --topbar-height: 56px;
  --accent: #0d6efd;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: #f0f2f5;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#sidebar .brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

#sidebar .brand span {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .02em;
}

#sidebar .brand small {
  color: rgba(255,255,255,.4);
  font-size: .7rem;
  margin-left: .4rem;
}

#sidebar .nav-link {
  color: rgba(255,255,255,.65);
  padding: .6rem 1.25rem;
  border-radius: .375rem;
  margin: .1rem .5rem;
  font-size: .875rem;
  transition: background .15s, color .15s;
}

#sidebar .nav-link:hover,
#sidebar .nav-link.active {
  background: var(--sidebar-hover);
  color: #fff;
}

#sidebar .nav-link .bi {
  margin-right: .6rem;
  font-size: 1rem;
  opacity: .8;
}

/* ─── Main content ───────────────────────────────────────────────────────────── */
#main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

#topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 99;
}

.page-content {
  padding: 1.75rem 1.5rem;
}

/* ─── Stat cards ─────────────────────────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: .75rem;
  padding: 1.25rem 1.5rem;
  border: 1px solid #e5e7eb;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-label {
  font-size: .8rem;
  color: #6b7280;
  margin-top: .3rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

button.stat-card-btn { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
button.stat-card-btn:hover { border-color: #d1d5db; }
button.stat-card-btn.active { border-color: #dc3545; box-shadow: 0 0 0 .15rem rgba(220, 53, 69, .2); }

/* ─── Alertes cabine (incidents) ─────────────────────────────────────────────── */
#cabines-tbody tr.row-alert-error > td:first-child { box-shadow: inset 4px 0 0 #dc3545; }
#cabines-tbody tr.row-alert-warning > td:first-child { box-shadow: inset 4px 0 0 #f59e0b; }
.btn-alerts {
  display: inline-flex; align-items: center; gap: .3rem;
  max-width: 220px; margin-top: .25rem;
  font-size: .75rem; font-weight: 600; line-height: 1.2;
  padding: .2rem .5rem; border-radius: 999px; border: 1px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-alerts span { overflow: hidden; text-overflow: ellipsis; }
.btn-alerts.alert-level-error { background: #fdecee; color: #b02a37; border-color: #f5c2c7; }
.btn-alerts.alert-level-error.has-fault { animation: pulse-alert 2s infinite; }
.btn-alerts.alert-level-warning { background: #fff7e6; color: #92590a; border-color: #fcd9a0; }
@keyframes pulse-alert {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, .35); }
  50% { box-shadow: 0 0 0 4px rgba(220, 53, 69, 0); }
}
.incident-item { display: flex; gap: .75rem; padding: .6rem .75rem; border: 1px solid #e5e7eb; border-radius: .5rem; margin-bottom: .5rem; }
.incident-item .incident-icon { font-size: 1.1rem; line-height: 1.3; }
.incident-item.unread { background: #fffbeb; border-color: #fde68a; }
.incident-item .incident-msg { font-size: .8rem; color: #6b7280; word-break: break-word; }
.incident-item .incident-meta { font-size: .75rem; color: #9ca3af; }

/* ─── Online badge ───────────────────────────────────────────────────────────── */
.badge-online {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .75rem;
}

.badge-online::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  animation: pulse-green 2s infinite;
}

.badge-offline::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  margin-right: .35rem;
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

/* ─── Tables ─────────────────────────────────────────────────────────────────── */
.table-card {
  background: #fff;
  border-radius: .75rem;
  border: 1px solid #e5e7eb;
  overflow: hidden;
}

.table-card .table {
  margin-bottom: 0;
}

.table thead th {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6b7280;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 600;
}

/* ─── Login ──────────────────────────────────────────────────────────────────── */
.login-wrapper {
  position:absolute;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1d21 0%, #2c3e50 100%);
}

.login-card {
  width: 380px;
  background: #fff;
  border-radius: 1rem;
  padding: 2.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

/* ─── Table actions ──────────────────────────────────────────────────────────── */
.table td:last-child {
  white-space: nowrap;
}

/* ─── Sortable headers ───────────────────────────────────────────────────────── */
th.th-sort {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.th-sort:hover {
  color: #374151;
}

th.th-sort .sort-icon {
  font-size: .65rem;
  opacity: .5;
  margin-left: .2rem;
  vertical-align: middle;
}

th.th-sort .bi-chevron-up,
th.th-sort .bi-chevron-down {
  opacity: 1;
  color: var(--accent);
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
#sidebar {
  transition: transform .25s ease;
}

#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
}

#sidebar-backdrop.active {
  display: block;
}

@media (max-width: 768px) {
  #sidebar {
    transform: translateX(-100%);
    z-index: 100;
  }
  #sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.35);
  }
  #main-content { margin-left: 0; }

  #modal-reader-info .modal-body {
    overflow-x: hidden;
  }
  #modal-reader-info .modal-body .table td {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  #modal-reader-info .modal-body .table td:first-child {
    white-space: normal;
  }
  #modal-reader-info .modal-body code {
    word-break: break-all;
  }
}
