/* --- Global Resets & Base Styles --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #121212; 
    color: #e0e0e0; 
    line-height: 1.6;
    font-size: 16px;
    padding-top: 48px; 
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
.container { width: 92%; max-width: 1280px; margin: 25px auto; padding: 0 10px; }
header h1 { text-align: center; color: #64b5f6; font-size: clamp(1.7rem, 4.5vw, 2.4rem); font-weight: 500; margin-bottom: 35px; letter-spacing: 0.5px; }

/* --- Marquee Styling --- */
.marquee-container { position: fixed; top: 0; left: 0; width: 100%; background-color: #0a0a0a; color: #8899aa; padding: 9px 0; overflow: hidden; white-space: nowrap; z-index: 1000; box-shadow: 0 2px 6px rgba(0,0,0,0.35); }
.marquee-text { display: inline-block; padding-left: 100%; animation: marquee 35s linear infinite; }
.marquee-text span { display: inline-block; padding: 0 30px; font-size: 0.85rem; font-weight: 400; }
@keyframes marquee { 0% { transform: translateX(0); } 100% { transform: translateX(-100%); } }

/* --- Card Styling --- */
.card { background-color: #1e1e1e; border-radius: 10px; padding: 20px 22px; margin-bottom: 22px; box-shadow: 0 5px 18px rgba(0, 0, 0, 0.4); border: 1px solid #2c2c2c; }
.card h2 { color: #90caf9; font-size: clamp(1.15rem, 2.8vw, 1.4rem); margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid #2c2c2c; font-weight: 500; }
.card h3 { color: #b0bec5; font-size: clamp(0.95rem, 2.2vw, 1.1rem); margin-bottom: 12px; font-weight: 400; }

/* --- Grid Layout for Cards --- */
.grid-container { display: grid; grid-template-columns: 1fr; gap: 22px; }

/* --- Status Card --- */
.status-card .status-grid-internal { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 20px;}
.status-card .status-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #282d33; font-size: clamp(0.88rem, 1.9vw, 0.95rem); }
.status-card .status-item:last-child { border-bottom: none; }
.status-card .status-item.full-width { grid-column: 1 / -1; }
.status-card .label { color: #b0bec5; }
.status-card .value { color: #81c784; font-weight: 500; }
.status-card .value.small { font-size: 0.82em; color: #8a9bb1; }
#fan-control-mode { color: #fff176; }

/* --- Simulated RGB Ring --- */
.simulated-rgb-ring-container { display: flex; flex-direction: column; align-items: center; margin-top: 20px; }
.simulated-rgb-ring { width: 80px; height: 80px; border-radius: 50%; position: relative; display: flex; justify-content: center; align-items: center; background-color: #2c2c2c; box-shadow: inset 0 0 10px rgba(0,0,0,0.5); }
.simulated-led { width: 12px; height: 12px; background-color: #444; border-radius: 50%; position: absolute; border: 1px solid #333; box-shadow: 0 0 3px rgba(0,0,0,0.3); }
.rgb-status-text { margin-top: 10px; font-size: 0.85em; color: #90caf9; }


/* --- Pyramid Diagram Card --- */
.diagram-card { padding-bottom: 10px; min-height: 300px; }
.pyramid-diagram-container {
    display: flex; 
    justify-content: center;
    align-items: center;
    position: relative; 
    width: 100%;
    height: 280px; 
    margin-top: 10px;
    overflow: visible; /* Allow markers to show if lines go to edge */
}
.pyramid-node {
    background-color: #2a2f36; 
    color: #d0d8e2;
    padding: 8px 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid #4a5568;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    font-size: clamp(0.7rem, 1.5vw, 0.85rem); 
    text-align: center;
    position: absolute; 
    min-width: 120px; 
    max-width: 140px; 
    z-index: 2; 
    white-space: nowrap; 
}
.node-icon { font-size: 1em; margin-right: 4px; }
.status-dot {
    width: 8px; height: 8px; border-radius: 50%; background-color: #555;
    margin-left: 6px; transition: background-color 0.3s ease, box-shadow 0.3s ease;
    flex-shrink: 0; 
}
.status-dot.online { background-color: #66bb6a; box-shadow: 0 0 6px #66bb6a; }
.status-dot.offline { background-color: #ef5350; box-shadow: 0 0 6px #ef5350; }
.status-dot.degraded { background-color: #ffee58; box-shadow: 0 0 6px #ffee58; }

/* Node Positioning - Desktop First, then adjust for mobile */
.flask-node { top: 10%; left: 50%; transform: translateX(-50%); }
.pyramid-base-row { position: absolute; bottom: 10%; width: 90%; left: 5%; display: flex; justify-content: space-between; align-items: flex-end; }
.esp-node, .supabase-node, .web-node { position: relative; left: auto; top: auto; transform: none; width: 30%; }

/* SVG Arrows */
.pyramid-arrows { width: 100%; height: 100%; position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none; }
.arrow-line {
    stroke: #525252; 
    stroke-width: 1.5;
    opacity: 0.6;
    transition: stroke 0.3s ease, opacity 0.3s ease;
    stroke-linecap: round;
}
.arrow-line.active {
    stroke: #76d7c4; 
    opacity: 1;
    stroke-dasharray: 4 4; 
    animation: dashAnimate 0.7s linear infinite; /* Adjusted speed */
}
.arrowhead-path { /* Base style for path inside marker */
    transition: fill 0.3s ease;
}
.arrowhead-path.default { fill: #525252; }
.arrowhead-path.active { fill: #76d7c4; }

@keyframes dashAnimate {
    to { stroke-dashoffset: -16; } /* Adjust for visible speed with dasharray 4 4 */
}


/* --- Controls Card --- */
.controls-card .control-group { margin-bottom: 16px; }
.controls-card label { display: block; color: #b0bec5; margin-bottom: 6px; font-size: 0.9rem; }
.controls-card input[type="number"] { width: 100%; padding: 9px 11px; background-color: #161a1e; border: 1px solid #383e46; color: #e4e8f0; border-radius: 5px; font-size: 0.95em; }
.btn { width: 100%; padding: 10px 14px; background-color: #64b5f6; color: #000; border: none; border-radius: 5px; cursor: pointer; font-size: 0.95em; font-weight: 500; transition: background-color 0.2s ease, transform 0.1s ease; margin-top: 6px; }
.btn:hover { background-color: #42a5f5; } .btn:active { transform: translateY(1px); }
.manual-fan-controls { margin-top: 22px; padding-top: 16px; border-top: 1px solid #2c2c2c; }
.switch-container { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.manual-mode-label { color: #e4e8f0; font-size: 0.95em; }
.switch { position: relative; display: inline-block; width: 42px; height: 22px; }
.switch input { display: none; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #546e7a; transition: .3s; border-radius: 22px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: #66bb6a; }
input:checked + .slider:before { transform: translateX(20px); }
.manual-buttons-container { display: flex; gap: 12px; margin-top: 12px; }
.btn-fan { flex-grow: 1; }
.btn-fan.active { background-color: #66bb6a; color: #121212; }
.btn-fan.active:hover { background-color: #4caf50; }
.message { margin-top: 12px; font-size: 0.88em; min-height: 1.1em; text-align: center; }
.message-success { color: #66bb6a; } .message-error { color: #ef5350; }

/* --- Chart Card --- */
.chart-card { padding-bottom: 12px; }
.chart-wrapper { position: relative; height: 280px; max-height: 55vh; background-color: #161a1e; border-radius: 7px; padding: 12px; }
#tempHumidityChart { width: 100% !important; height: 100% !important; }

/* --- Floating Button --- */
.floating-btn { position: fixed; bottom: 20px; right: 20px; background-color: #64b5f6; color: #121212; border: none; border-radius: 50%; width: 50px; height: 50px; font-size: 24px; display: flex; justify-content: center; align-items: center; box-shadow: 0 4px 10px rgba(0,0,0,0.3); cursor: pointer; transition: background-color 0.2s ease, transform 0.2s ease; z-index: 999; }
.floating-btn:hover { background-color: #42a5f5; transform: scale(1.1); }

/* --- Footer --- */
footer { text-align: center; margin-top: 45px; padding: 22px 0; border-top: 1px solid #2c2c2c; color: #788290; font-size: 0.85em; }


/* --- Responsive Adjustments --- */
@media (max-width: 767px) { 
    .pyramid-diagram-container { height: auto; padding-bottom: 20px; min-height: 400px; /* More space for stacked + arrows */ }
    .flask-node { top: 15px; } /* Slightly lower for mobile */
    .pyramid-base-row {
        flex-direction: column; 
        align-items: center; 
        top: 85px; /* Position below Flask node with more gap */
        bottom: auto; 
        width: 100%; left: 0; 
        gap: 20px; /* Gap between stacked nodes */
    }
    .esp-node, .supabase-node, .web-node {
        width: 60%; 
        max-width: 180px; /* Slightly smaller max width */
        margin-bottom: 45px; /* Space for arrows to connect from below/above */
    }
    .esp-node { order: 1; }
    .supabase-node { order: 2; }
    .web-node { order: 3; }
}


@media (min-width: 768px) { 
    .grid-container { grid-template-columns: repeat(2, 1fr); }
    .status-card { grid-column: 1 / 2; grid-row: 1 / 2; }
    .controls-card { grid-column: 2 / 3; grid-row: 1 / 2; }
    .diagram-card { grid-column: 1 / -1; grid-row: 2 / 3; }
    .chart-card { grid-column: 1 / -1; grid-row: 3 / 4; }
    .pyramid-diagram-container { height: 280px; }
}

@media (min-width: 1024px) { 
    .grid-container {
        grid-template-columns: 320px 1fr 320px; 
        grid-template-areas: "status diagram controls" "chart chart chart";
         gap: 25px;
    }
    .status-card { grid-area: status; }
    .diagram-card { grid-area: diagram; min-height: 300px; }
    .controls-card { grid-area: controls; }
    .chart-card { grid-area: chart; }
    .pyramid-diagram-container { height: 250px; } 
    .flask-node { font-size: clamp(0.8rem, 1.5vw, 1rem); }
    .esp-node, .supabase-node, .web-node { font-size: clamp(0.75rem, 1.3vw, 0.9rem); }
    .chart-wrapper { height: 320px; }
}