/* Modern Solar Monitoring - Glassmorphism Design */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
    --primary: #667eea;
    --primary-dark: #5568d3;
    --secondary: #764ba2;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Deep Dark Purple Gradient */
    --bg-gradient: linear-gradient(135deg, #1e1e2f 0%, #292945 50%, #2d2b42 100%);

    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-dark: #1f2937;
    --text-light: #ffffff;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);

    --metric-bg: rgba(255, 255, 255, 0.03);
    /* Default Dark Mode Metric BG */
}

[data-theme="light"] {
    /* Nude / Warm Beige Palette (70% Brightness) */
    --bg-gradient: linear-gradient(135deg, #e3ddd3 0%, #cdc5b4 100%);
    --glass-bg: rgba(235, 231, 225, 0.5);
    --glass-border: rgba(120, 100, 80, 0.15);
    --text-light: #4a4036;
    /* Darker brown for better contrast */
    --text-dark: #4a4036;
    --shadow: 0 4px 15px -1px rgba(80, 60, 40, 0.1);
    --shadow-lg: 0 10px 25px -3px rgba(80, 60, 40, 0.15);

    --metric-bg: rgba(139, 115, 85, 0.1);
    /* Darker Nude for Metrics (Light Mode) */

    /* Adjust accent colors to be warmer/darker in light mode */
    --primary: #8b7355;
    --primary-dark: #6d5a43;
    --secondary: #968c80;
}

[data-theme="light"] .nav-brand h1 {
    background: linear-gradient(135deg, #5d534a 0%, #8b7355 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

body {
    transition: background 0.3s ease, color 0.3s ease;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-dark);
    overflow-x: hidden;
}

/* Animated Background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 20% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* Navigation Bar */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    margin: 0 auto;
    padding: 1.5rem 2rem;
    /* Increased padding */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

@media (min-width: 900px) {
    .nav-container {
        flex-direction: row;
        justify-content: center;
        /* Center all items horizontally */
        gap: 4rem;
        /* Add spacing between Title, Status, and Nav Links */
    }
}

.nav-brand {
    display: flex;
    flex-direction: column;
    /* Stack Title and Time */
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-light);
    font-weight: 700;
}

.nav-brand h1 {
    font-size: 2.22rem;
    /* Increased size */
    margin: 0;
    line-height: 1.2;
    text-align: center;
    letter-spacing: 1px;
}

/* Remove rotation for icon as it was removed */
.brand-icon {
    display: none;
}

.nav-clock {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--text-light);
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 8px;
    margin-left: 0;
    /* Remove horizontal margin */
    border: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

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

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: 2px solid transparent;
    border-radius: 12px;
    color: var(--text-light);
    opacity: 0.8;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    opacity: 1;
    transform: translateY(-2px);
}

.nav-btn.active {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: var(--text-light);
    opacity: 1;
}

.nav-icon {
    font-size: 1.25rem;
}

/* Connection Status */
.connection-status {
    position: sticky;
    top: 80px;
    z-index: 99;
    max-width: 1400px;
    margin: 1rem auto;
    padding: 0.75rem 2rem;
    background: transparent;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    box-shadow: var(--shadow);
    animation: slideDown 0.5s ease-out;
}

.connection-status .status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--warning);
}

.connection-status .status-text {
    font-weight: 600;
    font-size: 0.95rem;
}

.connection-status.connected {
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    color: #155724;
}

.connection-status.connected .status-dot {
    background: var(--success);
    animation: pulse 2s infinite;
}

.connection-status.disconnected {
    background: linear-gradient(135deg, #f8d7da, #f5c6cb);
    color: #721c24;
}

.connection-status.disconnected .status-dot {
    background: var(--danger);
}

.connection-status.connecting .status-dot {
    background: var(--warning);
    animation: blink 1s infinite;
}

/* Container */
.container {
    position: relative;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    z-index: 1;
}

/* Page System */
.page {
    display: none;
    animation: fadeIn 0.5s ease-out;
}

.page.active {
    display: block;
}

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

/* Glass Card */
.card {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    overflow: hidden;
}

.card.glass {
    background: rgba(255, 255, 255, 0.1);
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(255, 255, 255, 0.3);
}

.card-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.card-icon {
    display: flex;
    align-items: center;
    color: var(--accent);
    margin-right: 0.5rem;
}

.card-icon svg {
    filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.3));
    transform: perspective(500px) rotateX(10deg) rotateY(-10deg) scale(1.1);
    transition: transform 0.3s ease;
}

.card:hover .card-icon svg {
    transform: perspective(500px) rotateX(0deg) rotateY(0deg) scale(1.2) translateZ(20px);
}

.nav-brand h1 {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-right: 15px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Status Dots */
.status-dots {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-left: 20px;
    padding-left: 20px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-label {
    font-size: 0.75rem;
    color: var(--text-light);
    opacity: 0.6;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--danger);
    /* Default Red */
    box-shadow: 0 0 5px rgba(239, 68, 68, 0.5);
    transition: all 0.3s ease;
    cursor: help;
}

/* MQTT Status Colors */
.status-dot.connected {
    background-color: var(--success);
    /* Green for MQTT Online */
    box-shadow: 0 0 8px var(--success);
}

.status-dot.connecting {
    background-color: #3b82f6;
    /* Blue for Connecting */
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.8);
    animation: pulse-dot 1s infinite alternate;
}

/* GSheet Logging Active */
.status-dot.uploading {
    background-color: var(--success);
    /* Green for Logging */
    box-shadow: 0 0 8px var(--success);
    animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes pulse-dot {
    from {
        opacity: 0.5;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1.1);
    }
}

@keyframes ping {

    75%,
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

.nav-links {
    padding: 0;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.card-header h2 {
    color: var(--text-light);
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    /* Center Header Text */
}

.card-body {
    padding: 2rem;
}

/* Status Badge */
.status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Center Status Text */
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.status.online {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}

.status.online .status-dot {
    background: #10b981;
    animation: pulse 2s infinite;
}

.status.offline {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.status.offline .status-dot {
    background: #ef4444;
}

.status.waiting {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.status.waiting .status-dot {
    background: #f59e0b;
}

/* Metric Grid */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.metric {
    background: var(--metric-bg);
    border-radius: 16px;
    padding: 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.metric:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

.metric-label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    /* Center Label */
    display: block;
}

.metric-value {
    color: var(--text-light);
    font-size: 2rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    text-align: center;
    /* Center Value */
    display: block;
}

/* Quick Stats */
.quick-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    font-size: 3rem;
    opacity: 0.9;
}

.stat-content {
    flex: 1;
}

.stat-label {
    color: var(--text-light);
    opacity: 0.8;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

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

/* Graphs Container */
.graphs-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.graphs-container .card {
    width: 100%;
}

.chart-controls {
    display: flex;
    gap: 0.5rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: var(--text-light);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.875rem;
}

.btn-small:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 0;
    right: -500px;
    width: 100%;
    max-width: 500px;
    height: 100vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    box-shadow: -10px 0 50px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    /* Increased to overlay Navbar */
    transition: right 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    overflow-y: auto;
}

.settings-panel.active {
    right: 0;
}

.settings-content {
    padding: 2rem;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}

.settings-header h2 {
    color: var(--text-dark);
    font-size: 1.75rem;
}

.btn-close {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    transform: rotate(90deg);
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-group label {
    color: var(--text-dark);
    font-weight: 600;
    font-size: 0.95rem;
}

.setting-group input[type="text"],
.setting-group input[type="number"],
.setting-group input[type="password"] {
    padding: 0.875rem 1rem;
    border: 2px solid rgba(0, 0, 0, 0.3);
    /* Darker Border */
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: #f8fafc;
    /* Slightly darker white */
}

.setting-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.setting-group small {
    color: #6b7280;
    font-size: 0.8rem;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* Buttons */
.btn-primary {
    padding: 1rem 2rem;
    background: var(--bg-gradient);
    color: var(--text-light);
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-install {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
    margin: 2rem auto;
    display: block;
}

.btn-install:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(1.2);
    }
}

@keyframes blink {

    0%,
    50%,
    100% {
        opacity: 1;
    }

    25%,
    75% {
        opacity: 0.3;
    }
}

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

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

@media (max-width: 768px) {
    .container {
        padding: 0.5rem;
        /* Reduce padding on very small screens */
    }

    .nav-container {
        padding: 1rem;
        /* Flex direction/align already set globally */
        width: 100%;
        gap: 1rem;
    }

    .nav-brand {
        width: 100%;
        justify-content: center;
        flex-direction: column;
        gap: 0.5rem;
    }

    .nav-brand h1 {
        margin-right: 0;
        text-align: center;
        font-size: 1.5rem;
        /* Ensure it fits */
    }

    .nav-links {
        width: 100%;
        display: flex;
        justify-content: center;
        /* Force center alignment */
        gap: 0.5rem;
    }

    .nav-btn {
        flex-direction: column;
        padding: 0.75rem;
        gap: 0.25rem;
        flex: 1;
    }

    .nav-text {
        font-size: 0.75rem;
    }

    .connection-status {
        margin: 1rem;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }

    .stats-grid {
        gap: 1rem;
        grid-template-columns: 1fr;
    }

    .card-header {
        padding: 1rem;
        flex-direction: column;
        align-items: center;
        /* Center align header items on mobile */
        gap: 0.75rem;
    }

    .card-body {
        padding: 0.75rem;
    }

    .metric-grid {
        grid-template-columns: repeat(2, 1fr);
        /* 2 columns on mobile for better density */
        gap: 0.75rem;
    }

    .metric-value {
        font-size: 1.5rem;
    }

    .quick-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-icon {
        font-size: 2.5rem;
    }

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

    .settings-panel {
        max-width: 100%;
    }

    .btn-primary,
    .btn-install {
        width: 100%;
        min-height: 48px;
    }
}

@media (max-width: 480px) {
    .nav-brand {
        font-size: 1.25rem;
    }

    .brand-icon {
        font-size: 1.5rem;
    }

    .card-header h2 {
        font-size: 1.25rem;
    }

    .card-icon {
        font-size: 1.5rem;
    }

    .metric {
        padding: 1rem;
    }

    .metric-value {
        font-size: 1.25rem;
    }

    /* Hide Status Labels on Mobile to save space */
    .status-label {
        display: none;
    }

    .status-dots {
        margin-left: 10px;
        padding-left: 10px;
        gap: 8px;
    }
}

/* App Footer */
.app-footer {
    text-align: center;
    padding: 2rem 1rem;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    margin-top: auto;
    width: 100%;
}

.brand-name {
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.5px;
}

#app-version {
    font-family: monospace;
    opacity: 0.7;
    margin-left: 5px;
}