/**
 * Shared Theme Variables and Base Styles
 * Include this on all pages for consistent theming
 */

/* ============================================
   CSS VARIABLES (Theme Support)
   ============================================ */
:root {
    /* Core backgrounds */
    --bg-body: #f8f9fa;
    --bg-surface: #ffffff;
    --bg-surface-secondary: #f8f9fa;
    --bg-surface-tertiary: #e9ecef;
    
    /* Core text colors */
    --text-primary: #212529;
    --text-secondary: #343a40;
    --text-muted: #5a6268;
    
    /* Border colors */
    --border-color: #dee2e6;
    --border-color-subtle: #e5e7eb;
    
    /* Primary brand colors */
    --primary-color: #667eea;
    --primary-hover: #5a6fd6;
    --secondary-color: #764ba2;
    
    /* Status colors */
    --danger-color: #dc3545;
    --success-color: #22c55e;
    --warning-color: #ffc107;
    --info-color: #3b82f6;
    
    /* Semantic colors */
    --semantic-green: #059669;
    --semantic-orange: #d97706;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* Aliases for cross-compatibility */
    --color-text: var(--text-primary);
    --color-text-muted: var(--text-muted);
    --color-primary: var(--primary-color);
    --color-secondary: var(--secondary-color);
    --color-success: var(--success-color);
    --color-danger: var(--danger-color);
    --color-warning: var(--warning-color);
    --color-info: var(--info-color);
    --color-card-bg: var(--bg-surface);
    --color-surface: var(--bg-surface-secondary);
    --color-border: var(--border-color);
    
    /* Terminal colors */
    --color-terminal-bg: #1a1b26;
    --color-terminal-text: #e2e8f0;
}

[data-theme="dark"] {
    /* Core backgrounds */
    --bg-body: #121212;
    --bg-surface: #1e1e1e;
    --bg-surface-secondary: #2d2d2d;
    --bg-surface-tertiary: #383838;
    
    /* Core text colors */
    --text-primary: #f8f9fa;
    --text-secondary: #e9ecef;
    --text-muted: #adb5bd;
    
    /* Border colors */
    --border-color: #404040;
    --border-color-subtle: #333333;
    
    /* Primary brand colors */
    --primary-color: #818cf8;
    --primary-hover: #a5b4fc;
    --secondary-color: #c084fc;
    
    /* Status colors */
    --danger-color: #f87171;
    --success-color: #4ade80;
    --warning-color: #fbbf24;
    --info-color: #60a5fa;
    
    /* Semantic colors */
    --semantic-green: #34d399;
    --semantic-orange: #fbbf24;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    
    /* Terminal colors */
    --color-terminal-bg: #0d0d0d;
    --color-terminal-text: #e2e8f0;
}

/* ============================================
   BASE STYLES
   ============================================ */
html, body {
    min-height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
}

body {
    padding-top: 56px; /* Header height */
}

/* ============================================
   LOADING OVERLAY
   ============================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-body);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-logo {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-logo .hexagon {
    width: 60px;
    height: 60px;
    color: var(--primary-color);
    animation: pulse-logo 2s ease-in-out infinite;
}

.loading-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin-ring 1s linear infinite;
}

.loading-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    animation: fade-text 2s ease-in-out infinite;
}

@keyframes pulse-logo {
    0% { transform: scale(0.9); opacity: 0.8; }
    50% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.9); opacity: 0.8; }
}

@keyframes spin-ring {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Spinning animation for icons */
.spinning {
    animation: spin-ring 1s linear infinite;
}

@keyframes fade-text {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ============================================
   BOOTSTRAP OVERRIDES FOR THEMING
   ============================================ */
.text-body {
    color: var(--text-primary) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

.text-secondary {
    color: var(--text-secondary) !important;
}

.bg-light {
    background-color: var(--bg-surface-secondary) !important;
}

.bg-white {
    background-color: var(--bg-surface) !important;
}

.border {
    border-color: var(--border-color) !important;
}

/* Card Theming */
.card {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.card-header {
    background-color: var(--bg-surface-secondary);
    border-color: var(--border-color);
}

.card-footer {
    background-color: var(--bg-surface-secondary);
    border-color: var(--border-color);
}

/* Modal Theming */
.modal-content {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.modal-header {
    border-color: var(--border-color);
}

.modal-footer {
    border-color: var(--border-color);
}

/* Form Controls Theming */
.form-control {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.form-control:focus {
    background-color: var(--bg-surface);
    border-color: var(--primary-color);
    color: var(--text-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-select {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.form-select:focus {
    background-color: var(--bg-surface);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.form-check-input {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
}

.input-group-text {
    background-color: var(--bg-surface-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Table Theming */
.table {
    color: var(--text-primary);
    border-color: var(--border-color);
}

.table > thead {
    background-color: var(--bg-surface-secondary);
}

.table > tbody > tr:hover {
    background-color: var(--bg-surface-secondary);
}

.table-striped > tbody > tr:nth-of-type(odd) {
    background-color: var(--bg-surface-secondary);
}

/* List Group Theming */
.list-group-item {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.list-group-item-action:hover,
.list-group-item-action:focus {
    background-color: var(--bg-surface-secondary);
    color: var(--text-primary);
}

/* Dropdown Theming */
.dropdown-menu {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    box-shadow: var(--shadow-md);
}

.dropdown-item {
    color: var(--text-primary);
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--bg-surface-secondary);
    color: var(--text-primary);
}

.dropdown-divider {
    border-color: var(--border-color);
}

/* Alert Theming for dark mode */
[data-theme="dark"] .alert-info {
    background-color: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--text-primary);
}

[data-theme="dark"] .alert-success {
    background-color: rgba(52, 211, 153, 0.15);
    border-color: rgba(52, 211, 153, 0.3);
    color: var(--text-primary);
}

[data-theme="dark"] .alert-warning {
    background-color: rgba(251, 191, 36, 0.15);
    border-color: rgba(251, 191, 36, 0.3);
    color: var(--text-primary);
}

[data-theme="dark"] .alert-danger {
    background-color: rgba(231, 76, 60, 0.15);
    border-color: rgba(231, 76, 60, 0.3);
    color: var(--text-primary);
}

/* Nav Tabs/Pills Theming */
.nav-tabs {
    border-color: var(--border-color);
}

.nav-tabs .nav-link {
    color: var(--text-secondary);
}

.nav-tabs .nav-link:hover {
    border-color: var(--border-color);
}

.nav-tabs .nav-link.active {
    background-color: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* ============================================
   PAGE LAYOUT UTILITIES
   ============================================ */
.page-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-title i {
    color: var(--primary-color);
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.9375rem;
    margin-top: 0.25rem;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.bg-theme-surface { background-color: var(--bg-surface) !important; }
.bg-theme-surface-secondary { background-color: var(--bg-surface-secondary) !important; }
.bg-theme-surface-tertiary { background-color: var(--bg-surface-tertiary) !important; }
.text-theme-primary { color: var(--text-primary) !important; }
.text-theme-secondary { color: var(--text-secondary) !important; }
.border-theme { border-color: var(--border-color) !important; }

/* ============================================
   IN-PAGE LOADING INDICATOR
   ============================================ */
#loading-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-surface);
    color: var(--text-primary);
    padding: 1.25rem 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    z-index: 9999;
    backdrop-filter: blur(4px);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.clarity-toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    min-width: 280px;
    max-width: 400px;
    padding: 1rem 1.25rem;
    border-radius: 0.5rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    animation: toast-slide-in 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.clarity-toast.toast-success {
    border-left: 4px solid var(--success-color);
}

.clarity-toast.toast-error {
    border-left: 4px solid var(--danger-color);
}

.clarity-toast.toast-warning {
    border-left: 4px solid var(--warning-color);
}

.clarity-toast.toast-info {
    border-left: 4px solid var(--primary-color);
}

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Artifact Selection Modal */
.artifact-selection-list {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-surface-secondary);
}

.artifact-selection-item {
    border-bottom: 1px solid var(--border-color-subtle);
}

.artifact-selection-item:last-child {
    border-bottom: none;
}

.artifact-selection-item label {
    transition: background 0.15s ease;
}

.artifact-selection-item label:hover {
    background: var(--bg-surface);
}

.artifact-selection-item .min-width-0 {
    min-width: 0;
}

/* Mode Cards */
.mode-card {
    cursor: pointer;
    transition: all 0.15s ease;
}

.mode-card:hover {
    border-color: var(--primary-color) !important;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.hover-bg:hover {
    background: var(--bg-surface);
}

.cursor-pointer {
    cursor: pointer;
}

/* Depth Card Selection (used in extraction settings) */
.depth-card {
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}

.depth-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.depth-card:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.depth-card.selected {
    border-color: var(--primary-color) !important;
}

/* ============================================
   SIGNALR CONNECTION BANNER
   ============================================ */
.signalr-connection-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.signalr-connection-banner.signalr-reconnecting {
    background: linear-gradient(90deg, var(--warning-color), #ffdb4d);
    color: #664d00;
}

.signalr-connection-banner.signalr-failed {
    background: linear-gradient(90deg, var(--danger-color), #f04e5e);
    color: white;
}

.signalr-connection-banner i {
    margin-right: 0.5rem;
}

.signalr-connection-banner .spin-animation {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
