* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --bg-gradient-start: #0f172a;
    --bg-gradient-mid: #1e3a8a;
    --bg-gradient-end: #0f172a;
    --card-bg: rgba(255, 255, 255, 0.1);
    --card-bg-hover: rgba(255, 255, 255, 0.15);
    --text: #ffffff;
    --text-light: #cbd5e1;
    --text-lighter: #94a3b8;
    --border: rgba(255, 255, 255, 0.2);
    --border-light: rgba(255, 255, 255, 0.1);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.3);
    --temp-color: #f97316;
    --hum-color: #06b6d4;
    --batt-color: #22c55e;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(to bottom right, var(--bg-gradient-start), var(--bg-gradient-mid), var(--bg-gradient-end));
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* Animated background circles */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.2;
    pointer-events: none;
    z-index: 0;
}

body::before {
    width: 400px;
    height: 400px;
    background: #3b82f6;
    top: -200px;
    left: -200px;
    animation: pulse 4s ease-in-out infinite;
}

body::after {
    width: 400px;
    height: 400px;
    background: #06b6d4;
    bottom: -200px;
    right: -200px;
    animation: pulse 4s ease-in-out infinite 2s;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.2;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.3;
    }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* Header */
header {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 24px 32px;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    transition: all 0.3s ease;
}

header:hover {
    box-shadow: var(--shadow-hover);
}

header h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

#last-update {
    color: var(--text-light);
    font-size: 14px;
}

.debug-link {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-light);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    display: inline-block;
}

.debug-link:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: var(--text);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

button {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

button:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Devices Overview */
.devices-overview {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 24px;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.devices-overview h2 {
    margin-bottom: 20px;
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
}

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.device-card {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.device-card:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border);
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px) scale(1.02);
}

.device-card .mac {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.device-card .metrics {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.device-card .metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.device-card .metric:hover {
    background: rgba(255, 255, 255, 0.05);
}

.device-card .metric-label {
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 8px;
}

.device-card .metric-value {
    font-weight: 600;
    color: var(--text);
}

.device-card .timestamp {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-lighter);
    border-top: 1px solid var(--border-light);
    padding-top: 12px;
}

/* Device Detail */
.device-detail {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 24px;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.detail-header h2 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
}

.detail-header button {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    border: 1px solid var(--border-light);
}

.detail-header button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--border);
}

/* Current Values */
.current-values {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.value-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    border: 1px solid;
    transition: all 0.3s ease;
}

.value-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.value-card.temp {
    border-color: rgba(249, 115, 22, 0.3);
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
}

.value-card.hum {
    border-color: rgba(6, 182, 212, 0.3);
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
}

.value-card.batt {
    border-color: rgba(34, 197, 94, 0.3);
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
}

.value-icon {
    font-size: 32px;
}

.value-info {
    display: flex;
    flex-direction: column;
}

.value-label {
    font-size: 12px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.value-number {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

/* History Controls */
.history-controls {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.controls-left,
.controls-center,
.controls-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.controls-center {
    flex: 1;
    justify-content: center;
}

.history-controls label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
}

.history-controls select {
    padding: 8px 12px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.history-controls select option {
    background: #3b82f6;
    color: var(--text);
}

.history-controls select:hover {
    border-color: var(--border);
    background: rgba(255, 255, 255, 0.15);
}

.history-controls select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.history-controls button {
    padding: 8px 16px;
    font-size: 14px;
}

.history-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.history-controls button:disabled:hover {
    background: var(--primary);
    transform: none;
}

#history-info {
    font-size: 14px;
    color: var(--text-lighter);
    font-weight: 500;
    min-width: 150px;
    text-align: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Rename button in device cards */
.device-card .rename-btn {
    background: transparent;
    color: var(--primary);
    border: none;
    padding: 4px 8px;
    font-size: 16px;
    cursor: pointer;
    margin-left: auto;
    transition: transform 0.2s;
}

.device-card .rename-btn:hover {
    transform: scale(1.2);
}

.device-card .mac {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.device-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.device-mac-small {
    font-size: 12px;
    color: var(--text-lighter);
    font-weight: 400;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    max-width: 500px;
    width: 90%;
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

.modal-header .close-btn {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--text-light);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.modal-header .close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px;
}

.modal-mac {
    font-size: 14px;
    color: var(--text-lighter);
    margin-bottom: 16px;
}

.modal-body label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 8px;
}

.modal-body input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    font-size: 16px;
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.2s;
}

.modal-body input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.modal-hint {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-lighter);
    font-style: italic;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border: 1px solid var(--border-light);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: 1px solid var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* Charts */
.charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

.chart-container {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    padding: 20px;
    border-radius: 12px;
    height: 300px;
    transition: all 0.3s ease;
}

.chart-container:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border);
}

.chart-container canvas {
    max-height: 100%;
}

/* Loading & Error */
.loading,
.error {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

.error {
    color: #ef4444;
}

/* Responsive */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }

    .devices-grid {
        grid-template-columns: 1fr;
    }

    .charts {
        grid-template-columns: 1fr;
    }

    .chart-container {
        height: 250px;
    }

    .history-controls {
        flex-direction: column;
        gap: 12px;
    }

    .controls-left,
    .controls-center,
    .controls-right {
        width: 100%;
        justify-content: center;
    }

    #history-info {
        min-width: auto;
    }
}
