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

* { 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: 28px; 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; }

/* ============================================
   СЕТКА КАРТОЧЕК
   ============================================ */

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

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

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

.device-group-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 16px;
    width: 100%;
}

/* ============================================
   КАРТОЧКА УСТРОЙСТВА (ОБЩАЯ)
   ============================================ */

.device-card {
    background: white;
    border-radius: 18px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
    border: 1px solid #dcf2ff;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    width: auto;
    min-width: 280px;
    max-width: 350px;
    flex-shrink: 0;
}
.device-card:hover { box-shadow: 0 8px 20px rgba(2, 132, 199, 0.12); border-color: #b8dff5; }
.device-card.inactive { opacity: 0.65; background: #f5f7fa; border-color: #d4dee8; filter: grayscale(0.3); pointer-events: none; }
.device-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; min-width: 0; gap: 8px; flex-wrap: wrap; }
.device-name { font-size: 0.9rem; font-weight: 500; color: #0369a1; letter-spacing: -0.2px; display: flex; align-items: center; gap: 6px; white-space: normal; word-break: keep-all; }
.device-location { font-size: 0.65rem; background: #eef4fa; padding: 2px 10px; border-radius: 40px; color: #2c6e9e; font-weight: 500; display: flex; align-items: center; gap: 4px; white-space: nowrap; flex-shrink: 0; }

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

.sensor-big-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.sensor-big-block {
    background: #fafeff;
    border-radius: 16px;
    border: 1px solid #e2edf7;
    padding: 12px 8px;
    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: 90px;
    border-top-width: 3px;
    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: 1.2rem;
    margin-bottom: 2px;
}

.sensor-big-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.2;
}

.sensor-big-unit {
    font-size: 0.9rem;
    font-weight: 400;
    color: #64748b;
    margin-left: 2px;
}

.sensor-big-comment {
    font-size: 0.65rem;
    color: #475569;
    margin-top: 2px;
}

.sensor-small-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sensor-metrics-stack { margin: 4px 0; }
.sensor-metric-block { display: flex; background: #fafeff; border-radius: 16px; border: 1px solid #e2edf7; overflow: hidden; margin-bottom: 0; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease; border-left-width: 3px; 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: 40px; flex-shrink: 0; font-size: 1.2rem; }
.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: 8px 10px; }
.sensor-metric-label { font-size: 0.6rem; font-weight: 600; color: #2c6e9e; margin-bottom: 2px; text-transform: uppercase; letter-spacing: 0.3px; }
.sensor-metric-main { font-size: 1.2rem; font-weight: 500; color: #0b3b4f; line-height: 1.15; }
.sensor-metric-unit { font-size: 0.7rem; color: #64748b; font-weight: 400; margin-left: 4px; }
.sensor-metric-comment { font-size: 0.55rem; color: #475569; margin-top: 2px; display: flex; align-items: center; gap: 4px; }
.sensor-metrics-empty { text-align: center; color: #6c8eae; padding: 12px 10px; background: #f8fafc; border-radius: 16px; border: 1px solid #e2edf7; margin: 8px 0; font-size: 0.7rem; }

/* ============================================
   БАТАРЕЯ 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: 1.2rem;
    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: 16px; border: 1px solid #e2edf7; overflow: hidden; cursor: pointer; margin-bottom: 8px; transition: background 0.15s ease, border-color 0.15s ease; border-left-width: 3px; 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: 40px; font-size: 1.2rem; }
.coolant-icon { color: #ef4444; }
.room-icon { color: #3b82f6; }
.power-icon { color: #f59e0b; }
.coolant-content, .room-content, .power-content { flex: 1; padding: 8px 10px; }
.coolant-value, .room-value, .power-value { font-size: 1.2rem; font-weight: 500; color: #0b3b4f; line-height: 1.15; }
.coolant-unit, .room-unit, .power-unit { font-size: 0.7rem; color: #64748b; font-weight: 400; margin-left: 4px; }
.coolant-label, .room-label, .power-label { font-size: 0.6rem; font-weight: 600; color: #2c6e9e; margin-bottom: 2px; text-transform: uppercase; letter-spacing: 0.3px; }
.coolant-main, .room-main, .power-main { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.progress-bar { width: 100%; height: 4px; background: #e2e8f0; border-radius: 10px; overflow: hidden; margin-top: 4px; }
.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: 4px; font-size: 0.55rem; color: #6b7280; width: 100%; }

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

.buttons-container-simple {
    margin: 2px 0 4px 0;
    padding: 0;
}

.buttons-section-title {
    font-size: 0.6rem;
    font-weight: 600;
    color: #2c6e9e;
    margin: 4px 0 10px 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: 18px;
    margin: 4px 0 8px 0;
}

.button-item-simple {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 70px;
}

.button-item-simple.disabled {
    opacity: 0.5;
}

/* КРУГЛАЯ КНОПКА */
.device-btn-simple {
    width: 90px;
    height: 90px;
    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: 3px solid #4338ca;
    box-shadow: 0 4px 14px 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 6px 24px rgba(79, 70, 229, 0.4);
}

.device-btn-simple:active:not(.disabled) {
    transform: scale(0.92);
}

/* КРУПНАЯ ЦИФРА */
.device-btn-simple .btn-number {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    position: relative;
    z-index: 2;
    line-height: 1;
    text-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
}

/* МАЛЕНЬКАЯ ПОДПИСЬ "сек" */
.device-btn-simple .btn-label-inside {
    font-size: 0.55rem;
    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.5rem;
}

@keyframes number-countdown {
    0% { transform: scale(1); }
    100% { transform: scale(0.85); }
}

/* КОЛЬЦО ПРОГРЕССА (ободок) */
.device-btn-simple .btn-progress-ring {
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50%;
    border: 4px 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.75rem;
    font-weight: 500;
    color: #1e293b;
    text-align: center;
    line-height: 1.3;
    max-width: 90px;
    word-wrap: break-word;
}

.button-item-simple:hover .btn-label-simple {
    color: #0284c7;
}

.btn-help-simple {
    font-size: 0.55rem;
    color: #94a3b8;
    text-align: center;
    padding: 4px 10px;
    margin-top: 4px;
}

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

.switches-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 8px 0;
}

.switch-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: #fafeff;
    border-radius: 16px;
    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.55rem;
    color: #dc2626;
}

/* ===== CSS ТУМБЛЕР ===== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    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: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px 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(24px);
}

.toggle-switch input:disabled + .toggle-slider {
    cursor: not-allowed;
    opacity: 0.5;
}

.switch-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #1e293b;
    flex: 1;
}

.switch-state {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 20px;
    background: #f1f5f9;
    color: #64748b;
}

.switch-state:contains('ВКЛ') {
    background: #dcfce7;
    color: #166534;
}

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

.card-footer {
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid #e2edf7;
}

.footer-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.footer-bottom {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.footer-left {
    display: flex;
    align-items: center;
}

.footer-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.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; }

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

.power-btn {
    background: #0284c7 !important;
    border-radius: 40px !important;
    width: auto !important;
    padding: 4px 12px !important;
    gap: 6px;
    font-size: 0.7rem !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;
}

.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: 28px !important;
    height: 28px !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.8rem !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);
}

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

.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; }

.login-prompt { text-align: center; color: white; padding: 80px 30px; background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%); border-radius: 40px; box-shadow: 0 8px 25px rgba(2, 132, 199, 0.3); }
.login-prompt i { font-size: 4rem; color: white; margin-bottom: 20px; display: block; text-shadow: 0 2px 5px rgba(0,0,0,0.2); }
.login-prompt h3 { color: white; margin-bottom: 10px; font-size: 1.5rem; }
.login-prompt p { color: rgba(255,255,255,0.9); margin-bottom: 10px; }
.login-prompt .login-btn-large { background: white; color: #0284c7; border: none; padding: 12px 30px; border-radius: 40px; font-size: 1rem; font-weight: 600; cursor: pointer; margin-top: 20px; transition: all 0.2s; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.login-prompt .login-btn-large:hover { background: #f0f9ff; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

.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 4px 14px rgba(74, 222, 128, 0.3);
}

/* Состояние ВЫКЛ (красный пастельный) */
.device-btn-simple.state-off {
    background: #fca5a5 !important;
    border-color: #f87171 !important;
    box-shadow: 0 4px 14px rgba(248, 113, 113, 0.3);
}

/* Индикатор состояния */
.btn-state-indicator {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    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);
}

/* Анимация для индикатора при изменении состояния */
@keyframes pulse-indicator {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

/* Отключаем анимацию когда есть активное состояние */
.device-btn-simple.state-on .btn-state-indicator,
.device-btn-simple.state-off .btn-state-indicator {
    animation: none;
}

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

@media (max-width: 768px) {
    .device-group { margin-bottom: 24px; }
    .device-card { width: calc(50% - 8px) !important; min-width: 200px; }
    .footer-top { flex-wrap: wrap; gap: 6px; }
    .footer-left, .footer-right { min-width: auto; }
    .footer-bottom { flex-wrap: wrap; gap: 6px; }
    .power-btn { padding: 3px 10px !important; font-size: 0.65rem !important; }
    .icon-btn { width: 26px !important; height: 26px !important; font-size: 0.7rem !important; }
    
    .sensor-big-row { gap: 6px; }
    .sensor-big-block { min-height: 75px; padding: 10px 6px; }
    .sensor-big-value { font-size: 1.5rem; }
    .sensor-big-unit { font-size: 0.8rem; }
    .sensor-big-icon { font-size: 1rem; }
    
    .buttons-grid-simple { gap: 14px; }
    .device-btn-simple { width: 76px; height: 76px; }
    .device-btn-simple .btn-number { font-size: 1.8rem; }
    .device-btn-simple .btn-label-inside { font-size: 0.5rem; }
    .btn-label-simple { font-size: 0.7rem; max-width: 75px; }
    
    .switch-item { flex-wrap: wrap; gap: 8px; }
    .switch-label { font-size: 0.7rem; }
    .switch-state { font-size: 0.6rem; }
}

@media (max-width: 480px) {
    body { padding: 12px; }
    h1 { font-size: 1.4rem; }
    .device-group { margin-bottom: 20px; }
    .device-card { width: 100% !important; }
    .sensor-metric-icon, .coolant-icon, .room-icon, .power-icon { width: 35px !important; font-size: 1rem !important; }
    .sensor-metric-main, .coolant-value, .room-value, .power-value { font-size: 1.1rem !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.8rem; }
    .device-location { font-size: 0.55rem; }
    .settings-switch-label { font-size: 0.8rem; }
    .help-section h3 { font-size: 0.9rem; }
    .help-section p { font-size: 0.75rem; margin-left: 20px; }
    .footer-top { flex-direction: column; gap: 8px; }
    .footer-left, .footer-right { min-width: auto; justify-content: center; }
    .footer-bottom { flex-direction: column; gap: 4px; }
    .power-btn { padding: 3px 10px !important; font-size: 0.65rem !important; }
    .icon-btn { width: 26px !important; height: 26px !important; font-size: 0.7rem !important; }
    
    .sensor-big-row { grid-template-columns: 1fr 1fr; gap: 6px; }
    .sensor-big-block { min-height: 70px; padding: 8px 4px; }
    .sensor-big-value { font-size: 1.3rem; }
    .sensor-big-unit { font-size: 0.7rem; }
    .sensor-big-icon { font-size: 0.9rem; }
    .sensor-big-comment { font-size: 0.55rem; }
    
    .buttons-grid-simple { gap: 12px; }
    .device-btn-simple { width: 68px; height: 68px; border-width: 2px; }
    .device-btn-simple .btn-number { font-size: 1.6rem; }
    .device-btn-simple .btn-label-inside { font-size: 0.45rem; }
    .btn-label-simple { font-size: 0.65rem; max-width: 65px; }
    .buttons-section-title { font-size: 0.55rem; }
    
    .toggle-switch { width: 44px; height: 24px; }
    .toggle-slider:before { height: 16px; width: 16px; }
    .toggle-switch input:checked + .toggle-slider:before { transform: translateX(20px); }
}

@media (max-width: 380px) {
    .sensor-big-row { grid-template-columns: 1fr 1fr; gap: 4px; }
    .sensor-big-block { min-height: 60px; padding: 6px 4px; }
    .sensor-big-value { font-size: 1.1rem; }
    
    .buttons-grid-simple { gap: 10px; }
    .device-btn-simple { width: 58px; height: 58px; }
    .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.6rem; max-width: 55px; }
    
    .btn-state-indicator {
        top: 4px;
        right: 4px;
        width: 6px;
        height: 6px;
    }
}