/* DeviceFree — Universal Smart Device Control */

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: #1a2035;
    --bg-card-hover: #1f2847;
    --bg-card-active: #162040;
    --text-primary: #f0f4ff;
    --text-secondary: #8892b0;
    --text-muted: #5a6485;
    --accent: #22d3ee;
    --accent-dim: rgba(34, 211, 238, 0.15);
    --accent-glow: rgba(34, 211, 238, 0.3);
    --green: #34d399;
    --green-dim: rgba(52, 211, 153, 0.15);
    --amber: #fbbf24;
    --amber-dim: rgba(251, 191, 36, 0.15);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.15);
    --purple: #a78bfa;
    --purple-dim: rgba(167, 139, 250, 0.15);
    --orange: #fb923c;
    --border: rgba(255, 255, 255, 0.06);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-pill: 50px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.app {
    width: 100%;
    max-width: 420px;
    position: relative;
    padding-bottom: 80px;
}

/* Status Bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.status-icons {
    display: flex;
    gap: 6px;
    font-size: 12px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0 16px;
}

.header-left h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent), #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.connection-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--green);
    background: var(--green-dim);
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    margin-top: 2px;
}

.pulse {
    width: 6px;
    height: 6px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); }
    50% { opacity: 0.8; box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
}

.icon-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
    background: var(--accent-dim);
}

/* Quick Stats */
.quick-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 22px;
    font-weight: 800;
    color: var(--text-primary);
}

.stat:nth-child(3) .stat-number,
.stat:nth-child(4) .stat-number {
    color: var(--green);
}

.stat-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Scene Bar */
.scene-bar {
    display: flex;
    gap: 8px;
    padding-bottom: 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.scene-bar::-webkit-scrollbar { display: none; }

.scene-pill {
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.scene-pill:hover { border-color: var(--accent-dim); }

.scene-pill.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* Room Tabs */
.room-tabs {
    display: flex;
    gap: 4px;
    padding-bottom: 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.room-tabs::-webkit-scrollbar { display: none; }

.room-tab {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.room-tab:hover { color: var(--text-secondary); }

.room-tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Device Grid */
.device-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

.device-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: transparent;
    transition: background 0.3s;
}

.device-card:hover {
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.device-card.on {
    background: var(--bg-card-active);
    border-color: rgba(34, 211, 238, 0.2);
}

.device-card.on::before {
    background: linear-gradient(90deg, var(--accent), var(--purple));
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.device-icon {
    font-size: 28px;
    filter: grayscale(0.3);
    transition: filter 0.3s;
}

.device-card.on .device-icon {
    filter: grayscale(0) drop-shadow(0 0 8px rgba(34, 211, 238, 0.5));
}

/* Toggle Switch */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--text-muted);
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle.on {
    background: var(--accent);
}

.toggle.on::after {
    transform: translateX(20px);
}

.device-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.device-status {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.device-status .dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-muted);
}

.device-card.on .device-status .dot {
    background: var(--green);
}

.device-card.on .device-status {
    color: var(--text-secondary);
}

.device-protocol {
    font-size: 9px;
    font-weight: 700;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 8px;
    display: inline-block;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-width: 420px;
    padding: 24px;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 85vh;
    overflow-y: auto;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}

.modal-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-icon {
    font-size: 36px;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 700;
}

.modal-brand {
    font-size: 12px;
    color: var(--text-muted);
}

.modal-close {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modal Controls */
.control-group {
    margin-bottom: 20px;
}

.control-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-value {
    color: var(--accent);
    font-size: 13px;
    text-transform: none;
    letter-spacing: 0;
}

/* Slider */
.slider-track {
    width: 100%;
    height: 40px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.slider-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-dim), var(--accent));
    border-radius: var(--radius-sm);
    transition: width 0.15s;
    position: relative;
}

.slider-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 24px;
    background: white;
    border-radius: 2px;
}

/* Color Temp */
.color-temp-track {
    width: 100%;
    height: 40px;
    background: linear-gradient(90deg, #ff9329, #fff5e6, #a5c8ff);
    border-radius: var(--radius-sm);
    position: relative;
    cursor: pointer;
}

.color-temp-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 28px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: left 0.15s;
}

/* Color Picker */
.color-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}

.color-dot {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.color-dot:hover {
    transform: scale(1.15);
}

.color-dot.selected {
    border-color: white;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
}

/* Power Toggle */
.power-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.power-label {
    font-size: 16px;
    font-weight: 700;
}

.power-toggle {
    width: 56px;
    height: 30px;
}

.power-toggle::after {
    width: 26px;
    height: 26px;
}

.power-toggle.on::after {
    transform: translateX(26px);
}

/* Modal Footer */
.modal-footer {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

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

.local-badge {
    font-size: 11px;
    color: var(--green);
    font-weight: 600;
}

.latency {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
}

/* Sensor Values */
.sensor-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.sensor-value-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}

.sensor-big-number {
    font-size: 32px;
    font-weight: 800;
    color: var(--text-primary);
}

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

.sensor-type {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}

/* Plug controls */
.plug-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.plug-stat {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    text-align: center;
}

.plug-stat-value {
    font-size: 20px;
    font-weight: 800;
}

.plug-stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Scan Modal */
.scan-modal {
    text-align: center;
    border-radius: 24px;
    max-width: 360px;
    margin: auto;
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#scanOverlay.active .scan-modal {
    transform: scale(1);
    opacity: 1;
}

.scan-animation {
    margin-bottom: 20px;
}

.radar {
    width: 160px;
    height: 160px;
    border-radius: 50%;
    position: relative;
    margin: 0 auto;
    background: radial-gradient(circle, var(--accent-dim), transparent 70%);
}

.radar-ring {
    position: absolute;
    border: 1px solid var(--accent-dim);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.r1 { width: 50px; height: 50px; }
.r2 { width: 100px; height: 100px; }
.r3 { width: 150px; height: 150px; }

.radar-sweep {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent));
    transform-origin: left center;
    animation: sweep 2s linear infinite;
}

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

.radar-dot {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0;
    box-shadow: 0 0 8px var(--accent);
    transition: opacity 0.3s;
}

#dot1 { top: 30%; left: 65%; }
#dot2 { top: 60%; left: 25%; }
#dot3 { top: 45%; left: 75%; }

.radar-dot.found {
    opacity: 1;
    animation: dotPulse 1.5s ease infinite;
}

@keyframes dotPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.4); }
}

.scan-status {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 8px;
}

.scan-found {
    margin-top: 16px;
    text-align: left;
}

.scan-found-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 13px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.scan-found-icon {
    font-size: 18px;
}

.scan-found-name {
    font-weight: 600;
}

.scan-found-protocol {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: auto;
    text-transform: uppercase;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 16px;
    transition: opacity 0.2s;
}

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

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 420px;
    display: flex;
    justify-content: space-around;
    padding: 8px 0 20px;
    background: linear-gradient(to top, var(--bg-primary) 80%, transparent);
    backdrop-filter: blur(20px);
    z-index: 50;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    padding: 4px 12px;
    transition: color 0.2s;
}

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

/* Responsive */
@media (max-width: 420px) {
    body { padding: 0; }
    .app { border-radius: 0; }
    .app-header, .quick-stats, .scene-bar, .room-tabs, .device-grid {
        padding-left: 16px;
        padding-right: 16px;
    }
}
