/* ===================================
   Pyr User Dashboard
   Warm Tech Monitor Aesthetic
   =================================== */

/* Fonts — IBM Plex Sans for UI, JetBrains Mono for data readouts */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ===================================
   Design Tokens
   =================================== */

:root {
    /* Surfaces */
    --pyr-bg: #F0EAE0;
    --pyr-surface: #FFFFFF;
    --pyr-surface-raised: #FFFFFF;
    --pyr-surface-muted: #F5F0EA;

    /* Text */
    --pyr-text: #2C1810;
    --pyr-text-secondary: #7A6555;
    --pyr-text-muted: #A89888;

    /* Accents */
    --pyr-amber: #C8956C;
    --pyr-amber-soft: rgba(200, 149, 108, 0.12);
    --pyr-tint: #C4956A;

    /* Status */
    --pyr-green: #34A853;
    --pyr-green-bg: rgba(52, 168, 83, 0.08);
    --pyr-red: #D93025;
    --pyr-red-bg: rgba(217, 48, 37, 0.08);
    --pyr-orange: #E8710A;
    --pyr-orange-bg: rgba(232, 113, 10, 0.08);
    --fire-red: #D4442A;
    --fire-red-light: #FDECEA;

    /* Borders & Depth */
    --pyr-border: rgba(44, 24, 16, 0.1);
    --pyr-border-strong: rgba(44, 24, 16, 0.15);
    --pyr-shadow-sm: 0 1px 3px rgba(44, 24, 16, 0.08), 0 1px 2px rgba(44, 24, 16, 0.12);
    --pyr-shadow-md: 0 4px 12px rgba(44, 24, 16, 0.1), 0 2px 4px rgba(44, 24, 16, 0.12);
    --pyr-shadow-lg: 0 12px 32px rgba(44, 24, 16, 0.12), 0 4px 8px rgba(44, 24, 16, 0.1);

    /* Spacing */
    --pyr-space-xs: 4px;
    --pyr-space-sm: 8px;
    --pyr-space-md: 16px;
    --pyr-space-lg: 24px;
    --pyr-space-xl: 32px;
    --pyr-space-2xl: 48px;

    /* Radius */
    --pyr-radius-sm: 8px;
    --pyr-radius-md: 12px;
    --pyr-radius-lg: 16px;
    --pyr-radius-pill: 100px;

    /* Fonts */
    --pyr-font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --pyr-font-mono: 'JetBrains Mono', 'IBM Plex Mono', monospace;

    /* Transitions */
    --pyr-ease: cubic-bezier(0.4, 0, 0.2, 1);

    /* Backward compat aliases for CSS used by admin-portal.css overrides */
    --vera-background: var(--pyr-bg);
    --vera-surface: var(--pyr-surface);
    --vera-text-primary: var(--pyr-text);
    --vera-text-secondary: var(--pyr-text-secondary);
    --vera-text-light: var(--pyr-text-muted);
    --vera-tint: var(--pyr-tint);
    --vera-border: var(--pyr-border-strong);
    --vera-icon: var(--pyr-text-secondary);
    --vera-button-primary: var(--pyr-tint);
    --vera-button-text: #FFFFFF;
    --vera-error: var(--pyr-red);
    --vera-success: var(--pyr-green);
    --vera-warning: var(--pyr-orange);
    --vera-active: var(--pyr-green);
    --vera-inactive: var(--pyr-red);
    --vera-font-family: var(--pyr-font);
    --vera-font-mono: var(--pyr-font-mono);
    --vera-transition-fast: 150ms var(--pyr-ease);
    --vera-transition-normal: 250ms var(--pyr-ease);
    --vera-radius-md: var(--pyr-radius-sm);
    --vera-radius-lg: var(--pyr-radius-md);
    --vera-radius-xl: var(--pyr-radius-lg);
    --vera-radius-pill: var(--pyr-radius-pill);
    --vera-radius-round: 50%;
    --vera-spacing-xs: var(--pyr-space-xs);
    --vera-spacing-sm: var(--pyr-space-sm);
    --vera-spacing-base: 12px;
    --vera-spacing-md: var(--pyr-space-md);
    --vera-spacing-lg: 20px;
    --vera-spacing-xl: var(--pyr-space-lg);
    --vera-spacing-2xl: var(--pyr-space-xl);
    --vera-spacing-3xl: var(--pyr-space-2xl);
    --vera-shadow-subtle: var(--pyr-shadow-sm);
    --vera-shadow-medium: var(--pyr-shadow-md);
    --vera-shadow-strong: var(--pyr-shadow-lg);
    --vera-divider: var(--pyr-border-strong);
    --vera-accent: var(--pyr-amber);
    --vera-notification: var(--pyr-orange);

    /* Chart Colors */
    --chart-line-color: var(--pyr-green);
    --chart-area-color: rgba(52, 168, 83, 0.1);
    --chart-active-tooltip: rgba(52, 168, 83, 0.95);
    --chart-axis-color: var(--pyr-border-strong);
    --chart-active-line: rgba(100, 100, 100, 0.3);
}

/* ===================================
   Base Layout
   =================================== */

.dashboard,
.login-container,
.modal-content {
    font-family: var(--pyr-font);
}

.dashboard {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--pyr-bg);
}

/* ===================================
   Toolbar Header — minimal, functional
   =================================== */

.dashboard-header {
    background: var(--pyr-bg);
    padding: 0 var(--pyr-space-lg);
    border-bottom: none;
    box-shadow: none;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--pyr-space-sm);
    flex-wrap: wrap;
    padding: var(--pyr-space-md) 0;
    border-bottom: 1px solid var(--pyr-border);
}

.header-content h1 {
    font-family: var(--pyr-font);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--pyr-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-sm);
}

.dashboard-main {
    padding: var(--pyr-space-lg);
}

/* ===================================
   Device Tiles Grid
   =================================== */

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--pyr-space-md);
    padding: 0;
}

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

/* ===================================
   Device Tile — monitoring card
   =================================== */

.device-tile {
    background: var(--pyr-surface);
    border: 1px solid var(--pyr-border);
    border-radius: var(--pyr-radius-md);
    padding: 0;
    box-shadow: var(--pyr-shadow-sm);
    cursor: pointer;
    transition: box-shadow 250ms var(--pyr-ease), transform 250ms var(--pyr-ease), border-color 250ms var(--pyr-ease);
    overflow: hidden;
}

.device-tile:hover {
    box-shadow: var(--pyr-shadow-md);
    border-color: var(--pyr-border-strong);
    transform: translateY(-2px);
}

.device-tile:active {
    transform: translateY(0);
    opacity: 0.95;
}

.device-tile-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: var(--pyr-space-md) var(--pyr-space-md) 0;
    margin-bottom: 0;
}

.device-tile-info {
    flex: 1;
    min-width: 0;
}

.device-tile-name {
    font-family: var(--pyr-font);
    font-size: 1rem;
    font-weight: 600;
    color: var(--pyr-text);
    margin: 0 0 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-tile-id {
    font-family: var(--pyr-font-mono);
    font-size: 0.6875rem;
    font-weight: 400;
    color: var(--pyr-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-tile-status {
    flex-shrink: 0;
    margin-left: var(--pyr-space-sm);
}

/* Temperature Readout — the hero element */
.device-tile-temp {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-md);
    padding: var(--pyr-space-md);
    margin: var(--pyr-space-sm) var(--pyr-space-md);
    background: var(--pyr-surface-muted);
    border-radius: var(--pyr-radius-sm);
}

.device-tile-temp-icon {
    flex-shrink: 0;
    color: var(--pyr-amber);
    opacity: 0.7;
}

.device-tile-temp-content {
    flex: 1;
}

.device-tile-temp-value {
    font-family: var(--pyr-font-mono);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--pyr-text);
    line-height: 1;
    margin-bottom: 2px;
    letter-spacing: -0.02em;
}

.device-tile-temp-label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--pyr-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.device-tile-no-data {
    padding: var(--pyr-space-md);
    text-align: center;
    color: var(--pyr-text-muted);
    font-size: 0.875rem;
    background: var(--pyr-surface-muted);
    border-radius: var(--pyr-radius-sm);
    margin: var(--pyr-space-sm) var(--pyr-space-md);
}

/* Tile Footer */
.device-tile-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--pyr-text-muted);
    padding: var(--pyr-space-sm) var(--pyr-space-md) var(--pyr-space-md);
}

.device-tile-last-seen {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-xs);
}

/* ===================================
   Gateway Card — Mast with nested sensors
   =================================== */

.gateway-card {
    grid-column: 1 / -1;
    background: var(--pyr-surface);
    border: 1px solid var(--pyr-border);
    border-radius: var(--pyr-radius-md);
    box-shadow: var(--pyr-shadow-sm);
    overflow: hidden;
}

.gateway-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--pyr-space-md) var(--pyr-space-lg);
    cursor: pointer;
    transition: background 200ms var(--pyr-ease);
    border-bottom: 1px solid var(--pyr-border);
}

.gateway-card-header:hover {
    background: var(--pyr-surface-muted);
}

.gateway-card-info {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-md);
    min-width: 0;
}

.gateway-card-icon {
    flex-shrink: 0;
    color: var(--pyr-amber);
    opacity: 0.8;
}

.gateway-card-name {
    font-family: var(--pyr-font);
    font-size: 1rem;
    font-weight: 600;
    color: var(--pyr-text);
    margin: 0 0 2px;
}

.gateway-card-id {
    font-family: var(--pyr-font-mono);
    font-size: 0.6875rem;
    color: var(--pyr-text-muted);
}

.gateway-card-status {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-sm);
    flex-shrink: 0;
}

.gateway-card-last-seen {
    font-size: 0.75rem;
    color: var(--pyr-text-muted);
}

.gateway-card-chevron {
    color: var(--pyr-text-muted);
    opacity: 0.5;
}

.gateway-card-body {
    padding: var(--pyr-space-md) var(--pyr-space-lg);
    background: var(--pyr-surface-muted);
}

.gateway-card-units {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--pyr-space-sm);
}

.gateway-card-empty {
    text-align: center;
    color: var(--pyr-text-muted);
    font-size: 0.875rem;
    padding: var(--pyr-space-md) 0;
}

/* Compact Tile — nested sensor readout */

.compact-tile {
    background: var(--pyr-surface);
    border: 1px solid var(--pyr-border);
    border-radius: var(--pyr-radius-sm);
    padding: var(--pyr-space-sm) var(--pyr-space-md);
    cursor: pointer;
    transition: box-shadow 200ms var(--pyr-ease), border-color 200ms var(--pyr-ease);
}

.compact-tile:hover {
    box-shadow: var(--pyr-shadow-sm);
    border-color: var(--pyr-border-strong);
}

.compact-tile-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.compact-tile-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.compact-tile-status-dot.online {
    background: var(--pyr-green);
}

.compact-tile-status-dot.offline {
    background: var(--pyr-red);
}

.compact-tile-status-dot.warning {
    background: var(--pyr-orange);
}

.compact-tile-name {
    font-family: var(--pyr-font);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--pyr-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compact-tile-temp {
    font-family: var(--pyr-font-mono);
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--pyr-text);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.compact-tile-temp.no-data {
    color: var(--pyr-text-muted);
    font-size: 1rem;
}

.compact-tile-footer {
    font-size: 0.6875rem;
    color: var(--pyr-text-muted);
    margin-top: 2px;
}

@media (max-width: 768px) {
    .gateway-card-header {
        padding: var(--pyr-space-md);
    }
    .gateway-card-body {
        padding: var(--pyr-space-sm) var(--pyr-space-md);
    }
    .gateway-card-units {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    .gateway-card-last-seen {
        display: none;
    }
}

/* ===================================
   Status Badges — refined indicators
   =================================== */

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--pyr-radius-pill);
    font-family: var(--pyr-font);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-badge.status-success {
    background: var(--pyr-green-bg);
    color: var(--pyr-green);
}

.status-badge.status-error {
    background: var(--pyr-red-bg);
    color: var(--pyr-red);
}

.status-badge.status-warning {
    background: var(--pyr-orange-bg);
    color: var(--pyr-orange);
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-badge.status-success::before {
    background: var(--pyr-green);
}

.status-badge.status-error::before {
    background: var(--pyr-red);
}

.status-badge.status-warning::before {
    background: var(--pyr-orange);
}

/* ===================================
   Buttons
   =================================== */

.btn-primary {
    background: var(--pyr-tint);
    color: #fff;
    font-family: var(--pyr-font);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 10px 20px;
    border: none;
    border-radius: var(--pyr-radius-sm);
    cursor: pointer;
    transition: all 200ms var(--pyr-ease);
    width: 100%;
    text-align: center;
}

.btn-primary:hover {
    opacity: 0.9;
    box-shadow: var(--pyr-shadow-sm);
}

.btn-primary:active { opacity: 0.8; }

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--pyr-surface);
    color: var(--pyr-text-secondary);
    font-family: var(--pyr-font);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 10px 20px;
    border: 1px solid var(--pyr-border-strong);
    border-radius: var(--pyr-radius-sm);
    cursor: pointer;
    transition: all 200ms var(--pyr-ease);
}

.btn-secondary:hover {
    background: var(--pyr-surface-muted);
    border-color: var(--pyr-border-strong);
}

.btn-secondary:active { opacity: 0.8; }

.btn-icon {
    background: none;
    border: none;
    padding: var(--pyr-space-sm);
    color: var(--pyr-text-muted);
    cursor: pointer;
    border-radius: var(--pyr-radius-sm);
    transition: all 150ms var(--pyr-ease);
}

.btn-icon:hover {
    background: var(--pyr-surface-muted);
    color: var(--pyr-text-secondary);
}

.btn-icon:active { opacity: 0.7; }

.btn-add-device {
    width: auto !important;
    padding: 8px 16px !important;
    white-space: nowrap;
    border-radius: var(--pyr-radius-sm) !important;
}

@media (max-width: 768px) {
    .btn-add-device {
        padding: 8px 12px !important;
        font-size: 0.8125rem;
    }
    .btn-add-device svg { display: none; }
}

/* ===================================
   Device Detail Page
   =================================== */

.device-detail-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--pyr-space-lg);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--pyr-space-sm);
    color: var(--pyr-text-muted);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: color 150ms var(--pyr-ease);
}

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

.device-header {
    margin-bottom: var(--pyr-space-lg);
}

.device-info h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--pyr-text);
    margin: 0 0 var(--pyr-space-sm);
}

.device-meta {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-sm);
    flex-wrap: wrap;
}

.device-id-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--pyr-surface-muted);
    color: var(--pyr-text-muted);
    font-family: var(--pyr-font-mono);
    font-size: 0.6875rem;
    border-radius: var(--pyr-radius-sm);
    border: 1px solid var(--pyr-border);
}

.last-seen {
    font-size: 0.8125rem;
    color: var(--pyr-text-muted);
}

/* Current Temperature — hero card */
.current-temp-section {
    margin-bottom: var(--pyr-space-lg);
}

.current-temp-card {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-lg);
    padding: var(--pyr-space-lg);
    background: var(--pyr-surface);
    border: 1px solid var(--pyr-border);
    border-radius: var(--pyr-radius-md);
    box-shadow: var(--pyr-shadow-sm);
}

.current-temp-icon {
    flex-shrink: 0;
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--pyr-amber-soft);
    border-radius: 50%;
    color: var(--pyr-amber);
}

.current-temp-content { flex: 1; }

.current-temp-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--pyr-text-muted);
    margin-bottom: var(--pyr-space-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.current-temp-value {
    font-family: var(--pyr-font-mono);
    font-size: 3rem;
    font-weight: 600;
    color: var(--pyr-text);
    line-height: 1;
    margin-bottom: var(--pyr-space-xs);
    letter-spacing: -0.02em;
}

.current-temp-time {
    font-size: 0.8125rem;
    color: var(--pyr-text-muted);
}

@media (max-width: 768px) {
    .current-temp-card {
        flex-direction: column;
        text-align: center;
        gap: var(--pyr-space-md);
    }
}

/* Dashboard Section */
.dashboard-section {
    background: var(--pyr-surface);
    border: 1px solid var(--pyr-border);
    border-radius: var(--pyr-radius-md);
    padding: var(--pyr-space-md);
    margin-bottom: var(--pyr-space-md);
    box-shadow: var(--pyr-shadow-sm);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--pyr-space-md);
    flex-wrap: wrap;
    gap: var(--pyr-space-sm);
}

.section-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--pyr-text);
    margin: 0;
}

/* Time Period Selector */
.time-period-selector {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.period-btn {
    padding: 6px 12px;
    background: transparent;
    color: var(--pyr-text-muted);
    border: 1px solid var(--pyr-border-strong);
    border-radius: var(--pyr-radius-pill);
    font-family: var(--pyr-font);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 150ms var(--pyr-ease);
}

.period-btn:hover {
    background: var(--pyr-surface-muted);
    color: var(--pyr-text-secondary);
}

.period-btn.active {
    background: var(--pyr-text);
    color: #fff;
    border-color: var(--pyr-text);
}

.period-btn:active { opacity: 0.8; }

/* Chart */
.chart-container {
    position: relative;
    height: 400px;
    margin: var(--pyr-space-md) 0;
    padding: var(--pyr-space-md);
    background: var(--pyr-surface);
    border-radius: var(--pyr-radius-sm);
}

@media (max-width: 768px) {
    .chart-container { height: 300px; }
}

.chart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--pyr-space-2xl);
    gap: var(--pyr-space-md);
}

.chart-loading .spinner { width: 40px; height: 40px; }

/* Chart Stats */
.chart-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--pyr-space-sm);
    margin-top: var(--pyr-space-md);
}

.stat-item {
    padding: var(--pyr-space-md);
    background: var(--pyr-surface-muted);
    border-radius: var(--pyr-radius-sm);
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--pyr-text-muted);
    margin-bottom: var(--pyr-space-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-value {
    display: block;
    font-family: var(--pyr-font-mono);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--pyr-text);
}

@media (max-width: 768px) {
    .chart-stats { grid-template-columns: repeat(2, 1fr); }
}

/* Temperature History Controls */
.temp-history-controls {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-sm);
    flex-wrap: wrap;
}

/* Heatmap Smooth Toggle */
.heatmap-toggle {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-xs);
    font-family: var(--pyr-font);
    font-size: 0.8125rem;
    color: var(--pyr-text-muted);
    cursor: pointer;
    user-select: none;
}

.heatmap-toggle input[type="checkbox"] {
    accent-color: var(--pyr-tint);
}

/* Heatmap Container */
.heatmap-container {
    min-height: 200px;
    margin: var(--pyr-space-md) 0;
}

@media (max-width: 768px) {
    .temp-history-controls { justify-content: center; }
}

/* ===================================
   State Displays
   =================================== */

.loading-state,
.error-state,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--pyr-space-2xl);
    text-align: center;
}

.loading-state p,
.error-state p,
.empty-state p {
    color: var(--pyr-text-muted);
    margin-top: var(--pyr-space-md);
    font-size: 0.875rem;
}

.loading-state h3,
.error-state h3,
.empty-state h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--pyr-text);
    margin: var(--pyr-space-md) 0 0;
}

.spinner {
    border: 3px solid var(--pyr-border-strong);
    border-top-color: var(--pyr-tint);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    animation: spin 0.8s linear infinite;
}

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

/* ===================================
   Modal
   =================================== */

.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--pyr-space-lg);
}

.modal-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(44, 24, 16, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--pyr-surface);
    border-radius: var(--pyr-radius-lg);
    box-shadow: var(--pyr-shadow-lg);
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    z-index: 1;
}

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

.modal-header h2 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--pyr-text);
}

.modal-close {
    background: none;
    border: none;
    padding: var(--pyr-space-sm);
    cursor: pointer;
    color: var(--pyr-text-muted);
    border-radius: var(--pyr-radius-sm);
    transition: all 150ms var(--pyr-ease);
}

.modal-close:hover { background: var(--pyr-surface-muted); }

.modal-body {
    padding: var(--pyr-space-lg);
}

.modal-body p {
    font-size: 0.9375rem;
    color: var(--pyr-text);
    margin-bottom: var(--pyr-space-md);
}

.modal-loading,
.modal-error {
    text-align: center;
    padding: var(--pyr-space-lg) 0;
}

.modal-loading .spinner { margin: 0 auto var(--pyr-space-md); }
.modal-error p { color: var(--pyr-red); margin-bottom: var(--pyr-space-md); }

/* Linking Key */
.linking-key-container {
    display: flex;
    align-items: center;
    gap: var(--pyr-space-sm);
    margin: var(--pyr-space-md) 0;
    padding: var(--pyr-space-md);
    background: var(--pyr-surface-muted);
    border: 1px solid var(--pyr-border);
    border-radius: var(--pyr-radius-sm);
}

.linking-key {
    flex: 1;
    font-family: var(--pyr-font-mono);
    font-size: 0.9375rem;
    color: var(--pyr-text);
    background: var(--pyr-surface);
    padding: var(--pyr-space-sm) 12px;
    border-radius: 6px;
    word-break: break-all;
    user-select: all;
}

.linking-key-info {
    padding: var(--pyr-space-md);
    background: var(--pyr-surface-muted);
    border-radius: var(--pyr-radius-sm);
}

.linking-key-info p { font-size: 0.875rem; margin: 0 0 var(--pyr-space-xs); }
.linking-key-info p:last-child { margin-bottom: 0; }
.linking-key-info strong { font-weight: 700; }
.text-muted { color: var(--pyr-text-muted); font-size: 0.875rem; }

/* ===================================
   Login / Signup
   =================================== */

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--pyr-bg);
    padding: var(--pyr-space-lg);
}

.login-card {
    background: var(--pyr-surface);
    border-radius: var(--pyr-radius-lg);
    padding: var(--pyr-space-xl);
    box-shadow: var(--pyr-shadow-lg);
    width: 100%;
    max-width: 400px;
}

.login-header {
    margin-bottom: var(--pyr-space-lg);
    text-align: center;
    background: none;
    padding: 0;
}

.login-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--pyr-text);
    margin: 0 0 var(--pyr-space-xs);
}

.login-header p {
    font-size: 0.9375rem;
    color: var(--pyr-text-secondary);
    margin: 0;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--pyr-space-md);
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--pyr-text-secondary);
    margin-bottom: var(--pyr-space-xs);
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    font-family: var(--pyr-font);
    font-size: 0.9375rem;
    color: var(--pyr-text);
    background: var(--pyr-surface-muted);
    border: 1px solid var(--pyr-border-strong);
    border-radius: var(--pyr-radius-sm);
    transition: all 200ms var(--pyr-ease);
}

.form-group input::placeholder { color: var(--pyr-text-muted); }

.form-group input:focus {
    outline: none;
    border-color: var(--pyr-tint);
    background: var(--pyr-surface);
    box-shadow: 0 0 0 3px rgba(139, 111, 71, 0.1);
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--pyr-text-muted);
    margin-top: var(--pyr-space-xs);
}

.error-message {
    padding: 10px 14px;
    background: var(--pyr-red-bg);
    border: 1px solid rgba(217, 48, 37, 0.2);
    color: var(--pyr-red);
    border-radius: var(--pyr-radius-sm);
    font-size: 0.875rem;
    text-align: center;
}

.success-message {
    padding: 10px 14px;
    background: var(--pyr-green-bg);
    border: 1px solid rgba(52, 168, 83, 0.2);
    color: var(--pyr-green);
    border-radius: var(--pyr-radius-sm);
    font-size: 0.875rem;
    text-align: center;
}

.login-divider {
    text-align: center;
    margin: var(--pyr-space-lg) 0 var(--pyr-space-md);
    position: relative;
}

.login-divider::before {
    content: '';
    position: absolute;
    top: 50%; left: 0; right: 0;
    height: 1px;
    background: var(--pyr-border-strong);
}

.login-divider span {
    position: relative;
    display: inline-block;
    padding: 0 var(--pyr-space-md);
    background: var(--pyr-surface);
    color: var(--pyr-text-muted);
    font-size: 0.8125rem;
    z-index: 1;
}

.btn-link {
    display: block;
    width: 100% !important;
    text-align: center;
    text-decoration: none;
    box-sizing: border-box;
}

.login-card .btn-secondary { width: 100%; }

.login-footer {
    margin-top: var(--pyr-space-lg);
    text-align: center;
}

.login-footer p {
    font-size: 0.75rem;
    color: var(--pyr-text-muted);
    margin: 0;
}

.button-text,
.button-loader {
    font-family: var(--pyr-font);
}

/* ===================================
   Animations
   =================================== */

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.device-tile,
.gateway-card {
    animation: fadeInUp 0.35s var(--pyr-ease) backwards;
}

.device-tile:nth-child(1),
.gateway-card:nth-child(1) { animation-delay: 0.03s; }
.device-tile:nth-child(2),
.gateway-card:nth-child(2) { animation-delay: 0.08s; }
.device-tile:nth-child(3),
.gateway-card:nth-child(3) { animation-delay: 0.13s; }
.device-tile:nth-child(4),
.gateway-card:nth-child(4) { animation-delay: 0.18s; }
.device-tile:nth-child(5),
.gateway-card:nth-child(5) { animation-delay: 0.23s; }
.device-tile:nth-child(6),
.gateway-card:nth-child(6) { animation-delay: 0.28s; }

@media (prefers-reduced-motion: reduce) {
    .device-tile,
    .gateway-card { animation: none; }
}

/* ===================================
   Responsive
   =================================== */

@media (max-width: 768px) {
    body { min-height: 100dvh; }
    .dashboard { min-height: 100dvh; }
    .dashboard-header { padding: 0 var(--pyr-space-md); }

    .dashboard-main { padding: var(--pyr-space-md); }

    .time-period-selector { justify-content: center; }
    .period-btn { flex: 1 1 auto; min-width: 60px; }

    .device-detail-main { padding: var(--pyr-space-md); }
    .login-card { padding: var(--pyr-space-lg); }
}
