/* ========== DASHBOARD STYLES ========== */

/* Dashboard Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 16px;
}

.dashboard-header h1 {
    font-size: 28px;
    margin-bottom: 4px;
}

.dashboard-header p {
    color: var(--text-muted);
}

.btn-add-device {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 12px 24px;
    border-radius: 40px;
    text-decoration: none;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-add-device:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-add-device span {
    font-size: 20px;
    font-weight: 700;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    text-align: center;
    transition: all 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.stat-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-value.online-value {
    color: #22c55e;
}

.stat-value.warning-value {
    color: #f59e0b;
}

/* Section Header */
.section-header {
    margin: 32px 0 20px 0;
}

.section-header h2 {
    font-size: 20px;
    margin-bottom: 4px;
}

.section-header p {
    color: var(--text-muted);
    font-size: 14px;
}

/* Devices Grid */
.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 20px;
}

/* Device Card */
.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    transition: all 0.2s;
}

.device-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.device-card-header {
    padding: 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.device-info {
    flex: 1;
}

.device-name-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.device-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.edit-name-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    opacity: 0.5;
    padding: 2px 4px;
    border-radius: 4px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.edit-name-btn:hover {
    opacity: 1;
    background: var(--bg-secondary);
    color: var(--primary);
}

.device-id {
    font-size: 10px;
    font-family: monospace;
    color: var(--text-muted);
    margin-top: 4px;
}

.device-board {
    font-size: 10px;
    color: var(--primary-light);
    margin-top: 2px;
}

/* Token Badge */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 9px;
    font-weight: 600;
    margin-top: 6px;
}

.badge.secure {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge.legacy {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Status Badge */
.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-text {
    color: var(--text-primary);
}

.status-badge.online .status-dot {
    background: #22c55e;
    box-shadow: 0 0 4px #22c55e;
}

.status-badge.online .status-text {
    color: #22c55e;
}

.status-badge.offline .status-dot {
    background: #64748b;
}

.status-badge.offline .status-text {
    color: #64748b;
}

.status-badge.away .status-dot {
    background: #f59e0b;
}

.status-badge.away .status-text {
    color: #f59e0b;
}

/* Device Details */
.device-details {
    padding: 12px 16px;
    background: var(--bg-elevated);
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
}

.detail-label {
    color: var(--text-muted);
}

.detail-value {
    color: var(--text-primary);
    font-family: monospace;
}

/* Sensors Status */
.sensors-status {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.sensors-grid {
    display: flex;
    gap: 12px;
    justify-content: space-around;
    flex-wrap: wrap;
}

.sensor-mini-card {
    flex: 1;
    min-width: 70px;
    text-align: center;
    padding: 8px;
    background: var(--bg-elevated);
    border-radius: 12px;
    transition: all 0.2s;
    color: var(--text-primary);
}

.sensor-mini-card:hover {
    transform: translateY(-2px);
}

.sensor-mini-icon {
    font-size: 20px;
    margin-bottom: 4px;
}

.sensor-mini-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.sensor-mini-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.sensor-mini-unit {
    font-size: 9px;
    color: var(--text-muted);
}

/* Pin Mapping */
.pin-mapping {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.pin-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pin-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-elevated);
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 10px;
    color: var(--text-primary);
}

.pin-label {
    font-weight: 700;
    color: var(--primary);
}

.pin-name {
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.pin-gpio {
    color: var(--text-muted);
    font-family: monospace;
}

/* Session Info */
.session-info {
    padding: 10px 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.session-label {
    font-size: 11px;
    color: var(--text-muted);
}

.session-value {
    font-size: 11px;
    font-weight: 600;
    font-family: monospace;
    color: var(--text-primary);
}

.session-value.good {
    color: #22c55e;
}

.session-value.warning {
    color: #f59e0b;
}

.session-value.critical {
    color: #ef4444;
}

/* Relays Section */
.relays-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.relays-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.relay-btn {
    flex: 1;
    min-width: 70px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 6px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    color: var(--text-primary);
}

.relay-btn:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.relay-btn.loading {
    opacity: 0.6;
    cursor: wait;
}

.relay-number {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    display: block;
    letter-spacing: 0.5px;
}

.relay-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    display: block;
    margin: 4px 0;
}

.relay-state {
    font-size: 10px;
    font-weight: 700;
    margin-top: 4px;
    display: block;
}

.relay-state.on {
    color: #22c55e;
}

.relay-state.off {
    color: #ef4444;
}

/* Temperature Card */
.temp-card {
    background: linear-gradient(135deg, #1a1f2e, #0f1422);
    border: 2px solid var(--primary);
    border-radius: 16px;
    padding: 16px;
    margin: 12px 16px;
    text-align: center;
}

.temp-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
    margin-bottom: 8px;
}

.temp-value {
    font-size: 28px;
    font-weight: 800;
    color: #f59e0b;
}

.temp-humidity {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 10px 0;
    font-size: 12px;
    color: #93c5fd;
}

.temp-humidity strong {
    color: var(--text-primary);
}

.temp-offset {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid rgba(59, 130, 246, 0.2);
}

.offset-input {
    width: 70px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 11px;
    text-align: center;
}

.offset-label {
    font-size: 10px;
    color: #94a3b8;
}

/* Migration Prompt */
.migration-prompt {
    padding: 12px 16px;
    margin: 0 16px 12px;
    background: rgba(245, 158, 11, 0.1);
    border-radius: 12px;
    border-left: 3px solid #f59e0b;
}

.migration-warning {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.migration-icon {
    font-size: 20px;
}

.migration-text {
    flex: 1;
}

.migration-text strong {
    font-size: 11px;
    color: #f59e0b;
    display: block;
}

.migration-text span {
    font-size: 10px;
    color: var(--text-muted);
}

.btn-migrate {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-migrate:hover {
    transform: translateY(-1px);
}

/* Action Buttons */
.device-actions {
    padding: 16px;
    display: flex;
    gap: 10px;
}

.btn-renew, .btn-details, .btn-delete {
    flex: 1;
    padding: 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    text-decoration: none;
    border: none;
}

.btn-alert {
    background: var(--bg-elevated);
    color: #f59e0b;
    flex: 1;
    padding: 10px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 11px;
    cursor: pointer;
    text-align: center;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.btn-alert:hover {
    background: rgba(245, 158, 11, 0.1);
    transform: translateY(-2px);
}

.btn-renew {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.btn-details {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-delete {
    background: var(--bg-elevated);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-renew:hover, .btn-details:hover, .btn-delete:hover {
    transform: translateY(-2px);
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Pending Devices */
.pending-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 16px;
}

.pending-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    border-left: 3px solid #f59e0b;
}

.pending-header {
    padding: 14px 16px;
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    gap: 12px;
}

.pending-icon {
    font-size: 28px;
}

.pending-info h3 {
    font-size: 14px;
    margin-bottom: 2px;
    color: var(--text-primary);
}

.pending-temp-id {
    font-size: 10px;
    font-family: monospace;
    color: var(--text-muted);
}

.pending-board {
    font-size: 9px;
    color: var(--primary-light);
}

.pending-status.ready {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
}

.pending-details {
    padding: 12px 16px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.pending-actions {
    padding: 12px 16px;
    display: flex;
    gap: 10px;
}

.btn-claim, .btn-delete-pending {
    flex: 1;
    padding: 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}

.btn-claim {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

.btn-delete-pending {
    background: var(--bg-elevated);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: 24px;
    border: 1px solid var(--border);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-muted);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 24px;
    max-width: 450px;
    width: 90%;
    padding: 24px;
    text-align: center;
    border: 1px solid var(--border);
}

.modal-content.modal-large {
    max-width: 700px;
}

.modal-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.modal-message {
    margin-bottom: 24px;
    color: var(--text-primary);
}

.modal-message ul {
    text-align: left;
    margin-top: 12px;
    margin-left: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-btn {
    padding: 10px 24px;
    border-radius: 40px;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.modal-btn.cancel {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.modal-btn.confirm {
    background: var(--primary);
    color: white;
}

.modal-btn.copy {
    background: #22c55e;
    color: white;
}

.modal-btn.close {
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.code-block {
    background: #1e293b;
    color: #cbd5e6;
    padding: 16px;
    border-radius: 12px;
    overflow-x: auto;
    font-size: 11px;
    font-family: monospace;
    margin: 16px 0;
    text-align: left;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 400px;
    overflow-y: auto;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    left: 20px;
    max-width: 300px;
    margin: 0 auto;
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 500;
    z-index: 1100;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    pointer-events: none;
    text-align: center;
    font-size: 13px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background: #22c55e;
    color: white;
}

.toast.error {
    background: #ef4444;
    color: white;
}

/* Activation Banner */
.activation-banner {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    border-radius: 16px;
    padding: 12px 20px;
    margin-bottom: 24px;
}

.activation-message {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: space-between;
    flex-wrap: wrap;
}

.activation-text {
    color: white;
    font-weight: 500;
}

.activation-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
}

/* Alert Bell Styles */
.alert-bell-container {
    position: relative;
    display: inline-block;
}

.alert-bell {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 40px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 20px;
    position: relative;
}

.alert-bell:hover {
    transform: scale(1.05);
    border-color: var(--primary);
}

.alert-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Alert Dropdown */
.alert-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 350px;
    max-width: 90vw;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    margin-top: 8px;
    overflow: hidden;
}

.alert-dropdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.alert-dropdown-header button {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
}

.alert-dropdown-list {
    max-height: 400px;
    overflow-y: auto;
}

.alert-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.alert-item:hover {
    background: var(--bg-elevated);
}

.alert-item.unread {
    background: rgba(59, 130, 246, 0.05);
}

.alert-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

.alert-message {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.alert-time {
    font-size: 10px;
    color: var(--text-muted);
}

.alert-unread-dot {
    width: 8px;
    height: 8px;
    background: #3b82f6;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 8px;
}

.alert-loading, .alert-empty, .alert-error {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.alert-dropdown-footer {
    padding: 10px 16px;
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
}

.alert-dropdown-footer a {
    color: var(--primary);
    text-decoration: none;
    font-size: 12px;
}

/* Responsive */
@media (max-width: 768px) {
    .dashboard-header {
        flex-direction: column;
        text-align: center;
    }

    .btn-add-device {
        width: 100%;
        justify-content: center;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .devices-grid {
        grid-template-columns: 1fr;
    }

    .device-actions {
        flex-direction: column;
    }

    .pending-details {
        grid-template-columns: 1fr;
    }

    .pending-actions {
        flex-direction: column;
    }

    .sensors-grid {
        flex-wrap: wrap;
    }

    .modal-content.modal-large {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .alert-dropdown {
        width: 320px;
        right: -10px;
    }
}

@media (max-width: 480px) {
    .stat-value {
        font-size: 22px;
    }

    .relays-grid {
        gap: 6px;
    }

    .relay-btn {
        min-width: 55px;
        padding: 8px 4px;
    }

    .relay-name {
        font-size: 10px;
    }

    .relay-number {
        font-size: 8px;
    }

    .pin-row {
        gap: 4px;
    }

    .pin-item {
        font-size: 9px;
        padding: 3px 6px;
    }

    .pin-name {
        max-width: 45px;
    }
}