/* ============================================================
   DASHBOARD LAYOUT – STRUCTURE GLOBALE
============================================================ */

html,
body {
    height: 100%;
    margin: 0;
    overflow: hidden; /* pas de scroll page */
}

.dashboard-layout {
    display: flex;
    height: calc(100vh - 70px); /* header pris en compte */
    overflow: hidden;
}

/* ============================================================
   HEADER
============================================================ */

.dashboard-header {
    height: 70px;
    background: var(--card);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.dashboard-header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
}

/* ============================================================
   SIDEBAR
============================================================ */

.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--card);
    padding: 15px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.08);
}

.sidebar-item {
    padding: 12px 14px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    transition: background 0.2s;
}

.sidebar-item:hover {
    background: rgba(37, 99, 235, 0.12);
}

.sidebar-item.active {
    background: var(--accent);
    color: #fff;
}

/* ============================================================
   CONTENU CENTRAL
============================================================ */

.dashboard-content {
    flex: 1;
    height: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--bg);
    overflow: hidden;
}

/* ============================================================
   CARTES
============================================================ */

.dashboard-card {
    height: calc((100% - 20px) / 2); /* 2 cartes = 50% chacune */
    display: flex;
    flex-direction: column;
    padding: 20px;
    background: var(--card);
    border-radius: 14px;
    overflow: hidden;

    border: 1px solid rgba(148, 163, 184, 0.15);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.08),
        0 1px 3px rgba(0, 0, 0, 0.12);
}

.dashboard-card > h2 {
    margin: 0 0 10px 0;
    padding-bottom: 10px;
    font-size: 18px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    flex-shrink: 0;
}

/* Dark mode cartes */
:root.dark .dashboard-card {
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow:
        0 6px 16px rgba(0, 0, 0, 0.45),
        0 1px 2px rgba(0, 0, 0, 0.6);
}

/* ============================================================
   TABLES D’ÉVÉNEMENTS
============================================================ */

.event-tables-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    min-height: 0;
}

.event-tables-grid > div {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.event-subtitle {
    margin: 0 0 6px 0;
    font-size: 14px;
    font-weight: 700;
    opacity: 0.85;
    flex-shrink: 0;
}

.event-table-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border-radius: 10px;
}

/* ============================================================
   TABLE
============================================================ */

.event-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.event-table thead {
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}

.event-table th,
.event-table td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.event-table th {
    font-size: 13px;
    font-weight: 700;
    opacity: 0.85;
}

.event-table tbody tr:hover {
    background: rgba(148, 163, 184, 0.12);
}

.event-loading {
    text-align: center;
    font-style: italic;
    opacity: 0.7;
}

/* ============================================================
   ÉVÉNEMENTS (ÉTATS)
============================================================ */

.event-on {
    color: #22c55e;
    font-weight: 600;
}

.event-off {
    color: #ef4444;
    font-weight: 600;
}
.event-action {
    color: #0ea5e9; /* bleu info */
    font-weight: 600;
}

/* ============================================================
   ANIMATION NOUVEL ÉVÉNEMENT
============================================================ */

.event-new {
    animation: slideIn 0.35s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================
   RESPONSIVE
============================================================ */

@media (max-width: 900px) {
    .event-tables-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .dashboard-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
    }

    .sidebar-item {
        white-space: nowrap;
    }

    .dashboard-card {
        height: auto;
    }

    .event-table-wrapper {
        max-height: 240px;
    }
}
/* ============================================================
   RELAY CARDS – ÉTAT SYSTÈME
============================================================ */

.relay-cards-container {
    flex: 1;
    min-height: 0;

    display: grid;
    grid-auto-flow: row;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;

    overflow-y: auto;
}

/* Carte relais */
.relay-card {
    background: var(--bg);
    border-radius: 12px;
    padding: 14px;

    display: flex;
    flex-direction: column;
    gap: 6px;

    border: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.08);

    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.relay-card:hover {
    transform: translateY(-2px);
    box-shadow:
        0 4px 10px rgba(0, 0, 0, 0.12);
}

/* Titre */
.relay-title {
    font-weight: 700;
    font-size: 14px;
}

/* Description */
.relay-desc {
    font-size: 12px;
    opacity: 0.8;
}

/* Delay en S */
.relay-delayS {
    font-size: 12px;
    opacity: 0.8;
}

/* Type lisible */
.relay-type {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.85;
}

/* État */
.relay-state {
    margin-top: auto;
    font-size: 13px;
    font-weight: 700;
}

/* États ON / OFF */
.relay-on {
    color: #22c55e;
}
.relay-off {
    color: #ef4444;
}
/* ============================================================
   RELAY ACTION UI
============================================================ */

/* Interrupteur (SW) */
.relay-switch {
    position: relative;
    width: 48px;
    height: 26px;
    background: #64748b;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.relay-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.relay-switch.on {
    background: #22c55e;
}

.relay-switch.on::after {
    transform: translateX(22px);
}

/* Bouton poussoir (BP) */
.relay-button {
    padding: 8px 14px;
    border-radius: 10px;
    background: #2563eb;
    color: white;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s, background 0.1s;
}

.relay-button:active {
    transform: scale(0.95);
    background: #1d4ed8;
}
.relay-button {
    transition: background 0.2s, opacity 0.2s;
}

.relay-button[style*="pointer-events: none"] {
    background: #64748b;
}
