/* ============================================
   SHARED COMPONENTS STYLES
   Common UI patterns used across multiple pages
   Version: 1.1.0 - Enhanced UX/UI
   ============================================ */

/* ===========================================
   Panel Styles (Selection, Filter, Controls)
   =========================================== */

.selection-panel,
.filter-panel,
.controls-panel,
.status-section {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
    transition: box-shadow var(--transition-base), border-color var(--transition-base);
}

.selection-panel:hover,
.status-section:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(49, 151, 149, 0.3);
}

/* Animated gradient top border accent */
.selection-panel::before,
.status-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-cyan) 0%, var(--success-green) 50%, var(--accent-cyan) 100%);
    background-size: 200% 100%;
    animation: gradient-shift 4s ease infinite;
}

@keyframes gradient-shift {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

/* Panel headers */
.panel-header,
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.panel-header h2,
.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.action-btn {
    background: var(--bg-white);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary-blue);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.action-btn:hover {
    background: var(--accent-cyan);
    color: white;
    border-color: var(--accent-cyan);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm), 0 4px 12px rgba(49, 151, 149, 0.25);
}

.action-btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-xs);
}

.action-btn:focus-visible {
    outline: 2px solid var(--accent-cyan);
    outline-offset: 2px;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.action-btn.primary {
    background: linear-gradient(135deg, var(--accent-cyan) 0%, #2c7a7b 100%);
    color: white;
    border: none;
    box-shadow: var(--shadow-sm);
}

.action-btn.primary:hover {
    box-shadow: var(--shadow-md), 0 4px 16px rgba(49, 151, 149, 0.4);
    transform: translateY(-2px);
    filter: brightness(1.08);
}

.action-btn.primary:active {
    transform: translateY(0);
    filter: brightness(0.95);
}

.action-btn.success {
    color: var(--success-green);
    border-color: var(--success-green);
}

.action-btn.success:hover {
    background: var(--success-green);
    color: white;
}

.action-btn.danger {
    color: var(--error-red);
    border-color: var(--error-red);
}

.action-btn.danger:hover {
    background: var(--error-red);
    color: white;
    box-shadow: var(--shadow-sm), 0 4px 12px rgba(239, 68, 68, 0.25);
}

/* Button loading state */
.action-btn.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.action-btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-top: -8px;
    margin-left: -8px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===========================================
   Selection Actions (Select All, Clear, Count)
   =========================================== */

.selection-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.selection-count {
    font-size: 0.8125rem;
    color: var(--primary-blue);
    padding: 8px 16px;
    background: rgba(0, 120, 212, 0.08);
    border-radius: var(--radius-full);
    font-weight: 600;
}

/* ===========================================
   Survey Selection Grid
   =========================================== */

.survey-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
    max-height: 380px;
    overflow-y: auto;
    padding: 4px;
    margin: -4px;
}

/* Custom scrollbar */
.survey-selection-grid::-webkit-scrollbar {
    width: 8px;
}

.survey-selection-grid::-webkit-scrollbar-track {
    background: var(--bg-light);
    border-radius: 4px;
}

.survey-selection-grid::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 4px;
}

.survey-selection-grid::-webkit-scrollbar-thumb:hover {
    background: var(--primary-blue);
}

/* Survey checkbox items */
.survey-checkbox-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--bg-light);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.survey-checkbox-item::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: calc(var(--radius-md) + 2px);
    opacity: 0;
    transition: opacity var(--transition-fast);
    pointer-events: none;
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.15);
}

.survey-checkbox-item:hover {
    background: var(--bg-white);
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.survey-checkbox-item:hover::after {
    opacity: 1;
}

.survey-checkbox-item:active {
    transform: translateY(0);
}

.survey-checkbox-item.selected {
    background: linear-gradient(135deg, rgba(0, 120, 212, 0.08) 0%, rgba(0, 212, 255, 0.04) 100%);
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.12);
}

.survey-checkbox-item.selected::after {
    opacity: 0;
}

.survey-checkbox-item input[type="checkbox"],
.survey-checkbox-item input[type="radio"] {
    width: 22px;
    height: 22px;
    cursor: pointer;
    accent-color: var(--primary-blue);
    flex-shrink: 0;
}

.survey-checkbox-label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    min-width: 0;
}

.survey-checkbox-label .survey-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.survey-checkbox-label .survey-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'Cascadia Code', 'Consolas', 'Monaco', monospace;
    letter-spacing: 0.3px;
}

/* ===========================================
   Filter Panel
   =========================================== */

.filter-panel {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 16px 24px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.filter-group select,
.filter-group input {
    padding: 8px 14px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: var(--bg-white);
    color: var(--text-primary);
    min-width: 150px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.1);
}

/* ===========================================
   Controls Panel
   =========================================== */

.controls-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    flex-wrap: wrap;
}

.controls-left,
.controls-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* ===========================================
   Status Badges
   =========================================== */

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    width: fit-content;
}

.status-badge.success,
.status-badge.healthy {
    background: var(--success-light);
    color: var(--success-green);
}

.status-badge.warning {
    background: var(--warning-light);
    color: #92400E;
}

.status-badge.error,
.status-badge.danger {
    background: var(--error-light);
    color: var(--error-red);
}

.status-badge.info {
    background: rgba(0, 120, 212, 0.1);
    color: var(--primary-blue);
}

.status-badge.checking {
    background: var(--bg-gray);
    color: var(--text-secondary);
}

/* ===========================================
   Health Cards (API Status, System Health)
   =========================================== */

.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.health-card {
    background: linear-gradient(135deg, var(--bg-light) 0%, var(--bg-white) 100%);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.health-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--border-medium);
    transition: background var(--transition-base);
}

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

.health-card.healthy {
    border-color: var(--success-green);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.06) 0%, var(--bg-white) 100%);
}

.health-card.healthy::before {
    background: linear-gradient(90deg, var(--success-green), #34D399);
}

.health-card.warning {
    border-color: var(--warning-orange);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.06) 0%, var(--bg-white) 100%);
}

.health-card.warning::before {
    background: linear-gradient(90deg, var(--warning-orange), #FBBF24);
}

.health-card.error {
    border-color: var(--error-red);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.06) 0%, var(--bg-white) 100%);
    animation: pulse-error 2s ease-in-out infinite;
}

.health-card.error::before {
    background: linear-gradient(90deg, var(--error-red), #F87171);
}

@keyframes pulse-error {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
    }
}

.health-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.health-icon {
    font-size: 1.75rem;
    line-height: 1;
}

.health-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.health-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.health-details {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}

.health-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.health-stat .stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.health-stat .stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===========================================
   Toggle Switches
   =========================================== */

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border-medium);
    border-radius: 24px;
    transition: var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-xs);
}

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

.toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(20px);
}

.toggle-switch input:focus+.toggle-slider {
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.15);
}

/* ===========================================
   Last Updated Text
   =========================================== */

.last-updated {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ===========================================
   Auto-refresh Toggle
   =========================================== */

.auto-refresh-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* ===========================================
   Empty State
   =========================================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.empty-state p {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin: 0;
    max-width: 400px;
}

/* ===========================================
   Modal Styles (Shared)
   =========================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn var(--transition-fast) ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-2xl);
    animation: modalSlideIn var(--transition-base) ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 1.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

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

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
}

/* ===========================================
   Responsive Adjustments
   =========================================== */

@media (max-width: 768px) {

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

    .selection-actions {
        justify-content: space-between;
    }

    .filter-panel,
    .controls-panel {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .controls-left,
    .controls-right {
        justify-content: space-between;
    }

    .survey-selection-grid {
        grid-template-columns: 1fr;
    }

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