/* Стили для страницы устройств */
.devices-filters {
    margin-bottom: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(145deg, #2d3748 0%, #4a5568 100%);
    border-radius: 10px;
}

/* Контейнер для прокрутки карточек */
.devices-scroll-container {
    height: calc(100vh - 220px); /* Увеличил отступ для надежности */
    min-height: 350px;
    overflow-y: auto;
    overflow-x: hidden; /* Убираем горизонтальную прокрутку */
    border-radius: 8px;
    margin-right: -5px; /* Компенсируем ширину скроллбара */
    padding-right: 5px; /* Компенсируем ширину скроллбара */
}

.devices-scroll-container::-webkit-scrollbar {
    width: 6px;
}

.devices-scroll-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.devices-scroll-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.devices-scroll-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Убираем лишние отступы у контейнера с карточками */
#devicesGrid {
    margin-bottom: 0;
    min-height: min-content;
    width: 100%; /* Гарантируем 100% ширину */
}

/* Стили для фильтров в одну строку */
.filter-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
}

.filter-row::-webkit-scrollbar {
    height: 3px;
}

.filter-row::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.filter-row::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.filter-row .form-select {
    flex: 1;
    min-width: 130px;
}

/* Адаптивность для очень маленьких экранов */
@media (max-width: 480px) {
    .devices-scroll-container {
        height: calc(100vh - 200px); /* Увеличил отступ */
        min-height: 320px;
    }
    
    .filter-row {
        gap: 6px;
    }
    
    .filter-row .form-select {
        min-width: 110px;
        font-size: 0.75rem;
    }
}

@media (max-width: 430px) {
    .devices-scroll-container {
        height: calc(100vh - 190px); /* Увеличил отступ */
    }
    
    .filter-row {
        gap: 4px;
    }
    
    .filter-row .form-select {
        min-width: 100px;
        font-size: 0.7rem;
    }
}

@media (max-width: 380px) {
    .devices-scroll-container {
        height: calc(100vh - 180px); /* Увеличил отступ */
        min-height: 280px;
    }
    
    .filter-row {
        gap: 3px;
    }
    
    .filter-row .form-select {
        min-width: 90px;
        font-size: 0.65rem;
    }
}

/* На мобильных устройствах учитываем высоту шапки */
@media (max-width: 991.98px) {
    .devices-scroll-container {
        height: calc(100vh - 240px); /* Увеличил отступ для мобильных */
    }
}

/* Стили карточек устройств */
.device-card {
    background: linear-gradient(145deg, #2d3748 0%, #4a5568 100%);
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    height: 140px;
    display: flex;
    flex-direction: column;
}

.device-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}



.device-header {
    padding: 10px 12px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.device-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: white;
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-room {
    font-size: 0.7rem;
    color: #a0aec0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-area {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-online {
    background: #48bb78;
    box-shadow: 0 0 4px #48bb78;
}

.status-offline {
    background: #a0aec0;
}

.battery-badge {
    font-size: 0.65rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 1px 5px;
    border-radius: 6px;
}

.battery-high {
    color: #68d391;
}

.battery-medium {
    color: #f6ad55;
}

.battery-low {
    color: #fc8181;
}

.device-body {
    padding: 10px 12px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.device-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.sensor-icon {
    opacity: 0.8;
}

.temperature,
.humidity {
    font-size: 1.3rem;
    font-weight: 300;
    color: white;
    line-height: 1;
}

.temperature-unit {
    font-size: 0.7rem;
    opacity: 0.8;
    vertical-align: super;
}

.sensor-metrics {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
}

.metric-with-icon {
    display: flex;
    align-items: center;
    gap: 4px;
}

.socket-on {
    color: #68d391;
}

.socket-off {
    color: #a0aec0;
}

.light-on {
    color: #ffd700;
}

.light-off {
    color: #a0aec0;
}

.contact-open {
    color: #68d391;
}

.contact-closed {
    color: #a0aec0;
}

.control-btn {
    width: 70px;
    padding: 8px 6px;
    font-size: 0.75rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-on {
    background: #68d391;
    color: white;
}

.btn-on:hover {
    background: #48bb78;
}

.btn-off {
    background: #e53e3e;
    color: white;
}

.btn-off:hover {
    background: #c53030;
}

.btn-text {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.btn-icon {
    font-size: 0.8rem;
}

.contact-state {
    font-size: 0.9rem;
    font-weight: 400;
    color: white;
    text-align: right;
    flex: 1;
}

.state-open {
    color: #68d391;
}

.state-closed {
    color: #a0aec0;
}

.footer-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.65rem;
    color: #a0aec0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 12px 8px;
    flex-shrink: 0;
}

.signal-info {
    display: flex;
    align-items: center;
    gap: 4px;
}

.signal-strength {
    font-size: 0.65rem;
    font-family: 'Courier New', monospace;
}

.update-time {
    font-size: 0.65rem;
    font-family: 'Courier New', monospace;
}

.signal-icon {
    font-size: 0.75rem;
}

.signal-4 {
    color: #68d391;
}

.signal-3 {
    color: #f6ad55;
}

.signal-2 {
    color: #f6ad55;
}

.signal-1 {
    color: #fc8181;
}

/* Адаптивность для карточек */
@media (max-width: 768px) {
    .device-card {
        height: 130px;
    }
    
    .device-header {
        padding: 8px 10px 5px;
    }
    
    .device-body {
        padding: 8px 10px;
    }
    
    .device-icon {
        font-size: 1.2rem;
    }
    
    .temperature,
    .humidity {
        font-size: 1.1rem;
    }
    
    .control-btn {
        width: 65px;
        padding: 6px 4px;
        font-size: 0.7rem;
    }
}

@media (max-width: 576px) {
    .device-card {
        height: 120px;
    }
    
    .device-header {
        padding: 6px 8px 4px;
    }
    
    .device-body {
        padding: 6px 8px;
    }
    
    .device-name {
        font-size: 0.75rem;
    }
    
    .device-room {
        font-size: 0.65rem;
    }
    
    .device-icon {
        font-size: 1.1rem;
    }
    
    .temperature,
    .humidity {
        font-size: 1rem;
    }
    
    .control-btn {
        width: 60px;
        padding: 5px 3px;
        font-size: 0.65rem;
    }
    
    .footer-info {
        padding: 4px 8px 6px;
        font-size: 0.6rem;
    }
}

@media (min-width: 1400px) {
    #devicesGrid .col-lg-3 {
        flex: 0 0 auto;
        width: 20%; /* 5 карточек в строке */
    }
}

@media (min-width: 1920px) {
    #devicesGrid .col-lg-3 {
        width: 16.666%; /* 6 карточек в строке */
    }
}

@media (min-width: 2560px) {
    #devicesGrid .col-lg-3 {
        width: 12.5%; /* 8 карточек в строке */
    }
}

.status-pending {
    background: #f6ad55;
    box-shadow: 0 0 4px #f6ad55;
}

.status-error {
    background: #fc8181;
    box-shadow: 0 0 4px #fc8181;
}

/* Стили для новых типов устройств */
.contact-pending {
    color: #f6ad55;
}

.socket-error {
    color: #fc8181;
}

.light-offline {
    color: #a0aec0;
    opacity: 0.5;
}

.thermo-icon {
    color: #68d391;
}

.thermo-pending {
    color: #f6ad55;
}

.camera-on {
    color: #68d391;
}

.camera-error {
    color: #fc8181;
}

.thermo-state, .camera-state {
    font-size: 0.9rem;
    font-weight: 400;
    color: white;
    text-align: right;
    flex: 1;
}

/* Стили для кнопок с разными статусами */
.btn-error {
    background: #fc8181;
    color: white;
    cursor: not-allowed;
}

.btn-offline {
    background: #a0aec0;
    color: white;
    cursor: not-allowed;
}

.btn-error:hover, .btn-offline:hover {
    background: inherit;
}
/* Стили для устройств в состоянии ожидания */
.light-pending, .socket-pending {
    color: #f6ad55;
}

.btn-pending {
    background: #f6ad55;
    color: white;
    cursor: not-allowed;
}

.btn-pending:hover {
    background: #f6ad55;
}

/* Стили для датчиков протечки */
.leak-dry {
    color: #68d391;
}

.leak-wet {
    color: #63b3ed;
}

.leak-alarm {
    color: #fc8181;
}

.leak-state {
    font-size: 0.9rem;
    font-weight: 400;
    text-align: right;
    flex: 1;
}

.state-dry {
    color: #68d391;
}

.state-wet {
    color: #63b3ed;
}

.state-alarm {
    color: #fc8181;
    font-weight: 600;
}

/* Стили для датчиков движения */
.motion-clear {
    color: #68d391;
}

.motion-detected {
    color: #f6ad55;
}

.motion-state {
    font-size: 0.9rem;
    font-weight: 400;
    text-align: right;
    flex: 1;
}

.state-clear {
    color: #68d391;
}

.state-detected {
    color: #f6ad55;
    font-weight: 600;
}

/* Стили для датчиков газа */
.gas-normal {
    color: #68d391;
}

.gas-warning {
    color: #f6ad55;
}

.gas-alarm {
    color: #fc8181;
}

.gas-state {
    font-size: 0.9rem;
    font-weight: 400;
    text-align: right;
    flex: 1;
}

.state-normal {
    color: #68d391;
}

.state-warning {
    color: #f6ad55;
    font-weight: 600;
}

.state-alarm {
    color: #fc8181;
    font-weight: 600;
}