/* ============================================
   ОБЩИЕ СТИЛИ
   ============================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', 'Inter', -apple-system, Roboto, sans-serif; background: #eef4fa; padding: 20px; }
.container { max-width: 1500px; margin: 0 auto; }
h1 { text-align: center; margin-bottom: 24px; color: #0c4a6e; font-size: 1.9rem; display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 500; }

/* ============================================
   ВЕРХНЯЯ ПАНЕЛЬ
   ============================================ */

.user-info { position: fixed; top: 20px; right: 20px; display: flex; align-items: center; gap: 12px; background: white; padding: 8px 16px; border-radius: 40px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); z-index: 1000; }
.user-avatar { width: 32px; height: 32px; background: #0284c7; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; }
.user-details { font-size: 0.85rem; }
.user-name { font-weight: 600; color: #0c4a6e; }
.user-role { font-size: 0.7rem; color: #6b7280; }
.logout-btn { background: #ef4444; color: white; border: none; padding: 6px 12px; border-radius: 40px; cursor: pointer; font-size: 0.75rem; font-weight: 500; transition: background 0.2s; }
.logout-btn:hover { background: #dc2626; }
.login-btn-header { background: #0284c7; color: white; border: none; padding: 6px 16px; border-radius: 40px; cursor: pointer; font-size: 0.75rem; font-weight: 500; transition: background 0.2s; }
.login-btn-header:hover { background: #0369a1; }
.admin-btn { background: #8b5cf6; color: white; border: none; padding: 6px 12px; border-radius: 40px; cursor: pointer; font-size: 0.75rem; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.admin-btn:hover { background: #7c3aed; }
.settings-btn { background: #eef4fa; color: #0284c7; border: none; padding: 6px 12px; border-radius: 40px; cursor: pointer; font-size: 0.9rem; font-weight: 500; transition: background 0.2s; display: flex; align-items: center; gap: 6px; }
.settings-btn:hover { background: #cde9fe; }

/* ============================================
   ТАБЛИЦЫ
   ============================================ */

.devices-table-container { background: white; border-radius: 24px; overflow: hidden; margin-top: 20px; box-shadow: 0 8px 20px rgba(0, 60, 90, 0.08); border: 1px solid #dcf2ff; }
.devices-table { width: 100%; border-collapse: collapse; }
.devices-table th { background: #f8fafc; padding: 14px 16px; text-align: left; font-size: 0.75rem; font-weight: 600; color: #2c6e9e; border-bottom: 1px solid #e2edf7; }
.devices-table td { padding: 12px 16px; font-size: 0.85rem; border-bottom: 1px solid #eef2f6; }
.devices-table tr:hover { background: #f8fafc; cursor: pointer; }
.device-status { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; transition: background-color 0.2s ease; }
.device-status.active { background: #22c55e; box-shadow: 0 0 4px #22c55e; }
.device-status.inactive { background: #ef4444; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 0.7rem; font-weight: 600; }
.badge-heater { background: #ffedd5; color: #c2410c; }
.badge-sensor { background: #dcfce7; color: #166534; }
.badge-button { background: #e0e7ff; color: #4338ca; }
.badge-admin { background: #ede9fe; color: #5b21b6; }
.badge-user { background: #e0f2fe; color: #0369a1; }

.users-modal-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.users-modal-stats { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.stat-pill { display: inline-flex; align-items: center; gap: 8px; background: #f8fafc; padding: 8px 16px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; color: #0c4a6e; border: 1px solid #e2edf7; }
.stat-pill i { font-size: 0.95rem; color: #0284c7; }

.tabs { display: flex; gap: 10px; margin-bottom: 20px; border-bottom: 1px solid #e2edf7; padding-bottom: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.tabs-buttons { display: flex; gap: 10px; }
.tab-btn { background: none; border: none; padding: 8px 20px; font-size: 0.9rem; font-weight: 500; cursor: pointer; border-radius: 20px; transition: 0.2s; color: #6b7280; }
.tab-btn.active { background: #0284c7; color: white; }
.tab-btn:hover:not(.active) { background: #e0f2fe; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.refresh-discovered-btn, .clear-discovered-btn { background: #0284c7; color: white; border: none; padding: 8px 16px; border-radius: 40px; font-size: 0.75rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: background 0.2s; }
.refresh-discovered-btn:hover { background: #0369a1; }
.clear-discovered-btn { background: #dc2626; }
.clear-discovered-btn:hover { background: #b91c1c; }

/* ============================================
   ФИЛЬТРЫ
   ============================================ */

.filters { background: white; padding: 18px 20px; border-radius: 24px; margin-bottom: 24px; box-shadow: 0 6px 14px rgba(2, 136, 209, 0.08); border: 1px solid #cde9fe; }
.filter-row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.filter-group { flex: 1; min-width: 150px; }
.filter-group label { display: block; font-size: 0.7rem; font-weight: 600; color: #2c6e9e; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
.filter-group select { width: 100%; padding: 10px 12px; border: 1px solid #cde9fe; border-radius: 18px; font-size: 0.85rem; background: white; color: #0c4a6e; font-weight: 500; cursor: pointer; }
.btn-reset { background: #6b7280; color: white; border: none; padding: 10px 24px; border-radius: 40px; font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: 0.2s; }
.btn-reset:hover { background: #4b5563; }
.btn-refresh { background: #0284c7; color: white; border: none; padding: 10px 24px; border-radius: 40px; font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: 0.2s; }
.btn-refresh:hover { background: #0369a1; }

/* ============================================
   ПЕРЕКЛЮЧАТЕЛЬ ВИДА
   ============================================ */

.view-toggle {
    display: flex;
    gap: 3px;
    background: #f0f9ff;
    padding: 3px;
    border-radius: 14px;
    border: 1px solid #cde9fe;
    margin-left: auto;
    align-self: flex-end;
}

.view-btn {
    background: transparent;
    border: none;
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    color: #64748b;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
}

.view-btn.active {
    background: #0284c7;
    color: white;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);
}

.view-btn:hover:not(.active) {
    background: #e0f2fe;
    color: #0284c7;
}

/* ============================================
   СЕТКА КАРТОЧЕК (ULTRA COMPACT)
   ============================================ */

.devices-grid {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
}

.devices-grid.hidden {
    display: none;
}

.device-group {
    width: 100% !important;
    margin-bottom: 16px;
}

.device-group:last-child {
    margin-bottom: 0;
}

.device-group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
    width: 100%;
    align-items: start;
    justify-content: start;
}

/* ============================================
   ★ НОВОЕ: УРОВНИ ТРЕВОГИ КАРТОЧКИ
   ============================================ */

/* 🟢 Норма — обычная карточка */
.device-card.alert-level-normal {
    /* обычный вид */
}

/* 🟡 Внимание — жёлтая подсветка */
.device-card.alert-level-warning {
    border-color: #fbbf24;
    background: linear-gradient(135deg, #ffffff 0%, #fffbeb 100%);
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.15);
}

.device-card.alert-level-warning::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
    border-radius: 12px 0 0 12px;
    pointer-events: none;
}

/* 🟠 Предупреждение — оранжевая подсветка */
.device-card.alert-level-alert {
    border-color: #f97316;
    background: linear-gradient(135deg, #ffffff 0%, #fff7ed 100%);
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.2);
}

.device-card.alert-level-alert::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, #fb923c 0%, #ea580c 100%);
    border-radius: 12px 0 0 12px;
    pointer-events: none;
}

/* 🔴 Критично — красная подсветка + пульсация */
.device-card.alert-level-critical {
    border-color: #ef4444;
    background: linear-gradient(135deg, #ffffff 0%, #fef2f2 100%);
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.25);
    animation: card-critical-pulse 2s ease-in-out infinite;
}

.device-card.alert-level-critical::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, #f87171 0%, #dc2626 100%);
    border-radius: 12px 0 0 12px;
    pointer-events: none;
}

@keyframes card-critical-pulse {
    0%, 100% {
        box-shadow: 0 4px 20px rgba(239, 68, 68, 0.25);
    }
    50% {
        box-shadow: 0 4px 28px rgba(239, 68, 68, 0.55), 0 0 0 2px rgba(239, 68, 68, 0.15);
    }
}

/* Неактивное устройство — переопределяет уровни тревоги */
.device-card.inactive {
    opacity: 0.55;
    background: #f5f7fa !important;
    border-color: #d4dee8 !important;
    filter: grayscale(0.5);
    pointer-events: none;
    animation: none !important;
    box-shadow: none !important;
}

.device-card.inactive::before {
    display: none !important;
}

/* ============================================
   ★ НОВОЕ: БЕЙДЖ СТАТУСА В ХЕДЕРЕ КАРТОЧКИ
   ============================================ */

.alert-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.55rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    flex-shrink: 0;
    animation: badge-appear 0.3s ease;
}

@keyframes badge-appear {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.alert-badge.normal {
    background: #dcfce7;
    color: #166534;
}

.alert-badge.warning {
    background: #fef3c7;
    color: #92400e;
}

.alert-badge.alert {
    background: #fed7aa;
    color: #9a3412;
}

.alert-badge.critical {
    background: #fee2e2;
    color: #991b1b;
    animation: badge-critical-blink 1s ease-in-out infinite;
}

@keyframes badge-critical-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ============================================
   ★ НОВОЕ: ЦВЕТНОЙ ИНДИКАТОР В ЗАГОЛОВКЕ
   ============================================ */

.device-card.alert-level-warning .device-name {
    color: #92400e;
}

.device-card.alert-level-alert .device-name {
    color: #9a3412;
}

.device-card.alert-level-critical .device-name {
    color: #991b1b;
}

/* ============================================
   КАРТОЧКА УСТРОЙСТВА
   ============================================ */

.device-card {
    background: white;
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    border: 1px solid #dcf2ff;
    transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease, background 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    min-width: 0;
    height: auto;
    max-width: 340px;
    contain: layout paint;
    overflow: hidden;
}

.device-card:hover { 
    box-shadow: 0 6px 18px rgba(2, 132, 199, 0.15); 
    border-color: #b8dff5; 
    transform: translateY(-2px);
}

.device-card-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 6px;
    min-width: 0; 
    gap: 6px; 
    flex-wrap: wrap; 
    position: relative;
    min-height: 22px;
    padding-left: 2px;
}

.device-name { 
    font-size: 0.75rem;
    font-weight: 600; 
    color: #0369a1; 
    letter-spacing: -0.2px; 
    display: flex; 
    align-items: center; 
    gap: 4px; 
    white-space: normal; 
    word-break: keep-all; 
    line-height: 1.2;
}

.device-location { 
    font-size: 0.55rem;
    background: #eef4fa; 
    padding: 1px 6px;
    border-radius: 40px; 
    color: #2c6e9e; 
    font-weight: 500; 
    display: flex; 
    align-items: center; 
    gap: 3px; 
    white-space: nowrap; 
    flex-shrink: 0; 
}

.device-power-type {
    font-size: 0.45rem;
    color: #88a4bc;
    margin-left: 4px;
}

/* ============================================
   КНОПКИ В ХЕДЕРЕ КАРТОЧКИ
   ============================================ */

.card-header-actions {
    position: absolute;
    top: -4px;
    right: -4px;
    display: flex;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 10;
}

.device-card:hover .card-header-actions {
    opacity: 1;
    pointer-events: auto;
}

.card-header-actions .icon-btn {
    width: 22px !important;
    height: 22px !important;
    font-size: 0.65rem !important;
    background: #f0f9ff !important;
    color: #0284c7 !important;
    border: 1px solid #cde9fe !important;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.15) !important;
}

.card-header-actions .icon-btn:hover {
    background: #0284c7 !important;
    color: white !important;
}

/* ============================================
   КАРТОЧКА ДАТЧИКА (СЕНСОРА)
   ============================================ */

.sensor-big-row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 4px; }
.sensor-big-block { background: #fafeff; border-radius: 10px; border: 1px solid #e2edf7; padding: 6px 4px; text-align: center; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 62px; border-top-width: 2px; border-top-style: solid; }
.sensor-big-block:hover { background: #ffffff; border-color: #7ab7d4; transform: translateY(-1px); }
.sensor-big-block:active { transform: scale(0.98); }
.sensor-big-block--temp { border-top-color: #ef4444; }
.sensor-big-block--temp .sensor-big-icon { color: #ef4444; }
.sensor-big-block--temp .sensor-big-value { color: #dc2626; }
.sensor-big-block--humidity { border-top-color: #22c55e; }
.sensor-big-block--humidity .sensor-big-icon { color: #22c55e; }
.sensor-big-block--humidity .sensor-big-value { color: #16a34a; }
.sensor-big-icon { font-size: 0.85rem; margin-bottom: 1px; }
.sensor-big-value { font-size: 1.25rem; font-weight: 700; line-height: 1.1; }
.sensor-big-unit { font-size: 0.65rem; font-weight: 400; color: #64748b; margin-left: 1px; }
.sensor-big-comment { font-size: 0.5rem; color: #475569; margin-top: 1px; }
.sensor-small-stack { display: flex; flex-direction: column; gap: 4px; }
.sensor-metrics-stack { margin: 2px 0; }
.sensor-metric-block { display: flex; background: #fafeff; border-radius: 10px; border: 1px solid #e2edf7; overflow: hidden; margin-bottom: 0; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease; border-left-width: 2px; border-left-style: solid; }
.sensor-metric-block:hover { background: #ffffff; border-color: #7ab7d4; }
.sensor-metric-block--temp { border-left-color: #ef4444; }
.sensor-metric-block--humidity { border-left-color: #22c55e; }
.sensor-metric-block--pressure { border-left-color: #8b5cf6; }
.sensor-metric-icon { display: flex; align-items: center; justify-content: center; width: 28px; flex-shrink: 0; font-size: 0.85rem; }
.sensor-metric-block--temp .sensor-metric-icon { color: #ef4444; }
.sensor-metric-block--humidity .sensor-metric-icon { color: #22c55e; }
.sensor-metric-block--pressure .sensor-metric-icon { color: #8b5cf6; }
.sensor-metric-content { flex: 1; padding: 4px 6px; }
.sensor-metric-label { font-size: 0.5rem; font-weight: 600; color: #2c6e9e; margin-bottom: 1px; text-transform: uppercase; letter-spacing: 0.3px; }
.sensor-metric-main { font-size: 0.9rem; font-weight: 500; color: #0b3b4f; line-height: 1.1; }
.sensor-metric-unit { font-size: 0.55rem; color: #64748b; font-weight: 400; margin-left: 3px; }
.sensor-metric-comment { font-size: 0.45rem; color: #475569; margin-top: 1px; display: flex; align-items: center; gap: 3px; }
.sensor-metrics-empty { text-align: center; color: #6c8eae; padding: 10px 8px; background: #f8fafc; border-radius: 10px; border: 1px solid #e2edf7; margin: 6px 0; font-size: 0.65rem; }

/* ============================================
   БАТАРЕЯ CR123A
   ============================================ */

.sensor-metric-block--battery { border-left-color: #22c55e; transition: background 0.2s ease; }
.sensor-metric-block--battery .sensor-metric-main span:first-child { font-weight: 700; font-size: 0.9rem; color: #166534; }
.sensor-metric-block--battery .sensor-metric-icon { color: #22c55e; }
.sensor-metric-block--battery.battery-good { background: #f0fdf4; border-left-color: #22c55e; }
.sensor-metric-block--battery.battery-good .sensor-metric-icon { color: #22c55e; }
.sensor-metric-block--battery.battery-good .sensor-metric-main span:first-child { color: #166534; }
.sensor-metric-block--battery.battery-medium { background: #fffbeb; border-left-color: #f59e0b; }
.sensor-metric-block--battery.battery-medium .sensor-metric-icon { color: #f59e0b; }
.sensor-metric-block--battery.battery-medium .sensor-metric-main span:first-child { color: #d97706; }
.sensor-metric-block--battery.battery-low { background: #fef2f2; border-left-color: #ef4444; }
.sensor-metric-block--battery.battery-low .sensor-metric-icon { color: #ef4444; }
.sensor-metric-block--battery.battery-low .sensor-metric-main span:first-child { color: #dc2626; }
.sensor-metric-block--battery.battery-critical { background: #fef2f2; border-left-color: #ef4444; animation: battery-critical-pulse 2s ease-in-out infinite; }
.sensor-metric-block--battery.battery-critical .sensor-metric-icon { color: #ef4444; }
.sensor-metric-block--battery.battery-critical .sensor-metric-main span:first-child { color: #dc2626; }
@keyframes battery-critical-pulse { 0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); } 50% { opacity: 0.85; box-shadow: 0 0 20px 4px rgba(239, 68, 68, 0.2); } }
.sensor-metric-block--battery.battery-critical .fa-battery-empty { animation: battery-icon-pulse 1s ease-in-out infinite; }
@keyframes battery-icon-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* ============================================
   КАРТОЧКА ОБОГРЕВАТЕЛЯ
   ============================================ */

.coolant-block, .room-block, .power-block { display: flex; background: #fafeff; border-radius: 10px; border: 1px solid #e2edf7; overflow: hidden; cursor: pointer; margin-bottom: 4px; transition: background 0.15s ease, border-color 0.15s ease; border-left-width: 2px; border-left-style: solid; }
.coolant-block { border-left-color: #ef4444; }
.room-block { border-left-color: #3b82f6; }
.power-block { border-left-color: #f59e0b; }
.coolant-block:hover, .room-block:hover, .power-block:hover { background: #ffffff; border-color: #7ab7d4; }
.coolant-icon, .room-icon, .power-icon { display: flex; align-items: center; justify-content: center; width: 28px; font-size: 0.85rem; }
.coolant-icon { color: #ef4444; }
.room-icon { color: #3b82f6; }
.power-icon { color: #f59e0b; }
.coolant-content, .room-content, .power-content { flex: 1; padding: 4px 6px; }
.coolant-value, .room-value, .power-value { font-size: 0.95rem; font-weight: 500; color: #0b3b4f; line-height: 1.1; }
.coolant-unit, .room-unit, .power-unit { font-size: 0.55rem; color: #64748b; font-weight: 400; margin-left: 3px; }
.coolant-label, .room-label, .power-label { font-size: 0.5rem; font-weight: 600; color: #2c6e9e; margin-bottom: 1px; text-transform: uppercase; letter-spacing: 0.3px; }
.coolant-main, .room-main, .power-main { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.progress-bar { width: 100%; height: 3px; background: #e2e8f0; border-radius: 10px; overflow: hidden; margin-top: 3px; }
.progress-fill { height: 100%; background: #0284c7; border-radius: 10px; transition: width 0.15s linear; }
.footer-row { display: flex; justify-content: space-between; align-items: center; margin-top: 2px; font-size: 0.45rem; color: #6b7280; width: 100%; }

/* ============================================
   КАРТОЧКА КНОПКИ - ИМПУЛЬСНАЯ
   ============================================ */

.buttons-container-simple { margin: 2px 0 4px 0; padding: 0; }
.buttons-section-title { font-size: 0.5rem; font-weight: 600; color: #2c6e9e; margin: 2px 0 6px 0; letter-spacing: 0.5px; text-align: center; }
.buttons-grid-simple { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin: 4px 0 6px 0; }
.button-item-simple { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 54px; }
.button-item-simple.disabled { opacity: 0.5; }
.device-btn-simple { width: 62px; height: 62px; border-radius: 50%; cursor: pointer; transition: all 0.25s ease; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #4f46e5; color: white; font-weight: 600; border: 2px solid #4338ca; box-shadow: 0 3px 10px rgba(79, 70, 229, 0.3); -webkit-tap-highlight-color: transparent; user-select: none; overflow: hidden; }
.device-btn-simple:hover:not(.disabled) { transform: scale(1.05); box-shadow: 0 5px 18px rgba(79, 70, 229, 0.4); }
.device-btn-simple:active:not(.disabled) { transform: scale(0.92); }
.device-btn-simple .btn-number { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.5px; position: relative; z-index: 2; line-height: 1; text-shadow: 0 2px 6px rgba(0,0,0,0.15); transition: all 0.3s ease; }
.device-btn-simple .btn-label-inside { font-size: 0.4rem; font-weight: 400; opacity: 0.8; position: relative; z-index: 2; text-shadow: 0 1px 4px rgba(0,0,0,0.1); letter-spacing: 0.5px; margin-top: -2px; transition: all 0.3s ease; }
.device-btn-simple.long-press-active .btn-number { animation: number-countdown 0.3s ease-in-out infinite alternate; }
.device-btn-simple.long-press-active .btn-label-inside { opacity: 0.6; font-size: 0.35rem; }
@keyframes number-countdown { 0% { transform: scale(1); } 100% { transform: scale(0.85); } }
.device-btn-simple .btn-progress-ring { position: absolute; top: -3px; left: -3px; right: -3px; bottom: -3px; border-radius: 50%; border: 3px solid transparent; transition: all 0.05s linear; pointer-events: none; z-index: 1; }
.device-btn-simple .btn-progress-fill { position: absolute; top: 50%; left: 50%; width: 0%; height: 0%; border-radius: 50%; background: rgba(255, 255, 255, 0.25); transform: translate(-50%, -50%); transition: width 0.05s linear, height 0.05s linear, opacity 0.3s ease; pointer-events: none; z-index: 0; opacity: 0; }
.device-btn-simple.long-press-active .btn-progress-fill { opacity: 1; }
.btn-label-simple { font-size: 0.6rem; font-weight: 500; color: #1e293b; text-align: center; line-height: 1.2; max-width: 62px; word-wrap: break-word; }
.button-item-simple:hover .btn-label-simple { color: #0284c7; }
.btn-help-simple { font-size: 0.45rem; color: #94a3b8; text-align: center; padding: 3px 8px; margin-top: 2px; }

/* ============================================
   КАРТОЧКА ПЕРЕКЛЮЧАТЕЛЯ (ТУМБЛЕРА)
   ============================================ */

.switches-grid { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.switch-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: #fafeff; border-radius: 10px; border: 1px solid #e2edf7; transition: background 0.15s ease, border-color 0.15s ease; }
.switch-item:hover { background: #ffffff; border-color: #7ab7d4; }
.switch-item.disabled { opacity: 0.5; cursor: not-allowed; }
.switch-disabled-reason { font-size: 0.45rem; color: #dc2626; }
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: 0.3s; border-radius: 34px; border: 2px solid #94a3b8; }
.toggle-slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 2px; bottom: 2px; background-color: white; transition: 0.3s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle-switch input:checked + .toggle-slider { background-color: var(--switch-bg, #4f46e5); border-color: var(--switch-border, #4338ca); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }
.toggle-switch input:disabled + .toggle-slider { cursor: not-allowed; opacity: 0.5; }
.switch-label { font-size: 0.65rem; font-weight: 500; color: #1e293b; flex: 1; }
.switch-state { font-size: 0.55rem; font-weight: 600; padding: 2px 6px; border-radius: 20px; background: #f1f5f9; color: #64748b; }

/* ============================================
   ФУТЕР КАРТОЧКИ
   ============================================ */

.device-id { font-size: 0.5rem; font-family: monospace; color: #88a4bc; }
.last-update { font-size: 0.5rem; color: #88a4bc; }
.last-update.stale { color: #f59e0b; background: #fef3c7; padding: 2px 6px; border-radius: 12px; display: inline-block; }
.last-update.stale i { color: #f59e0b; }

.card-footer-compact { margin-top: auto; padding-top: 5px; border-top: 1px solid #e2edf7; display: flex; flex-direction: column; gap: 3px; }
.card-footer-compact .footer-power { display: flex; justify-content: center; margin-bottom: 3px; }
.card-footer-compact .footer-meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; }
.card-footer-compact .device-id { font-size: 0.45rem; font-family: monospace; color: #88a4bc; }
.card-footer-compact .last-update { font-size: 0.45rem; color: #88a4bc; }
.card-footer-compact .last-update.stale { color: #f59e0b; background: #fef3c7; padding: 1px 4px; border-radius: 8px; }
.card-footer-compact .last-update.stale i { color: #f59e0b; }

/* ============================================
   КНОПКИ УПРАВЛЕНИЯ
   ============================================ */

.power-btn { background: #0284c7 !important; border-radius: 40px !important; width: auto !important; padding: 3px 10px !important; gap: 4px; font-size: 0.65rem !important; font-weight: 600; color: white !important; transition: background 0.15s ease, color 0.15s ease; border: none !important; outline: none !important; box-shadow: none !important; cursor: pointer; }
.power-btn.active { background: #dc2626 !important; color: white !important; }
.power-btn:hover { background: #0369a1 !important; opacity: 0.9; }
.power-btn.active:hover { background: #b91c1c !important; }

.icon-btn { background: #0284c7 !important; border: none !important; border-radius: 50% !important; width: 26px !important; height: 26px !important; padding: 0 !important; margin: 0 !important; display: inline-flex !important; align-items: center !important; justify-content: center !important; cursor: pointer !important; transition: background 0.15s ease, transform 0.1s ease !important; color: white !important; font-size: 0.75rem !important; box-shadow: none !important; outline: none !important; }
.icon-btn:hover { background: #0369a1 !important; transform: scale(1.05); }
.icon-btn:active { transform: scale(0.95); }

.camera-rotate-btn.is-on {
    background: #d97706 !important;
}
.camera-rotate-btn.is-on:hover {
    background: #b45309 !important;
}

/* ============================================
   ТАБЛИЧНЫЙ ВИД УСТРОЙСТВ
   ============================================ */

.devices-table-view {
    display: none;
    width: 100%;
    background: white;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(2, 132, 199, 0.08);
    border: 1px solid #dcf2ff;
}

.devices-table-view.active {
    display: block;
}

.devices-table-view table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.devices-table-view thead {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    position: sticky;
    top: 0;
    z-index: 10;
}

.devices-table-view th {
    padding: 12px 14px;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    color: #2c6e9e;
    border-bottom: 2px solid #e2edf7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    user-select: none;
}

.devices-table-view th.col-status { width: 30px; }
.devices-table-view th.col-name { min-width: 180px; }
.devices-table-view th.col-type { width: 110px; }
.devices-table-view th.col-location { width: 150px; }
.devices-table-view th.col-temp,
.devices-table-view th.col-hum,
.devices-table-view th.col-press,
.devices-table-view th.col-batt,
.devices-table-view th.col-power { width: 100px; }
.devices-table-view th.col-updated { width: 130px; }
.devices-table-view th.col-actions { width: 100px; text-align: right; }

.devices-table-view td {
    padding: 10px 14px;
    font-size: 0.8rem;
    border-bottom: 1px solid #eef2f6;
    color: #1e293b;
    vertical-align: middle;
}

.devices-table-view tr {
    transition: background 0.15s ease;
    cursor: pointer;
    position: relative;
}

.devices-table-view tr:hover {
    background: #f0f9ff;
}

.devices-table-view tr.inactive-row {
    opacity: 0.55;
    background: #f8fafc;
}

/* ★ НОВОЕ: строки с уровнем тревоги */
.devices-table-view tr.alert-level-warning {
    background: linear-gradient(90deg, #fffbeb 0%, #ffffff 15%);
    border-left: 4px solid #fbbf24;
}
.devices-table-view tr.alert-level-warning:hover {
    background: linear-gradient(90deg, #fef3c7 0%, #ffffff 20%);
}

.devices-table-view tr.alert-level-alert {
    background: linear-gradient(90deg, #fff7ed 0%, #ffffff 15%);
    border-left: 4px solid #f97316;
}
.devices-table-view tr.alert-level-alert:hover {
    background: linear-gradient(90deg, #fed7aa 0%, #ffffff 20%);
}

.devices-table-view tr.alert-level-critical {
    background: linear-gradient(90deg, #fef2f2 0%, #ffffff 15%);
    border-left: 4px solid #ef4444;
    animation: table-critical-pulse 2s ease-in-out infinite;
}
.devices-table-view tr.alert-level-critical:hover {
    background: linear-gradient(90deg, #fee2e2 0%, #ffffff 20%);
}

@keyframes table-critical-pulse {
    0%, 100% { background-color: rgba(254, 226, 226, 0.5); }
    50% { background-color: rgba(254, 226, 226, 1); }
}

/* Статус */
.devices-table-view .status-cell {
    width: 30px;
    text-align: center;
}

.devices-table-view .status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.devices-table-view .status-dot.active { background: #22c55e; box-shadow: 0 0 6px rgba(34, 197, 94, 0.6); }
.devices-table-view .status-dot.inactive { background: #ef4444; box-shadow: 0 0 4px rgba(239, 68, 68, 0.4); }

/* Имя устройства */
.devices-table-view .device-name-cell {
    font-weight: 500;
    color: #0c4a6e;
    line-height: 1.3;
}

.devices-table-view .device-name-cell .device-id-small {
    display: block;
    font-size: 0.55rem;
    font-family: monospace;
    color: #88a4bc;
    font-weight: 400;
    margin-top: 1px;
}

.devices-table-view .device-name-cell .alert-badge-inline {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.5rem;
    padding: 1px 5px;
    border-radius: 8px;
    font-weight: 700;
    vertical-align: middle;
}

.devices-table-view .device-name-cell .alert-badge-inline.warning { background: #fef3c7; color: #92400e; }
.devices-table-view .device-name-cell .alert-badge-inline.alert { background: #fed7aa; color: #9a3412; }
.devices-table-view .device-name-cell .alert-badge-inline.critical { background: #fee2e2; color: #991b1b; }

/* Тип устройства (badge) */
.devices-table-view .type-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 600;
    white-space: nowrap;
}

.devices-table-view .type-badge.sensor { background: #dcfce7; color: #166534; }
.devices-table-view .type-badge.heater { background: #ffedd5; color: #c2410c; }
.devices-table-view .type-badge.button { background: #e0e7ff; color: #4338ca; }

/* Локация */
.devices-table-view .location-cell {
    font-size: 0.7rem;
    color: #2c6e9e;
}

/* Значения */
.devices-table-view .value-cell {
    font-weight: 600;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    position: relative;
}

.devices-table-view .value-cell .unit {
    font-size: 0.6rem;
    color: #64748b;
    font-weight: 400;
    margin-left: 3px;
}

.devices-table-view .value-cell.temp { color: #dc2626; }
.devices-table-view .value-cell.humidity { color: #16a34a; }
.devices-table-view .value-cell.pressure { color: #8b5cf6; }
.devices-table-view .value-cell.battery { color: #f59e0b; }
.devices-table-view .value-cell.battery.battery-critical { color: #dc2626; animation: battery-critical-pulse 2s ease-in-out infinite; }
.devices-table-view .value-cell.battery.battery-low { color: #f59e0b; }
.devices-table-view .value-cell.battery.battery-medium { color: #d97706; }
.devices-table-view .value-cell.power { color: #f59e0b; }
.devices-table-view .value-cell.coolant { color: #dc2626; }
.devices-table-view .value-cell.room { color: #3b82f6; }
.devices-table-view .value-cell.empty { color: #cbd5e1; font-weight: 400; }

/* ★ НОВОЕ: значения с уровнем тревоги */
.devices-table-view .value-cell.alert-warning { 
    background: #fef3c7; 
    padding: 2px 6px; 
    border-radius: 6px;
    color: #92400e;
}

.devices-table-view .value-cell.alert-alert { 
    background: #fed7aa; 
    padding: 2px 6px; 
    border-radius: 6px;
    color: #9a3412;
    font-weight: 700;
}

.devices-table-view .value-cell.alert-critical { 
    background: #fee2e2; 
    padding: 2px 6px; 
    border-radius: 6px;
    color: #991b1b;
    font-weight: 700;
    animation: badge-critical-blink 1s ease-in-out infinite;
}

/* Обновление */
.devices-table-view .updated-cell {
    font-size: 0.65rem;
    color: #6b7280;
    white-space: nowrap;
}

.devices-table-view .updated-cell.stale {
    color: #f59e0b;
    font-weight: 600;
}

.devices-table-view .updated-cell .age {
    display: block;
    font-size: 0.55rem;
    color: #f59e0b;
    margin-top: 1px;
}

/* Действия */
.devices-table-view .actions-cell {
    text-align: right;
    white-space: nowrap;
}

.devices-table-view .actions-cell .icon-btn {
    width: 28px !important;
    height: 28px !important;
    font-size: 0.75rem !important;
    margin-left: 4px;
}

.devices-table-view .actions-cell .icon-btn.power-on {
    background: #dc2626 !important;
}

.devices-table-view .actions-cell .icon-btn.power-on:hover {
    background: #b91c1c !important;
}

/* Пустое состояние */
.devices-table-view .empty-table-state {
    text-align: center;
    padding: 60px 30px;
    color: #6c8eae;
    font-size: 0.9rem;
}

.devices-table-view .empty-table-state i {
    font-size: 3rem;
    color: #9ca3af;
    margin-bottom: 16px;
    display: block;
}

/* ============================================
   ПУСТЫЕ СОСТОЯНИЯ И ЗАГРУЗКА
   ============================================ */

.empty-state { text-align: center; color: #6c8eae; padding: 60px 30px; background: white; border-radius: 40px; }
.empty-state i { font-size: 3rem; color: #9ca3af; margin-bottom: 16px; display: block; }
.empty-state .btn-primary { margin-top: 16px; background: #0284c7; color: white; border: none; padding: 10px 24px; border-radius: 40px; cursor: pointer; font-size: 0.9rem; }
.empty-state .btn-primary:hover { background: #0369a1; }

.loading-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.9); z-index: 9999; justify-content: center; align-items: center; }
.loading-overlay.active { display: flex; }
.loading-spinner { width: 40px; height: 40px; border: 3px solid #e2e8f0; border-top-color: #0284c7; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   МОДАЛЬНЫЕ ОКНА
   ============================================ */

.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 20, 30, 0.6); backdrop-filter: blur(4px); justify-content: center; align-items: center; z-index: 1100; }
.modal.active { display: flex; }
.modal-content { background: white; padding: 28px; border-radius: 32px; max-width: 1000px; width: 90%; max-height: 85vh; overflow-y: auto; }
.modal-content h2 { font-size: 1.3rem; font-weight: 500; color: #0369a1; margin-bottom: 20px; display: flex; align-items: center; gap: 10px; }

.action-icon { background: none; border: none; cursor: pointer; padding: 6px; border-radius: 8px; transition: 0.2s; font-size: 1rem; }
.action-icon.add { color: #22c55e; }
.action-icon.add:hover { background: #dcfce7; }
.action-icon.edit { color: #0284c7; }
.action-icon.edit:hover { background: #e0f2fe; }
.action-icon.delete { color: #dc2626; }
.action-icon.delete:hover { background: #fee2e2; }

.btn { padding: 10px 20px; border-radius: 40px; font-weight: 500; border: none; cursor: pointer; transition: 0.2s; font-size: 0.85rem; }
.btn-primary { background: #0284c7; color: white; }
.btn-primary:hover { background: #0369a1; }
.btn-secondary { background: #e2e8f0; color: #2d3e50; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: #dc2626; color: white; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

.form-group { margin: 20px 0; }
.form-group label { display: block; font-size: 0.75rem; font-weight: 600; color: #2c6e9e; margin-bottom: 8px; text-transform: uppercase; }
.form-group input, .form-group select { width: 100%; padding: 12px 16px; border: 2px solid #e2edf7; border-radius: 24px; font-size: 0.9rem; }

.info-row { display: flex; padding: 10px 0; border-bottom: 1px solid #eef2f6; }
.info-label { width: 160px; font-weight: 600; color: #2c6e9e; }
.info-value { flex: 1; color: #1e293b; }

.device-info-sensors { margin-top: 16px; background: #f8fafc; border-radius: 20px; padding: 16px; }
.device-info-sensors h4 { color: #0369a1; margin-bottom: 12px; font-size: 0.85rem; }
.sensor-tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.sensor-tag { background: #f8fafc; padding: 6px 12px; border-radius: 20px; margin: 4px; display: inline-block; font-size: 0.75rem; border: 1px solid #e2edf7; }

.device-list-checkboxes { max-height: 200px; overflow-y: auto; border: 1px solid #e2edf7; border-radius: 16px; padding: 10px; background: #fafeff; }
.device-checkbox-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid #eef2f6; }
.device-checkbox-item:last-child { border-bottom: none; }
.device-checkbox-item input { width: 18px; height: 18px; cursor: pointer; }
.device-checkbox-item label { margin: 0; font-size: 0.85rem; font-weight: normal; text-transform: none; color: #1e293b; cursor: pointer; flex: 1; }
.device-checkbox-item .device-type-badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 20px; background: #e2edf7; color: #2c6e9e; }
.access-hint { font-size: 0.7rem; color: #6b7280; margin-top: 8px; display: flex; align-items: center; gap: 6px; }

/* ============================================
   ГРАФИКИ
   ============================================ */

.chart-container { margin: 20px 0; position: relative; }
canvas { max-height: 300px; width: 100%; }
.param-selector { display: flex; justify-content: flex-end; margin-bottom: 20px; align-items: center; }
.param-selector select { padding: 8px 16px; border-radius: 24px; border: 1px solid #e2edf7; background: white; font-size: 0.85rem; width: auto; }

.modal-chart-section { margin-top: 20px; position: relative; }
.heater-chart-container { margin: 15px 0; position: relative; }
.chart-period-selector { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 15px; align-items: center; justify-content: flex-end; }
.chart-period-selector select { padding: 6px 12px; border-radius: 20px; border: 1px solid #e2edf7; background: white; font-size: 0.75rem; }
.chart-stats { font-size: 0.7rem; color: #6b7280; text-align: center; margin-top: 10px; }

.reset-zoom-btn { position: absolute; bottom: 10px; right: 10px; background: #0284c7; color: white; border: none; border-radius: 20px; padding: 5px 12px; font-size: 0.7rem; cursor: pointer; z-index: 100; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: background 0.2s; }
.reset-zoom-btn:hover { background: #0369a1; }

/* ============================================
   СЛАЙДЕРЫ
   ============================================ */

.slider-container { margin: 24px 0; width: 100%; }
.slider { width: 100%; height: 6px; border-radius: 10px; background: #e2e8f0; -webkit-appearance: none; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; background: #0284c7; border-radius: 50%; cursor: pointer; }
.slider-value { font-size: 1.2rem; font-weight: 500; text-align: center; margin-bottom: 12px; color: #0284c7; }

.dual-slider-item { margin: 20px 0; }
.dual-slider-item label { display: block; font-size: 0.75rem; font-weight: 500; color: #0369a1; margin-bottom: 8px; }
.slider-info { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 12px; color: #6b7280; }

.control-section { margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid #e2edf7; }
.sync-checkbox { display: flex; align-items: center; gap: 12px; margin: 15px 0 10px 0; padding: 8px 12px; background: #f0f9ff; border-radius: 40px; border: 1px solid #cde9fe; }
.sync-checkbox label { font-size: 0.8rem; font-weight: 500; color: #0369a1; cursor: pointer; margin: 0; display: flex; align-items: center; gap: 8px; }
.sync-checkbox input { width: 18px; height: 18px; cursor: pointer; margin: 0; }

/* ============================================
   НАСТРОЙКИ
   ============================================ */

.settings-section { margin: 20px 0; }
.settings-item { margin-bottom: 24px; }
.settings-item:last-child { margin-bottom: 0; }
.settings-switch { display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.settings-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.settings-switch-slider { position: relative; display: inline-block; width: 50px; height: 24px; background-color: #ccc; border-radius: 24px; transition: 0.3s; }
.settings-switch-slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: 0.3s; }
.settings-switch input:checked + .settings-switch-slider { background-color: #0284c7; }
.settings-switch input:checked + .settings-switch-slider:before { transform: translateX(26px); }
.settings-switch-label { flex: 1; margin-left: 12px; font-size: 0.9rem; font-weight: 500; color: #1e293b; }
.settings-label { display: block; font-size: 0.9rem; font-weight: 500; color: #1e293b; margin-bottom: 8px; }
.settings-select { width: 100%; padding: 10px 12px; border: 1px solid #cde9fe; border-radius: 12px; font-size: 0.85rem; background: white; color: #0c4a6e; cursor: pointer; }
.settings-hint { font-size: 0.7rem; color: #6b7280; margin-top: 6px; }

/* ============================================
   ПОМОЩЬ
   ============================================ */

.help-content { max-height: 60vh; overflow-y: auto; padding-right: 8px; }
.help-section { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid #e2edf7; }
.help-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.help-section h3 { font-size: 1rem; font-weight: 600; color: #0369a1; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.help-section p { font-size: 0.85rem; color: #334155; line-height: 1.5; margin-left: 28px; }
.help-section strong { color: #ea580c; }

/* ============================================
   УВЕДОМЛЕНИЯ
   ============================================ */

.notification { position: fixed; bottom: 24px; right: 24px; background: #0c4a6e; color: white; padding: 12px 22px; border-radius: 60px; z-index: 1300; display: none; font-weight: 500; font-size: 0.85rem; }
.notification.show { display: block; }
.notification.error { background: #dc2626; }

/* ============================================
   ДЕБАГ
   ============================================ */

.debug-panel { background: #1e293b; color: #a5f3fc; padding: 12px 20px; border-radius: 12px; margin-bottom: 20px; font-family: monospace; font-size: 12px; max-height: 160px; overflow-y: auto; display: none; }
.debug-panel.visible { display: block; }
.debug-log { max-height: 108px; overflow-y: auto; font-size: 11px; line-height: 1.4; }
.debug-log div { padding: 2px 0; border-bottom: 1px solid rgba(165, 243, 252, 0.2); white-space: nowrap; overflow-x: hidden; text-overflow: ellipsis; }

/* ============================================
   ВСПОМОГАТЕЛЬНЫЕ КЛАССЫ
   ============================================ */

.main-content-hidden { opacity: 0; transition: opacity 0.2s ease; }
.main-content-visible { opacity: 1; }
.spinning { animation: spin 0.5s linear infinite; }
.btn-pressed { transform: scale(0.95); transition: transform 0.05s ease; }

/* ============================================
   СОСТОЯНИЕ КНОПОК (ON/OFF)
   ============================================ */

.device-btn-simple.state-on { background: #86efac !important; border-color: #4ade80 !important; box-shadow: 0 3px 10px rgba(74, 222, 128, 0.3); }
.device-btn-simple.state-off { background: #fca5a5 !important; border-color: #f87171 !important; box-shadow: 0 3px 10px rgba(248, 113, 113, 0.3); }

.btn-state-indicator { position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: #f87171; box-shadow: 0 0 4px rgba(248, 113, 113, 0.6); transition: background-color 0.3s ease; z-index: 5; }
.btn-state-indicator.is-on { background: #4ade80; box-shadow: 0 0 4px rgba(74, 222, 128, 0.6); }

/* ============================================
   АДАПТИВНОСТЬ
   ============================================ */

@media (max-width: 768px) {
    .device-group { margin-bottom: 12px; }
    .device-group-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
    .device-card { max-width: none; }
    .card-header-actions { opacity: 1; pointer-events: auto; position: static; margin-left: auto; }
    .device-card-header { flex-wrap: wrap; }
    .card-header-actions .icon-btn { width: 20px !important; height: 20px !important; font-size: 0.6rem !important; }
    .power-btn { padding: 3px 8px !important; font-size: 0.6rem !important; }
    .icon-btn { width: 24px !important; height: 24px !important; font-size: 0.7rem !important; }
    .sensor-big-row { gap: 4px; }
    .sensor-big-block { min-height: 58px; padding: 5px 4px; }
    .sensor-big-value { font-size: 1.1rem; }
    .sensor-big-unit { font-size: 0.6rem; }
    .sensor-big-icon { font-size: 0.8rem; }
    .buttons-grid-simple { gap: 8px; }
    .device-btn-simple { width: 56px; height: 56px; }
    .device-btn-simple .btn-number { font-size: 1.3rem; }
    .device-btn-simple .btn-label-inside { font-size: 0.4rem; }
    .btn-label-simple { font-size: 0.55rem; max-width: 56px; }
    .switch-item { flex-wrap: wrap; gap: 6px; }
    .switch-label { font-size: 0.6rem; }
    .switch-state { font-size: 0.5rem; }

    .devices-table-view {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .devices-table-view table { min-width: 900px; }
    .devices-table-view th, .devices-table-view td { padding: 8px 10px; font-size: 0.7rem; }
    .devices-table-view .value-cell { font-size: 0.75rem; }
    .devices-table-view .actions-cell .icon-btn { width: 24px !important; height: 24px !important; font-size: 0.65rem !important; }

    .view-toggle { margin-left: 0; align-self: center; }
}

@media (max-width: 480px) {
    body { padding: 12px; }
    h1 { font-size: 1.4rem; }
    .device-group { margin-bottom: 10px; }
    .device-group-grid { grid-template-columns: 1fr; gap: 8px; }
    .device-card { max-width: none; }
    .card-header-actions .icon-btn { width: 18px !important; height: 18px !important; font-size: 0.55rem !important; }
    .sensor-metric-icon, .coolant-icon, .room-icon, .power-icon { width: 26px !important; font-size: 0.8rem !important; }
    .sensor-metric-main, .coolant-value, .room-value, .power-value { font-size: 0.85rem !important; }
    .modal-content { padding: 20px; width: 95%; }
    .tabs { flex-direction: column; align-items: stretch; }
    .tabs-buttons { justify-content: center; }
    .refresh-discovered-btn, .clear-discovered-btn { justify-content: center; }
    .info-label { width: 120px; font-size: 0.7rem; }
    .info-value { font-size: 0.7rem; }
    .chart-period-selector { justify-content: center; }
    .param-selector { justify-content: center; }
    .device-name { font-size: 0.7rem; }
    .device-location { font-size: 0.5rem; }
    .settings-switch-label { font-size: 0.8rem; }
    .help-section h3 { font-size: 0.9rem; }
    .help-section p { font-size: 0.75rem; margin-left: 20px; }
    .sensor-big-row { grid-template-columns: 1fr 1fr; gap: 4px; }
    .sensor-big-block { min-height: 54px; padding: 5px 3px; }
    .sensor-big-value { font-size: 1.05rem; }
    .sensor-big-unit { font-size: 0.55rem; }
    .sensor-big-icon { font-size: 0.75rem; }
    .sensor-big-comment { font-size: 0.45rem; }
    .buttons-grid-simple { gap: 8px; }
    .device-btn-simple { width: 52px; height: 52px; border-width: 2px; }
    .device-btn-simple .btn-number { font-size: 1.15rem; }
    .device-btn-simple .btn-label-inside { font-size: 0.35rem; }
    .btn-label-simple { font-size: 0.5rem; max-width: 52px; }
    .buttons-section-title { font-size: 0.45rem; }
    .toggle-switch { width: 36px; height: 20px; }
    .toggle-slider:before { height: 12px; width: 12px; }
    .toggle-switch input:checked + .toggle-slider:before { transform: translateX(16px); }
    .view-toggle { align-self: stretch; justify-content: center; }
}

@media (max-width: 380px) {
    .sensor-big-row { grid-template-columns: 1fr 1fr; gap: 3px; }
    .sensor-big-block { min-height: 48px; padding: 4px 3px; }
    .sensor-big-value { font-size: 0.95rem; }
    .buttons-grid-simple { gap: 6px; }
    .device-btn-simple { width: 46px; height: 46px; }
    .device-btn-simple .btn-number { font-size: 1rem; }
    .device-btn-simple .btn-label-inside { font-size: 0.3rem; }
    .btn-label-simple { font-size: 0.45rem; max-width: 46px; }
    .btn-state-indicator { top: 3px; right: 3px; width: 5px; height: 5px; }
}
/* ============================================
   V42: Виртуальные MQTT-устройства
   ============================================ */
.virtual-devices-modal-content { max-width: 1120px; }
.virtual-device-form-content { max-width: 900px; }
.virtual-devices-toolbar,
.virtual-controls-heading { display:flex; align-items:center; justify-content:space-between; gap:16px; margin:14px 0 18px; }
.virtual-devices-toolbar > div,
.virtual-controls-heading > div { display:flex; flex-direction:column; gap:4px; }
.virtual-devices-toolbar small,
.virtual-controls-heading small { color:#6b7280; }
.virtual-status-badge { display:inline-flex; align-items:center; border-radius:999px; padding:4px 9px; font-size:.72rem; font-weight:700; }
.virtual-status-badge.enabled { background:#dcfce7; color:#166534; }
.virtual-status-badge.disabled { background:#f1f5f9; color:#64748b; }
.virtual-topics-cell code { display:inline-block; max-width:320px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.68rem; background:#f1f5f9; padding:3px 6px; border-radius:6px; }
.badge-virtual { background:#ede9fe; color:#6d28d9; }
.virtual-device-basic-grid { display:grid; grid-template-columns:1fr 1fr; gap:0 16px; }
.virtual-device-enabled { display:flex; align-items:flex-start; gap:10px; margin:8px 0 20px; padding:12px 14px; border:1px solid #dbeafe; background:#f8fbff; border-radius:14px; cursor:pointer; }
.virtual-device-enabled input { margin-top:3px; }
.virtual-device-enabled span { display:flex; flex-direction:column; gap:2px; }
.virtual-device-enabled small { color:#64748b; }
.virtual-controls-section { border-top:1px solid #e5e7eb; padding-top:14px; }
.virtual-control-editor { border:1px solid #dbe4ef; background:#fbfdff; border-radius:16px; padding:14px; margin:12px 0; }
.virtual-control-editor-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
.virtual-control-editor-head strong { display:flex; align-items:center; gap:8px; color:#334155; }
.virtual-control-remove { border:0; background:#fee2e2; color:#b91c1c; width:32px; height:32px; border-radius:50%; cursor:pointer; }
.virtual-control-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.virtual-control-grid label { display:flex; flex-direction:column; gap:5px; font-size:.76rem; color:#475569; }
.virtual-control-grid label.wide { grid-column:1 / -1; }
.virtual-control-grid label.check { flex-direction:row; align-items:center; gap:8px; padding:8px 10px; background:#f8fafc; border-radius:10px; }
.virtual-control-grid input[type="text"],
.virtual-control-grid input[type="number"],
.virtual-control-grid select,
.virtual-control-grid textarea { width:100%; border:1px solid #cbd5e1; border-radius:10px; padding:9px 10px; background:#fff; font:inherit; color:#0f172a; }
.virtual-control-grid textarea { resize:vertical; min-height:58px; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; }

.virtual-device-card { padding:0; overflow:hidden; border:1px solid #ddd6fe; background:linear-gradient(145deg,#ffffff,#f7f5ff); }
.virtual-device-card.virtual-disabled { opacity:.72; }
.virtual-card-header { display:grid; grid-template-columns:auto 1fr auto; gap:12px; align-items:center; padding:18px 18px 12px; }
.virtual-card-icon { width:48px; height:48px; border-radius:15px; display:grid; place-items:center; background:#ede9fe; color:#7c3aed; font-size:1.25rem; }
.virtual-card-heading { min-width:0; display:flex; flex-direction:column; gap:2px; }
.virtual-card-heading small { color:#7c3aed; font-size:.68rem; text-transform:uppercase; letter-spacing:.06em; }
.virtual-card-heading strong { color:#172033; font-size:1.05rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.virtual-card-heading span { color:#64748b; font-size:.72rem; }
.virtual-card-controls { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:10px; padding:10px 18px 16px; }
.virtual-control-button { border:1px solid #ddd6fe; background:#fff; border-radius:14px; padding:12px; display:grid; grid-template-columns:auto 1fr; gap:9px; align-items:center; text-align:left; cursor:pointer; transition:.15s ease; min-height:68px; position:relative; }
.virtual-control-button:hover:not(:disabled) { border-color:#8b5cf6; box-shadow:0 7px 18px rgba(124,58,237,.12); transform:translateY(-1px); }
.virtual-control-button:disabled { cursor:not-allowed; opacity:.55; }
.virtual-control-button.is-sending { opacity:.7; }
.virtual-control-button.is-cooldown { opacity:.65; }
.virtual-control-icon { width:36px; height:36px; display:grid; place-items:center; border-radius:11px; background:#f3e8ff; color:#7e22ce; }
.virtual-control-copy { display:flex; flex-direction:column; min-width:0; }
.virtual-control-copy strong { color:#1e293b; font-size:.82rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.virtual-control-copy small { color:#64748b; font-size:.62rem; margin-top:2px; }
.virtual-control-state { grid-column:1/-1; color:#7c3aed; font-size:.61rem; text-transform:uppercase; letter-spacing:.05em; }
.virtual-card-footer { display:flex; justify-content:space-between; gap:12px; padding:10px 18px; background:rgba(237,233,254,.45); color:#64748b; font-size:.66rem; }
.virtual-card-footer i { font-size:.48rem; color:#16a34a; }
.virtual-table-controls { flex-wrap:wrap; }
.virtual-table-action { min-width:140px; }



/* Virtual controls v43: buttons + switches */
.virtual-switch-config-title{margin:12px 0 8px;font-weight:700;color:#5b21b6;font-size:.82rem;display:flex;gap:7px;align-items:center}
.virtual-control-common{margin-top:10px;padding-top:10px;border-top:1px dashed #ddd6fe}
.virtual-topic-separator{border:0;border-top:1px solid #ede9fe;margin:6px 0}
.virtual-switch-control{border:1px solid #d8dce5;background:#fff;border-radius:14px;padding:12px 13px;display:grid;grid-template-columns:1fr auto auto;gap:12px;align-items:center;text-align:left;cursor:pointer;min-height:60px;transition:.15s ease}
.virtual-switch-control:hover:not(:disabled){transform:translateY(-1px);box-shadow:0 5px 15px rgba(15,23,42,.08)}
.virtual-switch-copy{display:flex;flex-direction:column;gap:2px;min-width:0}.virtual-switch-copy strong{color:#172033}.virtual-switch-copy small{color:#64748b;font-size:.68rem}
.virtual-toggle-track{width:46px;height:26px;border-radius:999px;background:#cbd5e1;padding:3px;transition:.15s ease;display:block}.virtual-toggle-thumb{display:block;width:20px;height:20px;border-radius:50%;background:#fff;box-shadow:0 1px 4px rgba(0,0,0,.22);transition:.15s ease}
.virtual-switch-control.is-on{border-color:#86efac;background:#f0fdf4}.virtual-switch-control.is-on .virtual-toggle-track{background:#22c55e}.virtual-switch-control.is-on .virtual-toggle-thumb{transform:translateX(20px)}
.virtual-switch-control.is-off .virtual-control-state{color:#64748b}.virtual-switch-control.is-on .virtual-control-state{color:#15803d}.virtual-switch-control.is-unknown .virtual-toggle-track{background:#94a3b8}.virtual-switch-control.is-unknown .virtual-control-state{color:#64748b}
.virtual-switch-control:disabled{opacity:.55;cursor:not-allowed}.virtual-switch-control.is-sending{opacity:.7}
.virtual-table-switch.is-on{border-color:#86efac;background:#f0fdf4}.virtual-table-switch.is-on i{color:#16a34a}.virtual-table-switch.is-off i{color:#64748b}.virtual-table-switch.is-unknown i{color:#94a3b8}


/* ============================================
   VPN / TELEGRAM PROXY STATUS IN HEADER
   ============================================ */
.vpn-status-wrap { position: relative; flex: 0 0 auto; }
.vpn-status-btn {
    height: 34px; min-width: 66px; padding: 0 11px 0 9px; border: 1px solid #dbe7ef;
    border-radius: 999px; background: #f8fafc; color: #475569; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font: inherit; font-size: .72rem; font-weight: 700; transition: .18s ease;
}
.vpn-status-btn:hover { background: #f1f5f9; transform: translateY(-1px); }
.vpn-status-dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; box-shadow: 0 0 0 3px rgba(148,163,184,.14); }
.vpn-status-icon { font-size: .83rem; }
.vpn-status-ok { color: #15803d; background: #f0fdf4; border-color: #bbf7d0; }
.vpn-status-ok .vpn-status-dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.13); }
.vpn-status-updating { color: #a16207; background: #fffbeb; border-color: #fde68a; }
.vpn-status-updating .vpn-status-dot { background: #eab308; box-shadow: 0 0 0 3px rgba(234,179,8,.14); animation: vpnPulse 1.2s infinite; }
.vpn-status-error, .vpn-status-rollback { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.vpn-status-error .vpn-status-dot, .vpn-status-rollback .vpn-status-dot { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.13); }
.vpn-status-unknown, .vpn-status-stale { color: #64748b; background: #f8fafc; border-color: #e2e8f0; }
@keyframes vpnPulse { 50% { opacity: .4; transform: scale(.82); } }
.vpn-status-popover {
    position: absolute; top: calc(100% + 10px); right: 0; width: min(330px, calc(100vw - 28px));
    padding: 15px; border-radius: 18px; border: 1px solid #dce8ef; background: rgba(255,255,255,.98);
    box-shadow: 0 18px 50px rgba(15,23,42,.18); backdrop-filter: blur(14px); z-index: 1300;
}
.vpn-popover-head { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.vpn-popover-head > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.vpn-popover-head strong { color: #0f3d5e; font-size: .9rem; }
.vpn-popover-head small { color: #64748b; font-size: .72rem; line-height: 1.25; }
.vpn-popover-shield { width: 34px; height: 34px; border-radius: 12px; background: #e0f2fe; color: #0284c7; display: grid; place-items: center; flex: 0 0 auto; }
.vpn-popover-grid { display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; align-items: baseline; border-top: 1px solid #eef2f6; padding-top: 11px; }
.vpn-popover-grid span { color: #64748b; font-size: .72rem; }
.vpn-popover-grid strong { color: #1e293b; font-size: .74rem; text-align: right; font-weight: 700; }
.vpn-status-stale-note { margin-top: 11px; padding: 8px 10px; border-radius: 10px; background: #fff7ed; color: #c2410c; font-size: .7rem; }

/* Custom device card background editor */
.device-background-editor .device-background-preview {
    position: relative;
    width: 100%;
    height: 150px;
    margin: 8px 0 10px;
    border: 1px dashed rgba(100,116,139,.45);
    border-radius: 14px;
    overflow: hidden;
    background: rgba(148,163,184,.08);
}
.device-background-editor .device-background-preview img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center;
}
.device-background-editor .device-background-preview span {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #64748b;
    font-size: .92rem;
}
.device-background-editor input[type="file"] {
    width: 100%;
}
.device-background-editor .device-background-actions {
    display: flex;
    gap: 8px;
    margin-top: 9px;
    flex-wrap: wrap;
}

/* Tuya Cloud local usage dashboard */
.tuya-usage-panel {
    margin: 12px 0 16px;
    padding: 14px;
    border: 1px solid rgba(148,163,184,.28);
    border-radius: 16px;
    background: rgba(248,250,252,.82);
}
.tuya-usage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.tuya-usage-status {
    font-size: .78rem;
    font-weight: 600;
    color: #64748b;
}
.tuya-usage-status i { font-size: .55rem; margin-right: 5px; }
.tuya-usage-status.connected { color: #15803d; }
.tuya-usage-status.degraded { color: #b45309; }
.tuya-usage-status.disconnected { color: #b91c1c; }
.tuya-usage-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: 9px;
}
.tuya-usage-card {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    padding: 10px;
    border: 1px solid rgba(148,163,184,.22);
    border-radius: 12px;
    background: #fff;
}
.tuya-usage-card.warning { border-color: rgba(245,158,11,.55); }
.tuya-usage-card.danger { border-color: rgba(220,38,38,.58); }
.tuya-usage-card-icon {
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    background: rgba(14,165,233,.10);
    color: #0284c7;
}
.tuya-usage-card-title {
    color: #64748b;
    font-size: .68rem;
    line-height: 1.2;
}
.tuya-usage-card-value {
    margin-top: 2px;
    font-weight: 750;
    font-size: .92rem;
    color: #0f172a;
    white-space: nowrap;
}
.tuya-usage-card-note {
    margin-top: 2px;
    color: #94a3b8;
    font-size: .62rem;
}
.tuya-usage-progress {
    height: 6px;
    margin-top: 11px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(148,163,184,.22);
}
.tuya-usage-progress span {
    display: block;
    height: 100%;
    min-width: 1px;
    border-radius: inherit;
    background: currentColor;
    color: #0284c7;
}
.tuya-usage-breakdown-row {
    display: flex;
    gap: 10px 14px;
    flex-wrap: wrap;
    margin-top: 8px;
    color: #64748b;
    font-size: .67rem;
}
.tuya-usage-footnote {
    margin-top: 7px;
    color: #94a3b8;
    font-size: .62rem;
}
.tuya-usage-placeholder {
    grid-column: 1 / -1;
    padding: 12px;
    color: #64748b;
    text-align: center;
}
.tuya-usage-placeholder.error { color: #b91c1c; }
@media (max-width: 640px) {
    .tuya-usage-panel { padding: 10px; }
    .tuya-usage-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tuya-usage-card { padding: 8px; gap: 7px; }
    .tuya-usage-card-icon { width: 28px; height: 28px; flex-basis: 28px; }
    .tuya-usage-card-value { font-size: .8rem; }
}

/* Camera wall */
.camera-wall-header-btn {
    border: 0;
    border-radius: 40px;
    padding: 7px 13px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: #0f172a;
    color: #fff;
    cursor: pointer;
    font-size: .75rem;
    font-weight: 650;
}
.camera-wall-header-btn:hover { background: #1e293b; }

.camera-wall-page {
    position: fixed;
    inset: 0;
    z-index: 1650;
    display: none;
    flex-direction: column;
    background: #0b1220;
    color: #fff;
    overflow: hidden;
}
.camera-wall-page.active { display: flex; }
body.camera-wall-open { overflow: hidden; }

.camera-wall-header {
    flex: 0 0 auto;
    min-height: 72px;
    padding: 12px clamp(14px, 2.5vw, 32px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    background: rgba(15,23,42,.97);
    backdrop-filter: blur(16px);
}
.camera-wall-heading,
.camera-wall-actions {
    display: flex;
    align-items: center;
    gap: 11px;
}
.camera-wall-heading { min-width: 0; }
.camera-wall-heading > div { min-width: 0; }
.camera-wall-heading small {
    display: block;
    margin-bottom: 2px;
    color: #94a3b8;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .07em;
}
.camera-wall-heading h2 {
    margin: 0;
    color: #fff;
    font-size: clamp(1rem, 2vw, 1.3rem);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.camera-wall-heading-icon {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: rgba(14,165,233,.16);
    color: #38bdf8;
}
.camera-wall-back,
.camera-wall-close,
.camera-wall-reload {
    border: 1px solid rgba(255,255,255,.1);
    background: rgba(255,255,255,.08);
    color: #fff;
    cursor: pointer;
}
.camera-wall-back,
.camera-wall-close {
    width: 38px;
    height: 38px;
    border-radius: 12px;
}
.camera-wall-reload {
    min-height: 38px;
    padding: 0 13px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.camera-wall-back:hover,
.camera-wall-close:hover,
.camera-wall-reload:hover { background: rgba(255,255,255,.14); }
.camera-wall-count {
    color: #94a3b8;
    font-size: .78rem;
    white-space: nowrap;
}

.camera-wall-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: clamp(12px, 2vw, 24px);
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}
.camera-wall-grid {
    width: min(1600px, 100%);
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(430px, 100%), 1fr));
    gap: clamp(12px, 1.5vw, 20px);
}
.camera-wall-tile {
    min-width: 0;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 18px;
    background: #111827;
    box-shadow: 0 18px 45px rgba(0,0,0,.22);
}
.camera-wall-video-wrap {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 50%, rgba(30,41,59,.65), transparent 55%),
        #020617;
}
.camera-wall-video-wrap video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    background: #000;
}
.camera-wall-stream-status {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-width: 80%;
    padding: 8px 11px;
    border-radius: 10px;
    background: rgba(2,6,23,.78);
    color: #e2e8f0;
    font-size: .78rem;
    text-align: center;
    pointer-events: none;
}
.camera-wall-stream-status.error { color: #fecaca; }
.camera-wall-stream-status.hidden { display: none; }
.camera-wall-live-badge {
    position: absolute;
    left: 10px;
    top: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(2,6,23,.66);
    color: #86efac;
    font-size: .67rem;
    font-weight: 800;
    letter-spacing: .05em;
    backdrop-filter: blur(8px);
}
.camera-wall-live-badge i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
}
.camera-wall-expand {
    position: absolute;
    right: 10px;
    bottom: 10px;
    border: 1px solid rgba(255,255,255,.13);
    border-radius: 10px;
    padding: 8px 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(2,6,23,.66);
    color: #fff;
    cursor: pointer;
    font-size: .72rem;
    backdrop-filter: blur(8px);
}
/* Camera orientation controls */
.camera-wall-media {
    transform: rotate(0deg);
    transform-origin: center center;
    transition: transform .18s ease;
}
.camera-wall-media.camera-media-rotated {
    transform: rotate(180deg);
}
.camera-wall-rotate {
    position: absolute;
    left: 10px;
    bottom: 10px;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255,255,255,.13);
    border-radius: 10px;
    display: inline-grid;
    place-items: center;
    background: rgba(2,6,23,.66);
    color: #fff;
    cursor: pointer;
    font-size: .78rem;
    backdrop-filter: blur(8px);
    z-index: 4;
}
.camera-wall-rotate:hover {
    background: rgba(15,23,42,.9);
}
.camera-wall-rotate.is-on {
    background: rgba(217,119,6,.88);
    border-color: rgba(251,191,36,.55);
}

.camera-wall-expand:hover { background: rgba(15,23,42,.9); }
.camera-wall-tile-footer {
    min-height: 62px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.camera-wall-room-icon {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: rgba(56,189,248,.12);
    color: #38bdf8;
}
.camera-wall-tile-footer strong,
.camera-wall-tile-footer small {
    display: block;
}
.camera-wall-tile-footer strong {
    color: #f8fafc;
    font-size: .9rem;
}
.camera-wall-tile-footer small {
    margin-top: 2px;
    color: #94a3b8;
    font-size: .72rem;
}
.camera-wall-empty {
    min-height: 50vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 9px;
    color: #94a3b8;
    text-align: center;
}
.camera-wall-empty[hidden] { display: none; }
.camera-wall-empty i { font-size: 2.5rem; color: #475569; }
.camera-wall-empty strong { color: #e2e8f0; font-size: 1rem; }
.camera-wall-note {
    width: min(1600px, 100%);
    margin: 14px auto 0;
    color: #64748b;
    font-size: .7rem;
    text-align: center;
}

@media (max-width: 700px) {
    .camera-wall-header-btn { display: none !important; }
    .camera-wall-page { z-index: 1700; }
    .camera-wall-header {
        min-height: 60px;
        padding: 9px 10px;
    }
    .camera-wall-heading-icon { display: none; }
    .camera-wall-count { display: none; }
    .camera-wall-reload {
        width: 36px;
        min-height: 36px;
        padding: 0;
        justify-content: center;
    }
    .camera-wall-reload span { display: none; }
    .camera-wall-back,
    .camera-wall-close {
        width: 36px;
        height: 36px;
    }
    .camera-wall-body {
        padding: 8px 8px calc(84px + env(safe-area-inset-bottom));
    }
    .camera-wall-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .camera-wall-tile { border-radius: 14px; }
    .camera-wall-video-wrap { aspect-ratio: 16 / 10; }
    .camera-wall-tile-footer { min-height: 54px; padding: 8px 10px; }
    .camera-wall-expand span { display: none; }
}

/* Automation scenarios */
body.automation-open { overflow: hidden; }

.automation-modal {
    position: fixed;
    inset: 0;
    z-index: 2300;
    display: none;
    padding: 18px;
    background: rgba(7, 15, 30, .74);
    backdrop-filter: blur(10px);
}
.automation-modal.active { display: flex; }

.automation-shell {
    width: min(1280px, 100%);
    height: min(920px, calc(100vh - 36px));
    margin: auto;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.68);
    border-radius: 28px;
    background: #f8fafc;
    box-shadow: 0 30px 90px rgba(2, 8, 23, .34);
}

.automation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 22px;
    color: #fff;
    background: linear-gradient(135deg, #0f172a, #164e63);
}
.automation-header small {
    display: block;
    margin-bottom: 3px;
    color: rgba(255,255,255,.66);
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.automation-header h2 {
    margin: 0;
    font-size: 1.35rem;
}
.automation-header h2 i { margin-right: 8px; }
.automation-close,
.automation-back {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 12px;
    cursor: pointer;
}
.automation-close {
    color: #fff;
    background: rgba(255,255,255,.12);
}
.automation-close:hover { background: rgba(255,255,255,.22); }

.automation-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 16px;
    border-bottom: 1px solid #dbe4ee;
    background: #fff;
}
.automation-tabs button {
    border: 0;
    border-radius: 12px;
    padding: 9px 14px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #64748b;
    background: transparent;
    cursor: pointer;
    font-weight: 650;
}
.automation-tabs button.active {
    color: #0f766e;
    background: #ecfdf5;
}

.automation-body {
    min-height: 0;
    overflow: auto;
    padding: 18px;
}
.automation-loading,
.automation-error,
.automation-empty {
    min-height: 240px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 9px;
    color: #64748b;
    text-align: center;
}
.automation-empty > i { font-size: 2rem; color: #94a3b8; }

.automation-toolbar,
.automation-editor-head,
.automation-section-title,
.automation-editor-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.automation-toolbar {
    margin-bottom: 14px;
}
.automation-toolbar strong,
.automation-toolbar small {
    display: block;
}
.automation-toolbar strong { color: #0f172a; font-size: 1rem; }
.automation-toolbar small { margin-top: 2px; color: #64748b; font-size: .72rem; }

.automation-primary,
.automation-toolbar button,
.automation-editor-actions button,
.automation-add-rule {
    border: 1px solid #d7e0ea;
    border-radius: 12px;
    padding: 9px 13px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: #fff;
    color: #334155;
    cursor: pointer;
    font-weight: 650;
}
.automation-primary {
    border-color: #0f766e !important;
    color: #fff !important;
    background: #0f766e !important;
}
.automation-primary:hover { background: #115e59 !important; }

.automation-card {
    margin-bottom: 10px;
    padding: 14px;
    display: grid;
    grid-template-columns: minmax(0,1fr) auto;
    gap: 12px;
    border: 1px solid #dbe4ee;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 7px 22px rgba(15,23,42,.04);
}
.automation-card.disabled { opacity: .64; }
.automation-card-main {
    min-width: 0;
    display: flex;
    gap: 12px;
}
.automation-card-icon {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: #065f46;
    background: #d1fae5;
}
.automation-card.disabled .automation-card-icon {
    color: #64748b;
    background: #e2e8f0;
}
.automation-card-copy { min-width: 0; }
.automation-card-title {
    display: flex;
    align-items: center;
    gap: 9px;
}
.automation-card-title strong { color: #0f172a; }
.automation-state {
    padding: 3px 8px;
    border-radius: 999px;
    color: #047857;
    background: #ecfdf5;
    font-size: .64rem;
    font-weight: 700;
}
.automation-card.disabled .automation-state {
    color: #64748b;
    background: #f1f5f9;
}
.automation-card-rule {
    margin-top: 7px;
    color: #475569;
    font-size: .75rem;
}
.automation-card-copy > small {
    display: block;
    margin-top: 8px;
    color: #94a3b8;
    font-size: .65rem;
}
.automation-sep { margin: 0 5px; opacity: .45; }
.when, .if, .then {
    display: inline-flex;
    align-items: center;
    border-radius: 7px;
    padding: 3px 7px;
    font-size: .62rem;
    font-weight: 800;
}
.when { color: #1d4ed8; background: #dbeafe; }
.if { color: #92400e; background: #fef3c7; }
.then { color: #047857; background: #d1fae5; }

.automation-card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.automation-card-actions button,
.automation-remove {
    width: 36px;
    height: 36px;
    border: 1px solid #dbe4ee;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #475569;
    background: #fff;
    cursor: pointer;
}
.automation-card-actions button:hover { background: #f8fafc; }
.automation-card-actions button.danger,
.automation-remove { color: #dc2626; }

.automation-hint {
    margin-top: 13px;
    padding: 10px 12px;
    border-radius: 12px;
    color: #475569;
    background: #eef6ff;
    font-size: .72rem;
}

.automation-editor-head {
    margin-bottom: 14px;
    padding: 13px;
    border: 1px solid #dbe4ee;
    border-radius: 16px;
    background: #fff;
}
.automation-back { color: #334155; background: #f1f5f9; }
.automation-editor-head > div {
    flex: 1;
    min-width: 0;
}
.automation-editor-head small {
    display: block;
    color: #94a3b8;
    font-size: .65rem;
}
.automation-name {
    width: 100%;
    margin-top: 2px;
    border: 0;
    outline: 0;
    color: #0f172a;
    background: transparent;
    font-size: 1.1rem;
    font-weight: 750;
}
.automation-enabled {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #334155;
    font-size: .75rem;
    white-space: nowrap;
}

.automation-builder-section,
.automation-builder-options {
    margin-bottom: 13px;
    padding: 14px;
    border: 1px solid #dbe4ee;
    border-radius: 17px;
    background: #fff;
}
.automation-section-title {
    justify-content: flex-start;
    margin-bottom: 10px;
}
.automation-section-title > div {
    flex: 1;
}
.automation-section-title strong,
.automation-section-title small {
    display: block;
}
.automation-section-title strong { color: #0f172a; font-size: .88rem; }
.automation-section-title small { margin-top: 2px; color: #64748b; font-size: .65rem; }
.automation-section-title > select { width: auto; }

.automation-rule-list {
    display: grid;
    gap: 8px;
}
.automation-rule-row {
    display: grid;
    grid-template-columns: 28px minmax(0,1fr) 36px;
    align-items: start;
    gap: 8px;
    padding: 9px;
    border-radius: 13px;
    background: #f8fafc;
}
.automation-rule-index {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    color: #64748b;
    background: #e2e8f0;
    font-size: .68rem;
    font-weight: 800;
}
.automation-rule-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    min-width: 0;
}
.automation-rule-fields input,
.automation-rule-fields select,
.automation-section-title select,
.automation-builder-options input,
.automation-location-row input {
    min-width: 0;
    width: 100%;
    height: 38px;
    border: 1px solid #d5dee8;
    border-radius: 10px;
    padding: 0 10px;
    color: #1e293b;
    background: #fff;
    font: inherit;
}
.automation-inline-label {
    display: grid;
    grid-template-columns: auto 95px;
    align-items: center;
    gap: 7px;
    color: #64748b;
    font-size: .7rem;
}
.automation-days {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.automation-days label input { display: none; }
.automation-days label span {
    min-width: 34px;
    height: 28px;
    padding: 0 7px;
    display: grid;
    place-items: center;
    border: 1px solid #dbe4ee;
    border-radius: 8px;
    color: #64748b;
    background: #fff;
    cursor: pointer;
    font-size: .65rem;
}
.automation-days label input:checked + span {
    color: #fff;
    border-color: #0f766e;
    background: #0f766e;
}
.automation-add-rule {
    margin-top: 9px;
    padding: 7px 10px;
    font-size: .7rem;
}
.automation-builder-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #334155;
    font-size: .75rem;
}
.automation-builder-options input { width: 100px; }
.automation-builder-options small {
    display: block;
    margin-top: 7px;
    color: #94a3b8;
    font-size: .65rem;
}
.automation-editor-actions {
    justify-content: flex-end;
    padding: 4px 0 12px;
}

.automation-location-list {
    display: grid;
    gap: 8px;
}
.automation-location-row {
    display: grid;
    grid-template-columns: 1.25fr .8fr .8fr 1fr 36px;
    gap: 8px;
    padding: 10px;
    border: 1px solid #dbe4ee;
    border-radius: 13px;
    background: #fff;
}

.automation-log-list {
    display: grid;
    gap: 7px;
}
.automation-log-row {
    display: grid;
    grid-template-columns: 150px minmax(0,1fr);
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
}
.automation-log-row time { color: #94a3b8; font-size: .68rem; }
.automation-log-row strong,
.automation-log-row span,
.automation-log-row small { display: block; }
.automation-log-row strong { color: #1e293b; font-size: .78rem; }
.automation-log-row span { margin-top: 2px; color: #475569; font-size: .7rem; }
.automation-log-row small { margin-top: 3px; color: #94a3b8; font-size: .64rem; }
.automation-log-row.error { border-color: #fecaca; background: #fff7f7; }
.automation-log-row.completed { border-color: #bbf7d0; }

@media (max-width: 760px) {
    .automation-modal {
        padding: 0;
        background: #f8fafc;
    }
    .automation-shell {
        width: 100%;
        height: 100%;
        border: 0;
        border-radius: 0;
    }
    .automation-header { padding: 13px 14px; }
    .automation-tabs {
        overflow-x: auto;
        padding: 7px 8px;
    }
    .automation-tabs button {
        flex: 1 0 auto;
        justify-content: center;
        padding: 8px 10px;
        font-size: .72rem;
    }
    .automation-body { padding: 10px; }
    .automation-toolbar { align-items: flex-start; }
    .automation-toolbar small { max-width: 220px; }
    .automation-card {
        grid-template-columns: 1fr;
        padding: 11px;
    }
    .automation-card-actions {
        justify-content: flex-end;
        border-top: 1px solid #eef2f7;
        padding-top: 8px;
    }
    .automation-card-rule { font-size: .7rem; }
    .automation-editor-head { gap: 8px; }
    .automation-enabled span { display: none; }
    .automation-builder-section { padding: 10px; }
    .automation-section-title {
        align-items: flex-start;
        flex-wrap: wrap;
    }
    .automation-section-title > select {
        width: 100%;
    }
    .automation-rule-row {
        grid-template-columns: 24px minmax(0,1fr) 32px;
        padding: 7px;
    }
    .automation-rule-fields {
        grid-template-columns: 1fr;
    }
    .automation-days { grid-column: auto; }
    .automation-location-row {
        grid-template-columns: 1fr 1fr;
    }
    .automation-location-row input:first-child,
    .automation-location-row input:nth-child(4) {
        grid-column: 1 / -1;
    }
    .automation-log-row {
        grid-template-columns: 1fr;
        gap: 3px;
    }
    .automation-editor-actions {
        position: sticky;
        bottom: -10px;
        padding: 10px;
        margin: 0 -10px -10px;
        background: rgba(248,250,252,.96);
        backdrop-filter: blur(10px);
    }
}

/* Chart analysis redesign */
#sensorChartModal .modal-content,
#tempControlModal .modal-content,
#roomTempControlModal .modal-content,
#powerControlModal .modal-content {
    max-width: 1040px !important;
}

.chart-period-host,
.param-selector,
.chart-period-selector {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
}

.chart-period-source {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.chart-period-pills {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 4px;
    overflow-x: auto;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.chart-period-pill {
    flex: 0 0 auto;
    min-width: 48px;
    height: 34px;
    padding: 0 11px;
    border: 1px solid #dbe4ee;
    border-radius: 999px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-size: .72rem;
    font-weight: 700;
    transition: background .16s ease, color .16s ease, border-color .16s ease, transform .12s ease;
}

.chart-period-pill:hover {
    border-color: #94a3b8;
    color: #334155;
    transform: translateY(-1px);
}

.chart-period-pill.active {
    border-color: #0f766e;
    background: #0f766e;
    color: #fff;
    box-shadow: 0 5px 14px rgba(15,118,110,.18);
}

#sensorChartContainer,
#coolantChartContainer,
#roomChartContainer,
#pwmChartContainer {
    position: relative;
    height: 390px;
    margin: 12px 0 0;
    padding: 44px 10px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    background:
        linear-gradient(180deg, rgba(248,250,252,.96), rgba(255,255,255,.98));
    box-shadow: inset 0 1px 0 rgba(255,255,255,.85);
    overflow: hidden;
}

#sensorChartContainer canvas,
#coolantChartContainer canvas,
#roomChartContainer canvas,
#pwmChartContainer canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-analysis-caption {
    position: absolute;
    top: 11px;
    left: 14px;
    right: 116px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #64748b;
    font-size: .68rem;
    pointer-events: none;
    z-index: 3;
}

.chart-analysis-caption > span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.chart-analysis-caption > span:first-child {
    color: #0f172a;
}

.chart-analysis-caption strong {
    font-size: .72rem;
}

.chart-range-legend {
    margin-left: auto;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-range-legend > i {
    width: 18px;
    height: 7px;
    border-radius: 5px;
    background: rgba(15,118,110,.15);
    border-top: 2px solid #0f766e;
}

.reset-zoom-btn {
    position: absolute;
    top: 9px;
    right: 10px;
    z-index: 5;
    min-height: 30px;
    padding: 0 9px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #dbe4ee;
    border-radius: 9px;
    background: rgba(255,255,255,.92);
    color: #64748b;
    cursor: pointer;
    font-size: .64rem;
    font-weight: 650;
    box-shadow: 0 3px 10px rgba(15,23,42,.05);
}

.reset-zoom-btn:hover {
    color: #0f766e;
    border-color: #99f6e4;
    background: #f0fdfa;
}

.chart-stats,
#chartStats {
    margin-top: 12px !important;
}

.chart-stats-grid {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    color: inherit !important;
    text-align: left !important;
    font-size: inherit !important;
}

.chart-stat-card {
    min-width: 0;
    padding: 10px 11px;
    border: 1px solid #e2e8f0;
    border-radius: 13px;
    background: #fff;
}

.chart-stat-card > span,
.chart-stat-card > strong,
.chart-stat-card > small {
    display: block;
}

.chart-stat-card > span {
    color: #94a3b8;
    font-size: .61rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .045em;
}

.chart-stat-card > strong {
    margin-top: 4px;
    overflow: hidden;
    color: #0f172a;
    font-size: .92rem;
    line-height: 1.12;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chart-stat-card > small {
    margin-top: 3px;
    color: #94a3b8;
    font-size: .58rem;
}

.chart-stat-card.current {
    border-color: #99f6e4;
    background: #f0fdfa;
}

.chart-stat-card.current > strong {
    color: #0f766e;
}

.chart-stat-card.min > strong {
    color: #2563eb;
}

.chart-stat-card.max > strong {
    color: #dc2626;
}

.chart-stat-card.avg > strong {
    color: #7c3aed;
}

.chart-stat-card.delta.up > strong {
    color: #dc2626;
}

.chart-stat-card.delta.down > strong {
    color: #16a34a;
}

.chart-stat-card.delta.flat > strong {
    color: #64748b;
}

.chart-stats-empty {
    grid-column: 1 / -1;
    padding: 12px;
    border-radius: 12px;
    color: #64748b;
    background: #f8fafc;
    text-align: center;
}

.modal-chart-section {
    margin-top: 14px;
    padding-top: 4px;
}

@media (max-width: 700px) {
    #sensorChartModal .modal-content,
    #tempControlModal .modal-content,
    #roomTempControlModal .modal-content,
    #powerControlModal .modal-content {
        width: 96vw;
        max-width: 96vw !important;
    }

    .chart-period-pills {
        gap: 5px;
        padding: 3px 0 5px;
    }

    .chart-period-pill {
        min-width: 44px;
        height: 32px;
        padding: 0 9px;
        font-size: .68rem;
    }

    #sensorChartContainer,
    #coolantChartContainer,
    #roomChartContainer,
    #pwmChartContainer {
        height: 330px;
        padding: 50px 4px 6px;
        border-radius: 15px;
    }

    .chart-analysis-caption {
        top: 9px;
        left: 10px;
        right: 48px;
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 2px 8px;
        font-size: .60rem;
    }

    .chart-analysis-caption .chart-range-legend {
        grid-column: 1 / -1;
        margin-left: 0;
        font-size: .56rem;
    }

    .reset-zoom-btn {
        top: 8px;
        right: 8px;
        width: 32px;
        height: 32px;
        min-height: 32px;
        padding: 0;
        justify-content: center;
        border-radius: 9px;
    }

    .reset-zoom-btn span {
        display: none;
    }

    .chart-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
    }

    .chart-stat-card.current {
        grid-column: 1 / -1;
    }

    .chart-stat-card {
        padding: 9px 10px;
    }

    .chart-stat-card > strong {
        font-size: .86rem;
    }
}

/* Devices manager: keep edit/delete actions accessible on narrow screens */
#devicesManagerModal .modal-content {
    width: min(96vw, 1450px);
    max-width: 1450px;
}

#devicesManagerModal .devices-table-container {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
}

#devicesManagerModal #registeredDevicesTab .devices-table {
    min-width: 1180px;
}

#devicesManagerModal #discoveredDevicesTab .devices-table {
    min-width: 760px;
}

#devicesManagerModal .devices-table th:last-child,
#devicesManagerModal .devices-table td:last-child {
    position: sticky;
    right: 0;
    min-width: 92px;
    width: 92px;
    white-space: nowrap;
    text-align: center;
    background: #fff;
    box-shadow: -8px 0 12px -12px rgba(15, 23, 42, 0.45);
    z-index: 2;
}

#devicesManagerModal .devices-table th:last-child {
    background: #f8fafc;
    z-index: 3;
}

#devicesManagerModal .devices-table tr:hover td:last-child {
    background: #f8fafc;
}

#devicesManagerModal .action-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    margin: 0 2px;
    flex: 0 0 auto;
}

@media (max-width: 600px) {
    #devicesManagerModal {
        align-items: stretch;
    }

    #devicesManagerModal .modal-content {
        width: 100%;
        max-width: none;
        max-height: 100dvh;
        min-height: 100dvh;
        border-radius: 0;
        padding: 14px 10px 20px;
    }

    #devicesManagerModal .devices-table-container {
        margin-top: 12px;
        border-radius: 16px;
    }

    #devicesManagerModal .devices-table th,
    #devicesManagerModal .devices-table td {
        padding: 9px 10px;
        font-size: 0.72rem;
    }

    #devicesManagerModal .devices-table th:last-child,
    #devicesManagerModal .devices-table td:last-child {
        min-width: 84px;
        width: 84px;
    }

    #devicesManagerModal .action-icon {
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }
}

/* Smart switch per-channel names editor */
.smart-switch-channel-editor {
    margin-top: 4px;
    padding: 12px;
    border: 1px solid rgba(148,163,184,.22);
    border-radius: 14px;
    background: rgba(248,250,252,.72);
}
.smart-switch-channel-edit-row {
    display: grid;
    grid-template-columns: minmax(135px, .8fr) minmax(150px, 1.2fr);
    align-items: center;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid rgba(148,163,184,.18);
}
.smart-switch-channel-edit-row:last-child { border-bottom: 0; }
.smart-switch-channel-edit-meta { display:flex; align-items:center; gap:9px; min-width:0; }
.smart-switch-channel-edit-meta > span:last-child { display:flex; flex-direction:column; min-width:0; }
.smart-switch-channel-edit-meta strong { font-size:.82rem; }
.smart-switch-channel-edit-meta small { color:#64748b; font-size:.68rem; }
.smart-switch-channel-edit-index {
    width: 30px; height: 30px; flex: 0 0 30px;
    display:grid; place-items:center;
    border-radius:50%;
    color:#fff; background:#0f766e;
    font-weight:800; font-size:.75rem;
}
.smart-switch-channel-edit-row input { width:100%; min-width:0; }
.smart-switch-channel-empty { padding:10px; color:#64748b; font-size:.78rem; }
@media (max-width:600px) {
    .smart-switch-channel-edit-row { grid-template-columns:1fr; gap:7px; }
}

.connection-notice { margin: 12px 0; padding: 10px 16px; border-radius: 12px; background: #fff7ed; color: #9a3412; font-size: 14px; }
.connection-notice[hidden] { display: none; }
#diagnosticsModal .debug-panel { max-height: 380px; margin-top: 16px; }
#diagnosticsModal .debug-log { height: min(320px, 45vh); max-height: min(320px, 45vh); }

/* Delete action in device card settings. */
.device-settings-actions { flex-wrap: wrap; }
.device-settings-actions .device-settings-delete { margin-right: auto; }
.device-settings-actions .device-settings-delete[hidden] { display: none; }
.device-settings-actions .device-settings-delete:disabled { opacity: .6; cursor: wait; }
@media (max-width: 480px) {
    .device-settings-actions .device-settings-delete { width: 100%; margin-right: 0; }
}
