:root {
    --bg-color: #0f1016; /* Deep dark blue */
    --sidebar-bg: rgba(20, 21, 31, 0.7);
    --card-bg: rgba(30, 31, 45, 0.6);
    --border-color: rgba(255, 255, 255, 0.05);
    
    --text-primary: #f5f5f7;
    --text-secondary: #9ca3af;
    
    --color-available: #10b981;   /* Vibrant Green */
    --color-busy: #00e0ff;        /* Neon Blue -> Cyberpunk feel */
    --color-warning: #f59e0b;     /* Amber */
    --color-expired: #ef4444;     /* Vibrant Red */
    --color-offline: #374151;     /* Dark Gray */
    
    --primary-gradient: linear-gradient(135deg, #6366f1, #a855f7); /* Purple/Indigo */
    
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --transition-speed: 0.3s;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    min-height: 100vh;
    overflow-x: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(168, 85, 247, 0.15), transparent 25%);
    background-attachment: fixed;
}

/* Layout */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border-color); /* RTL */
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.5);
    z-index: 100;
    transition: width 0.4s ease, opacity 0.4s ease, transform 0.4s ease;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar.collapsed {
    width: 0;
    opacity: 0;
    padding: 0;
    border: none;
    transform: translateX(100%);
    pointer-events: none;
}

.sidebar-header {
    padding: 2rem 1.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: #fff;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.5rem 1rem;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    text-align: right;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    transform: translateX(-5px); /* RTL */
}

.nav-btn.active {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.nav-btn .icon { font-size: 1.3rem; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.collapse-btn {
    color: var(--text-secondary);
    justify-content: center;
}
.collapse-btn:hover {
    color: var(--color-expired);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-header {
    padding: 1.5rem 2rem;
    background: rgba(15, 16, 22, 0.5);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 2rem;
    cursor: pointer;
    transition: color 0.3s;
    line-height: 1;
}

.menu-btn:hover {
    color: var(--color-busy);
}

.top-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin: 0;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
    padding: 2rem;
}

/* Device Card (Glassmorphism & Neon) */
.device-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 2rem 1.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    transition: all var(--transition-speed) cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.device-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4), 0 0 15px var(--indicator-color);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Top colored indicator line */
.device-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: var(--indicator-color, var(--color-offline));
    box-shadow: 0 0 15px var(--indicator-color);
    transition: background var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
}

.device-icon {
    font-size: 2.8rem;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 10px rgba(255,255,255,0.2));
    transition: transform 0.3s ease;
}

.device-card:hover .device-icon {
    transform: scale(1.15) rotate(-5deg);
}

.device-name {
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.device-type {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: rgba(255,255,255,0.05);
    padding: 0.3rem 1rem;
    border-radius: 20px;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.delete-device-btn {
    position: absolute;
    top: 1rem;
    left: 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s ease;
    color: var(--color-expired);
    line-height: 1;
}

.device-card:hover .delete-device-btn {
    opacity: 1;
}

.delete-device-btn:hover {
    background: rgba(239, 68, 68, 0.3);
    transform: scale(1.1);
}

.timer {
    font-size: 3rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    margin: 1rem 0;
    min-height: 3.5rem;
    color: var(--timer-color, var(--text-primary));
    text-shadow: 0 0 10px rgba(255,255,255,0.1);
    transition: color 0.3s ease;
}

.btn {
    padding: 1rem 2rem;
    border: none;
    border-radius: 12px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    margin-top: 1.5rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.btn-start {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

/* Theme Toggle Button */
.theme-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-primary);
}

.theme-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(15deg) scale(1.1);
}

/* Light Theme overrides */
body.light-theme {
    --bg-color: #f3f4f6;
    --sidebar-bg: rgba(255, 255, 255, 0.9);
    --card-bg: rgba(255, 255, 255, 1);
    --border-color: rgba(0, 0, 0, 0.1);
    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --color-offline: #9ca3af;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.08), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(168, 85, 247, 0.08), transparent 25%);
}

body.light-theme .sidebar-header h2 {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.light-theme .nav-btn:hover {
    background: rgba(0,0,0,0.05);
}

body.light-theme .top-header {
    background: rgba(243, 244, 246, 0.8);
}

body.light-theme .device-type {
    background: rgba(0,0,0,0.05);
}

body.light-theme .modern-input {
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.2);
    color: #1f2937;
}

body.light-theme .modal-content {
    background: rgba(255, 255, 255, 0.98);
}

body.light-theme .form-group label {
    color: #374151;
}

body.light-theme .close-btn {
    color: #6b7280;
}

.btn-start:hover { 
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

.btn-stop {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-stop:hover { 
    transform: translateY(-2px); 
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.5);
}

/* Animations */
@keyframes pulseWarning {
    0% { transform: scale(1); text-shadow: 0 0 10px rgba(245, 158, 11, 0.3); }
    50% { transform: scale(1.05); text-shadow: 0 0 20px rgba(245, 158, 11, 0.8); color: var(--color-warning); }
    100% { transform: scale(1); text-shadow: 0 0 10px rgba(245, 158, 11, 0.3); }
}

@keyframes pulseExpired {
    0% { transform: scale(1); text-shadow: 0 0 10px rgba(239, 68, 68, 0.5); }
    50% { transform: scale(1.1); text-shadow: 0 0 25px rgba(239, 68, 68, 1); color: var(--color-expired); }
    100% { transform: scale(1); text-shadow: 0 0 10px rgba(239, 68, 68, 0.5); }
}

@keyframes cardShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px) rotate(-1deg); }
    75% { transform: translateX(3px) rotate(1deg); }
}

.anim-warning .timer { animation: pulseWarning 1s infinite alternate; color: var(--color-warning); }
.anim-expired .timer { animation: pulseExpired 0.6s infinite alternate; color: var(--color-expired); }
.anim-expired .device-card { 
    border-color: rgba(239, 68, 68, 0.5); 
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.2); 
    animation: cardShake 0.5s ease; /* gentle shake on expire */
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: rgba(25, 26, 35, 0.95);
    padding: 3rem 2.5rem;
    border-radius: 24px;
    width: 90%;
    max-width: 450px;
    position: relative;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    transform: scale(0.95);
    animation: scaleUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes scaleUp { to { transform: scale(1); } }

.close-btn {
    position: absolute;
    top: 1.5rem;
    right: 2rem;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.3s;
}

.close-btn:hover { color: var(--color-expired); }

.modal h2 { margin-bottom: 2rem; font-size: 1.8rem; text-align: center; }

.form-group { margin: 1.5rem 0; }
.form-group label { display: block; margin-bottom: 0.8rem; font-weight: 600; color: #e5e7eb; }

.radio-group { display: flex; gap: 1.5rem; }
.radio-group label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; color: var(--text-primary); font-weight: initial; }

/* Device Type Selector Cards */
.device-type-selector {
    gap: 1rem;
}

.type-option {
    flex: 1;
    display: flex;
    flex-direction: column !important;
    align-items: center !important;
    gap: 0.5rem !important;
    padding: 1.2rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.25s ease;
    background: rgba(255,255,255,0.03);
    font-weight: 600 !important;
    color: var(--text-secondary) !important;
}

.type-option input[type="radio"] {
    display: none;
}

.type-option .type-icon {
    font-size: 2.2rem;
    transition: transform 0.3s ease;
}

.type-option:hover {
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(99, 102, 241, 0.05);
    color: var(--text-primary) !important;
    transform: translateY(-3px);
}

.type-option:hover .type-icon {
    transform: scale(1.15);
}

.type-option:has(input:checked) {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.15);
    color: var(--text-primary) !important;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
}

.type-option:has(input:checked) .type-icon {
    transform: scale(1.2);
}

body.light-theme .type-option {
    background: rgba(0,0,0,0.03);
}

body.light-theme .type-option:has(input:checked) {
    background: rgba(99, 102, 241, 0.1);
}

.modern-input {
    width: 100%;
    padding: 1rem;
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    color: white;
    font-size: 1.1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.modern-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.primary-btn {
    width: 100%;
    padding: 1.2rem;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.2rem;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    margin-top: 1rem;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.5);
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-color); }
::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #6b7280; }

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100vh;
        transform: translateX(0);
    }
    .sidebar.collapsed {
        transform: translateX(100%);
    }
    .cards-grid {
        grid-template-columns: 1fr; 
        gap: 1.2rem;
        padding: 1.2rem;
    }
    .timer { font-size: 2.2rem; }
    .device-name { font-size: 1.3rem; }
    .top-header h1 { font-size: 1.3rem; }
    .modal-content {
        width: 95%;
        padding: 2rem 1.5rem;
    }
    .primary-btn { font-size: 1rem; padding: 1rem; }
    .btn { font-size: 0.95rem; padding: 0.8rem 1.5rem; }
}
