/* ============================================================================
   IMPRUF Cloud Dashboard - Main Styles
   ============================================================================ */

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #ffffff;
    --background-alt: #f9fafb;
    --border-color: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

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

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", sans-serif;
    background-color: var(--background-alt);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100%;
}

/* ============================================================================
   View Management
   ============================================================================ */

.view {
    display: block;
}

.view.hidden {
    display: none;
}

/* ============================================================================
   Login View
   ============================================================================ */

#login-view {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
    animation: slideIn 0.3s ease-out;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header h1 {
    font-size: 28px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-form {
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 14px;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.login-footer {
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.login-footer p {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.login-footer a:hover {
    text-decoration: underline;
}

/* ============================================================================
   Modal
   ============================================================================ */

.modal {
    display: flex;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: slideUp 0.3s ease-out;
}

.modal-content.modal-large {
    max-width: 600px;
}

.modal-close {
    position: absolute;
    right: 20px;
    top: 20px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal h2 {
    margin-bottom: 20px;
    font-size: 22px;
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #4b5563;
}

.btn-outline {
    background-color: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.btn-outline:hover {
    background-color: rgba(79, 70, 229, 0.1);
}

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

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

/* ============================================================================
   Messages
   ============================================================================ */

.error-message {
    padding: 12px;
    background-color: #fee2e2;
    color: #991b1b;
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 14px;
    border-left: 4px solid var(--danger-color);
}

.error-message.hidden {
    display: none;
}

.success-message {
    padding: 12px;
    background-color: #dcfce7;
    color: #166534;
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 14px;
    border-left: 4px solid var(--success-color);
}

.info-message {
    padding: 12px;
    background-color: #dbeafe;
    color: #1e40af;
    border-radius: 6px;
    margin: 15px 0;
    font-size: 14px;
    border-left: 4px solid #3b82f6;
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state.hidden {
    display: none;
}

/* ============================================================================
   Toast Notification
   ============================================================================ */

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #1f2937;
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    max-width: 400px;
    animation: slideInUp 0.3s ease-out;
}

.toast.hidden {
    display: none;
}

.toast.success {
    background-color: var(--success-color);
}

.toast.error {
    background-color: var(--danger-color);
}

.toast.warning {
    background-color: var(--warning-color);
}

/* ============================================================================
   Dashboard View
   ============================================================================ */

.navbar {
    background-color: white;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar-brand h2 {
    font-size: 20px;
    color: var(--primary-color);
    margin: 0;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-name {
    color: var(--text-secondary);
    font-size: 14px;
}

.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
}

.dashboard-header {
    margin-bottom: 40px;
}

.dashboard-header h1 {
    font-size: 32px;
    margin-bottom: 8px;
}

.dashboard-header p {
    color: var(--text-secondary);
    font-size: 16px;
}

.dashboard-content {
    background-color: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: var(--shadow);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.section-header h2 {
    font-size: 22px;
    margin: 0;
}

.section-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ============================================================================
   Devices Grid
   ============================================================================ */

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.device-card {
    background-color: var(--background-alt);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    transition: all 0.2s;
    cursor: pointer;
}

.device-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 15px;
}

.device-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.device-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.device-status.online {
    background-color: #dcfce7;
    color: #166534;
}

.device-status.offline {
    background-color: #fee2e2;
    color: #991b1b;
}

.device-status.unknown {
    background-color: #f3e8ff;
    color: #6b21a8;
}

.device-info {
    margin-bottom: 15px;
    font-size: 13px;
    color: var(--text-secondary);
}

.device-info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.device-info-label {
    color: var(--text-secondary);
}

.device-info-value {
    font-weight: 500;
    color: var(--text-primary);
}

.device-card-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.device-card-actions .btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
}

/* ============================================================================
   Device Detail Modal
   ============================================================================ */

#device-detail-content h2 {
    margin-bottom: 20px;
    font-size: 24px;
}

.detail-info {
    margin-bottom: 30px;
}

.detail-info h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-value {
    color: var(--text-primary);
    font-weight: 600;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 30px;
}

.modal-actions .btn {
    flex: 1;
}

/* ============================================================================
   QR Code Pairing Styles
   ============================================================================ */

.pairing-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.qr-scanner-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.qr-scanner-container.hidden {
    display: none;
}

#qr-video {
    width: 100%;
    border-radius: 8px;
    background-color: #000;
    display: block;
}

.qr-scanner-overlay {
    position: relative;
    text-align: center;
    margin-top: -120px;
    pointer-events: none;
}

.qr-scanner-frame {
    width: 250px;
    height: 250px;
    border: 3px solid var(--primary-color);
    border-radius: 8px;
    margin: 0 auto;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    position: relative;
}

.qr-scanner-frame::before,
.qr-scanner-frame::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid var(--success-color);
}

.qr-scanner-frame::before {
    top: -5px;
    left: -5px;
    border-right: none;
    border-bottom: none;
}

.qr-scanner-frame::after {
    bottom: -5px;
    right: -5px;
    border-left: none;
    border-top: none;
}

.qr-scanner-hint {
    color: white;
    font-size: 14px;
    margin-top: 30px;
    font-weight: 500;
}

.pairing-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.pairing-description {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

.pairing-buttons {
    display: flex;
    gap: 10px;
}

.pairing-buttons .btn {
    flex: 1;
}

/* ============================================================================
   Loading States
   ============================================================================ */

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ============================================================================
   Animations
   ============================================================================ */

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

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* ============================================================================
   Responsive Design
   ============================================================================ */

@media (max-width: 768px) {
    .login-card {
        padding: 30px 20px;
    }

    .dashboard-container {
        padding: 20px;
    }

    .dashboard-header h1 {
        font-size: 24px;
    }

    .dashboard-content {
        padding: 20px;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    .section-header .btn,
    .section-buttons .btn {
        width: 100%;
    }

    .section-buttons {
        flex-direction: column;
    }

    .devices-grid {
        grid-template-columns: 1fr;
    }

    .navbar-container {
        flex-direction: column;
        height: auto;
        padding: 12px 20px;
        gap: 15px;
    }

    .navbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .modal-content {
        width: 95%;
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .login-header h1 {
        font-size: 24px;
    }

    .device-card {
        padding: 15px;
    }

    .toast {
        right: 10px;
        left: 10px;
        bottom: 10px;
        max-width: none;
    }
}
