/* ============================================
   Smart Home - Main Stylesheet
   ============================================ */

/* === CSS Variables === */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent: #00d4ff;
    --accent-green: #00b894;
    --accent-red: #e74c3c;
    --accent-yellow: #f39c12;
    --accent-orange: #e17055;
}

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

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* === Layout === */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px 15px;
}

/* === Header === */
header {
    background: var(--bg-secondary);
    padding: 8px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid #2a2a4a;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--accent);
}

nav a {
    color: var(--text-secondary);
    text-decoration: none;
    margin-left: 15px;
    font-size: 13px;
    transition: color 0.2s;
}

nav a:hover, nav a.active {
    color: var(--accent);
}

/* === Cards === */
.card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #2a2a4a;
}

.card-title {
    font-size: 1em;
    color: var(--accent);
}

/* === Grid Layouts === */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 10px;
}

.grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
}

.stat-value {
    font-size: 1.4em;
    font-weight: bold;
    color: var(--accent);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.8em;
    margin-top: 2px;
}

.stat-unit {
    font-size: 0.5em;
    color: var(--text-secondary);
}

.stat-sub {
    font-size: 0.9em;
    color: var(--accent-green);
    margin-top: 3px;
}

.stat-dates {
    font-size: 0.8em;
    color: var(--text-secondary);
    display: block;
    margin-top: 2px;
}

/* === Tables === */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th, td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid #2a2a4a;
}

th {
    color: var(--accent);
    font-weight: 600;
    font-size: 12px;
}

tr:hover {
    background: rgba(0, 212, 255, 0.05);
}

/* === Buttons === */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: #666;
    color: white;
}

/* === Period Buttons === */
.period-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.period-btn {
    padding: 10px 20px;
    border: 1px solid #333;
    border-radius: 5px;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.period-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.period-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* === Chart Type Buttons === */
.chart-type-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.chart-type-btn {
    padding: 8px 15px;
    border: 1px solid #444;
    border-radius: 5px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.chart-type-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.chart-type-btn.active {
    background: #333;
    color: var(--text-primary);
    border-color: var(--accent);
}

/* === Chart Container === */
.chart-container {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    height: 400px;
    margin-bottom: 20px;
}

/* === Legend === */
.legend-container {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-card);
    border-radius: 6px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.legend-item.disabled {
    opacity: 0.4;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-name {
    font-size: 13px;
}

.legend-value {
    font-weight: bold;
    color: var(--accent);
}

/* === Status Badges === */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: 600;
}

.badge-online { background: var(--accent-green); color: white; }
.badge-offline { background: var(--accent-red); color: white; }
.badge-warning { background: var(--accent-yellow); color: #333; }
.badge-motion { 
    background: var(--accent-orange); 
    color: white;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* === Values === */
.value-temp {
    font-size: 1.1em;
    font-weight: bold;
    color: #ff6b6b;
}

.value-humidity {
    color: #4ecdc4;
}

.value-count {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--accent);
}

.consumption-value {
    color: var(--accent-green);
    font-weight: bold;
}

.daily-avg {
    color: var(--accent);
    font-size: 0.9em;
}

/* === Event List === */
.event-list {
    max-height: 300px;
    overflow-y: auto;
}

.event-item {
    padding: 5px 10px;
    border-left: 2px solid var(--accent-orange);
    background: var(--bg-secondary);
    margin: 4px 0;
    border-radius: 0 6px 6px 0;
    font-size: 12px;
}

.event-time {
    color: var(--accent);
    font-family: monospace;
    margin-right: 8px;
    font-size: 11px;
}

/* === Toggle Switch === */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle {
    position: relative;
    width: 50px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #555;
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background: var(--accent-green);
}

input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

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

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 10px;
    width: 90%;
    max-width: 400px;
}

.modal-content h3 {
    margin-bottom: 20px;
    color: var(--text-primary);
}

.modal-content input,
.modal-content select {
    width: 100%;
    padding: 12px;
    border: 1px solid #333;
    border-radius: 5px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 15px;
    box-sizing: border-box;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    border: none;
}

.modal-btn.cancel {
    background: #666;
    color: white;
}

.modal-btn.save {
    background: var(--accent);
    color: white;
}

/* === Data Table Container === */
.data-table {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    overflow-x: auto;
}

.data-table h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
}

/* === Header Row (title + button) === */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

/* === Year Selector === */
.year-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 20px;
}

.year-selector select {
    padding: 8px 12px;
    border: 1px solid #333;
    border-radius: 5px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
}

/* === Loading State === */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* === Sensor Info === */
.sensor-info {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.sensor-badge {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sensor-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-green);
}

.sensor-status.offline { 
    background: var(--accent-red); 
}

/* === Footer === */
footer {
    text-align: center;
    padding: 10px;
    color: var(--text-secondary);
    font-size: 0.8em;
}

/* === Hamburger Toggle Button === */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    z-index: 1001;
}

.nav-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-secondary);
    margin: 5px 0;
    transition: transform 0.3s, opacity 0.3s;
}

.nav-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.nav-toggle.active span:nth-child(2) {
    opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* === Paste Button === */
.btn-paste {
    background: none;
    border: 1px solid #444;
    color: #aaa;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    margin-left: 10px;
    font-size: 13px;
}

/* === Responsive === */
@media (max-width: 768px) {
    .grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    header .container {
        flex-wrap: wrap;
        position: relative;
    }

    .nav-toggle {
        display: block;
    }

    nav {
        display: none;
        width: 100%;
        flex-direction: column;
        background: var(--bg-secondary);
        border-top: 1px solid #2a2a4a;
        padding: 8px 0;
        order: 3;
    }

    nav.open {
        display: flex;
    }

    nav a {
        margin: 0;
        padding: 10px 16px;
        font-size: 15px;
        border-radius: 6px;
    }

    nav a:hover, nav a.active {
        background: rgba(0, 212, 255, 0.1);
    }

    .btn-paste {
        margin: 8px 16px 4px;
        padding: 8px;
        text-align: center;
    }

    .header-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .period-buttons {
        width: 100%;
    }

    .period-btn {
        flex: 1;
        text-align: center;
    }

    .chart-container {
        height: 280px;
        padding: 10px;
    }

    .card {
        padding: 10px;
    }

    .modal-content {
        width: 95%;
        padding: 20px;
    }

    table {
        font-size: 12px;
    }

    th, td {
        padding: 5px 4px;
    }

    .data-table {
        padding: 10px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 1.5em;
    }

    .container {
        padding: 8px 10px;
    }

    .logo {
        font-size: 1.1em;
    }

    .period-btn {
        padding: 8px 12px;
        font-size: 13px;
    }
}
