/**
 * Home Temperature Monitor - Modern PWA Styles
 * A beautiful, responsive design for temperature monitoring
 */

/* ========== CSS Variables ========== */
:root {
    /* Colors */
    --color-bg-primary: #0f0f1a;
    --color-bg-secondary: #1a1a2e;
    --color-bg-card: #252542;
    --color-bg-elevated: #2d2d4a;

    --color-text-primary: #ffffff;
    --color-text-secondary: #a0a0b8;
    --color-text-muted: #6b6b80;

    --color-accent: #4a90d9;
    --color-accent-light: #6ba3e0;
    --color-accent-dark: #3a7bc8;

    --color-success: #4ade80;
    --color-warning: #fbbf24;
    --color-danger: #f87171;
    --color-cold: #38bdf8;
    --color-hot: #fb923c;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* Safe areas */
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: var(--safe-top);
    padding-bottom: calc(70px + var(--safe-bottom));
}

/* ========== Header ========== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(180deg, var(--color-bg-secondary) 0%, var(--color-bg-primary) 100%);
    padding: var(--spacing-md);
    padding-top: calc(var(--spacing-md) + var(--safe-top));
}

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

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--color-text-primary) 0%, var(--color-accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.icon-btn:hover, .icon-btn:focus {
    background: var(--color-bg-elevated);
    color: var(--color-accent);
}

.icon-btn:active {
    transform: scale(0.95);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.icon-btn.active {
    color: var(--color-accent);
    background: rgba(74, 144, 217, 0.2);
}

.last-update {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: var(--spacing-xs);
}

/* ========== Alert Banner ========== */
.alert-banner {
    background: linear-gradient(135deg, var(--color-danger) 0%, #dc2626 100%);
    padding: var(--spacing-md);
    animation: slideDown 0.3s ease;
}

.alert-banner.hidden {
    display: none;
}

.alert-content {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    color: white;
    font-weight: 500;
}

.alert-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ========== Main Content ========== */
.main-content {
    flex: 1;
    padding: var(--spacing-md);
    padding-left: calc(var(--spacing-md) + var(--safe-left));
    padding-right: calc(var(--spacing-md) + var(--safe-right));
}

.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ========== Sensor Cards ========== */
.sensor-grid {
    display: grid;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.sensor-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    position: relative;
    overflow: hidden;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.sensor-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--color-accent);
}

.sensor-card.alert-cold::before {
    background: var(--color-cold);
}

.sensor-card.alert-hot::before {
    background: var(--color-hot);
}

.sensor-card:active {
    transform: scale(0.98);
}

.sensor-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-md);
}

.sensor-name {
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.sensor-location {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sensor-icon {
    width: 40px;
    height: 40px;
    background: var(--color-bg-elevated);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sensor-icon svg {
    width: 24px;
    height: 24px;
    color: var(--color-accent);
}

.sensor-temp {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: var(--spacing-sm);
}

.sensor-temp .unit {
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--color-text-secondary);
}

.sensor-card.alert-cold .sensor-temp {
    color: var(--color-cold);
}

.sensor-card.alert-hot .sensor-temp {
    color: var(--color-hot);
}

.sensor-humidity {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

.sensor-humidity svg {
    width: 16px;
    height: 16px;
}

.sensor-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: var(--spacing-sm);
}

/* ========== Differential Card ========== */
.differential-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.differential-card h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-md);
    text-align: center;
}

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

.floor-temp {
    text-align: center;
}

.floor-label {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-xs);
}

.floor-value {
    font-size: 1.5rem;
    font-weight: 600;
}

.differential-indicator {
    text-align: center;
    padding: var(--spacing-md);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-md);
}

.diff-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
}

.diff-value.positive {
    color: var(--color-hot);
}

.diff-value.negative {
    color: var(--color-cold);
}

.diff-label {
    font-size: 0.625rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ========== Chart Cards ========== */
.quick-chart-card,
.history-chart-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 500;
}

.text-btn {
    background: none;
    border: none;
    color: var(--color-accent);
    font-size: 0.875rem;
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.text-btn:hover {
    background: rgba(74, 144, 217, 0.1);
}

.chart-container {
    height: 150px;
    position: relative;
}

.chart-container.large {
    height: 250px;
}

/* ========== History View ========== */
.history-controls {
    margin-bottom: var(--spacing-lg);
}

.time-range-selector {
    display: flex;
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    padding: var(--spacing-xs);
    gap: var(--spacing-xs);
}

.range-btn {
    flex: 1;
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

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

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--spacing-md);
}

.stat-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
}

.stat-card h4 {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-xs);
}

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

.stat-label {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    gap: var(--spacing-md);
    margin-top: var(--spacing-sm);
}

.stat-row > div {
    text-align: center;
}

/* Refresh button spinning animation */
.icon-btn.spinning svg {
    animation: spin 1s linear infinite;
}

/* ========== Settings View ========== */
.settings-section {
    margin-bottom: var(--spacing-xl);
}

.settings-section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
}

.settings-description {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-lg);
}

.threshold-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.threshold-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
}

.threshold-card h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: var(--spacing-xs);
}

.threshold-card .location {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-md);
}

.threshold-row {
    display: flex;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.threshold-input {
    flex: 1;
}

.threshold-input label {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-xs);
}

.threshold-input input {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-bg-elevated);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    font-size: 1rem;
    transition: border-color var(--transition-fast);
}

.threshold-input input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-sm);
}

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

.setting-label {
    font-weight: 500;
}

.setting-description {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin: 0;
}

.setting-select {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-bg-elevated);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-bg-elevated);
    transition: var(--transition-fast);
    border-radius: 28px;
}

.toggle-slider::before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition-fast);
    border-radius: 50%;
}

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

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

/* About Section */
.about-info {
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.about-info p {
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-xs);
}

.about-info p:last-child {
    margin-bottom: 0;
}

.primary-btn {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    transition: background var(--transition-fast);
}

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

.primary-btn.hidden {
    display: none;
}

.primary-btn svg {
    width: 20px;
    height: 20px;
}

/* ========== Bottom Navigation ========== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(70px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-bg-elevated);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.625rem;
    font-weight: 500;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.nav-btn svg {
    width: 24px;
    height: 24px;
}

.nav-btn.active {
    color: var(--color-accent);
}

.nav-btn:hover {
    color: var(--color-text-secondary);
}

/* ========== Loading Overlay ========== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 26, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity var(--transition-normal);
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--color-bg-elevated);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: calc(90px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-bg-elevated);
    color: var(--color-text-primary);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    animation: toastIn 0.3s ease;
}

.toast.hidden {
    display: none;
}

.toast.success {
    background: var(--color-success);
    color: #0f0f1a;
}

.toast.error {
    background: var(--color-danger);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ========== Responsive Adjustments ========== */
@media (min-width: 768px) {
    .sensor-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .main-content {
        max-width: 800px;
        margin: 0 auto;
    }

    .chart-container.large {
        height: 300px;
    }
}

@media (min-width: 1024px) {
    .sensor-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .main-content {
        max-width: 1000px;
    }

    .bottom-nav {
        position: relative;
        height: auto;
        padding: var(--spacing-md);
        border-top: none;
        background: transparent;
        justify-content: center;
        gap: var(--spacing-xl);
    }

    #app {
        padding-bottom: 0;
    }
}

/* ========== Dark Mode Preference (already dark, but for system preference) ========== */
@media (prefers-color-scheme: light) {
    /* Keep dark theme regardless of system preference for this app */
}

/* ========== Reduced Motion ========== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========== Sign-in gate ========== */
.hidden {
    display: none !important;
}

.signin-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-primary);
    padding: var(--spacing-lg, 24px);
}

.signin-card {
    background: var(--color-bg-card);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: min(90vw, 380px);
    text-align: center;
    box-shadow: 0 10px 30px rgb(0 0 0 / 0.4);
}

.signin-card h1 {
    margin: 0 0 0.5rem;
    font-size: 1.4rem;
    color: var(--color-text-primary);
}

.signin-sub {
    color: var(--color-text-secondary);
    margin: 0 0 1.5rem;
    font-size: 0.9rem;
}

.signin-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    justify-content: center;
    width: 100%;
    padding: 0.7rem 1rem;
    border-radius: 999px;
    border: none;
    background: #fff;
    color: #1f1f1f;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.15s;
}

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