/* =====================================================
   Smart Home Hub - Glassmorphism UI
   Theme: Glass + Gradient Blue/White | Mobile-first
   ===================================================== */

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

:root {
    --bg-top: #0a2e4a;
    --bg-mid: #07334f;
    --bg-bot: #051c30;
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-bg-2: rgba(255, 255, 255, 0.13);
    --glass-border: rgba(255, 255, 255, 0.15);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --blue: #38bdf8;
    --blue-light: #7dd3fc;
    --blue-dark: #0284c7;
    --teal: #2dd4bf;
    --white: #ffffff;
    --white-70: rgba(255,255,255,0.7);
    --white-50: rgba(255,255,255,0.5);
    --white-30: rgba(255,255,255,0.3);
    --white-10: rgba(255,255,255,0.1);
    --text: #e8f4fd;
    --text-muted: rgba(255,255,255,0.5);
    --success: #4ade80;
    --danger: #f87171;
    --warning: #fbbf24;
    --radius: 20px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html, body {
    height: 100%;
    min-height: 100dvh;
}

body {
    background: linear-gradient(165deg, var(--bg-top) 0%, var(--bg-mid) 40%, var(--bg-bot) 100%);
    color: var(--text);
    font-family: inherit;
    overflow-x: hidden;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--white-30); border-radius: 99px; }

/* ---------- Glass Utilities ---------- */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow);
    transition: transform .2s, box-shadow .2s, border-color .2s;
}

.glass-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255,255,255,0.25);
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}

/* ---------- App Shell ---------- */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 16px 20px 12px;
    background: rgba(10, 46, 74, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.app-header .greeting {
    font-size: 15px;
    font-weight: 600;
    color: var(--white);
    line-height: 1.3;
}

.app-header .greeting small {
    font-size: 12px;
    font-weight: 400;
    color: var(--white-50);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    color: var(--white);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: background .15s;
}
.icon-btn:hover { background: var(--glass-bg-2); }

/* ---------- Main Content ---------- */
.app-content {
    flex: 1;
    padding: 16px 16px 100px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* ---------- Bottom Navigation ---------- */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 200;
    background: rgba(5, 28, 48, 0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--glass-border);
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    color: var(--white-50);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: color .15s;
    border: none;
    background: none;
    cursor: pointer;
    min-width: 56px;
}

.nav-item i { font-size: 20px; }

.nav-item.active { color: var(--blue-light); }
.nav-item.active i { filter: drop-shadow(0 0 6px rgba(56,189,248,0.6)); }

/* ---------- Section Headers ---------- */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 0 4px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--white);
    letter-spacing: -0.02em;
}

.section-link {
    font-size: 13px;
    color: var(--blue-light);
    text-decoration: none;
    font-weight: 500;
}

/* ---------- Stat Cards ---------- */
.stats-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 0 12px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.stats-scroll::-webkit-scrollbar { display: none; }

.stat-card {
    flex: 0 0 auto;
    scroll-snap-align: start;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    min-width: 140px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--glass-shadow);
}

.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-icon.blue   { background: rgba(56,189,248,0.18); color: var(--blue-light); }
.stat-icon.green  { background: rgba(74,222,128,0.18); color: var(--success); }
.stat-icon.purple { background: rgba(192,132,252,0.18); color: #c084fc; }
.stat-icon.orange { background: rgba(251,191,36,0.18); color: var(--warning); }

.stat-num {
    font-size: 22px;
    font-weight: 700;
    color: var(--white);
    line-height: 1;
}

.stat-label {
    font-size: 11px;
    color: var(--white-50);
    margin-top: 2px;
    white-space: nowrap;
}

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

.device-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--glass-shadow);
    transition: transform .2s, border-color .2s;
    cursor: pointer;
}

.device-card:active { transform: scale(0.97); }

.device-card.on {
    border-color: rgba(74,222,128,0.3);
    box-shadow: 0 8px 32px rgba(74,222,128,0.08), var(--glass-shadow);
}

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

.device-icon-wrap {
    width: 48px; height: 48px;
    border-radius: 14px;
    background: rgba(255,255,255,0.06);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    color: var(--white-50);
    transition: background .2s, color .2s;
}

.device-card.on .device-icon-wrap {
    background: rgba(74,222,128,0.18);
    color: var(--success);
}

.online-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--white-30);
    padding: 3px 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 99px;
    border: 1px solid rgba(255,255,255,0.08);
}

.online-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #6b7280;
}
.online-dot.on { background: var(--success); box-shadow: 0 0 4px var(--success); }

.device-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--white);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-sub {
    font-size: 11px;
    color: var(--white-50);
}

.device-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ---------- Toggle Switch ---------- */
.toggle {
    position: relative;
    width: 48px; height: 26px;
    flex-shrink: 0;
}

.toggle input { display: none; }

.toggle-track {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.2);
    border-radius: 99px;
    cursor: pointer;
    transition: background .2s;
}

.toggle-track::before {
    content: '';
    position: absolute;
    width: 20px; height: 20px;
    background: var(--white);
    border-radius: 50%;
    top: 3px; left: 3px;
    transition: transform .2s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.toggle input:checked + .toggle-track {
    background: linear-gradient(135deg, var(--blue), var(--teal));
    box-shadow: 0 0 12px rgba(56,189,248,0.35);
}

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

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: opacity .15s, transform .1s;
    text-decoration: none;
    line-height: 1;
}
.btn:active { transform: scale(0.96); opacity: 0.9; }

.btn-primary {
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    color: var(--white);
    box-shadow: 0 4px 16px rgba(56,189,248,0.25);
}
.btn-primary:hover { opacity: 0.9; }

.btn-ghost {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    color: var(--white);
}
.btn-ghost:hover { background: var(--glass-bg-2); }

.btn-danger { background: rgba(248,113,113,0.2); color: var(--danger); border: 1px solid rgba(248,113,113,0.3); }
.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: var(--radius-xs); }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: var(--radius-xs); }

/* ---------- Forms ---------- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--white-70);
}

.form-input, .form-select, .form-textarea {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xs);
    color: var(--white);
    padding: 11px 14px;
    font-size: 14px;
    font-family: inherit;
    width: 100%;
    transition: border-color .15s;
}

.form-input::placeholder { color: var(--white-30); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(56,189,248,0.12);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23ffffff50' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-select option { background: var(--bg-mid); color: var(--white); }

.form-hint { font-size: 11px; color: var(--white-30); }

/* ---------- Tables ---------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    color: var(--white-50);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 8px 12px;
    border-bottom: 1px solid var(--glass-border);
    text-align: left;
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--text);
}

.data-table tr:hover td { background: rgba(255,255,255,0.03); }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-blue   { background: rgba(56,189,248,0.15); color: var(--blue-light); }
.badge-green  { background: rgba(74,222,128,0.15); color: var(--success); }
.badge-red    { background: rgba(248,113,113,0.15); color: var(--danger); }
.badge-yellow { background: rgba(251,191,36,0.15); color: var(--warning); }
.badge-gray   { background: rgba(255,255,255,0.08); color: var(--white-50); }

/* ---------- Scene Tiles ---------- */
.scene-scroll {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 4px 0 12px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}
.scene-scroll::-webkit-scrollbar { display: none; }

.scene-tile {
    flex: 0 0 auto;
    scroll-snap-align: start;
    width: 96px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 14px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    color: var(--text);
    text-align: center;
    transition: transform .15s, border-color .15s;
}

.scene-tile:active { transform: scale(0.95); }
.scene-tile i { font-size: 24px; color: var(--blue-light); }

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-xs);
    margin-bottom: 12px;
    font-size: 13px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.alert-success { background: rgba(74,222,128,0.12); color: var(--success); border: 1px solid rgba(74,222,128,0.2); }
.alert-error   { background: rgba(248,113,113,0.12); color: var(--danger); border: 1px solid rgba(248,113,113,0.2); }
.alert-info    { background: rgba(56,189,248,0.12); color: var(--blue-light); border: 1px solid rgba(56,189,248,0.2); }
.alert i { margin-top: 1px; flex-shrink: 0; }

/* ---------- Toast ---------- */
#toast-container {
    position: fixed;
    top: 80px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center;
    gap: 8px; z-index: 9999; width: calc(100% - 32px); max-width: 380px; pointer-events: none;
}
.toast {
    background: rgba(10, 46, 74, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    color: var(--white);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: toastIn .25s ease;
    width: 100%;
    font-size: 13px;
}
.toast.success { border-color: rgba(74,222,128,0.4); }
.toast.error   { border-color: rgba(248,113,113,0.4); }
@keyframes toastIn { from { opacity:0; transform:translateY(-8px); } to { opacity:1; transform:none; } }

/* ---------- Code Block ---------- */
.code {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-xs);
    padding: 12px;
    font-family: 'Cascadia Code', Consolas, monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow: auto;
    color: var(--blue-light);
}

/* ---------- Misc ---------- */
a { color: var(--blue-light); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--white-50); font-size: 12px; }
.divider { height: 1px; background: var(--glass-border); margin: 16px 0; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }

/* ---------- Room grid ---------- */
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }

/* ---------- Empty State ---------- */
.empty-state {
    display: flex; flex-direction: column; align-items: center;
    padding: 48px 24px; text-align: center;
    gap: 12px;
}
.empty-state i { font-size: 48px; color: var(--white-30); }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--white-70); }
.empty-state p { font-size: 13px; color: var(--white-30); max-width: 240px; }

/* ---------- Quick Banner ---------- */
.quick-banner {
    background: linear-gradient(135deg, rgba(56,189,248,0.18), rgba(45,212,191,0.12));
    border: 1px solid rgba(56,189,248,0.25);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.quick-banner i { font-size: 24px; color: var(--blue-light); flex-shrink: 0; }
.quick-banner-text { flex: 1; }
.quick-banner-text h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.quick-banner-text p { font-size: 12px; color: var(--white-50); }

/* ---------- Page Sections ---------- */
.page-section { margin-bottom: 28px; }
.page-section:last-child { margin-bottom: 0; }

/* ---------- Auth Pages ---------- */
.auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background:
        radial-gradient(ellipse at 30% 10%, rgba(56,189,248,0.25) 0%, transparent 55%),
        radial-gradient(ellipse at 70% 90%, rgba(45,212,191,0.15) 0%, transparent 55%),
        linear-gradient(165deg, #0a2e4a 0%, #051c30 100%);
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--glass-bg);
    backdrop-filter: blur(32px) saturate(1.5);
    -webkit-backdrop-filter: blur(32px) saturate(1.5);
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    padding: 32px 28px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.45);
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo-icon {
    width: 64px; height: 64px;
    background: linear-gradient(135deg, var(--blue), var(--teal));
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px;
    color: white;
    margin: 0 auto 14px;
    box-shadow: 0 8px 24px rgba(56,189,248,0.3);
}

.auth-logo h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--white);
    letter-spacing: -0.02em;
}

.auth-logo p { font-size: 13px; color: var(--white-50); margin-top: 4px; }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-foot { text-align: center; margin-top: 20px; font-size: 13px; color: var(--white-50); }

/* ---------- Search ---------- */
.search-bar {
    position: relative;
    margin-bottom: 16px;
}
.search-bar i {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--white-30);
    font-size: 14px;
}
.search-bar input {
    width: 100%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--white);
    padding: 10px 12px 10px 36px;
    font-size: 14px;
    font-family: inherit;
}
.search-bar input::placeholder { color: var(--white-30); }
.search-bar input:focus { outline: none; border-color: var(--blue); }

/* ---------- Room Cards ---------- */
.room-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: border-color .15s;
    margin-bottom: 10px;
}
.room-card:hover { border-color: rgba(255,255,255,0.25); }
.room-icon-wrap {
    width: 44px; height: 44px;
    background: rgba(56,189,248,0.12);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    color: var(--blue-light);
    flex-shrink: 0;
}
.room-name { font-size: 14px; font-weight: 600; color: var(--white); }
.room-meta { font-size: 11px; color: var(--white-50); margin-top: 2px; }

/* ---------- Misc ---------- */
@media (min-width: 640px) {
    .app-content { padding: 20px 20px 100px; }
    .device-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) {
    body { background: linear-gradient(135deg, #0a2e4a 0%, #07334f 50%, #051c30 100%); }
    .app-content { max-width: 960px; padding: 24px 24px 100px; }
    .bottom-nav { display: none; }
    .sidebar-dock {
        display: flex;
        gap: 0;
    }
    .sidebar-dock .app-content {
        margin-left: 220px;
        max-width: calc(100% - 220px);
    }
}
