:root {
    --primary: #f97316;
    --primary-soft: rgba(249, 115, 22, 0.08);
    --sidebar-width: 230px;
    --bg-body: #f3f4f6;
    --bg-sidebar: #111827;
    --bg-topbar: #ffffff;
    --bg-card: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border-soft: #e5e7eb;
}

/* Global reset / base ---------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Shell layout ---------------------------------------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Sidebar --------------------------------------------- */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: #e5e7eb;
    padding: 14px 14px 16px;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 20;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px 12px;
}

.sidebar-header img {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: #fff;
    object-fit: contain;
    padding: 3px;
}

.sidebar-title {
    font-size: 18px;
    font-weight: 700;
}

.sidebar-subtitle {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #9ca3af;
}

.sidebar-nav {
    margin-top: 14px;
    flex: 1;
}

.nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #9ca3af;
    margin: 12px 6px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 13px;
    color: #e5e7eb;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-item span.icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.nav-item:hover {
    background: rgba(55, 65, 81, 0.85);
}

.nav-item.active {
    background: rgba(249, 115, 22, 0.15);
    color: #fbbf24;
}

.sidebar-footer {
    margin-top: 8px;
    padding: 8px 8px 6px;
    border-radius: 8px;
    background: rgba(31, 41, 55, 0.9);
    font-size: 11px;
    color: #9ca3af;
}

.sidebar-footer strong {
    color: #e5e7eb;
}

/* Main column (header + content + footer) ------------- */

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

/* Topbar ---------------------------------------------- */

.topbar {
    height: 56px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-soft);
    background: var(--bg-topbar);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hamburger {
    display: none;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    color: #374151;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

.topbar-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* User avatar & dropdown ------------------------------ */

.user-menu-wrapper {
    position: relative;
}

.user-avatar-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 3px 6px 3px 3px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    cursor: pointer;
    font-size: 12px;
    color: #374151;
}

.user-avatar-img,
.user-avatar-initials {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    background: #f97316;
    color: #ffffff;
    overflow: hidden;
}

.user-avatar-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-menu {
    position: absolute;
    right: 0;
    top: 40px;
    min-width: 190px;
    background: #ffffff;
    border-radius: 10px;
    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(229, 231, 235, 0.8);
    padding: 6px 0;
    display: none;
    z-index: 30;
}

.user-menu.open {
    display: block;
}

.user-menu-item {
    padding: 7px 12px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: #374151;
    transition: background 0.15s ease;
}

.user-menu-item span.icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
}

.user-menu-item:hover {
    background: #f3f4f6;
}

.user-menu-separator {
    height: 1px;
    margin: 6px 0;
    background: #e5e7eb;
}

.user-menu-item.logout {
    color: #b91c1c;
}

/* Content area ---------------------------------------- */

.app-content {
    padding: 18px 22px 18px;
}

/* Cards & grid (for dashboard) ------------------------ */

.grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr);
    gap: 16px;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px 18px 14px;
    box-shadow:
        0 2px 4px rgba(15, 23, 42, 0.06);
    border: 1px solid var(--border-soft);
}

.card h2 {
    margin: 0 0 6px;
    font-size: 18px;
    color: var(--text-main);
}

.card p {
    margin: 0;
    font-size: 13px;
    color: var(--text-muted);
}

.chips-row {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    border: 1px solid var(--border-soft);
    color: #374151;
    background: #f9fafb;
}

.stats-grid {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.stat-card {
    padding: 10px 10px 9px;
    border-radius: 10px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    font-size: 11px;
}

.stat-label {
    color: var(--text-muted);
    margin-bottom: 3px;
}

.stat-value {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}

.modules-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.module-card {
    border-radius: 10px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: 10px 10px 9px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
}

.module-card:hover {
    transform: translateY(-1px);
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

.module-title {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}

.module-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.module-footer {
    margin-top: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--primary);
}

.module-footer span.badge {
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--primary-soft);
    border: 1px solid rgba(249, 115, 22, 0.6);
    color: #9a3412;
}

/* Footer ---------------------------------------------- */

.app-footer {
    padding: 10px 22px;
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-soft);
    background: #ffffff;
}

.app-footer span strong {
    color: var(--primary);
}

/* Error text ------------------------------------------ */

.error {
    color: #b91c1c;
    margin-top: 8px;
    font-size: 12px;
}

/* ---------------- NEW: Generic UI for Leads / Tables / Forms ---------------- */

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 14px;
    border-radius: 999px;
    border: none;
    background: var(--primary);
    color: #ffffff;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15);
    transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease;
}

.btn:hover {
    background: #ea580c;
    box-shadow: 0 4px 8px rgba(15, 23, 42, 0.18);
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: default;
    box-shadow: none;
    transform: none;
}

.btn-outline {
    background: #ffffff;
    color: #374151;
    border: 1px solid #d1d5db;
    box-shadow: none;
}

.btn-outline:hover {
    background: #f9fafb;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 11px;
}

/* Form controls */

.form-control {
    display: block;
    width: 100%;
    padding: 6px 9px;
    font-size: 12px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.3);
}

.form-control::placeholder {
    color: #9ca3af;
}

/* Table layout */

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.table thead th {
    text-align: left;
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #f9fafb;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}

.table tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid #f3f4f6;
    background: #ffffff;
    vertical-align: middle;
}

.table tbody tr:hover {
    background: #f9fafb;
}

/* Badges (lead status) */

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid transparent;
}

.badge-soft {
    background: #f9fafb;
    color: #4b5563;
    border-color: #e5e7eb;
}

.badge-info {
    background: rgba(59, 130, 246, 0.08);
    color: #1d4ed8;
    border-color: rgba(59, 130, 246, 0.4);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.08);
    color: #b45309;
    border-color: rgba(245, 158, 11, 0.45);
}

.badge-success {
    background: rgba(34, 197, 94, 0.08);
    color: #15803d;
    border-color: rgba(34, 197, 94, 0.45);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.08);
    color: #b91c1c;
    border-color: rgba(239, 68, 68, 0.45);
}

.badge-muted {
    background: #f3f4f6;
    color: #6b7280;
    border-color: #d1d5db;
}

/* Chips as filter buttons */

.chip.chip-filter {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip.chip-filter:hover {
    background: #f3f4f6;
}

.chip.chip-filter.active {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: #9a3412;
}

/* Responsive ------------------------------------------ */

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease-out;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0;
    }

    .hamburger {
        display: inline-flex;
    }

    .grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .app-content {
        padding: 14px 16px 14px;
    }
}

@media (max-width: 540px) {
    .topbar {
        padding: 8px 12px;
    }

    .user-avatar-name {
        max-width: 90px;
    }

    .app-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 8px 16px;
    }
}