/* ===========================
   Reusable Components
   =========================== */

/* ---- Cards ---- */
.card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    transition: all var(--transition-base);
}

.card:hover {
    background: var(--glass-bg-hover);
    border-color: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.card-header i {
    font-size: var(--text-xl);
    color: var(--accent-primary);
}

.card-header h3 {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
}

/* ---- Active device card glow ---- */
.card.active-glow {
    border-color: rgba(16, 185, 129, 0.3);
    animation: glow 2s ease-in-out infinite;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 0.625rem 1.25rem;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.2) 0%, transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn:active::after {
    opacity: 1;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), hsl(160, 70%, 38%));
    color: var(--text-inverse);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-primary);
}

.btn-danger {
    background: linear-gradient(135deg, var(--accent-danger), hsl(0, 70%, 50%));
    color: white;
}

.btn-danger:hover {
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.3);
}

.btn-sm { padding: 0.375rem 0.75rem; font-size: var(--text-xs); }
.btn-lg { padding: 0.875rem 1.75rem; font-size: var(--text-base); }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: var(--radius-md);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
}

.btn-icon:hover {
    background: var(--glass-bg-hover);
    color: var(--accent-primary);
}

/* ---- Toggle Switch ---- */
.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-elevated);
    border-radius: var(--radius-full);
    transition: all var(--transition-base);
    border: 1px solid var(--glass-border);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all var(--transition-base);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateY(-50%) translateX(24px);
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ---- Fan Speed Slider ---- */
.speed-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: linear-gradient(to right, var(--bg-elevated) 0%, var(--accent-primary) 100%);
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
}

.speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-primary);
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.speed-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.speed-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent-primary);
    border: none;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

/* ---- Speed Buttons ---- */
.speed-btn-group {
    display: flex;
    gap: var(--space-xs);
}

.speed-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-base);
}

.speed-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.speed-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: var(--text-inverse);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

/* ---- Status Dot ---- */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--accent-primary);
    animation: statusPulse 2s infinite;
}

.status-dot.offline { background: var(--accent-danger); }
.status-dot.idle { background: var(--text-muted); }

/* ---- Badge ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.125rem 0.5rem;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    border-radius: var(--radius-full);
    background: var(--accent-primary-dim);
    color: var(--accent-primary);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-warning);
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-primary);
}

/* ---- Input Field ---- */
.input-field {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
    transition: all var(--transition-base);
}

.input-field::placeholder {
    color: var(--text-muted);
}

.input-field:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.input-sm {
    padding: 0.5rem 0.75rem;
    font-size: var(--text-xs);
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group i {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
    transition: color var(--transition-base);
    z-index: 1;
}

.input-group .input-field {
    padding-left: 2.75rem;
}

.input-group:focus-within i {
    color: var(--accent-primary);
}

/* ---- Modal Overlay ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--space-md);
}

.modal-overlay.visible {
    display: flex;
    animation: fadeIn 0.2s var(--ease-out);
}

.modal-overlay.pin-modal {
    display: flex;
    animation: fadeIn 0.2s var(--ease-out);
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: var(--space-2xl);
    max-width: 420px;
    width: 100%;
    animation: scaleIn 0.3s var(--ease-spring);
    box-shadow: var(--shadow-lg);
}

.modal-close {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: var(--text-xl);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
}

/* ---- Sensor Gauge ---- */
.gauge-container {
    position: relative;
    width: 100px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---- Loader ---- */
.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 17, 32, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    z-index: var(--z-loader);
}

.loader-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loader-text {
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: var(--space-3xl) var(--space-xl);
}

.empty-state i {
    font-size: var(--text-4xl);
    color: var(--text-muted);
    margin-bottom: var(--space-md);
}

.empty-state p {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

/* ---- Divider ---- */
.divider {
    height: 1px;
    background: var(--glass-border);
    margin: var(--space-lg) 0;
}
