/* ============================================
   GLOBAL STYLES & CSS VARIABLES
   ============================================ */
:root {
    /* Color Palette */
    --primary: #667eea;
    --primary-dark: #5568d3;
    --secondary: #764ba2;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #1e293b;
    --light: #f8fafc;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gradient-danger: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --gradient-info: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --gradient-dark: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    
    /* Shadows */
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    
    /* Transitions */
    --transition-fast: 0.15s ease-in-out;
    --transition-base: 0.3s ease-in-out;
    --transition-slow: 0.5s ease-in-out;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
}

/* ============================================
   GLOBAL RESETS & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    min-height: 100vh;
    color: var(--dark);
    overflow-x: hidden;
}

/* ============================================
   LOADING OVERLAY
   ============================================ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--gradient-primary);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

/* ============================================
   NAVIGATION BAR
   ============================================ */
.navbar {
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.bg-gradient-primary {
    background: var(--gradient-primary) !important;
}

.navbar-brand {
    font-size: 1.25rem;
    transition: transform var(--transition-fast);
}

.navbar-brand:hover {
    transform: scale(1.05);
}

.pulse-icon {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ============================================
   STATISTICS CARDS
   ============================================ */
.stat-card {
    background: white;
    border-radius: 1rem;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 100%);
    pointer-events: none;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-xl);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: white;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.stat-card-primary .stat-icon {
    background: var(--gradient-success);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.stat-card-success .stat-icon {
    background: var(--gradient-primary);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.stat-card-warning .stat-icon {
    background: var(--gradient-warning);
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.stat-card-info .stat-icon {
    background: var(--gradient-info);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.stat-content {
    flex: 1;
    min-width: 0;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark);
    line-height: 1;
}

/* ============================================
   MODERN CARD STYLES
   ============================================ */
.modern-card {
    background: white;
    border: none;
    border-radius: 1rem;
    overflow: hidden;
    transition: all var(--transition-base);
}

.modern-card:hover {
    box-shadow: var(--shadow-xl);
}

.rtc-icon {
    width: 50px;
    height: 50px;
    background: var(--gradient-primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    flex-shrink: 0;
}

.rtc-display {
    font-size: 1rem;
    font-weight: 600;
    color: var(--dark);
    margin-top: 0.5rem;
}

/* ============================================
   RELAY CARDS
   ============================================ */
.relay-card {
    background: white;
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-base);
    border: 1px solid rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

.relay-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--gradient-primary);
    transition: width var(--transition-base);
}

.relay-card:hover::before {
    width: 8px;
}

.relay-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-xl);
}

.relay-card.active {
    border-color: rgba(16, 185, 129, 0.3);
    box-shadow: 0 10px 30px rgba(16, 185, 129, 0.2);
}

.relay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #f1f5f9;
}

.relay-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--dark);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.relay-title i {
    color: var(--primary);
}

.relay-state-badge {
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-weight: 600;
    font-size: 0.875rem;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-base);
}

.relay-state-on {
    background: var(--gradient-success);
    color: white;
    animation: pulse-glow 2s ease-in-out infinite;
}

.relay-state-off {
    background: var(--gradient-dark);
    color: white;
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
    }
    50% {
        box-shadow: 0 8px 25px rgba(16, 185, 129, 0.6);
    }
}

/* ============================================
   RELAY CONTROLS
   ============================================ */
.relay-controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1;
    min-width: 100px;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.875rem;
    border: 2px solid transparent;
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}

.mode-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width var(--transition-base), height var(--transition-base);
}

.mode-btn:hover::before {
    width: 300px;
    height: 300px;
}

.mode-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.mode-btn.active {
    border-color: currentColor;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    font-weight: 700;
}

/* ============================================
   ROUTINES SECTION
   ============================================ */
.routines-section {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 1.25rem;
    border-radius: 0.75rem;
    margin-top: 1.25rem;
}

.routines-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.routines-header h6 {
    margin: 0;
    font-weight: 700;
    color: var(--dark);
    font-size: 1rem;
}

.routine-item {
    background: white;
    padding: 1rem;
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all var(--transition-base);
    border: 2px solid transparent;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.routine-item:hover {
    transform: translateX(5px);
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.routine-item.disabled {
    opacity: 0.5;
    background: #f8fafc;
}

.routine-time {
    display: flex;
    gap: 1rem;
    align-items: center;
    font-weight: 600;
    color: var(--dark);
    flex-wrap: wrap;
}

.routine-time i {
    color: var(--success);
    font-size: 1.125rem;
}

.routine-time span {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ============================================
   MODAL STYLES
   ============================================ */
.modal-content {
    border-radius: 1rem;
    border: none;
    box-shadow: var(--shadow-xl);
}

.modal-header {
    border-radius: 1rem 1rem 0 0;
    border-bottom: none;
    padding: 1.5rem;
}

.modal-body {
    max-height: 70vh;
    overflow-y: auto;
}

/* Custom Scrollbar */
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* ============================================
   ROUTINE INPUT GROUP
   ============================================ */
.routine-input-group {
    background: white;
    padding: 1.5rem;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    border: 2px solid #e2e8f0;
    transition: all var(--transition-base);
}

.routine-input-group:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.routine-input-group.disabled {
    opacity: 0.6;
    background: #f8fafc;
}

.routine-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.routine-header h6 {
    margin: 0;
    font-weight: 700;
    color: var(--dark);
}

.time-input {
    padding: 0.75rem 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: all var(--transition-base);
    width: 100%;
}

.time-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    outline: none;
}

/* ============================================
   FORM CONTROLS
   ============================================ */
.form-check-input {
    cursor: pointer;
    width: 3em;
    height: 1.5em;
    transition: all var(--transition-base);
}

.form-check-input:checked {
    background-color: var(--success);
    border-color: var(--success);
}

.form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    border-radius: 0.75rem;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    transition: all var(--transition-base);
    border: none;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width var(--transition-fast), height var(--transition-fast);
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--gradient-primary);
}

.btn-success {
    background: var(--gradient-success);
}

.btn-danger {
    background: var(--gradient-danger);
}

.btn-warning {
    background: var(--gradient-warning);
}

.btn-info {
    background: var(--gradient-info);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

/* ============================================
   ALERTS
   ============================================ */
.alert {
    border-radius: 0.75rem;
    border: none;
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast {
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    border: none;
}

.toast-body {
    font-weight: 600;
}

/* ============================================
   BADGES
   ============================================ */
.badge {
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.slide-in {
    animation: slideIn 0.5s ease-out;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Mobile Phones (up to 576px) */
@media (max-width: 575.98px) {
    .stat-card {
        padding: 1rem;
    }
    
    .stat-icon {
        width: 45px;
        height: 45px;
        font-size: 1.25rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .relay-card {
        padding: 1.25rem;
    }
    
    .relay-title {
        font-size: 1.125rem;
    }
    
    .relay-controls {
        flex-direction: column;
    }
    
    .mode-btn {
        width: 100%;
        min-width: auto;
    }
    
    .routine-item {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .routine-time {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* Tablets (576px to 768px) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .stat-card {
        padding: 1.125rem;
    }
    
    .stat-icon {
        width: 50px;
        height: 50px;
    }
}

/* Desktop (768px and up) */
@media (min-width: 768px) {
    .relay-controls {
        flex-wrap: nowrap;
    }
}

/* Large Desktop (1200px and up) */
@media (min-width: 1200px) {
    .container-fluid {
        max-width: 1400px;
        margin: 0 auto;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.text-gradient {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.bg-blur {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.9);
}

.shadow-smooth {
    box-shadow: var(--shadow-lg);
}

.rounded-xl {
    border-radius: 1rem;
}

.transition-all {
    transition: all var(--transition-base);
}

/* ============================================
   DARK MODE (Optional - Toggle Feature)
   ============================================ */
body.dark-mode {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #f8fafc;
}

body.dark-mode .modern-card,
body.dark-mode .relay-card,
body.dark-mode .stat-card {
    background: #1e293b;
    color: #f8fafc;
}

body.dark-mode .stat-label,
body.dark-mode .relay-title {
    color: #cbd5e1;
}

body.dark-mode .stat-value {
    color: #f8fafc;
}

/* ============================================
   LOADING STATES
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    body {
        background: white;
    }
    
    .navbar,
    .btn,
    .modal,
    .toast-container {
        display: none;
    }
    
    .relay-card,
    .stat-card,
    .modern-card {
        box-shadow: none;
        border: 1px solid #e2e8f0;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
