/* ==================== Material Design 3 - Dark Theme ==================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* M3 Color Tokens - Dark */
    --md-sys-color-primary: #8ECAFF;
    --md-sys-color-on-primary: #00344D;
    --md-sys-color-primary-container: #004C6E;
    --md-sys-color-on-primary-container: #C8E6FF;
    
    --md-sys-color-secondary: #B6C9D8;
    --md-sys-color-on-secondary: #21333E;
    --md-sys-color-secondary-container: #374955;
    --md-sys-color-on-secondary-container: #D2E5F4;
    
    --md-sys-color-tertiary: #CDBFE7;
    --md-sys-color-on-tertiary: #342F4A;
    --md-sys-color-tertiary-container: #4B4562;
    --md-sys-color-on-tertiary-container: #E9DCFF;
    
    --md-sys-color-error: #FFB4AB;
    --md-sys-color-error-container: #93000A;
    --md-sys-color-on-error-container: #FFDAD6;
    
    --md-sys-color-surface: #111418;
    --md-sys-color-on-surface: #E1E2E6;
    --md-sys-color-on-surface-variant: #C1C7CE;
    --md-sys-color-surface-container-lowest: #0B0E11;
    --md-sys-color-surface-container-low: #191C20;
    --md-sys-color-surface-container: #1D2024;
    --md-sys-color-surface-container-high: #272A2F;
    --md-sys-color-surface-container-highest: #32353A;
    --md-sys-color-outline: #8B9198;
    --md-sys-color-outline-variant: #41484D;
    
    /* Success colors */
    --md-sys-color-success: #7FD998;
    --md-sys-color-on-success: #003919;
    --md-sys-color-success-container: #005226;
    
    /* State layers */
    --md-sys-state-hover: 0.08;
    --md-sys-state-pressed: 0.12;
    
    /* Elevation */
    --md-sys-elevation-1: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
    --md-sys-elevation-2: 0 1px 2px rgba(0,0,0,0.3), 0 2px 6px 2px rgba(0,0,0,0.15);
    --md-sys-elevation-3: 0 4px 8px 3px rgba(0,0,0,0.15), 0 1px 3px rgba(0,0,0,0.3);
    
    /* Motion */
    --md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
    --md-sys-motion-duration-short: 150ms;
    --md-sys-motion-duration-medium: 250ms;
    --md-sys-motion-duration-long: 400ms;
    
    /* Shape */
    --md-sys-shape-corner-small: 8px;
    --md-sys-shape-corner-medium: 12px;
    --md-sys-shape-corner-large: 16px;
    --md-sys-shape-corner-extra-large: 28px;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Google Sans', 'Roboto', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    -webkit-font-smoothing: antialiased;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==================== TOP APP BAR ==================== */

.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--md-sys-color-surface);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.top-bar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    padding: 0 16px;
    max-width: 1400px;
    margin: 0 auto;
}

.top-bar-start {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    font-size: 28px;
    color: var(--md-sys-color-primary);
}

.brand-name {
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -0.25px;
}

.top-bar-end {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ==================== USER & STATUS BADGES ==================== */

.user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px 6px 8px;
    background: var(--md-sys-color-surface-container-high);
    border-radius: 20px;
    font-size: 13px;
    color: var(--md-sys-color-on-surface);
}

.user-pill .material-icons {
    font-size: 20px;
    color: var(--md-sys-color-primary);
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.1px;
}

.status-pill.live {
    background: rgba(127, 217, 152, 0.16);
    color: var(--md-sys-color-success);
}

.status-pill.offline {
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface-variant);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.status-pill.live .status-dot {
    box-shadow: 0 0 6px currentColor;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ==================== BUTTONS ==================== */

.filled-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 24px;
    border: none;
    border-radius: 20px;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.1px;
    cursor: pointer;
    transition: all var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.filled-button:hover {
    box-shadow: var(--md-sys-elevation-1);
    filter: brightness(1.08);
}

.filled-button.large {
    height: 48px;
    padding: 0 32px;
    font-size: 15px;
}

.filled-button .material-icons {
    font-size: 20px;
}

.icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    transition: background var(--md-sys-motion-duration-short);
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.08);
}

.icon-button .material-icons {
    font-size: 24px;
}

/* ==================== MAIN CONTENT ==================== */

.main-content {
    flex: 1;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 16px;
}

.view.hidden {
    display: none;
}

/* ==================== LOGIN ==================== */

.login-hero {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 160px);
}

.login-card {
    text-align: center;
    padding: 48px 40px;
    border-radius: var(--md-sys-shape-corner-extra-large);
    max-width: 400px;
    width: 100%;
}

.surface-container-high {
    background: var(--md-sys-color-surface-container-high);
}

.login-icon-wrap {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    border-radius: 24px;
    background: var(--md-sys-color-primary-container);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-icon-wrap .material-icons {
    font-size: 40px;
    color: var(--md-sys-color-on-primary-container);
}

.login-card h1 {
    font-size: 28px;
    font-weight: 500;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.login-card p {
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 32px;
    font-size: 15px;
}

/* ==================== SECTION HEADER ==================== */

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 16px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-title .material-icons {
    font-size: 24px;
    color: var(--md-sys-color-primary);
}

.section-title h2 {
    font-size: 22px;
    font-weight: 500;
    letter-spacing: -0.25px;
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ==================== FILTER CHIP ==================== */

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 16px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    background: transparent;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--md-sys-motion-duration-short);
}

.filter-chip input {
    display: none;
}

.filter-chip .chip-icon {
    font-size: 18px;
}

.filter-chip:has(input:checked) {
    background: var(--md-sys-color-secondary-container);
    border-color: transparent;
    color: var(--md-sys-color-on-secondary-container);
}

.filter-chip:has(input:checked) .chip-icon {
    color: var(--md-sys-color-primary);
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: 12px;
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface-variant);
    font-size: 12px;
    font-weight: 500;
}

/* ==================== DEVICE GRID ==================== */

.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

/* ==================== DEVICE CARD ==================== */

.device-card {
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 20px;
    cursor: pointer;
    transition: all var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
    border: 1px solid transparent;
}

.device-card:hover {
    background: var(--md-sys-color-surface-container-high);
    transform: translateY(-2px);
    box-shadow: var(--md-sys-elevation-2);
}

.device-card.online {
    border-color: rgba(127, 217, 152, 0.24);
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.device-card-title h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 2px;
    color: var(--md-sys-color-on-surface);
}

.device-card-title span {
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
}

.device-status {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.device-status.online {
    background: rgba(127, 217, 152, 0.16);
    color: var(--md-sys-color-success);
}

.device-status.offline {
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface-variant);
}

.device-status .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ==================== VIRTUAL VALUES DISPLAY ==================== */

.virtual-values {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.v-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 12px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 500;
}

.v-chip .material-icons {
    font-size: 16px;
}

.v-chip.on {
    background: rgba(127, 217, 152, 0.16);
    color: var(--md-sys-color-success);
}

.v-chip.off {
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface-variant);
}

.v-chip.number {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.v-chip.temp {
    background: rgba(255, 138, 101, 0.16);
    color: #FF8A65;
}

.v-chip.humidity {
    background: rgba(100, 181, 246, 0.16);
    color: #64B5F6;
}

.v-chip.text {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.v-chip.enum {
    background: var(--md-sys-color-tertiary-container);
    color: var(--md-sys-color-on-tertiary-container);
}

.device-card-meta {
    display: flex;
    gap: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    font-size: 12px;
    color: var(--md-sys-color-on-surface-variant);
}

.device-card-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.device-card-meta .material-icons {
    font-size: 16px;
    color: var(--md-sys-color-outline);
}

/* ==================== MODAL ==================== */

.modal-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 200;
    opacity: 1;
    transition: opacity var(--md-sys-motion-duration-medium);
}

.modal-scrim.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    border-radius: var(--md-sys-shape-corner-extra-large);
    display: flex;
    flex-direction: column;
    transform: scale(1);
    transition: transform var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.modal-scrim.hidden .modal {
    transform: scale(0.95);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 24px 24px 16px;
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 16px;
}

.modal-title .material-icons {
    font-size: 32px;
    color: var(--md-sys-color-primary);
}

.modal-title h2 {
    font-size: 20px;
    font-weight: 500;
}

.modal-subtitle {
    font-size: 13px;
    color: var(--md-sys-color-on-surface-variant);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px 24px;
}

/* ==================== COMPONENT GROUPS IN MODAL ==================== */

.component-group {
    margin-bottom: 16px;
    background: var(--md-sys-color-surface-container);
    border-radius: var(--md-sys-shape-corner-medium);
    overflow: hidden;
}

.component-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--md-sys-color-surface-container-highest);
    font-size: 13px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
}

.component-group-header .material-icons {
    font-size: 20px;
    color: var(--md-sys-color-primary);
}

.component-list {
    padding: 8px;
}

.component-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--md-sys-shape-corner-small);
}

.component-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.component-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.component-icon .material-icons {
    font-size: 22px;
}

.component-icon.boolean,
.component-icon.switch {
    background: rgba(127, 217, 152, 0.12);
    color: var(--md-sys-color-success);
}

.component-icon.number,
.component-icon.voltmeter {
    background: rgba(142, 202, 255, 0.12);
    color: var(--md-sys-color-primary);
}

.component-icon.temperature {
    background: rgba(255, 138, 101, 0.12);
    color: #FF8A65;
}

.component-icon.humidity {
    background: rgba(100, 181, 246, 0.12);
    color: #64B5F6;
}

.component-icon.text {
    background: rgba(182, 201, 216, 0.12);
    color: var(--md-sys-color-secondary);
}

.component-icon.enum {
    background: rgba(205, 191, 231, 0.12);
    color: var(--md-sys-color-tertiary);
}

.component-icon.input {
    background: rgba(255, 213, 79, 0.12);
    color: #FFD54F;
}

.component-info {
    flex: 1;
    min-width: 0;
}

.component-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
}

.component-id {
    font-size: 11px;
    color: var(--md-sys-color-outline);
    font-family: 'Roboto Mono', monospace;
}

.component-value {
    padding: 6px 14px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 600;
}

.component-value.on {
    background: rgba(127, 217, 152, 0.2);
    color: var(--md-sys-color-success);
}

.component-value.off {
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface-variant);
}

.component-value.number {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.component-value.temp {
    background: rgba(255, 138, 101, 0.2);
    color: #FF8A65;
}

.component-value.humidity {
    background: rgba(100, 181, 246, 0.2);
    color: #64B5F6;
}

.component-value.text {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.component-value.enum {
    background: var(--md-sys-color-tertiary-container);
    color: var(--md-sys-color-on-tertiary-container);
}

/* ==================== EMPTY STATE ==================== */

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 64px 24px;
    color: var(--md-sys-color-on-surface-variant);
}

.empty-state .material-icons {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 15px;
}

/* ==================== SNACKBAR ==================== */

.snackbar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 288px;
    max-width: 568px;
    padding: 14px 16px;
    background: var(--md-sys-color-surface-container-highest);
    color: var(--md-sys-color-on-surface);
    border-radius: var(--md-sys-shape-corner-small);
    box-shadow: var(--md-sys-elevation-3);
    font-size: 14px;
    z-index: 300;
    opacity: 0;
    transition: all var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.snackbar.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.snackbar.error {
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}

.snackbar.success {
    background: var(--md-sys-color-success-container);
    color: var(--md-sys-color-success);
}

.snackbar-icon {
    font-size: 20px;
}

/* ==================== SCROLLBAR ==================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--md-sys-color-outline-variant);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--md-sys-color-outline);
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 600px) {
    .device-grid {
        grid-template-columns: 1fr;
    }
    
    .top-bar-row {
        height: 56px;
    }
    
    .user-pill span:not(.material-icons) {
        display: none;
    }
    
    .filter-chip .chip-label {
        display: none;
    }
    
    .modal {
        margin: 0;
        max-height: 100vh;
        border-radius: var(--md-sys-shape-corner-large) var(--md-sys-shape-corner-large) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: none;
    }
}
