:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --accent-yellow: #f59e0b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --btn-bg: #334155;
    --btn-hover: #475569;
    --color-red: #ef4444;
    --color-green: #10b981;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --link-color: #38bdf8;
    --code-bg: #0f172a;
    --border-color: rgba(255,255,255,0.05);
}

body { 
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    background: var(--bg-color); 
    color: var(--text-main); 
    margin: 0; 
    padding: 20px; 
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    box-sizing: border-box;
}

body.align-center { align-items: center; }
body.text-center { text-align: center; }

.container { 
    background: var(--card-bg); 
    padding: 40px; 
    border-radius: 24px; 
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); 
    width: 100%;
    max-width: 1000px; 
    border: 1px solid var(--border-color);
    box-sizing: border-box;
}

.container.admin { max-width: 1100px; overflow-x: auto; }
.container.container-contributors { max-width: 1200px; }
.container.small { max-width: 600px; border-radius: 20px; margin: 0 auto; }

.card { 
    position: relative; 
    background: var(--card-bg); 
    padding: 48px 32px; 
    border-radius: 24px; 
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); 
    text-align: center; 
    width: 100%; 
    max-width: 440px; 
    border: 1px solid var(--border-color);
    box-sizing: border-box;
}

h1 { color: var(--accent-yellow); margin: 10px 0 20px 0; font-size: 1.5rem; text-align: center; letter-spacing: -0.025em; }
h2 { color: var(--accent-yellow); font-size: 1.25rem; margin-top: 0; letter-spacing: -0.025em; }
p { color: var(--text-muted); line-height: 1.6; }

.back-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text-muted); text-decoration: none; font-size: 0.9rem; font-weight: 500; transition: color 0.2s; }
.back-link:hover { color: var(--text-main); }
.back-link.mb-24 { margin-bottom: 24px; }
.back-link.mb-20 { margin-bottom: 20px; }
.back-link.mt-30 { margin-top: 30px; }

.status-badges { display: flex; justify-content: center; gap: 15px; margin-bottom: 30px; }
.badge { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); background: rgba(255,255,255,0.03); padding: 4px 12px; border-radius: 20px; border: 1px solid rgba(255,255,255,0.1); }
.dot { width: 8px; height: 8px; border-radius: 50%; }

.chart-wrapper { display: flex; width: 100%; background: rgba(0,0,0,0.2); border-radius: 16px; padding: 15px 0 15px 10px; box-sizing: border-box; overflow: hidden; }
.canvas-container, .y-axis-container { position: relative; height: 450px; }
.canvas-container.h-500, .y-axis-container.h-500 { height: 500px; }
.canvas-container { min-width: 100%; }

#scrollContainer { flex-grow: 1; overflow-x: auto; padding-right: 15px; }

.slider-container { margin-top: 35px; color: var(--text-muted); text-align: center; background: rgba(255,255,255,0.02); padding: 20px; border-radius: 16px; }
.slider-container.transparent { background: transparent; margin: 24px 0; padding: 0; }
.slider-container label { font-size: 0.9rem; font-weight: 500; }
.slider-container strong { color: var(--accent-yellow); }

input[type="range"] { -webkit-appearance: none; width: 100%; max-width: 500px; height: 6px; background: var(--btn-bg); border-radius: 5px; margin-top: 20px; outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; background: var(--accent-yellow); border-radius: 50%; cursor: pointer; box-shadow: 0 0 10px rgba(0,0,0,0.5); }

.input-text { padding: 8px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.2); color: var(--text-main); font-size: 0.9rem; outline: none; }
.input-text:focus { border-color: var(--accent-yellow); }

.cluster-subtitle { text-align: center; color: var(--text-muted); font-size: 0.95rem; margin-top: -15px; margin-bottom: 25px; }

.custom-legend { display: flex; flex-wrap: wrap; gap: 15px; justify-content: center; margin-top: 25px; padding-top: 20px; border-top: 1px solid rgba(255,255,255,0.05); }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-muted); background: rgba(255,255,255,0.02); padding: 6px 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.05); cursor: pointer; user-select: none; transition: opacity 0.2s, background 0.2s; }
.legend-item:hover { background: rgba(255,255,255,0.05); }
.color-box { width: 12px; height: 12px; border-radius: 3px; }

.notification { padding: 16px; border-radius: 12px; margin-bottom: 24px; font-weight: 500; font-size: 0.9rem; }
.notification.success { background: rgba(16, 185, 129, 0.1); color: var(--success); border: 1px solid var(--success); }

table { width: 100%; border-collapse: separate; border-spacing: 0 8px; margin-top: 10px; min-width: 800px; }
th { padding: 8px 8px; text-align: left; color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
td { padding: 16px 8px; background: rgba(255,255,255,0.02); border-top: 1px solid rgba(255,255,255,0.05); border-bottom: 1px solid rgba(255,255,255,0.05); }
td:first-child { border-left: 1px solid rgba(255,255,255,0.05); border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
td:last-child { border-right: 1px solid rgba(255,255,255,0.05); border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
tr:hover td { background: rgba(255,255,255,0.05); }

.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; background: rgba(0,0,0,0.2); }
.chip-link { color: var(--text-main); text-decoration: none; font-weight: 600; }
.chip-link:hover { color: var(--accent-yellow); }

.action-btn { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.2); color: var(--danger); padding: 8px; border-radius: 8px; cursor: pointer; transition: all 0.2s; }
.action-btn:hover { background: var(--danger); color: white; }

.cleanup-card { margin-top: 40px; padding: 30px; background: rgba(0,0,0,0.2); border-radius: 20px; border: 1px solid var(--border-color); }
.btn-cleanup { background: var(--danger); color: #fff; border: none; padding: 8px 16px; border-radius: 10px; cursor: pointer; font-size: 0.67rem; font-weight: 600; transition: opacity 0.2s; }
.btn-cleanup:hover { opacity: 0.9; }
.cluster-input { width: 110px; padding: 6px 8px; font-size: 0.8rem; }

.message { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid #10b981; padding: 15px; border-radius: 8px; margin-bottom: 20px; line-height: 1.5; }
.message.error { background: rgba(239, 68, 68, 0.1); color: #ef4444; border-color: #ef4444; }

.btn-solid { background: var(--accent-yellow); color: #0f172a; padding: 8px 16px; border-radius: 8px; text-decoration: none; font-weight: bold; display: inline-block; margin-top: 20px; transition: background 0.2s; border: none; cursor: pointer; font-size: 0.67rem; }
.btn-solid:hover { background: #d97706; }
.btn-clean { background: #ef4444; color: #f8fafc; }
.btn-clean:hover { background: #dc2626; }

#markdown-content h1, #markdown-content h2, #markdown-content h3 { color: var(--accent-yellow); margin-top: 1.5em; letter-spacing: -0.025em; }
#markdown-content h1 { text-align: center; border-bottom: 1px solid var(--border-color); padding-bottom: 15px; margin-bottom: 30px; }
#markdown-content a { color: var(--link-color); text-decoration: none; }
#markdown-content a:hover { text-decoration: underline; }
#markdown-content code { background: var(--code-bg); color: #e2e8f0; padding: 3px 6px; border-radius: 6px; font-family: monospace; font-size: 0.9em; border: 1px solid var(--border-color); }
#markdown-content pre { background: var(--code-bg); padding: 15px; border-radius: 12px; overflow-x: auto; border: 1px solid var(--border-color); }
#markdown-content pre code { color: var(--text-main); background: none; padding: 0; border: none; }
#markdown-content hr { border: 0; border-top: 1px solid var(--border-color); margin: 30px 0; }
#markdown-content ul, #markdown-content ol { padding-left: 20px; }
#markdown-content li { margin-bottom: 8px; color: var(--text-muted); }
#markdown-content p { color: var(--text-muted); }
#markdown-content strong { color: var(--text-main); }

.nav-icon { position: absolute; top: 24px; color: var(--text-muted); text-decoration: none; transition: color 0.2s, transform 0.2s; }
.nav-icon:hover { color: var(--text-main); transform: scale(1.1); }
.nav-icon svg { width: 1.5rem; height: 1.5rem; }
.icon-left { left: 24px; }

.top-right-nav { position: absolute; top: 24px; right: 24px; display: flex; gap: 16px; }
.top-right-nav .nav-icon { position: relative; top: auto; right: auto; }

header h1.title { font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent-yellow); margin: 0 0 8px 0; }
.stats { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 40px; }

.power-container { margin-bottom: 40px; }
.power-value { font-size: 4rem; font-weight: 800; line-height: 1; display: block; color: var(--text-main); }
.power-unit { font-size: 1.25rem; font-weight: 500; color: var(--text-muted); margin-left: 4px; }
.status-badge { display: inline-block; margin-top: 12px; padding: 4px 12px; border-radius: 20px; background: rgba(255,255,255,0.05); border: 1px solid var(--status-color); color: var(--status-color); font-size: 0.85rem; font-weight: 600; text-transform: capitalize; }

.button-group { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.btn-block { display: block; width: 100%; padding: 14px; background: var(--btn-bg); color: #fff; text-decoration: none; border-radius: 12px; font-weight: 600; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-sizing: border-box; }
.btn-block:hover { background: var(--btn-hover); transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3); }

.api-section { margin-top: 32px; padding-top: 24px; border-top: 1px solid rgba(255,255,255,0.1); text-align: left; }
.api-section p { font-size: 0.75rem; color: var(--text-muted); margin: 6px 0; display: flex; justify-content: space-between; }
.api-section a { color: var(--link-color); text-decoration: none; font-family: monospace; }
.api-section a:hover { text-decoration: underline; }

#progress-bar { position: fixed; bottom: 0; left: 0; height: 4px; background: var(--accent-yellow); animation: countdown 300s linear forwards; opacity: 0.6; }
@keyframes countdown { from { width: 100%; } to { width: 0%; } }

@media (max-width: 600px), (orientation: portrait) {
    html { font-size: 110%; }
    body { padding: 0; margin: 0; }
    .container { padding: 3vh 5vw; width: 90%; min-height: 75vh; max-width: none; margin: 1.5vh auto 3vh auto; }
    .container.small { min-height: auto; }
    .card { padding: 3vh 5vw; width: 90%; min-height: 75vh; max-width: none; margin: 1.5vh auto 3vh auto; display: flex; flex-direction: column; justify-content: flex-start; }
    .card header { margin-top: 35px; } /* Évite que le titre ne chevauche les icônes de navigation */
    .canvas-container, .y-axis-container { height: 350px; }
    .canvas-container.h-500, .y-axis-container.h-500 { height: 400px; }
    .api-section { margin-top: auto; }
    .power-value { font-size: 18vw; }
    .button-group { width: fit-content; margin: 0 auto; }

    /* Affichage du tableau d'administration sur 3 lignes */
    table.devices-table { display: block; min-width: 100%; border: none; }
    table.devices-table thead { display: none; }
    table.devices-table tbody { display: block; width: 100%; }
    table.devices-table tr {
        display: grid;
        grid-template-columns: auto auto auto 1fr auto auto;
        grid-template-areas: 
            "status chip fw . admin action"
            "power name cluster cluster cluster cluster"
            "seen seen seen seen seen seen";
        gap: 12px 8px;
        align-items: center;
        background: rgba(255,255,255,0.02);
        border: 1px solid rgba(255,255,255,0.05);
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 12px;
    }
    table.devices-table td { display: flex; align-items: center; border: none !important; padding: 0 !important; background: transparent !important; border-radius: 0 !important; white-space: nowrap; }
    
    table.devices-table td:nth-child(1) { grid-area: status; }
    table.devices-table td:nth-child(2) { grid-area: chip; }
    table.devices-table td:nth-child(5) { grid-area: fw; justify-content: flex-start; }
    table.devices-table td:nth-child(8) { grid-area: admin; justify-content: flex-end; }
    table.devices-table td:nth-child(9) { grid-area: action; justify-content: flex-end; }
    
    table.devices-table td:nth-child(7) { grid-area: power; justify-content: flex-start; }
    table.devices-table td:nth-child(3) { grid-area: name; white-space: normal; word-break: break-word; justify-content: flex-start; }
    table.devices-table td:nth-child(4) { grid-area: cluster; justify-content: flex-start; width: 100%; }
    table.devices-table td:nth-child(4) form { width: 100%; }
    
    table.devices-table td:nth-child(6) { grid-area: seen; justify-content: flex-start; font-size: 0.8rem; color: var(--text-muted); }

    .cluster-input { width: 100% !important; max-width: none; }
}

/* Grands écrans mobiles (ex. S25 Ultra, iPhone Pro Max) */
@media (max-width: 600px) and (min-height: 840px) and (orientation: portrait),
       (min-width: 400px) and (max-width: 600px) and (orientation: portrait) {
    html { font-size: 175%; }
}