/* ====================================================================
   Smart-home bubble dashboard — Cyber Smart
   Dedicated stylesheet for ha-demo.html
   ==================================================================== */

:root {
    --ha-bg: #13182A;
    --ha-bg-2: #1B2238;
    --ha-card: rgba(255, 255, 255, 0.04);
    --ha-card-2: rgba(255, 255, 255, 0.06);
    --ha-border: rgba(255, 255, 255, 0.08);
    --ha-text: #EDEFF5;
    --ha-text-dim: rgba(237, 239, 245, 0.62);
    --ha-text-mute: rgba(237, 239, 245, 0.42);
    --ha-accent: #1B98E0;
    --ha-accent-2: #00C9A7;
    --ha-danger: #E85A6C;
    --ha-warn: #F5B14B;
    --ha-radius: 22px;
    --ha-radius-sm: 16px;
    --ha-radius-pill: 999px;
}

body[data-page="ha_demo"] {
    background: linear-gradient(180deg, #0D1020 0%, #151A2E 100%);
    color: var(--ha-text);
    font-family: 'Inter', sans-serif;
}

body[data-page="ha_demo"] .navbar {
    background: rgba(13, 16, 32, 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--ha-border);
}

/* ---------- Page shell ---------- */
.ha-demo {
    padding: 110px 32px 48px;
    max-width: 1480px;
    margin: 0 auto;
}

.ha-demo-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 28px;
}

.ha-demo-head-text h1 {
    font-family: 'Poppins', sans-serif;
    font-size: clamp(1.6rem, 2vw + 1rem, 2.4rem);
    font-weight: 700;
    color: var(--ha-text);
    margin-bottom: 6px;
    line-height: 1.2;
}

.ha-demo-head-text p {
    color: var(--ha-text-dim);
    font-size: 0.98rem;
    max-width: 640px;
}

.ha-demo-head-badges {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.ha-demo-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--ha-card);
    border: 1px solid var(--ha-border);
    border-radius: var(--ha-radius-pill);
    font-size: 0.82rem;
    color: var(--ha-text-dim);
}

.ha-demo-badge strong {
    color: var(--ha-text);
    font-weight: 600;
}

.ha-demo-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ha-accent-2);
    box-shadow: 0 0 12px rgba(0, 201, 167, 0.7);
}

/* ---------- Layout grid ---------- */
.ha-dash {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 20px;
}

.ha-dash-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ha-dash-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    grid-auto-rows: min-content;
}

.ha-panel {
    background: var(--ha-card);
    border: 1px solid var(--ha-border);
    border-radius: var(--ha-radius);
    padding: 20px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.ha-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.ha-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 1.02rem;
    color: var(--ha-text);
}

.ha-panel-title svg {
    width: 22px;
    height: 22px;
    color: var(--ha-accent-2);
}

.ha-panel-meta {
    font-size: 0.78rem;
    color: var(--ha-text-mute);
}

/* ---------- Bubble buttons ---------- */
.ha-bubble-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.ha-bubble {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--ha-card-2);
    border: 1px solid var(--ha-border);
    border-radius: 18px;
    color: var(--ha-text);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease, border-color 0.2s ease;
    min-height: 60px;
    text-align: start;
    overflow: hidden;
    box-sizing: border-box;
}

.ha-bubble:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.14);
}

.ha-bubble:active {
    transform: scale(0.98);
}

.ha-bubble-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(27, 152, 224, 0.18);
    color: var(--ha-accent);
    flex-shrink: 0;
}

.ha-bubble-icon svg {
    width: 19px;
    height: 19px;
}

.ha-bubble-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.ha-bubble-meta {
    font-size: 0.72rem;
    color: var(--ha-text-mute);
}

.ha-bubble[data-state="on"] {
    background: linear-gradient(135deg, rgba(27, 152, 224, 0.28), rgba(0, 201, 167, 0.18));
    border-color: rgba(27, 152, 224, 0.45);
}

.ha-bubble[data-state="on"] .ha-bubble-icon {
    background: var(--ha-accent);
    color: #fff;
    box-shadow: 0 0 18px rgba(27, 152, 224, 0.5);
}

.ha-bubble[data-state="alert"] {
    background: linear-gradient(135deg, rgba(232, 90, 108, 0.25), rgba(232, 90, 108, 0.1));
    border-color: rgba(232, 90, 108, 0.45);
}

.ha-bubble[data-state="alert"] .ha-bubble-icon {
    background: var(--ha-danger);
    color: #fff;
}

/* ---------- Device cards (wider) ---------- */
.ha-device {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--ha-card-2);
    border: 1px solid var(--ha-border);
    border-radius: var(--ha-radius);
    transition: border-color 0.2s ease;
}

.ha-device:hover {
    border-color: rgba(255, 255, 255, 0.14);
}

.ha-device-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ha-accent-2);
    flex-shrink: 0;
}

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

.ha-device-body {
    flex: 1;
    min-width: 0;
}

.ha-device-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.ha-device-meta {
    font-size: 0.78rem;
    color: var(--ha-text-mute);
}

.ha-device-controls {
    display: flex;
    gap: 6px;
}

.ha-icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--ha-border);
    color: var(--ha-text-dim);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ha-icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--ha-text);
    border-color: rgba(255, 255, 255, 0.18);
}

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

.ha-icon-btn { width: 38px; height: 38px; }

/* ---------- Slider ---------- */
.ha-slider {
    margin-top: 10px;
    position: relative;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
}

.ha-slider-fill {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    background: linear-gradient(90deg, var(--ha-accent), var(--ha-accent-2));
    border-radius: 999px;
}

/* ---------- Big climate cards ---------- */
.ha-climate {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 22px;
    background: linear-gradient(145deg, rgba(27, 152, 224, 0.14), rgba(0, 201, 167, 0.06));
    border: 1px solid rgba(27, 152, 224, 0.24);
    border-radius: var(--ha-radius);
    min-height: 180px;
    position: relative;
    overflow: hidden;
}

.ha-climate::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 85% 15%, rgba(27, 152, 224, 0.18), transparent 60%);
    pointer-events: none;
}

.ha-climate-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.ha-climate-name {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 1.05rem;
}

.ha-climate-icon {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(27, 152, 224, 0.22);
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--ha-accent);
}
.ha-climate-icon svg { width: 20px; height: 20px; }

.ha-climate-values {
    display: flex;
    align-items: baseline;
    gap: 16px;
    position: relative;
    z-index: 1;
}

.ha-climate-temp {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    font-size: 2rem;
    color: var(--ha-text);
    line-height: 1;
}

.ha-climate-hum {
    font-size: 0.95rem;
    color: var(--ha-text-dim);
}

.ha-climate-chart {
    margin-top: auto;
    position: relative;
    z-index: 1;
}

.ha-climate-chart svg {
    width: 100%;
    height: 60px;
    display: block;
}

/* ---------- Sensor grid ---------- */
.ha-sensors {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.ha-sensor {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 14px;
    background: var(--ha-card-2);
    border: 1px solid var(--ha-border);
    border-radius: var(--ha-radius-sm);
    min-height: 96px;
}

.ha-sensor-icon {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(0, 201, 167, 0.14);
    color: var(--ha-accent-2);
    display: inline-flex; align-items: center; justify-content: center;
}
.ha-sensor-icon svg { width: 18px; height: 18px; }

.ha-sensor-name {
    font-size: 0.85rem;
    font-weight: 500;
}

.ha-sensor-state {
    font-size: 0.74rem;
    color: var(--ha-text-mute);
}

.ha-sensor[data-state="warn"] .ha-sensor-icon {
    background: rgba(245, 177, 75, 0.18);
    color: var(--ha-warn);
}

.ha-sensor[data-state="alert"] {
    border-color: rgba(232, 90, 108, 0.35);
}
.ha-sensor[data-state="alert"] .ha-sensor-icon {
    background: rgba(232, 90, 108, 0.18);
    color: var(--ha-danger);
}

/* ---------- Power / energy cards ---------- */
.ha-power-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.ha-power {
    padding: 18px;
    background: var(--ha-card-2);
    border: 1px solid var(--ha-border);
    border-radius: var(--ha-radius);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 150px;
}

.ha-power-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ha-power-name {
    font-weight: 600;
    font-size: 0.92rem;
}

.ha-power-values {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.ha-power-now {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--ha-accent);
}

.ha-power-total {
    font-size: 0.88rem;
    color: var(--ha-text-dim);
}

.ha-power-chart {
    margin-top: auto;
}

.ha-power-chart svg {
    width: 100%;
    height: 44px;
    display: block;
}

.ha-power-legend {
    display: flex;
    gap: 14px;
    font-size: 0.72rem;
    color: var(--ha-text-mute);
}
.ha-power-legend span::before {
    content: '';
    display: inline-block;
    width: 8px; height: 8px; border-radius: 50%;
    margin-inline-end: 6px;
    vertical-align: middle;
    background: var(--ha-accent);
}
.ha-power-legend span:last-child::before { background: var(--ha-accent-2); }

/* ---------- Alert strip ---------- */
.ha-alert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(232, 90, 108, 0.18), rgba(232, 90, 108, 0.06));
    border: 1px solid rgba(232, 90, 108, 0.35);
    border-radius: var(--ha-radius);
    color: var(--ha-text);
    font-size: 0.9rem;
}

.ha-alert-icon {
    width: 32px; height: 32px; border-radius: 50%;
    background: rgba(232, 90, 108, 0.25);
    color: var(--ha-danger);
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.ha-alert-icon svg { width: 16px; height: 16px; }

/* ---------- Climate header bar (top stats) ---------- */
.ha-stats-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.ha-stat {
    padding: 14px 18px;
    background: var(--ha-card);
    border: 1px solid var(--ha-border);
    border-radius: var(--ha-radius-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ha-stat-label {
    font-size: 0.72rem;
    color: var(--ha-text-mute);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.25;
}

.ha-stat-value {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    font-size: 1.35rem;
    color: var(--ha-text);
    overflow-wrap: anywhere;
}

.ha-stat-sub {
    font-size: 0.75rem;
    color: var(--ha-text-dim);
    overflow-wrap: anywhere;
}

.ha-stat { min-width: 0; }

/* Universal overflow containment — nothing should escape its card */
.ha-stat,
.ha-sensor,
.ha-device,
.ha-climate,
.ha-power,
.ha-media,
.ha-alert,
.ha-panel {
    box-sizing: border-box;
    overflow: hidden;
    min-width: 0;
}

.ha-sensor-name,
.ha-sensor-state,
.ha-device-title,
.ha-device-meta,
.ha-power-name,
.ha-climate-name,
.ha-media-title,
.ha-media-meta {
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}

/* ---------- Media (TV) card wide ---------- */
.ha-media {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
    border: 1px solid var(--ha-border);
    border-radius: var(--ha-radius);
}

.ha-media-art {
    width: 60px; height: 60px; border-radius: 14px;
    background: linear-gradient(135deg, #E85A6C, #F5A14B);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
}
.ha-media-art svg { width: 24px; height: 24px; }

.ha-media-body { flex: 1; min-width: 0; }
.ha-media-title { font-weight: 600; }
.ha-media-meta { font-size: 0.78rem; color: var(--ha-text-mute); }
.ha-media-controls { display: flex; gap: 6px; }

/* ---------- RTL mirroring guarantees ---------- */
html[dir="rtl"] .ha-bubble-label,
html[dir="rtl"] .ha-device-body,
html[dir="rtl"] .ha-power-name,
html[dir="rtl"] .ha-sensor-name {
    text-align: right;
}
html[dir="rtl"] .ha-climate-chart svg,
html[dir="rtl"] .ha-power-chart svg {
    transform: scaleX(-1);
}

/* ---------- Dashboard wrapper on live-demo page ---------- */
.ha-stage-wrap.ha-demo {
    position: relative;
    padding: 60px 24px 80px;
    margin: 40px auto 80px;
    max-width: 1480px;
    background: linear-gradient(180deg, #0D1020 0%, #151A2E 100%);
    color: #EDEFF5;
    border-radius: 28px;
    box-shadow: 0 40px 80px -40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04);
    overflow: hidden;
}

.ha-stage-wrap.ha-demo::after {
    /* subtle bottom glow so the panel doesn't feel welded to the next section */
    content: '';
    position: absolute;
    left: 10%;
    right: 10%;
    bottom: -20px;
    height: 40px;
    background: radial-gradient(ellipse at center, rgba(27, 152, 224, 0.12), transparent 70%);
    pointer-events: none;
}

.ha-stage-wrap.ha-demo > .container {
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
}

@media (max-width: 1024px) {
    .ha-stage-wrap.ha-demo {
        margin: 24px 16px 48px;
        padding: 40px 18px 56px;
        border-radius: 22px;
    }
}

@media (max-width: 560px) {
    .ha-stage-wrap.ha-demo {
        margin: 16px 10px 32px;
        padding: 32px 12px 44px;
        border-radius: 18px;
    }
}

/* ---------- Scenario tabs ---------- */
.ha-scenario-switch {
    display: inline-flex;
    gap: 6px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--ha-border);
    border-radius: 999px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.ha-scenario-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: transparent;
    border: 0;
    border-radius: 999px;
    color: var(--ha-text-dim);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    min-height: 44px;
}

.ha-scenario-btn:hover {
    color: var(--ha-text);
    background: rgba(255, 255, 255, 0.05);
}

.ha-scenario-btn.active {
    background: linear-gradient(135deg, rgba(27, 152, 224, 0.28), rgba(0, 201, 167, 0.2));
    color: #fff;
    box-shadow: 0 0 0 1px rgba(27, 152, 224, 0.4);
}

.ha-scenario-btn svg {
    width: 18px;
    height: 18px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
    .ha-dash {
        grid-template-columns: 320px 1fr;
        gap: 16px;
    }
    .ha-stats-row { gap: 10px; }
    .ha-stat { padding: 12px 14px; }
}

@media (max-width: 1024px) {
    .ha-demo { padding: 100px 20px 40px; }
    .ha-dash {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .ha-dash-main { grid-template-columns: 1fr 1fr; }
    .ha-bubble-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .ha-sensors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
    .ha-stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ha-dash-main { grid-template-columns: 1fr; }
    .ha-bubble-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ha-sensors { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ha-power-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .ha-demo { padding: 88px 14px 32px; }
    .ha-panel { padding: 16px; }
    .ha-climate { padding: 18px; min-height: auto; }
    .ha-power { padding: 16px; min-height: auto; }
    .ha-scenario-switch { width: 100%; justify-content: center; }
    .ha-scenario-btn { flex: 1; justify-content: center; padding: 10px 12px; font-size: 0.85rem; }
    .ha-scenario-btn span { white-space: nowrap; }
    .ha-stat-value { font-size: 1.15rem; }
    .ha-climate-temp { font-size: 1.7rem; }
}

@media (max-width: 560px) {
    .ha-bubble-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .ha-bubble { padding: 10px 12px; min-height: 52px; gap: 10px; font-size: 0.82rem; }
    .ha-bubble-icon { width: 36px; height: 36px; }
    .ha-bubble-icon svg { width: 18px; height: 18px; }
    .ha-sensors { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .ha-sensor { padding: 10px; min-height: 80px; }
    .ha-power-grid { grid-template-columns: 1fr; gap: 10px; }
    .ha-media { flex-wrap: wrap; gap: 10px; }
    .ha-media-art { width: 48px; height: 48px; }
    .ha-media-art svg { width: 20px; height: 20px; }
    .ha-media-body { flex: 1; min-width: 100px; }
    .ha-media-controls { width: 100%; justify-content: flex-start; }
    .ha-device { flex-wrap: wrap; gap: 10px; }
    .ha-device-body { min-width: 100px; }
    .ha-device-controls { width: 100%; justify-content: flex-start; }
    .ha-device-icon { width: 38px; height: 38px; }
    .ha-device-icon svg { width: 18px; height: 18px; }
}

@media (max-width: 480px) {
    .ha-demo { padding: 84px 12px 28px; }
    .ha-demo-head { gap: 14px; }
    .ha-stats-row { grid-template-columns: 1fr; gap: 8px; }
    .ha-stat { padding: 10px 12px; }
    .ha-stat-label { font-size: 0.66rem; }
    .ha-stat-value { font-size: 1.05rem; }
    .ha-stat-sub { font-size: 0.7rem; }
    .ha-panel { padding: 14px; border-radius: 18px; }
    .ha-panel-title { font-size: 0.95rem; }
    .ha-panel-meta { font-size: 0.72rem; }
    .ha-climate { padding: 16px; border-radius: 18px; }
    .ha-climate-temp { font-size: 1.5rem; }
    .ha-climate-hum { font-size: 0.85rem; }
    .ha-power-now { font-size: 1.2rem; }
    .ha-power-total { font-size: 0.8rem; }
    .ha-alert { padding: 10px 12px; font-size: 0.85rem; }
    .ha-alert-icon { width: 28px; height: 28px; }
    .ha-scenario-btn svg { width: 16px; height: 16px; }
    .ha-scenario-btn { padding: 9px 10px; font-size: 0.8rem; gap: 6px; }
}

@media (max-width: 360px) {
    .ha-bubble-grid { grid-template-columns: 1fr; }
    .ha-sensors { grid-template-columns: 1fr; }
    .ha-stats-row { grid-template-columns: 1fr; }
    .ha-scenario-btn span { font-size: 0.75rem; }
    .ha-scenario-btn { padding: 8px; }
}
