:root {
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --primary: #0d6efd;
    --secondary: #6c757d;
    --success: #198754;
    --info: #0dcaf0;
    --warning: #ffc107;
    --danger: #dc3545;
    --dark: #212529;
    --light: #f8f9fa;
    --body-bg: #f4f6f9;
    --sidebar-bg: #1a1d29;
    --sidebar-color: #a6b0cf;
    --sidebar-active: #0d6efd;
    --sidebar-hover: #252a3c;
}

* { box-sizing: border-box; }
html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--body-bg);
    color: #333;
}

.crm-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.crm-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-color);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1040;
    overflow-y: auto;
    transition: transform .3s ease;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-brand a {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.sidebar-brand i { color: var(--primary); }
.sidebar-close {
    background: none; border: none; color: #fff; font-size: 1.2rem;
}

.sidebar-nav {
    padding: .75rem 0;
    flex: 1;
}
.nav-section {
    padding: .5rem 1.25rem;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: rgba(255,255,255,.4);
    margin-top: .5rem;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1.25rem;
    color: var(--sidebar-color);
    text-decoration: none;
    font-size: .92rem;
    transition: all .15s;
    border-left: 3px solid transparent;
}
.nav-link:hover, .nav-link.active {
    background: var(--sidebar-hover);
    color: #fff;
    border-left-color: var(--primary);
}
.nav-link i { width: 20px; text-align: center; font-size: .95rem; }
.nav-link .badge { font-size: .7rem; }

.sidebar-overlay {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1035;
}

/* Topbar */
.crm-topbar {
    position: fixed;
    top: 0; left: var(--sidebar-width); right: 0;
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    z-index: 1030;
    gap: 1rem;
}
.topbar-toggle {
    background: none; border: none; font-size: 1.2rem; color: var(--dark);
    display: none;
}
.topbar-title {
    font-weight: 600; font-size: 1.05rem; flex: 1;
}
.topbar-user .dropdown-toggle {
    display: flex; align-items: center; gap: .5rem;
    text-decoration: none; color: var(--dark);
}
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #e2e8f0; }

/* Main */
.crm-main {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    flex: 1;
    min-height: calc(100vh - var(--topbar-height));
}

/* Cards & stats */
.stat-card {
    background: #fff; border-radius: .75rem; padding: 1.25rem;
    border: 1px solid #e2e8f0; box-shadow: 0 1px 2px rgba(0,0,0,.04);
    display: flex; align-items: center; gap: 1rem;
}
.stat-icon {
    width: 48px; height: 48px; border-radius: .5rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; color: #fff;
}
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: .82rem; color: var(--secondary); }

/* Order cards */
.order-card {
    background: #fff; border-radius: .75rem;
    border: 1px solid #e2e8f0;
    transition: box-shadow .2s;
}
.order-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.06); }
.order-card-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid #e2e8f0;
    display: flex; justify-content: space-between; align-items: center;
}
.order-card-body { padding: 1rem 1.25rem; }
.order-card-footer {
    padding: .75rem 1.25rem; border-top: 1px solid #e2e8f0;
    background: #fafbfc; border-radius: 0 0 .75rem .75rem;
    display: flex; justify-content: space-between; align-items: center;
}

/* Status badges */
.badge-status {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .35em .65em; border-radius: .375rem; font-size: .78rem; font-weight: 500;
}

/* Chat */
.chat-container {
    display: flex; flex-direction: column; height: calc(100vh - var(--topbar-height) - 3rem);
    background: #fff; border-radius: .75rem; border: 1px solid #e2e8f0;
}
.chat-messages {
    flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .75rem;
    background: #f8f9fa;
}
.chat-message {
    max-width: 75%; padding: .75rem 1rem; border-radius: .75rem;
    font-size: .92rem; line-height: 1.5; position: relative;
}
.chat-message.own {
    align-self: flex-end;
    background: var(--primary); color: #fff;
    border-bottom-right-radius: .25rem;
}
.chat-message.other {
    align-self: flex-start;
    background: #fff; color: #333;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: .25rem;
}
.chat-meta { font-size: .7rem; opacity: .7; margin-top: .25rem; }
.chat-input {
    padding: .75rem 1rem; border-top: 1px solid #e2e8f0;
    display: flex; gap: .5rem; background: #fff;
}
.chat-input textarea {
    flex: 1; resize: none; border-radius: .5rem; border: 1px solid #e2e8f0; padding: .5rem .75rem;
}

/* Order timeline */
.timeline {
    position: relative; padding-left: 1.5rem;
}
.timeline::before {
    content: ''; position: absolute; left: .4rem; top: .25rem; bottom: .25rem;
    width: 2px; background: #e2e8f0;
}
.timeline-item { position: relative; margin-bottom: 1rem; }
.timeline-dot {
    position: absolute; left: -1.3rem; top: .2rem;
    width: 10px; height: 10px; border-radius: 50%; background: var(--primary);
    border: 2px solid #fff; box-shadow: 0 0 0 2px var(--primary);
}
.timeline-text { font-size: .85rem; }
.timeline-time { font-size: .75rem; color: var(--secondary); }

/* Forms */
.form-label { font-weight: 500; font-size: .88rem; }
.form-control, .form-select { font-size: .9rem; }

/* Tables */
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--secondary); font-weight: 600; }
.table td { font-size: .88rem; vertical-align: middle; }

/* Notifications dropdown / page */
.notif-item {
    padding: .75rem 1rem; border-bottom: 1px solid #f0f0f0;
    display: flex; gap: .75rem; align-items: flex-start;
}
.notif-item.unread { background: #f0f7ff; }
.notif-icon { width: 36px; height: 36px; border-radius: 50%; background: #e9ecef; display: flex; align-items: center; justify-content: center; font-size: .85rem; color: var(--primary); flex-shrink: 0; }

/* Mobile */
@media (max-width: 991.98px) {
    .crm-sidebar { transform: translateX(-100%); }
    .crm-sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .crm-main { margin-left: 0; }
    .crm-topbar { left: 0; }
    .topbar-toggle { display: block; }
}

/* Login page */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1a1d29 0%, #2d3142 100%);
}
.login-card {
    width: 100%; max-width: 420px; padding: 2rem;
    background: #fff; border-radius: 1rem; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo i { font-size: 2.5rem; color: var(--primary); }
.login-logo h2 { font-size: 1.5rem; margin-top: .5rem; font-weight: 700; }
