/* ==============================================================================
   AMETIST IOT PLATFORM — devstyle.css
   Device Dashboard, Sidebar Navigation Widget, Controls & Responsive Layout
   ============================================================================== */

/* --- General Typography & Layout Base --- */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.01em;
}

.dashboard-container {
    background: rgba(14, 10, 36, 0.78);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 24px;
    padding: 32px 28px;
    border: 1px solid rgba(124, 58, 237, 0.25);
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(124, 58, 237, 0.1);
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
}

.dashboard-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #7c3aed, #a855f7, #38bdf8);
}

.dashboard-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(124, 58, 237, 0.2);
}

/* --- Device Header in Dashboard --- */
.device-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.device-title {
    font-size: 1.65rem;
    font-weight: 800;
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.device-id {
    font-family: monospace;
    font-size: 0.8rem;
    font-weight: 600;
    color: #d8b4fe;
    background: rgba(124, 58, 237, 0.15);
    border: 1px solid rgba(168, 85, 247, 0.35);
    padding: 4px 12px;
    border-radius: 9999px;
    letter-spacing: 0.05em;
    vertical-align: middle;
}

.device-status {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.status-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    color: #cbd5e1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 6px 14px;
    border-radius: 9999px;
}

.status-online {
    color: #34d399;
    border-color: rgba(52, 211, 153, 0.35);
    background: rgba(52, 211, 153, 0.1);
}

.status-online span {
    color: #34d399;
    font-size: 0.9rem;
    animation: statusPulse 2s infinite ease-in-out;
}

.status-offline {
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.1);
}

.status-offline span {
    color: #f87171;
    font-size: 0.9rem;
}

.dev-online {
    color: #34d399 !important;
    font-style: normal;
    font-weight: 700;
}

.dev-offline {
    color: #f87171 !important;
    font-style: normal;
    font-weight: 700;
}

.device-status.status-online,
.current-device-status.status-online {
    color: #34d399;
    border: 1px solid rgba(52, 211, 153, 0.35);
    background: rgba(52, 211, 153, 0.12);
}

.device-status.status-offline,
.current-device-status.status-offline {
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.12);
}

#dtm {
    display: inline-block;
    color: #94a3b8;
    font-family: monospace;
    font-size: 0.84rem;
}

/* ==============================================================================
   SIDEBAR WIDGET (#widjget, .sidebar-widget)
   ============================================================================== */
/* Two-Column Responsive Layout for Device Dashboard & Sidebar */
.dashboard-layout,
.text-content:has(#widjget) {
    display: flex;
    flex-direction: row-reverse;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    width: 100%;
}

.dashboard-layout > .dashboard-container,
.dashboard-layout > :not(#widjget),
.text-content:has(#widjget) > :not(#widjget) {
    flex: 1 1 0%;
    min-width: 0;
    width: 100%;
}

#widjget {
    flex: 0 0 clamp(250px, 25vw, 290px);
    width: clamp(250px, 25vw, 290px);
    min-width: 240px;
    max-width: 300px;
}

.sidebar-widget {
    background: rgba(14, 10, 36, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 18px;
    padding: 16px 14px;
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.4), 0 0 25px rgba(124, 58, 237, 0.15);
    border: 1px solid rgba(124, 58, 237, 0.25);
    width: 100%;
    margin: 0;
    position: sticky;
    top: 80px;
    transition: all 0.3s ease;
}

.widget-header {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(124, 58, 237, 0.2);
}

.widget-title {
    font-size: 1rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-fast, 0.2s);
}

.widget-header a {
    text-decoration: none;
}

.widget-header a:hover .widget-title {
    color: #c084fc;
    transform: translateX(2px);
}

.device-selector {
    margin-bottom: 10px;
}

.device-dropdown {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid rgba(124, 58, 237, 0.35);
    border-radius: 10px;
    background: rgba(8, 6, 26, 0.75);
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%23c084fc' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
}

.device-dropdown:focus {
    outline: none;
    border-color: #a855f7;
    box-shadow: 0 0 14px rgba(168, 85, 247, 0.35);
}

.device-dropdown option {
    background: #0e0a2d;
    color: #ffffff;
    padding: 8px;
}

/* Scrollable Device List with compact max-height and custom scrollbar */
.device-list {
    max-height: 250px;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(168, 85, 247, 0.45) rgba(14, 10, 36, 0.4);
}

.device-list::-webkit-scrollbar {
    width: 4px;
}

.device-list::-webkit-scrollbar-track {
    background: rgba(14, 10, 36, 0.4);
    border-radius: 4px;
}

.device-list::-webkit-scrollbar-thumb {
    background: rgba(124, 58, 237, 0.4);
    border-radius: 4px;
}

.device-list::-webkit-scrollbar-thumb:hover {
    background: rgba(168, 85, 247, 0.7);
}

.device-scroll-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Compact Device Item */
.sidebar-widget .device-item {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(124, 58, 237, 0.18);
    transition: all 0.2s ease;
    position: relative;
}

.sidebar-widget .device-item:hover {
    background: rgba(124, 58, 237, 0.1);
    border-color: rgba(168, 85, 247, 0.4);
    transform: translateX(3px);
}

.sidebar-widget .device-item.active {
    border-color: #a855f7;
    background: rgba(124, 58, 237, 0.18);
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.25);
}

.sidebar-widget .device-item.status-online {
    border-color: rgba(52, 211, 153, 0.35);
}

.sidebar-widget .device-item.status-online:hover {
    border-color: rgba(52, 211, 153, 0.65);
    background: rgba(52, 211, 153, 0.08);
    box-shadow: 0 0 12px rgba(52, 211, 153, 0.2);
}

.sidebar-widget .device-item.status-offline {
    border-color: rgba(239, 68, 68, 0.25);
}

.sidebar-widget .device-item.status-offline:hover {
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.06);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.15);
}

.sidebar-widget .device-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 65%;
    background: #a855f7;
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px #a855f7;
}

.sidebar-widget .device-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}

.sidebar-widget .device-icon {
    font-size: 1.15rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(124, 58, 237, 0.15);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 8px;
    flex-shrink: 0;
}

.sidebar-widget .device-info {
    flex: 1;
    min-width: 0;
    line-height: 1.25;
}

.sidebar-widget .device-name {
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 2px;
    font-size: 0.84rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-widget .device-data {
    color: #38bdf8;
    font-weight: 600;
    font-size: 0.76rem;
    margin-bottom: 1px;
}

.sidebar-widget .device-status {
    font-size: 0.72rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.device-status-text {
    font-size: 0.74rem;
    font-weight: 500;
}

/* Quick Action Buttons */
.add-device-btn, .add-device-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 7px 14px;
    background: linear-gradient(135deg, #7c3aed 0%, #9333ea 50%, #a855f7 100%);
    color: #ffffff;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.82rem;
    border: 1px solid rgba(168, 85, 247, 0.5);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
    transition: all 0.25s ease;
    margin-top: 6px;
}

.add-device-btn:hover, .add-device-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(168, 85, 247, 0.5);
    color: #ffffff;
}

.widget-footer {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(124, 58, 237, 0.2);
}

/* --- Empty States --- */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: #cbd5e1;
}

.empty-icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    filter: drop-shadow(0 0 15px rgba(124, 58, 237, 0.4));
}

.empty-text {
    font-size: 1.3rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 8px;
}

/* --- Switch Toggle Controls --- */
.switch {
    position: relative;
    display: inline-block;
    width: 54px;
    height: 30px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 30px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: #ffffff;
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

input:checked + .slider {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border-color: #c084fc;
    box-shadow: 0 0 15px rgba(124, 58, 237, 0.5);
}

input:checked + .slider:before {
    transform: translateX(24px);
    background-color: #ffffff;
}

/* --- Mobile Version of Sidebar Widget --- */
.widget-desktop {
    display: block;
}

.widget-mobile {
    display: none;
}

/* --- Responsive Layout for Tablets & Smartphones --- */
@media (max-width: 960px) {
    .dashboard-layout,
    .text-content:has(#widjget) {
        flex-direction: column-reverse;
        gap: 20px;
    }
    
    #widjget {
        flex: 1 1 auto;
        width: 100%;
        max-width: 100%;
    }
    
    .sidebar-widget {
        position: static;
        width: 100%;
        max-width: 100%;
        margin-bottom: 0;
    }
    
    .device-list {
        max-height: 200px;
    }
}

@media (max-width: 768px) {
    .dashboard-layout,
    .text-content:has(#widjget) {
        flex-direction: column;
        gap: 16px;
    }
    
    .widget-desktop {
        display: none !important;
    }
    
    .widget-mobile {
        display: block !important;
        background: rgba(14, 10, 36, 0.85);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-radius: 16px;
        padding: 14px 16px;
        border: 1px solid rgba(124, 58, 237, 0.25);
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
        margin-bottom: 0;
    }
    
    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
    }
    
    .mobile-title {
        font-size: 0.98rem;
        font-weight: 700;
        color: #ffffff;
        margin: 0;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .mobile-toggle {
        cursor: pointer;
        padding: 5px 12px;
        border-radius: 8px;
        background: rgba(124, 58, 237, 0.15);
        border: 1px solid rgba(168, 85, 247, 0.3);
        color: #c084fc;
        font-size: 0.78rem;
        transition: all 0.25s ease;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .mobile-toggle .toggle-icon {
        display: inline-block;
        transition: transform 0.25s ease;
    }
    
    .mobile-toggle.active .toggle-icon {
        transform: rotate(180deg);
    }
    
    .mobile-device-selector {
        display: none;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid rgba(124, 58, 237, 0.2);
    }
    
    .mobile-device-selector.active {
        display: block;
    }
    
    .mobile-device-dropdown {
        width: 100%;
        padding: 10px 14px;
        border-radius: 10px;
        background: #0e0a2d;
        border: 1px solid rgba(124, 58, 237, 0.35);
        color: #ffffff;
        font-size: 0.88rem;
        font-weight: 600;
        cursor: pointer;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%23c084fc' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        background-size: 12px;
    }
    
    .mobile-device-info {
        margin-top: 10px;
    }
    
    .current-device {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid rgba(124, 58, 237, 0.2);
        border-radius: 12px;
    }
    
    .current-device-icon {
        font-size: 1.3rem;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(124, 58, 237, 0.15);
        border: 1px solid rgba(168, 85, 247, 0.3);
        border-radius: 8px;
        flex-shrink: 0;
    }
    
    .current-device-details {
        flex: 1;
        min-width: 0;
    }
    
    .current-device-name {
        font-size: 0.88rem;
        font-weight: 700;
        color: #ffffff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .current-device-data {
        font-size: 0.78rem;
        font-weight: 600;
        color: #38bdf8;
    }
    
    .current-device-status {
        font-size: 0.72rem;
        font-weight: 500;
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }
    
    .mobile-empty {
        text-align: center;
        padding: 14px;
    }
    
    .mobile-empty-icon {
        font-size: 2rem;
        margin-bottom: 4px;
    }
    
    .mobile-empty-text {
        font-size: 0.9rem;
        color: #94a3b8;
        margin-bottom: 8px;
    }
    
    .mobile-add-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 6px 14px;
        background: linear-gradient(135deg, #7c3aed, #a855f7);
        color: #ffffff;
        font-size: 0.8rem;
        font-weight: 600;
        border-radius: 8px;
        text-decoration: none;
    }
    
    .dashboard-container {
        padding: 20px 16px;
        border-radius: 18px;
    }
    
    .device-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .device-title {
        font-size: 1.25rem;
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .dashboard-container {
        padding: 16px 12px;
        border-radius: 16px;
    }
    
    .device-title {
        font-size: 1.1rem;
        gap: 8px;
    }
    
    .device-id {
        font-size: 0.72rem;
        padding: 2px 8px;
    }
    
    .status-item {
        font-size: 0.78rem;
        padding: 4px 10px;
    }
}
