/* ========================================
   APEX Components
   Buttons, cards, forms, tables, badges, alerts,
   metrics, loading states
   Consolidated from: components.css, components-modern.css,
   enhanced-forms.css, loading-states.css
   ======================================== */


/* ========================================
   1. BUTTONS
   ======================================== */

/* Bootstrap Override Base */
.btn {
    font-weight: 500;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: var(--radius-lg);
    padding: 0.625rem 1.25rem;
    transition: var(--transition-base);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
    user-select: none;
    position: relative;
    overflow: hidden;
    text-align: center !important;
}

.btn-primary {
    background: var(--color-primary-gradient);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    transform: translateY(-1px);
    color: white;
}

.btn-secondary {
    background: var(--gradient-secondary);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-secondary:hover {
    box-shadow: var(--shadow-lg), var(--shadow-glow-purple);
    transform: translateY(-1px);
    color: white;
}

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

.btn-outline-primary:hover {
    background: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-ghost {
    background: var(--glass-bg);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    backdrop-filter: var(--backdrop-blur);
}

.btn-ghost:hover {
    background: var(--gradient-glass);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    color: var(--text-primary);
}

.btn-sm { padding: 0.5rem 1rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.875rem 1.75rem; font-size: 1rem; }

/* APEX Button System */
.btn-apex {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    line-height: 1;
    text-decoration: none;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: var(--transition-smooth);
    white-space: nowrap;
    text-align: center !important;
}

button,
input[type="button"],
input[type="submit"],
[role="button"] {
    text-align: center;
}

.btn-apex:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-apex-primary {
    background: var(--color-primary-gradient);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-glow-primary);
}

.btn-apex-primary:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgb(37 99 235 / 35%);
}

.btn-apex-secondary {
    background: var(--color-secondary);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-glow-secondary);
}

.btn-apex-secondary:hover:not(:disabled) {
    background: var(--color-secondary-dark);
    transform: translateY(-1px);
}

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

.btn-apex-outline:hover:not(:disabled) {
    background: rgb(37 99 235 / 5%);
}

.btn-apex-ghost {
    background: var(--color-background);
    color: var(--color-text);
    border: 1px solid rgb(0 0 0 / 8%);
}

.btn-apex-ghost:hover:not(:disabled) {
    background: var(--color-background-alt);
    border-color: rgb(0 0 0 / 12%);
}

.btn-apex-icon { width: 40px; height: 40px; padding: 0; border-radius: var(--radius-full); }
.btn-apex-sm { padding: var(--space-2) var(--space-4); font-size: var(--text-xs); }
.btn-apex-lg { padding: var(--space-4) var(--space-6); font-size: var(--text-base); }


/* ========================================
   2. CARDS
   ======================================== */

/* Bootstrap Card Override */
.card {
    background: var(--pure-white);
    border: 1px solid var(--medium-grey);
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-base);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.card-header {
    background: linear-gradient(135deg, var(--light-grey), #F1F5F9);
    border-bottom: 1px solid var(--medium-grey);
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body { padding: 1.25rem; }

.card-footer {
    background: var(--light-grey);
    border-top: 1px solid var(--medium-grey);
    padding: 1rem 1.25rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* APEX Card System */
.card-apex {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-apex-body { padding: var(--space-5); }

.card-apex-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid rgb(0 0 0 / 4%);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-apex-title {
    font-size: var(--text-base);
    font-weight: var(--font-semibold);
    color: var(--color-text);
    margin: 0;
}

.card-apex-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid rgb(0 0 0 / 4%);
    background: var(--color-background);
}

/* Modern Card Variants */
.card-modern {
    background: var(--gradient-card);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    transition: var(--transition-base);
    overflow: hidden;
    position: relative;
}

.card-modern:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card-glass {
    background: var(--glass-bg);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-base);
}

.card-glass:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* ========================================
   Utility Helpers (Week 3 Hardening)
   ======================================== */
.apex-text-xs-75 { font-size: 0.75rem; }
.apex-text-xs-70 { font-size: 0.7rem; }
.apex-text-xs-65 { font-size: 0.65rem; }
.apex-text-xs-11 { font-size: 11px; }
.apex-dot-8 { font-size: 8px; }
.apex-dot-6 { font-size: 6px; }

.apex-avatar-32 {
    width: 32px;
    height: 32px;
    min-width: 32px;
}

.apex-icon-36 {
    width: 36px;
    height: 36px;
}
.apex-chart-h-300 { height: 300px; }
.apex-chart-h-250 { height: 250px; }

.apex-chart-wrap {
    position: relative;
}
.apex-card-radius-16 { border-radius: 16px; }
.apex-opacity-30 { opacity: 0.3; }
.apex-inline-form { display: inline; }
.apex-chevron-xs { font-size: 0.7rem; }
.apex-alert-text-sm { font-size: 0.82rem; }
.apex-legend-dot-12 { width: 12px; height: 12px; }
.apex-progress-h-8 { height: 8px; }
.apex-fw-700 { font-weight: 700; }
.apex-progress-var { width: var(--pct, 0%); }

.apex-confidence-fill {
    height: 100%;
    border-radius: 99px;
    width: var(--pct, 0%);
}
.apex-confidence-fill-high { background: var(--color-status-success, #15803D); }
.apex-confidence-fill-medium { background: var(--color-status-warning, #B45309); }
.apex-confidence-fill-low { background: var(--color-status-error, #B91C1C); }

.apex-beacon-badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
}
.apex-beacon-badge-uploaded { background: #e0e7ff; color: #3730a3; }
.apex-beacon-badge-processing { background: #fef3c7; color: #92400e; }
.apex-beacon-badge-complete { background: #d1fae5; color: #065f46; }
.apex-beacon-badge-failed { background: #fee2e2; color: #991b1b; }
.apex-beacon-badge-pending { background: #e0e7ff; color: #3730a3; }
.apex-beacon-badge-approved { background: #d1fae5; color: #065f46; }
.apex-beacon-badge-rejected { background: #fee2e2; color: #991b1b; }

.apex-portal-hero-soft {
    background: linear-gradient(
        135deg,
        rgb(255 38 116 / 8%) 0%,
        rgb(51 23 184 / 8%) 100%
    );
    border-radius: var(--radius-xl);
    padding: 1.5rem;
}

.apex-portal-session-note {
    background: rgb(255 38 116 / 5%);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--primary-pink);
}

.apex-portal-icon-circle-45 {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.apex-portal-icon-primary { background: var(--gradient-primary); }
.apex-portal-icon-med { background: linear-gradient(135deg, var(--dark-navy) 0%, var(--dark-teal) 100%); }
.apex-portal-icon-purple-solid { background: var(--primary-purple); }
.apex-portal-icon-telehealth { background: linear-gradient(135deg, var(--dark-teal) 0%, var(--primary-pink) 100%); }
.apex-portal-icon-secondary { background: var(--gradient-secondary); }

.apex-badge-gradient-telehealth {
    background: linear-gradient(135deg, var(--dark-teal) 0%, var(--primary-pink) 100%);
    color: white;
    border-radius: var(--radius-lg);
}

.apex-badge-gradient-secondary {
    background: var(--gradient-secondary);
    color: white;
    border-radius: var(--radius-lg);
}
.apex-text-primary-var { color: var(--text-primary); }
.apex-text-secondary-var { color: var(--text-secondary); }
.apex-text-dark-navy { color: var(--dark-navy); }
.apex-text-dark-teal { color: var(--dark-teal); }

.apex-btn-outline-pink {
    border-color: var(--primary-pink);
    color: var(--primary-pink);
}

.apex-btn-outline-navy {
    border-color: var(--dark-navy);
    color: var(--dark-navy);
}
.apex-card-radius-xl { border-radius: var(--radius-xl); }
.apex-card-radius-lg { border-radius: var(--radius-lg); }
.apex-th-letterspace-05 { letter-spacing: 0.5px; }

.apex-row-divider-soft {
    border-bottom: 1px solid var(--neutral-100);
    transition: background-color 0.2s;
}
.apex-minw-50 { min-width: 50px; }

.apex-note-truncate-150 {
    max-width: 150px;
    color: var(--text-secondary);
}

.apex-page-link-circle-32 {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.apex-object-cover { object-fit: cover; }
.apex-status-dot-20 { width: 20px; height: 20px; }
.apex-input-bg-soft { background-color: var(--neutral-50); }

.apex-avatar-frame-120 {
    width: 120px;
    height: 120px;
    border: 4px solid var(--neutral-100);
}
.apex-icon-w-20 { width: 20px; }
.apex-border-white-3 { border: 3px solid white; }
.apex-alert-radius-md { border-radius: var(--radius-md); }
.apex-hidden-file-input { display: none; }

/* ========================================
   Accessibility Polish (Week 4 Starter)
   ======================================== */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
.btn:focus-visible,
.page-link:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 2px solid var(--color-primary, var(--primary-color, #2563eb));
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}


/* ========================================
   MICRO-INTERACTION POLISH
   Consistent hover, press, and transition behaviors
   ======================================== */

/* Base transition for all interactive elements */
.btn,
.nav-link,
.dropdown-item,
.apex-card,
.apex-stat-card,
a[class*="btn"],
[role="button"] {
    transition: background-color 0.15s ease, color 0.15s ease,
                border-color 0.15s ease, box-shadow 0.15s ease,
                transform 0.15s ease;
}

/* Card lift on hover */
.apex-card:hover {
    box-shadow: var(--shadow-md, 0 4px 12px rgb(15 23 42 / 10%));
}

.apex-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg, 0 10px 24px rgb(15 23 42 / 14%));
}

/* Button press feedback */
.btn:active:not(:disabled),
.submit-btn:active:not(:disabled),
[role="button"]:active:not(:disabled) {
    transform: scale(0.97);
}

/* Link hover underline */
.apex-content a:not(.btn, .nav-link, .dropdown-item, [class*="card"]):hover {
    text-decoration-color: var(--color-primary, #2563EB);
}

/* Table row hover highlight */
.table tbody tr {
    transition: background-color 0.1s ease;
}

.table-hover tbody tr:hover {
    background-color: rgb(37 99 235 / 4%);
}

/* Badge pulse for live indicators */
@keyframes subtlePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.badge-live,
.status-live {
    animation: subtlePulse 2s ease-in-out infinite;
}

/* Dropdown smooth open */
.dropdown-menu {
    animation: dropdownFade 0.12s ease-out;
}

@keyframes dropdownFade {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Toast/alert entrance */
.apex-alert {
    animation: alertSlideIn 0.25s ease-out;
}

@keyframes alertSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}


/* ========================================
   3. METRIC CARDS (Dashboard Stats)
   ======================================== */

.metric-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgb(0 0 0 / 4%);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevated);
}

.metric-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: inset 0 2px 4px rgb(0 0 0 / 3%);
}

.metric-icon.icon-blue { background: rgb(37 99 235 / 8%); color: var(--color-primary); }
.metric-icon.icon-teal { background: rgb(13 148 136 / 8%); color: var(--color-secondary); }
.metric-icon.icon-purple { background: rgb(99 102 241 / 8%); color: var(--color-accent-purple); }
.metric-icon.icon-orange { background: rgb(249 115 22 / 8%); color: var(--color-accent-orange); }
.metric-icon.icon-pink { background: rgb(236 72 153 / 8%); color: var(--color-accent-pink); }
.metric-icon.icon-green { background: rgb(34 197 94 / 8%); color: var(--color-success); }
.metric-icon.icon-red { background: rgb(239 68 68 / 8%); color: var(--color-error); }

.metric-content { flex: 1; }

.metric-value {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
    color: var(--color-text);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.metric-label {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-top: var(--space-1);
    font-weight: var(--font-medium);
}

.metric-trend {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 11px;
    font-weight: var(--font-semibold);
    margin-top: var(--space-2);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
}

.metric-trend.up { color: var(--color-success); background: rgb(34 197 94 / 10%); }
.metric-trend.down { color: var(--color-error); background: rgb(239 68 68 / 10%); }

.metric-sub {
    font-size: 0.75rem;
    color: var(--color-status-success, #15803D);
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.metric-sub.negative { color: var(--color-status-error, #B91C1C); }

/* Metric Grid */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* Metric Icon Variants (Module Layout) */
.metric-icon-blue { background: rgb(37 99 235 / 10%); color: #2563EB; }
.metric-icon-green { background: rgb(21 128 61 / 10%); color: #15803D; }
.metric-icon-purple { background: rgb(139 92 246 / 10%); color: #8B5CF6; }
.metric-icon-orange { background: rgb(249 115 22 / 10%); color: #F97316; }
.metric-icon-pink { background: rgb(236 72 153 / 10%); color: #EC4899; }
.metric-icon-cyan { background: rgb(6 182 212 / 10%); color: #06B6D4; }

/* Stat Cards (Legacy) */
.stat-card {
    background: var(--gradient-card);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border-light);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    text-align: center;
    transition: var(--transition-base);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.stat-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
}

.stat-icon-small {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}


/* ========================================
   4. CHART CARDS
   ======================================== */

.chart-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    border: 1px solid rgb(0 0 0 / 4%);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
    height: 100%;
}

.chart-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid rgb(0 0 0 / 4%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.chart-body {
    padding: var(--space-6);
    position: relative;
}

/* Time Pills */
.time-pills {
    display: flex;
    gap: 4px;
    background: var(--color-background);
    padding: 4px;
    border-radius: var(--radius-pill);
}

.time-pill {
    padding: 6px 16px;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: var(--font-semibold);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: var(--transition-fast);
}

.time-pill.active {
    background: var(--color-surface);
    color: var(--color-primary);
    box-shadow: 0 2px 8px rgb(0 0 0 / 5%);
}


/* ========================================
   5. FEATURE CARDS
   ======================================== */

.feature-card {
    background: var(--color-surface);
    border: 1px solid rgb(0 0 0 / 4%);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    text-align: left;
    transition: var(--transition-smooth);
}

.feature-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
}

.feature-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: var(--space-4);
}

.feature-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-text);
    margin-bottom: var(--space-2);
}

.feature-description {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    line-height: var(--leading-relaxed);
}


/* ========================================
   6. ALERTS
   ======================================== */

.alert-apex {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
}

.alert-apex-info { background: var(--color-info-bg); color: var(--color-info); }
.alert-apex-success { background: var(--color-success-bg); color: var(--color-success); }
.alert-apex-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.alert-apex-error { background: var(--color-error-bg); color: var(--color-error); }

.alert-apex i { margin-top: 2px; }
.alert-apex-content { flex: 1; }
.alert-apex-title { font-weight: var(--font-semibold); margin-bottom: var(--space-1); }

.alert-critical {
    background: var(--color-error-bg);
    border-left: 4px solid var(--color-error);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
}


/* ========================================
   7. BADGES
   ======================================== */

.badge {
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
}

.badge.bg-success { background: var(--success-color) !important; }
.badge.bg-warning { background: var(--warning-color) !important; }
.badge.bg-info { background: var(--info-color) !important; }

.badge-apex {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    font-size: 11px;
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
}

.badge-apex-primary { background: rgb(37 99 235 / 10%); color: var(--color-primary); }
.badge-apex-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-apex-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-apex-error { background: var(--color-error-bg); color: var(--color-error); }
.badge-apex-purple { background: var(--color-accent-purple-bg); color: var(--color-accent-purple); }


/* ========================================
   8. FORMS
   ======================================== */

.form-control,
.form-select {
    border: 1px solid var(--medium-grey);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    transition: var(--transition-base);
    background: var(--pure-white);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 0.2rem rgb(37 99 235 / 25%);
    outline: none;
}

.form-label {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.apex-form-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.apex-form-field .form-label {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    margin-bottom: 0;
}

.apex-form-field .form-control,
.apex-form-field .form-select {
    min-height: 40px;
    font-size: var(--text-sm);
}

.apex-form-field .form-text {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.apex-search-group {
    display: flex;
    align-items: stretch;
}

.apex-search-group .form-control {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: 0;
}

.apex-search-group .btn {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.apex-filter-bar {
    background: var(--color-surface);
    border: 1px solid var(--medium-grey);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
}

.apex-filter-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
}

/* APEX Form Inputs */
.input-apex {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid rgb(0 0 0 / 10%);
    border-radius: var(--radius-lg);
    transition: var(--transition-fast);
}

.input-apex::placeholder { color: var(--color-text-light); }

.input-apex:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 10%);
}

.input-apex:disabled {
    background: var(--color-background);
    opacity: 0.7;
    cursor: not-allowed;
}

/* APEX Search Input */
.search-apex { position: relative; }

.search-apex .search-icon {
    position: absolute;
    left: var(--space-4);
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-light);
    pointer-events: none;
}

.search-apex .input-apex {
    padding-left: var(--space-10);
    background: var(--color-background);
    border-radius: var(--radius-xl);
}

/* Enhanced Form Wizard */
.form-wizard {
    position: relative;
    background: var(--gradient-card);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.form-wizard-header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    padding: 1.5rem 2rem;
    color: white;
}

.form-wizard-steps {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.form-step {
    display: flex;
    align-items: center;
    flex: 1;
    position: relative;
}

.step-indicator {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgb(255 255 255 / 20%);
    border: 2px solid rgb(255 255 255 / 30%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    margin-right: 0.75rem;
    position: relative;
    z-index: 2;
    transition: all 0.3s ease;
}

.form-step.active .step-indicator {
    background: white;
    color: var(--color-primary);
    border-color: white;
    box-shadow: 0 0 0 4px rgb(255 255 255 / 20%);
}

.form-step.completed .step-indicator {
    background: rgb(255 255 255 / 90%);
    color: var(--color-primary);
    border-color: rgb(255 255 255 / 90%);
}

.form-step.completed .step-indicator::before { content: '\2713'; font-weight: bold; }

.form-step-content {
    display: none;
    padding: 2rem;
    animation: fadeInUp 0.3s ease;
}

.form-step-content.active { display: block; }

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

/* Form Navigation */
.form-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--neutral-50);
    border-top: 1px solid var(--glass-border-light);
}

.form-nav-button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-lg);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-nav-button.primary {
    background: var(--color-primary-gradient);
    color: white;
    box-shadow: var(--shadow-md);
}

.form-nav-button.primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.form-nav-button.secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid var(--glass-border-light);
}

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

/* File Upload */
.file-upload-enhanced {
    position: relative;
    border: 2px dashed var(--glass-border-light);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.file-upload-enhanced:hover {
    border-color: var(--color-primary);
    background: rgb(37 99 235 / 5%);
}

.file-upload-enhanced.dragover {
    border-color: var(--color-primary);
    background: rgb(37 99 235 / 10%);
    transform: scale(1.02);
}


/* ========================================
   9. TABLES
   ======================================== */

.table {
    background: var(--pure-white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table th {
    background: var(--light-grey);
    border-bottom: 1px solid var(--medium-grey);
    font-weight: 600;
    color: var(--text-primary);
    padding: 1rem;
}

.table td {
    padding: 1rem;
    border-bottom: 1px solid var(--neutral-200);
    vertical-align: middle;
}

.table tbody tr:hover { background: var(--neutral-50); }

.apex-table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--medium-grey);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table.apex-table {
    margin-bottom: 0;
    border-radius: 0;
    box-shadow: none;
}

.table.apex-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--light-grey);
}

.table.apex-table.apex-table-comfortable td,
.table.apex-table.apex-table-comfortable th {
    padding: var(--space-4);
}

.table.apex-table.apex-table-compact td,
.table.apex-table.apex-table-compact th {
    padding: var(--space-3);
}

.apex-table-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--medium-grey);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    background: var(--neutral-50);
}

.apex-avatar-chip {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
}

.apex-progress-xs {
    width: 52px;
    height: 6px;
}

.empty-state-icon-circle {
    width: 80px;
    height: 80px;
}


/* ========================================
   10. QUICK ACTIONS
   ======================================== */

.quick-actions {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.quick-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--color-background);
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    color: var(--color-text);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: var(--transition-smooth);
    text-decoration: none;
}

.quick-action-btn:hover {
    background: var(--color-surface);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* Quick Actions Row (Module Layout) */
.quick-actions-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: white;
    border: 1px solid #E2E8F0;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.action-btn:hover {
    background: #F8FAFC;
    border-color: #CBD5E1;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgb(0 0 0 / 8%);
}

.action-btn-primary {
    background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
    color: white;
    border: none;
}

.action-btn-primary:hover {
    background: linear-gradient(135deg, #1D4ED8 0%, #2563EB 100%);
    color: white;
    box-shadow: 0 4px 12px rgb(37 99 235 / 30%);
}

.action-btn-success {
    background: linear-gradient(135deg, #15803D 0%, #16A34A 100%);
    color: white;
    border: none;
}


/* ========================================
   11. MODULE LAYOUT COMPONENTS
   ======================================== */

.module-header {
    background: linear-gradient(135deg, rgb(37 99 235 / 8%) 0%, rgb(16 185 129 / 5%) 100%);
    border: 1px solid rgb(37 99 235 / 15%);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.module-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.module-title-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.module-icon {
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, #2563EB 0%, #3B82F6 100%);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.25rem;
    box-shadow: 0 4px 12px rgb(37 99 235 / 30%);
}

.module-title h1 { font-size: 1.5rem; font-weight: 700; color: #0F172A; margin: 0; }
.module-title p { font-size: 0.875rem; color: #64748B; margin: 0; }

.module-badges { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.module-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.module-badge-primary {
    background: rgb(37 99 235 / 10%);
    color: #2563EB;
    border: 1px solid rgb(37 99 235 / 20%);
}

.module-badge-success {
    background: rgb(21 128 61 / 10%);
    color: var(--color-status-success, #15803D);
    border: 1px solid rgb(21 128 61 / 20%);
}

/* Content Cards */
.content-card {
    background: white;
    border: 1px solid #E2E8F0;
    border-radius: 1rem;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.content-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: #F8FAFC;
    border-bottom: 1px solid #E2E8F0;
}

.content-card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #0F172A;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.content-card-title i { color: #2563EB; }
.content-card-actions { display: flex; gap: 0.5rem; }
.content-card-body { padding: 1.25rem; }

/* Module Grid */
.module-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}


/* ========================================
   12. PROGRESS & LOADING STATES
   ======================================== */

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(90deg, var(--neutral-200) 25%, var(--neutral-100) 50%, var(--neutral-200) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text { height: 1rem; margin-bottom: 0.5rem; }
.skeleton-text.large { height: 1.5rem; }
.skeleton-text.small { height: 0.75rem; }
.skeleton-avatar { width: 40px; height: 40px; border-radius: 50%; }
.skeleton-card { height: 200px; border-radius: var(--radius-xl); }
.skeleton-stat-card { height: 120px; border-radius: var(--radius-xl); }

/* Progress Bars */
.progress {
    background-color: var(--neutral-200);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.progress-bar.bg-gradient-primary { background: var(--gradient-primary) !important; }
.progress-bar.bg-gradient-secondary { background: var(--gradient-secondary) !important; }

.progress-enhanced {
    height: 8px;
    background: var(--neutral-200);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
}

.progress-enhanced .progress-bar {
    height: 100%;
    background: var(--color-primary-gradient);
    border-radius: var(--radius-md);
    transition: width 0.3s ease;
    position: relative;
    overflow: hidden;
}

.progress-enhanced .progress-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgb(255 255 255 / 40%), transparent);
    animation: progress-shine 2s infinite;
}

@keyframes progress-shine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Loading Spinner */
.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--neutral-200);
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgb(255 255 255 / 90%);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1070;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.loading-overlay.show { opacity: 1; visibility: visible; }

/* Toast Notification System */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1060;
    max-width: 400px;
}

.toast-enhanced {
    background: var(--gradient-card);
    backdrop-filter: var(--backdrop-blur);
    border: 1px solid var(--glass-border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    margin-bottom: 1rem;
    overflow: hidden;
    transform: translateX(100%);
    transition: all 0.3s ease;
}

.toast-enhanced.show { transform: translateX(0); }


/* ========================================
   13. WORKFLOW + AI INSIGHTS
   ======================================== */

.apex-workflow-stepper {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.apex-workflow-step {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--medium-grey);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}

.apex-workflow-step-index {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--neutral-200);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: var(--font-bold);
}

.apex-workflow-step.is-active {
    border-color: rgb(37 99 235 / 45%);
    background: rgb(37 99 235 / 5%);
    color: var(--color-primary);
}

.apex-workflow-step.is-active .apex-workflow-step-index {
    background: var(--color-primary);
    color: #fff;
}

.apex-workflow-step.is-complete {
    border-color: rgb(16 185 129 / 45%);
    background: rgb(16 185 129 / 6%);
    color: var(--color-success);
}

.apex-workflow-step.is-complete .apex-workflow-step-index {
    background: var(--color-success);
    color: #fff;
}

.apex-workflow-step-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.apex-insight-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

.apex-insight-card {
    border: 1px solid rgb(2 132 199 / 20%);
    border-radius: var(--radius-lg);
    background: linear-gradient(145deg, #fff 0%, #f6fbff 100%);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
}

.apex-insight-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

.apex-insight-title {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin: 0;
}

.apex-insight-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    border-radius: var(--radius-full);
    padding: 2px 8px;
    font-size: 11px;
    font-weight: var(--font-semibold);
    background: rgb(37 99 235 / 10%);
    color: var(--color-primary);
}

.apex-insight-text {
    margin: 0 0 var(--space-3);
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.apex-insight-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px dashed var(--medium-grey);
}

.apex-insight-meta-item {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.apex-insight-meta-item strong {
    color: var(--text-primary);
    font-weight: var(--font-semibold);
}


/* ========================================
   14. GRADIENT BACKGROUNDS (Utility)
   ======================================== */

.bg-gradient-primary { background: var(--gradient-primary) !important; }
.bg-gradient-secondary { background: var(--gradient-secondary) !important; }
.bg-gradient-accent { background: var(--gradient-accent) !important; }


/* ========================================
   15. RESPONSIVE COMPONENT ADJUSTMENTS
   ======================================== */

@media (width <= 1200px) {
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (width <= 992px) {
    .module-grid { grid-template-columns: 1fr; }
}

@media (width <= 768px) {
    .metric-grid { grid-template-columns: 1fr; }
    .quick-actions-row { flex-direction: column; }
    .action-btn { justify-content: center; }
    .form-wizard-steps { flex-direction: column; gap: 1rem; }
    .form-navigation { padding: 1rem; flex-direction: column; gap: 1rem; }
    .form-nav-button { width: 100%; justify-content: center; }
    .toast-container { top: 10px; right: 10px; left: 10px; max-width: none; }
    .apex-workflow-stepper { grid-template-columns: 1fr; }
    .apex-insight-grid { grid-template-columns: 1fr; }
}


/* ========================================
   13. SKELETON / SHIMMER LOADING STATES
   ======================================== */

@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--color-background, #F1F5F9) 25%,
        var(--color-border, #E2E8F0) 50%,
        var(--color-background, #F1F5F9) 75%
    );
    background-size: 800px 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: var(--radius-sm, 6px);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 10px;
    border-radius: 4px;
}

.skeleton-title {
    height: 20px;
    margin-bottom: 12px;
    border-radius: 4px;
}

.skeleton-avatar {
    width: 44px;
    height: 44px;
    border-radius: 99px;
    flex-shrink: 0;
}

.skeleton-card-layout {
    padding: var(--space-5, 20px);
}

.skeleton-btn {
    height: 40px;
    width: 120px;
    border-radius: var(--radius-md, 10px);
}

.skeleton-badge {
    height: 24px;
    width: 72px;
    border-radius: 99px;
    display: inline-block;
}

/* Dark mode */
[data-theme="dark"] .skeleton {
    background: linear-gradient(
        90deg,
        rgb(255 255 255 / 4%) 25%,
        rgb(255 255 255 / 8%) 50%,
        rgb(255 255 255 / 4%) 75%
    );
    background-size: 800px 100%;
}
