/* ═══════════════════════════════════════════
   CRM TE — Design System
   Premium B2B SaaS Identity
   ═══════════════════════════════════════════ */

:root {
    /* 1. Core Brand Colors (Deep, Professional, Tech) */
    /* Primary: A deep, sophisticated indigo/slate blue */
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --primary-300: #93c5fd;
    --primary-400: #60a5fa;
    --primary-500: #3b82f6; /* Base info */
    --primary-600: #2563eb; /* Main Primary */
    --primary-700: #1d4ed8;
    --primary-800: #1e40af;
    --primary-900: #1e3a8a;
    --primary-950: #172554;
    
    --primary: var(--primary-600);
    --primary-hover: var(--primary-700);
    --primary-active: var(--primary-800);
    --primary-soft: var(--primary-50);
    --primary-glow: rgba(37, 99, 235, 0.2);

    /* 2. Surfaces & Backgrounds */
    --bg-main: #f8fafc;        /* App background */
    --bg-surface: #ffffff;     /* Cards, Modals, Sidebar */
    --bg-surface-hover: #f1f5f9;
    --border-light: #e2e8f0;   /* Light dividers */
    --border-base: #cbd5e1;    /* Input borders */
    --border-dark: #94a3b8;    /* Input borders on hover/focus */

    /* 3. Typography Colors */
    --text-primary: #0f172a;   /* Headings, main text */
    --text-secondary: #334155; /* Body text */
    --text-muted: #64748b;     /* Helper text, placeholders */
    --text-disabled: #94a3b8;
    --text-inverse: #ffffff;   /* On primary backgrounds */

    /* 4. Semantic Colors (Status & Alerts) */
    --success-50: #ecfdf5;
    --success-500: #10b981;
    --success-600: #059669;
    --success-700: #047857;
    
    --warning-50: #fffbeb;
    --warning-500: #f59e0b;
    --warning-600: #d97706;
    --warning-700: #b45309;
    
    --danger-50: #fef2f2;
    --danger-500: #ef4444;
    --danger-600: #dc2626;
    --danger-700: #b91c1c;

    --info-50: #f0fdfa;
    --info-500: #14b8a6;
    --info-600: #0d9488;
    --info-700: #0f766e;

    /* 5. Typography Scales */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Space Grotesk', system-ui, sans-serif;
    
    --text-xs: 0.75rem;    /* 12px */
    --text-sm: 0.875rem;   /* 14px */
    --text-base: 1rem;     /* 16px */
    --text-lg: 1.125rem;   /* 18px */
    --text-xl: 1.25rem;    /* 20px */
    --text-2xl: 1.5rem;    /* 24px */
    --text-3xl: 1.875rem;  /* 30px */
    --text-4xl: 2.25rem;   /* 36px */

    /* 6. Spacing & Sizing */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.25rem;   /* 20px */
    --space-6: 1.5rem;    /* 24px */
    --space-8: 2rem;      /* 32px */
    --space-10: 2.5rem;   /* 40px */
    --space-12: 3rem;     /* 48px */
    --space-16: 4rem;     /* 64px */

    /* 7. Borders & Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;     /* Main cards */
    --radius-xl: 16px;     /* Modals */
    --radius-full: 9999px; /* Pills/Badges */

    /* 8. Shadows (Soft and layered) */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.05), 0 8px 10px -6px rgb(0 0 0 / 0.05);
    --shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);

    /* 9. Layout Metrics */
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 72px;
    --topbar-height: 64px;
    
    /* 10. Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Preferences (Auto) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-main: #0f172a;
        --bg-surface: #1e293b;
        --bg-surface-hover: #334155;
        --border-light: #334155;
        --border-base: #475569;
        --border-dark: #64748b;
        
        --text-primary: #f8fafc;
        --text-secondary: #cbd5e1;
        --text-muted: #94a3b8;
        
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.2);
        --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3);
    }
}

/* Base Reset & Typography */
html { font-size: 14px; scroll-behavior: smooth; }
@media (min-width: 1024px) { html { font-size: 15px; } }

body {
    font-family: var(--font-sans);
    color: var(--text-secondary);
    background-color: var(--bg-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }

p { margin-bottom: var(--space-4); }
a { color: var(--primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--primary-hover); }

/* Utility Classes */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }

.bg-surface { background-color: var(--bg-surface); }
.bg-main { background-color: var(--bg-main); }

.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* Flexbox Utils */
.d-flex { display: flex; }
.flex-col { flex-direction: column; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

/* Margin & Padding Utils */
.m-0 { margin: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.p-0 { padding: 0; }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

/* Standard UI Components */

/* 1. Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 0.625rem 1rem;
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
    line-height: 1.2;
}

.btn:focus-visible {
    outline: 2px solid var(--primary-400);
    outline-offset: 2px;
}

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

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

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    border-color: var(--border-base);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

.btn-danger {
    background-color: var(--danger-600);
    color: var(--text-inverse);
}

.btn-danger:hover:not(:disabled) {
    background-color: var(--danger-700);
}

.btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background-color: var(--border-light);
    color: var(--text-primary);
}

/* 2. Cards */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}

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

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

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

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

.card-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-light);
    background-color: var(--bg-main);
}

/* 3. Forms & Inputs */
.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-base);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-input::placeholder, .form-textarea::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

/* 4. Badges / Pills */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    border-radius: var(--radius-full);
}

.badge-success { background-color: var(--success-50); color: var(--success-700); border: 1px solid var(--success-500); }
.badge-warning { background-color: var(--warning-50); color: var(--warning-700); border: 1px solid var(--warning-500); }
.badge-danger { background-color: var(--danger-50); color: var(--danger-700); border: 1px solid var(--danger-500); }
.badge-info { background-color: var(--info-50); color: var(--info-700); border: 1px solid var(--info-500); }
.badge-neutral { background-color: var(--bg-main); color: var(--text-secondary); border: 1px solid var(--border-base); }

/* 5. Skeleton Loaders */
.skeleton {
    background: linear-gradient(90deg, var(--border-light) 25%, var(--bg-main) 50%, var(--border-light) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

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

.skeleton-text { height: 1rem; margin-bottom: 0.5rem; width: 100%; }
.skeleton-text.short { width: 60%; }
.skeleton-text.xs { width: 40%; }
.skeleton-avatar { width: 40px; height: 40px; border-radius: var(--radius-full); }
.skeleton-btn { width: 120px; height: 38px; border-radius: var(--radius-sm); }
.skeleton-badge { width: 72px; height: 24px; border-radius: var(--radius-full); }

/* Skeleton table row */
.skeleton-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-light);
}
.skeleton-row > * { flex-shrink: 0; }
.skeleton-row .skeleton-cell { flex: 1; }

/* Skeleton stat card */
.skeleton-stat {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
}
.skeleton-stat .skeleton-text:first-child { width: 50%; height: 0.75rem; margin-bottom: var(--space-3); }
.skeleton-stat .skeleton-text:last-child { width: 70%; height: 2rem; }

/* 6. Layout Components (Sidebar, Topbar, AI Panel) */
.app-container { min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 40;
    transition: transform var(--transition-normal);
}

.sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 30; opacity: 0; pointer-events: none;
    transition: opacity var(--transition-normal);
}
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left var(--transition-normal), margin-right var(--transition-normal);
}

.topbar {
    height: var(--topbar-height);
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    position: sticky; top: 0; z-index: 20;
}

.ai-panel {
    width: 360px;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 50;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
}

.ai-panel.open {
    transform: translateX(0);
}

/* Responsive Rules */
@media (max-width: 1023px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .ai-panel { width: 100%; max-width: 400px; }
}

@media (min-width: 1024px) {
    .main-wrapper { margin-left: var(--sidebar-width); }
    .sidebar-overlay { display: none; }
    .topbar-toggle { display: none; }
    .ai-panel.open ~ .main-wrapper { margin-right: 360px; }
}
