/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-online: #22c55e;
    --color-offline: #ef4444;
    --color-active: #fbbf24;
    --color-primary: #3b82f6;
    --color-bg: #f8fafc;
    --color-card: #ffffff;
    --color-text: #1e293b;
    --color-text-light: #64748b;
    --color-border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    padding-bottom: 2rem;
}

/* Page Management */
.page {
    display: none;
    min-height: 100vh;
}

.page.active {
    display: block;
}

/* Header */
header {
    background: var(--color-card);
    padding: 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

.refresh-btn, .back-btn {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.refresh-btn:hover, .back-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.refresh-btn:active, .back-btn:active {
    transform: translateY(0);
}

/* Chart Section */
.chart-section {
    background: var(--color-card);
    margin: 1rem;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.chart-section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.chart-container {
    max-width: 300px;
    margin: 0 auto 1rem;
    position: relative;
    height: 250px;
}

.stats-summary {
    display: flex;
    justify-content: space-around;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--color-text-light);
    font-weight: 500;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-value.online {
    color: var(--color-online);
}

.stat-value.offline {
    color: var(--color-offline);
}

/* Device List Section */
.device-list-section {
    margin: 1rem;
}

.device-list-section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-left: 0.5rem;
}

.device-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.device-card {
    background: var(--color-card);
    padding: 1rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.device-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.device-card:active {
    transform: translateY(0);
}

/* Traffic Light Indicator */
.traffic-light {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.traffic-light.online {
    background: var(--color-online);
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.5);
}

.traffic-light.offline {
    background: var(--color-offline);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

.traffic-light.active {
    background: var(--color-active);
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.5);
}

/* Device Info */
.device-info {
    flex: 1;
}

.device-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.device-id {
    font-size: 0.875rem;
    color: var(--color-text-light);
    margin-bottom: 0.5rem;
}

.device-status-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.status-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-weight: 500;
}

.status-badge.wifi {
    background: #dbeafe;
    color: #1e40af;
}

.status-badge.mqtt {
    background: #dcfce7;
    color: #15803d;
}

.status-badge.offline-badge {
    background: #fee2e2;
    color: #991b1b;
}

/* Device Detail Page */
.device-status-section {
    background: var(--color-card);
    margin: 1rem;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.device-status-section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.status-info {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.status-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--color-bg);
    border-radius: 0.5rem;
}

.status-label {
    font-weight: 500;
    color: var(--color-text-light);
}

.status-value {
    font-weight: 600;
    text-align: right;
}

.status-value.true {
    color: var(--color-online);
}

.status-value.false {
    color: var(--color-offline);
}

/* Device Events Section */
.device-events-section {
    margin: 1rem;
}

.device-events-section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-left: 0.5rem;
}

.events-list {
    max-height: 60vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.event-card {
    background: var(--color-card);
    padding: 1rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--color-border);
}

.event-card.info {
    border-left-color: #3b82f6;
}

.event-card.warn {
    border-left-color: #fbbf24;
}

.event-card.error {
    border-left-color: #ef4444;
}

.event-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
}

.event-code {
    font-weight: 600;
    font-size: 0.875rem;
}

.event-level {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-weight: 500;
    text-transform: uppercase;
}

.event-level.info {
    background: #dbeafe;
    color: #1e40af;
}

.event-level.warn {
    background: #fef3c7;
    color: #92400e;
}

.event-level.error {
    background: #fee2e2;
    color: #991b1b;
}

.event-message {
    font-size: 0.875rem;
    color: var(--color-text-light);
    margin-bottom: 0.5rem;
}

.event-footer {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--color-text-light);
}

/* Loading State */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-light);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-light);
}

.empty-state p {
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

/* Responsive Design */
@media (min-width: 640px) {
    header h1 {
        font-size: 1.5rem;
    }
    
    .chart-container {
        max-width: 350px;
        height: 300px;
    }
    
    .status-info {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .device-list {
        grid-template-columns: repeat(2, 1fr);
        display: grid;
    }
}

@media (min-width: 1024px) {
    body {
        max-width: 1200px;
        margin: 0 auto;
    }
    
    .device-list {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Scrollbar Styling */
.events-list::-webkit-scrollbar {
    width: 8px;
}

.events-list::-webkit-scrollbar-track {
    background: var(--color-bg);
    border-radius: 10px;
}

.events-list::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 10px;
}

.events-list::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-light);
}

/* Outage Chart Section */
.outage-chart-section {
    background: var(--color-card);
    margin: 1rem;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.outage-chart-section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.chart-controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.time-range-select {
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    background: var(--color-card);
    color: var(--color-text);
    font-size: 0.875rem;
}

.outage-chart-section .chart-container {
    position: relative;
    height: 300px;
    width: 100%;
    max-width: none;
    margin: 0;
}

