/* =========================================================
   ERP Dynamic CRM — modern brand theme
   Brand colors taken from the logo: vibrant orange + slate.
   ========================================================= */

:root {
    --brand-orange: #F97316;
    --brand-orange-600: #EA580C;
    --brand-orange-700: #C2410C;
    --brand-orange-50: #FFF7ED;
    --brand-orange-100: #FFEDD5;
    --brand-orange-200: #FED7AA;

    --brand-dark: #0F172A;
    --brand-slate-900: #0F172A;
    --brand-slate-800: #1E293B;
    --brand-slate-700: #334155;
    --brand-slate-500: #64748B;
    --brand-slate-400: #94A3B8;
    --brand-slate-300: #CBD5E1;
    --brand-slate-200: #E2E8F0;
    --brand-slate-100: #F1F5F9;
    --brand-slate-50:  #F8FAFC;

    --status-new:        #94A3B8;
    --status-contacted:  #3B82F6;
    --status-qualified:  #10B981;
    --status-demo:       #8B5CF6;
    --status-won:        #16A34A;
    --status-lost:       #EF4444;
    --status-unqual:     #F59E0B;
    --status-unreach:    #94A3B8;

    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
    --shadow:    0 1px 3px 0 rgba(15, 23, 42, 0.1), 0 1px 2px -1px rgba(15, 23, 42, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.1), 0 2px 4px -2px rgba(15, 23, 42, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.1);

    --sidebar-width: 260px;
    --topbar-height: 64px;
}

html, body {
    font-family: 'Tajawal', 'Segoe UI', 'Cairo', Tahoma, Arial, sans-serif;
    background: var(--brand-slate-50);
    color: var(--brand-slate-800);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    min-height: 100vh;
}

a { color: var(--brand-orange-600); text-decoration: none; }
a:hover { color: var(--brand-orange-700); }

::selection {
    background: var(--brand-orange-200);
    color: var(--brand-orange-700);
}

/* ----- App shell ----- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.app-sidebar {
    background: var(--brand-slate-900);
    color: white;
    padding: 1.25rem 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    z-index: 50;
}

.app-sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.5rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 1rem;
}

.app-sidebar .brand img {
    height: 38px;
    filter: brightness(0) invert(1);
}

.app-sidebar .brand-title {
    color: white;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.app-sidebar .brand-title span {
    color: var(--brand-orange);
}

.app-sidebar .brand-subtitle {
    color: var(--brand-slate-400);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.app-sidebar .nav-section-title {
    color: var(--brand-slate-400);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding: 1rem 1.5rem 0.5rem;
    font-weight: 600;
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.5rem;
    color: var(--brand-slate-300);
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.15s;
    position: relative;
    border-radius: 0;
}

.app-sidebar .nav-link:hover {
    background: rgba(249, 115, 22, 0.08);
    color: white;
}

.app-sidebar .nav-link.active {
    background: linear-gradient(90deg, rgba(249, 115, 22, 0.15) 0%, transparent 100%);
    color: var(--brand-orange);
}

[dir="rtl"] .app-sidebar .nav-link.active {
    background: linear-gradient(270deg, rgba(249, 115, 22, 0.15) 0%, transparent 100%);
}

.app-sidebar .nav-link.active::before {
    content: '';
    position: absolute;
    inset-inline-end: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--brand-orange);
}

.app-sidebar .nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.8;
}

.app-sidebar .nav-link.active .nav-icon {
    opacity: 1;
}

.app-sidebar .nav-badge {
    margin-inline-start: auto;
    background: var(--brand-orange);
    color: white;
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: 999px;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
}

.app-sidebar .nav-badge.warn {
    background: #FBBF24;
    color: var(--brand-slate-900);
}

.app-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-topbar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--brand-slate-200);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: var(--shadow-sm);
}

.app-topbar .page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--brand-slate-900);
    margin: 0;
}

.app-topbar .user-chip {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.9rem;
    background: var(--brand-slate-50);
    border-radius: 999px;
    color: var(--brand-slate-800);
    font-weight: 500;
}

.app-topbar .user-chip .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-orange) 0%, var(--brand-orange-600) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.app-content {
    flex: 1;
    padding: 1.75rem 2rem;
    overflow-x: hidden;
}

/* Mobile burger toggle */
.sidebar-toggle {
    display: none;
    background: transparent;
    border: 0;
    color: var(--brand-slate-700);
    font-size: 1.4rem;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
}

@media (max-width: 991px) {
    .app-shell { grid-template-columns: 1fr; }
    .app-sidebar {
        position: fixed;
        inset-inline-start: 0;
        top: 0;
        height: 100vh;
        width: var(--sidebar-width);
        transform: translateX(100%);
        transition: transform 0.25s ease;
    }
    [dir="ltr"] .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.show { transform: translateX(0); }
    .sidebar-toggle { display: inline-block; }
    .app-content { padding: 1.25rem 1rem; }
    .app-topbar { padding: 0 1rem; }
}

/* Mobile backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 45;
}
.sidebar-backdrop.show { display: block; }

/* ----- Cards ----- */
.card {
    border: 1px solid var(--brand-slate-200);
    border-radius: 14px;
    background: white;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s, transform 0.15s;
}

.card.shadow-sm { box-shadow: var(--shadow-sm); }
.card:hover { box-shadow: var(--shadow); }

.card-header {
    background: white;
    border-bottom: 1px solid var(--brand-slate-200);
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--brand-slate-900);
    border-radius: 14px 14px 0 0 !important;
}

.card-body { padding: 1.25rem; }

/* Stat cards */
.stat-card {
    background: white;
    border: 1px solid var(--brand-slate-200);
    border-radius: 14px;
    padding: 1.25rem;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--brand-orange-200);
}

.stat-card .stat-label {
    color: var(--brand-slate-500);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--brand-slate-900);
    line-height: 1;
    letter-spacing: -1px;
}

.stat-card .stat-icon {
    position: absolute;
    inset-inline-end: 1rem;
    top: 1rem;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-orange-50);
    color: var(--brand-orange-600);
    font-size: 1.1rem;
}

.stat-card.stat-success .stat-icon { background: #DCFCE7; color: #16A34A; }
.stat-card.stat-danger  .stat-icon { background: #FEE2E2; color: #DC2626; }
.stat-card.stat-warning .stat-icon { background: #FEF3C7; color: #D97706; }
.stat-card.stat-info    .stat-icon { background: #DBEAFE; color: #2563EB; }

/* ----- Buttons ----- */
.btn {
    border-radius: 10px;
    font-weight: 600;
    padding: 0.5rem 1.1rem;
    transition: all 0.15s;
    border-width: 1px;
}

.btn-sm { border-radius: 8px; padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.btn-lg { border-radius: 12px; padding: 0.75rem 1.5rem; }

.btn-primary {
    background: var(--brand-orange);
    border-color: var(--brand-orange);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--brand-orange-600);
    border-color: var(--brand-orange-600);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.35);
}

.btn-success {
    background: #16A34A;
    border-color: #16A34A;
}
.btn-success:hover { background: #15803D; border-color: #15803D; transform: translateY(-1px); }

.btn-warning {
    background: #F59E0B;
    border-color: #F59E0B;
    color: white;
}
.btn-warning:hover { color: white; background: #D97706; border-color: #D97706; }

.btn-danger { background: #EF4444; border-color: #EF4444; }
.btn-danger:hover { background: #DC2626; border-color: #DC2626; }

.btn-outline-secondary {
    color: var(--brand-slate-700);
    border-color: var(--brand-slate-300);
    background: white;
}
.btn-outline-secondary:hover {
    background: var(--brand-slate-50);
    color: var(--brand-slate-900);
    border-color: var(--brand-slate-400);
}

.btn-outline-primary {
    color: var(--brand-orange-600);
    border-color: var(--brand-orange-200);
    background: white;
}
.btn-outline-primary:hover {
    background: var(--brand-orange);
    border-color: var(--brand-orange);
    color: white;
}

/* ----- Tables ----- */
.table {
    margin-bottom: 0;
    color: var(--brand-slate-800);
}

.table thead {
    background: var(--brand-slate-50);
}

.table thead th {
    background: var(--brand-slate-50) !important;
    color: var(--brand-slate-700);
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--brand-slate-200);
    padding: 0.85rem 1rem;
}

.table tbody td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--brand-slate-100);
    vertical-align: middle;
}

.table-dark thead th {
    background: var(--brand-slate-900) !important;
    color: white;
    border-color: var(--brand-slate-800);
}

.table-hover tbody tr {
    transition: background 0.1s;
}
.table-hover tbody tr:hover {
    background: var(--brand-orange-50);
}

.table-striped tbody tr:nth-of-type(odd) {
    background: var(--brand-slate-50);
}

/* ----- Forms ----- */
.form-control, .form-select {
    border-radius: 10px;
    border: 1px solid var(--brand-slate-300);
    padding: 0.55rem 0.85rem;
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand-orange);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.form-control-sm, .form-select-sm {
    border-radius: 8px;
    padding: 0.35rem 0.65rem;
}

.form-label {
    font-weight: 600;
    color: var(--brand-slate-700);
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
}

/* ----- Badges ----- */
.badge {
    font-weight: 600;
    padding: 0.35em 0.75em;
    border-radius: 999px;
    font-size: 0.78rem;
    letter-spacing: 0.2px;
}

.badge-status-New          { background: var(--status-new); color: white; }
.badge-status-Contacted    { background: var(--status-contacted); color: white; }
.badge-status-Qualified    { background: var(--status-qualified); color: white; }
.badge-status-Discovery    { background: #0EA5E9; color: white; }       /* sky blue */
.badge-status-DemoBooked   { background: var(--status-demo); color: white; }
.badge-status-DemoCompleted{ background: #7C3AED; color: white; }       /* indigo */
.badge-status-ProposalSent { background: #2563EB; color: white; }       /* royal blue */
.badge-status-Negotiation  { background: #F97316; color: white; }       /* brand orange */
.badge-status-Won          { background: var(--status-won); color: white; }
.badge-status-Lost         { background: var(--status-lost); color: white; }
.badge-status-Unqualified  { background: var(--status-unqual); color: white; }
.badge-status-Unreachable  { background: var(--status-unreach); color: white; }

.badge-source-Meta      { background: #1877F2; }
.badge-source-Google    { background: #EA4335; }
.badge-source-LinkedIn  { background: #0A66C2; }
.badge-source-Referral  { background: #6366F1; }
.badge-source-WalkIn    { background: #06B6D4; }
.badge-source-Unknown   { background: var(--brand-slate-400); }
.badge-source-Other     { background: var(--brand-slate-600, #475569); }

/* ----- Alerts ----- */
.alert {
    border-radius: 12px;
    border: 1px solid transparent;
    padding: 0.85rem 1.1rem;
}

.alert-success {
    background: #DCFCE7;
    color: #166534;
    border-color: #BBF7D0;
}

.alert-danger {
    background: #FEE2E2;
    color: #991B1B;
    border-color: #FECACA;
}

.alert-warning {
    background: #FEF3C7;
    color: #92400E;
    border-color: #FDE68A;
}

.alert-info {
    background: #DBEAFE;
    color: #1E40AF;
    border-color: #BFDBFE;
}

/* ----- Page header ----- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-header h2,
.page-header h1 {
    margin: 0;
    color: var(--brand-slate-900);
    font-weight: 800;
    letter-spacing: -0.5px;
}

.page-header .lead-count {
    color: var(--brand-slate-500);
    font-size: 0.9rem;
}

/* ----- Timeline (Detail page activity) ----- */
.timeline-item {
    border-inline-start: 3px solid var(--brand-slate-200);
    padding: 0.65rem 1rem;
    margin-bottom: 0.85rem;
    background: var(--brand-slate-50);
    border-radius: 0 10px 10px 0;
    transition: all 0.15s;
}
[dir="rtl"] .timeline-item {
    border-radius: 10px 0 0 10px;
}

.timeline-item:hover { background: white; box-shadow: var(--shadow-sm); }
.timeline-item.created      { border-color: #16A34A; }
.timeline-item.statuschange { border-color: var(--brand-orange); }
.timeline-item.assignment   { border-color: #8B5CF6; }
.timeline-item.note         { border-color: var(--brand-slate-400); }
.timeline-item.lostrequested{ border-color: #F59E0B; background: #FEF3C7; }
.timeline-item.lostapproved { border-color: #EF4444; background: #FEE2E2; }
.timeline-item.lostrejected { border-color: var(--brand-slate-400); }

/* ----- Pagination ----- */
.page-link {
    color: var(--brand-orange-600);
    border-color: var(--brand-slate-200);
    border-radius: 8px;
    margin: 0 2px;
}
.page-link:hover { background: var(--brand-orange-50); color: var(--brand-orange-700); border-color: var(--brand-orange-200); }
.page-item.active .page-link {
    background: var(--brand-orange);
    border-color: var(--brand-orange);
    color: white;
}

/* ----- Login page ----- */
.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--brand-slate-50);
}

.login-hero {
    background: linear-gradient(135deg, var(--brand-slate-900) 0%, var(--brand-slate-800) 60%, var(--brand-orange-700) 100%);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem 4rem;
    position: relative;
    overflow: hidden;
}

.login-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(249, 115, 22, 0.2) 0, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(249, 115, 22, 0.15) 0, transparent 40%);
}

.login-hero > * { position: relative; }

.login-hero img {
    height: 56px;
    filter: brightness(0) invert(1);
    margin-bottom: 2.5rem;
    align-self: flex-start;
}

.login-hero h1 {
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.5px;
    margin-bottom: 1rem;
}

.login-hero h1 span { color: var(--brand-orange); }

.login-hero p {
    color: var(--brand-slate-300);
    font-size: 1.05rem;
    line-height: 1.7;
    max-width: 480px;
}

.login-hero .features {
    margin-top: 2.5rem;
    display: grid;
    gap: 0.85rem;
    max-width: 480px;
}

.login-hero .features li {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--brand-slate-200);
}

.login-hero .features li::before {
    content: '✓';
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--brand-orange);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    flex-shrink: 0;
}

.login-form-pane {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: white;
    border-radius: 18px;
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--brand-slate-200);
}

.login-card h2 {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--brand-slate-900);
    margin-bottom: 0.4rem;
}

.login-card .subtitle {
    color: var(--brand-slate-500);
    margin-bottom: 1.75rem;
}

.login-card-mobile-logo {
    display: none;
    text-align: center;
    margin-bottom: 1.5rem;
}
.login-card-mobile-logo img { height: 44px; }

@media (max-width: 991px) {
    .login-shell { grid-template-columns: 1fr; }
    .login-hero { display: none; }
    .login-card-mobile-logo { display: block; }
}

/* ----- Misc utilities ----- */
.muted { color: var(--brand-slate-500); }
.divider { height: 1px; background: var(--brand-slate-200); margin: 1.5rem 0; }

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--brand-slate-500);
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    background: var(--brand-orange-50);
    color: var(--brand-orange-600);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* ----- Animations ----- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.app-content > * {
    animation: fadeUp 0.25s ease-out;
}

/* Print: hide chrome */
@media print {
    .app-sidebar, .app-topbar, .sidebar-backdrop { display: none !important; }
    .app-shell { grid-template-columns: 1fr; }
    .app-content { padding: 0; }
}

/* Phone numbers: force LTR display so the leading "+" stays on the left even
   inside RTL containers. Applies automatically to anything wrapped in
   <bdi class="phone"> or .phone, plus every tel: anchor. */
.phone, a[href^="tel:"], bdi.phone {
    direction: ltr;
    unicode-bidi: bidi-override;
    display: inline-block;
}
