/* 
 * بوصلة كلينك - Theme Engine CSS Overrides
 * ==========================================
 * يعتمد على CSS Variables المعرّفة في theme-engine.js
 * يُحمّل بعد modern-ui.css لتطبيق البراندنج الديناميكي
 */

/* ============================================
   Additional CSS Variables from Branding
   ============================================ */
:root {
    --primary-rgb: 5, 150, 105;
    --primary-lighter: #ecfdf5;
    --info: #3b82f6;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-accent: #10b981;
    --sidebar-accent-rgb: 16, 185, 129;
    --sidebar-bg-start: #1e293b;
    --sidebar-bg-end: #0f172a;
    --sidebar-icon-color: inherit;
    --sidebar-text-color: #cbd5e1;
    --sidebar-active-text: #ffffff;
    --sidebar-border-color: rgba(16, 185, 129, 0.15);
    --header-icon-bg: var(--primary-gradient);
    --btn-accent: var(--primary);
    --btn-accent-dark: var(--primary-dark);
    --card-accent: var(--primary);
    --card-accent-gradient: var(--primary-gradient);
}

/* ============================================
   Sidebar Branding Overrides
   ============================================ */

/* Sidebar active link uses brand accent */
.sidebar-link.active {
    background: linear-gradient(135deg, rgba(var(--sidebar-accent-rgb), 0.28) 0%, rgba(var(--sidebar-accent-rgb), 0.10) 100%) !important;
    border-color: rgba(var(--sidebar-accent-rgb), 0.35) !important;
    border-inline-end: 3px solid var(--sidebar-accent, #10b981) !important;
    box-shadow: inset 0 0 12px rgba(var(--sidebar-accent-rgb), 0.08),
                0 2px 8px rgba(var(--sidebar-accent-rgb), 0.12) !important;
}

/* Active link icon uses brand accent */
.sidebar-link.active .sidebar-nav-icon,
.sidebar-link.active i,
.sidebar-link.active svg {
    color: var(--sidebar-accent, #10b981) !important;
    filter: drop-shadow(0 0 4px rgba(var(--sidebar-accent-rgb), 0.4));
}

/* Sidebar nav icon color (non-active) */
.sidebar-link:not(.active) .sidebar-nav-icon,
.sidebar-link:not(.active) i,
.sidebar-link:not(.active) svg {
    color: var(--sidebar-icon-color, inherit) !important;
    opacity: 0.85;
    transition: opacity 0.2s, color 0.2s;
}
.sidebar-link:hover:not(.active) .sidebar-nav-icon,
.sidebar-link:hover:not(.active) i,
.sidebar-link:hover:not(.active) svg {
    opacity: 1;
    color: var(--sidebar-accent, #10b981) !important;
}

/* Sidebar logo icon background */
.sidebar-logo-icon,
.sidebar .w-10.h-10.bg-emerald-500,
.sidebar [class*="bg-emerald-500"].rounded-xl {
    background: var(--sidebar-accent, #10b981) !important;
    box-shadow: 0 4px 14px rgba(var(--sidebar-accent-rgb), 0.35);
}

/* Sidebar user icon */
.sidebar-user-icon {
    background: rgba(var(--sidebar-accent-rgb, 16, 185, 129), 0.18) !important;
    border: 1px solid rgba(var(--sidebar-accent-rgb, 16, 185, 129), 0.2);
}
.sidebar-user-icon i,
.sidebar-user-icon svg {
    color: var(--sidebar-accent, #10b981) !important;
}

/* Sidebar active link icon glow */
.sidebar-link.active .w-9.h-9,
.sidebar-link.active [class*="rounded-xl"][class*="bg-"] {
    box-shadow: 0 4px 12px rgba(var(--sidebar-accent-rgb), 0.35) !important;
}

/* Sidebar hover animation uses brand color */
.sidebar-link:hover {
    background: rgba(var(--sidebar-accent-rgb), 0.10) !important;
}

/* Sidebar text colors */
.sidebar-link:not(.active) {
    color: var(--sidebar-text-color, #cbd5e1) !important;
}

.sidebar-link.active {
    color: var(--sidebar-active-text, #ffffff) !important;
    font-weight: 600;
}

/* Sidebar section titles */
.sidebar .text-slate-500,
.sidebar p.text-slate-500 {
    color: var(--sidebar-text-color, #64748b) !important;
    opacity: 0.7;
}

/* Sidebar subtitle text */
.sidebar .text-slate-400 {
    color: var(--sidebar-text-color, #94a3b8) !important;
    opacity: 0.65;
}

/* Sidebar border section dividers */
.sidebar .border-slate-700 {
    border-color: var(--sidebar-border-color, rgba(var(--sidebar-accent-rgb), 0.15)) !important;
}

/* Sidebar depth & polish */
.sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0; /* في RTL يكون على الحافة اليسرى */
    width: 1px;
    height: 100%;
    background: linear-gradient(180deg, rgba(var(--sidebar-accent-rgb), 0.3) 0%, transparent 40%, transparent 60%, rgba(var(--sidebar-accent-rgb), 0.3) 100%);
    pointer-events: none;
    z-index: 1;
}

/* Open group gets accent highlight */
.sidebar-group.open {
    border-color: rgba(var(--sidebar-accent-rgb, 16, 185, 129), 0.18) !important;
    background: rgba(var(--sidebar-accent-rgb, 16, 185, 129), 0.04) !important;
}

/* ============================================
   Card Accent Branding
   ============================================ */

/* Card top accent bar */
.modern-card::before,
.stat-card::before {
    background: var(--card-accent-gradient, var(--primary-gradient)) !important;
}

/* ============================================
   Header Branding Overrides
   ============================================ */

/* Colored header style */
[data-header-style="colored"] .shared-header {
    background: var(--primary) !important;
    border-bottom-color: var(--primary-dark) !important;
}

[data-header-style="colored"] .shared-header-title {
    color: #fff !important;
}

[data-header-style="colored"] .shared-header-subtitle {
    color: rgba(255, 255, 255, 0.75) !important;
}

[data-header-style="colored"] .header-menu-btn,
[data-header-style="colored"] .header-icon-btn {
    color: rgba(255, 255, 255, 0.8) !important;
}

[data-header-style="colored"] .header-menu-btn:hover,
[data-header-style="colored"] .header-icon-btn:hover {
    background: rgba(255, 255, 255, 0.15) !important;
    color: #fff !important;
}

/* Gradient header style */
[data-header-style="gradient"] .shared-header {
    background: var(--primary-gradient) !important;
    border-bottom: none !important;
}

[data-header-style="gradient"] .shared-header-title {
    color: #fff !important;
}

[data-header-style="gradient"] .shared-header-subtitle {
    color: rgba(255, 255, 255, 0.75) !important;
}

[data-header-style="gradient"] .header-menu-btn,
[data-header-style="gradient"] .header-icon-btn {
    color: rgba(255, 255, 255, 0.8) !important;
}

[data-header-style="gradient"] .header-menu-btn:hover,
[data-header-style="gradient"] .header-icon-btn:hover {
    background: rgba(255, 255, 255, 0.15) !important;
    color: #fff !important;
}

/* Header icon uses brand gradient or custom color */
.shared-header-icon {
    background: var(--header-icon-bg, var(--primary-gradient)) !important;
}

/* ============================================
   Button Branding Overrides
   ============================================ */
.btn-primary,
.header-btn-primary {
    background: var(--primary-gradient) !important;
}

.btn-primary:hover,
.header-btn-primary:hover {
    box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.4) !important;
}

.btn-secondary {
    background: var(--secondary-gradient) !important;
}

/* Generic brand-accent buttons */
[data-theme-applied="true"] button.bg-blue-600,
[data-theme-applied="true"] button.bg-emerald-600,
[data-theme-applied="true"] button.bg-green-600,
[data-theme-applied="true"] a.bg-blue-600,
[data-theme-applied="true"] a.bg-emerald-600,
[data-theme-applied="true"] a.bg-green-600 {
    background-color: var(--btn-accent, var(--primary)) !important;
}

[data-theme-applied="true"] button.hover\:bg-blue-700:hover,
[data-theme-applied="true"] button.hover\:bg-emerald-700:hover,
[data-theme-applied="true"] button.hover\:bg-green-700:hover,
[data-theme-applied="true"] a.hover\:bg-blue-700:hover,
[data-theme-applied="true"] a.hover\:bg-emerald-700:hover,
[data-theme-applied="true"] a.hover\:bg-green-700:hover {
    background-color: var(--btn-accent-dark, var(--primary-dark)) !important;
}

/* Override Tailwind bg-emerald/blue/green buttons to use brand */
[data-theme-applied="true"] .bg-blue-600,
[data-theme-applied="true"] .bg-emerald-600,
[data-theme-applied="true"] .bg-green-600 {
    background-color: var(--btn-accent, var(--primary)) !important;
}

[data-theme-applied="true"] .hover\:bg-blue-700:hover,
[data-theme-applied="true"] .hover\:bg-emerald-700:hover,
[data-theme-applied="true"] .hover\:bg-green-700:hover {
    background-color: var(--btn-accent-dark, var(--primary-dark)) !important;
}

/* Ring colors for focus */
[data-theme-applied="true"] .focus\:ring-blue-500:focus,
[data-theme-applied="true"] .focus\:ring-emerald-500:focus,
[data-theme-applied="true"] .focus\:ring-green-500:focus {
    --tw-ring-color: var(--primary) !important;
}

[data-theme-applied="true"] .focus\:ring-blue-300:focus,
[data-theme-applied="true"] .focus\:ring-emerald-300:focus {
    --tw-ring-color: var(--primary-light) !important;
}

/* Toggle switches */
[data-theme-applied="true"] .peer-checked\:bg-blue-600:is(.peer:checked ~ *),
[data-theme-applied="true"] .peer-checked\:bg-emerald-600:is(.peer:checked ~ *) {
    background-color: var(--primary) !important;
}

/* ============================================
   Card & Stat Branding Overrides
   ============================================ */

/* Quick action hover */
.quick-action:hover {
    border-color: var(--primary) !important;
    box-shadow: 0 16px 32px rgba(var(--primary-rgb), 0.2) !important;
}

.quick-action::after {
    background: linear-gradient(135deg, rgba(var(--primary-rgb), 0.05) 0%, transparent 100%) !important;
}

/* ============================================
   Input Focus Branding
   ============================================ */
.input-modern:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.1) !important;
}

/* General input focus ring override */
[data-theme-applied="true"] input:focus,
[data-theme-applied="true"] select:focus,
[data-theme-applied="true"] textarea:focus {
    --tw-ring-color: rgba(var(--primary-rgb), 0.3) !important;
    border-color: var(--primary) !important;
}

/* ============================================
   Table Branding
   ============================================ */
.table-modern tbody tr:hover td {
    border-color: rgba(var(--primary-rgb), 0.2) !important;
}

/* ============================================
   Activity & Hover Effects
   ============================================ */
.activity-item:hover {
    border-color: rgba(var(--primary-rgb), 0.2) !important;
}

.hover-glow:hover {
    box-shadow: 0 0 20px rgba(var(--primary-rgb), 0.4) !important;
}

.focus-ring:focus {
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.3) !important;
}

/* Live indicator */
.live-dot {
    background: var(--sidebar-accent) !important;
    box-shadow: 0 0 8px rgba(var(--sidebar-accent-rgb), 0.6) !important;
}

/* ============================================
   Tab Active State Branding
   ============================================ */
[data-theme-applied="true"] .tab-btn.active {
    border-color: var(--primary) !important;
    color: var(--primary) !important;
    background: var(--primary-light) !important;
}

/* ============================================
   Badge Branding
   ============================================ */
.badge-success {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-lighter, #ecfdf5) 100%) !important;
}

/* ============================================
   Scrollbar Branding
   ============================================ */
[data-theme-applied="true"]::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(var(--primary-rgb), 0.3), rgba(var(--primary-rgb), 0.15)) !important;
}

[data-theme-applied="true"]::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(var(--primary-rgb), 0.5), rgba(var(--primary-rgb), 0.3)) !important;
}

/* ============================================
   Gradient Text Override
   ============================================ */
.gradient-text {
    background: var(--primary-gradient) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    background-clip: text !important;
}

/* ============================================
   Link Colors
   ============================================ */
[data-theme-applied="true"] a.text-blue-600,
[data-theme-applied="true"] a.text-emerald-600,
[data-theme-applied="true"] .text-blue-600,
[data-theme-applied="true"] .text-emerald-600 {
    color: var(--primary) !important;
}

/* ============================================
   Selection Color
   ============================================ */
[data-theme-applied="true"] ::selection {
    background: rgba(var(--primary-rgb), 0.2);
    color: inherit;
}

/* ============================================
   Loading Skeleton with Brand Color
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, var(--primary-lighter, #f0f0f0) 25%, var(--primary-light, #e8e8e8) 50%, var(--primary-lighter, #f0f0f0) 75%) !important;
}

/* ============================================
   Tooltip & Toast Branding
   ============================================ */
[data-theme-applied="true"] #toast.bg-green-500,
[data-theme-applied="true"] #toast.bg-emerald-500 {
    background-color: var(--primary) !important;
}
