/* CSS Variables */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --info-color: #3b82f6;
    --warning-color: #f59e0b;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Base */
html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand a {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

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

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    flex: 1;
}

/* Flash Messages */
.flash-messages {
    margin-bottom: 1.5rem;
}

.flash {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
}

.flash-error {
    background-color: #fef2f2;
    color: var(--error-color);
    border: 1px solid #fecaca;
}

.flash-success {
    background-color: #f0fdf4;
    color: var(--success-color);
    border: 1px solid #bbf7d0;
}

.flash-info {
    background-color: #eff6ff;
    color: var(--info-color);
    border: 1px solid #bfdbfe;
}

.flash-warning {
    background-color: #fffbeb;
    color: var(--warning-color);
    border: 1px solid #fde68a;
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
}

.login-box {
    background-color: var(--card-bg);
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group.checkbox {
    display: flex;
    align-items: center;
}

.form-group.checkbox label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0;
    cursor: pointer;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
}

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

/* Dashboard */
.dashboard h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.dashboard > p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

/* Section Title */
.section-title {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-weight: 600;
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.card h3 {
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

.card ul {
    list-style: none;
}

.card ul li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.card ul li:last-child {
    border-bottom: none;
}

.card ul li a {
    color: var(--primary-color);
    text-decoration: none;
}

.card ul li a:hover {
    text-decoration: underline;
}

/* Clickable Card Links */
.card-link {
    display: block;
    text-decoration: none;
    cursor: pointer;
}

.card-link:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card-link h3 {
    color: var(--primary-color);
}

/* Disabled Cards (Coming Soon) */
.card-disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.card-disabled h3 {
    color: var(--text-muted);
}

/* Card Icon */
.card-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

/* Settings Page */
.settings-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.settings-page {
    max-width: 900px;
}

/* Page Header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.page-header p {
    color: var(--text-muted);
}

/* Back Link */
.back-link {
    display: inline-block;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--primary-color);
}

/* Info Grid */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* Info Card */
.info-card {
    background-color: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.info-card h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.info-card-wide {
    grid-column: span 2;
}

.info-card-warning {
    border-left: 4px solid var(--warning-color);
}

.info-card-warning code {
    background-color: var(--bg-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
}

/* Info Table */
.info-table {
    width: 100%;
    border-collapse: collapse;
}

.info-table td,
.info-table th {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.info-table tr:last-child td {
    border-bottom: none;
}

.info-table td:first-child {
    color: var(--text-muted);
    width: 40%;
}

.info-table code {
    background-color: var(--bg-color);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    word-break: break-all;
}

/* Metrics */
.metric {
    text-align: center;
    padding: 0.5rem 0;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.metric-label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Progress Bar */
.progress-bar {
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background-color: var(--primary-color);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-active {
    background-color: #dcfce7;
    color: var(--success-color);
}

.status-inactive {
    background-color: #fef2f2;
    color: var(--error-color);
}

/* Table List */
.table-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.table-list li code {
    background-color: var(--bg-color);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
}

/* Info Footer */
.info-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Error Pages */
.error-page {
    text-align: center;
    padding: 4rem 2rem;
}

.error-page h1 {
    font-size: 6rem;
    color: var(--primary-color);
    line-height: 1;
}

.error-page h2 {
    margin: 1rem 0;
    color: var(--text-color);
}

.error-page p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* Footer */
.footer {
    background-color: var(--card-bg);
    border-top: 1px solid var(--border-color);
    padding: 1rem 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ESP Blinker */
.espblinker-page {
    max-width: 1000px;
}

.espblinker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* Status Indicator */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-weight: 500;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.status-online {
    background-color: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

.status-offline {
    background-color: var(--error-color);
    box-shadow: 0 0 8px var(--error-color);
}

/* LED Control */
.led-control-card {
    text-align: center;
}

.led-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
}

.led-indicator {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-bottom: 1rem;
    transition: all 0.3s ease;
}

.led-on {
    background: radial-gradient(circle, #fef08a 0%, #facc15 50%, #eab308 100%);
    box-shadow: 0 0 30px #facc15, 0 0 60px #facc1580;
}

.led-off {
    background: radial-gradient(circle, #525252 0%, #404040 50%, #262626 100%);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.led-state-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
}

/* LED Buttons */
.led-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-led {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
}

.btn-led:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-led-on {
    background-color: var(--success-color);
    color: white;
}

.btn-led-on:hover:not(:disabled) {
    background-color: #16a34a;
    transform: translateY(-2px);
}

.btn-led-off {
    background-color: var(--text-muted);
    color: white;
}

.btn-led-off:hover:not(:disabled) {
    background-color: #475569;
    transform: translateY(-2px);
}

/* Secondary Button */
.btn-secondary {
    background-color: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

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

/* Error Text */
.error-text {
    color: var(--error-color);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    word-break: break-word;
}

/* Sensor Section */
.sensor-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.sensor-section h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.section-description {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Sensor Cards */
.sensor-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.sensor-card {
    background-color: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.25rem;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.sensor-icon {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.sensor-name {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.sensor-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-color);
}

.sensor-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Chart Grid */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-container {
    background-color: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chart-container h4 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-weight: 500;
}

.chart-container canvas {
    height: 200px !important;
}

/* Chart Info */
.chart-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-links {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .container {
        padding: 1rem;
    }
    
    .login-box {
        padding: 1.5rem;
    }
    
    .info-card-wide {
        grid-column: span 1;
    }
    
    .dashboard h1 {
        font-size: 2rem;
    }
    
    .dashboard-cards {
        grid-template-columns: 1fr;
    }
    
    .settings-cards {
        grid-template-columns: 1fr;
    }
    
    .info-grid {
        grid-template-columns: 1fr;
    }
    
    .espblinker-grid {
        grid-template-columns: 1fr;
    }
    
    .led-buttons {
        flex-direction: column;
    }
    
    .btn-led {
        width: 100%;
    }
    
    .sensor-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .chart-grid {
        grid-template-columns: 1fr;
    }
    
    .chart-info {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
}

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