/* ============================================================
   DNM Solutions CRM - App stylesheet
   Bootstrap 5 + custom design system
   ============================================================ */

:root {
    --app-bg: #f4f6fa;
    --app-sidebar-bg: #ffffff;
    --app-sidebar-width: 240px;
    --app-sidebar-collapsed: 0px;
    --app-topbar-h: 60px;
    --app-border: #e5e9f2;
    --app-primary: #0d6efd;
    --app-text: #1f2937;
    --app-text-muted: #6b7280;
    --radius-card: 10px;
    --radius-input: 8px;
    --shadow-card: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
    --shadow-drop: 0 8px 24px rgba(16, 24, 40, .12);
    --bottom-nav-h: 60px;
}

html, body { height: 100%; }
body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--app-bg);
    color: var(--app-text);
    font-size: .925rem;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Layout ---------- */
.app-wrapper { display: flex; min-height: 100vh; }

.app-sidebar {
    width: var(--app-sidebar-width);
    flex-shrink: 0;
    background: var(--app-sidebar-bg);
    border-right: 1px solid var(--app-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1040;
}

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

.app-content { flex: 1; padding-bottom: 2.5rem; }

/* ---------- Sidebar ---------- */
.sidebar-brand {
    height: var(--app-topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.1rem;
    border-bottom: 1px solid var(--app-border);
}
.brand-logo {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, #0d6efd, #4f8cff);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    overflow: hidden;
}
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.brand-text { font-weight: 700; font-size: .98rem; letter-spacing: -.01em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .7rem; }
.nav-section-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--app-text-muted);
    padding: .5rem .65rem .35rem;
    font-weight: 600;
}
.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .7rem;
    border-radius: 8px;
    color: #4b5563;
    font-weight: 500;
    font-size: .9rem;
    margin-bottom: 2px;
    transition: background .12s ease, color .12s ease;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-nav .nav-link:hover { background: #f1f5ff; color: var(--app-primary); }
.sidebar-nav .nav-link.active { background: var(--app-primary); color: #fff; box-shadow: 0 2px 8px rgba(13, 110, 253, .3); }

.sidebar-footer { border-top: 1px solid var(--app-border); padding: .5rem; }
.sidebar-user-name { font-size: .85rem; font-weight: 600; }
.sidebar-user-role { font-size: .72rem; color: var(--app-text-muted); }

/* ---------- Topbar ---------- */
.app-topbar {
    height: var(--app-topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--app-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.page-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em; }

.btn-icon { width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }
.btn-icon i { font-size: 1rem; }

.user-chip { border: 1px solid var(--app-border); border-radius: 24px; padding: .25rem .6rem .25rem .25rem; }

.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--app-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .85rem;
    flex-shrink: 0;
}
.avatar-sm { width: 30px; height: 30px; font-size: .75rem; }
.avatar-xs { width: 24px; height: 24px; font-size: .68rem; }
.avatar-md { width: 44px; height: 44px; font-size: 1rem; }
.avatar-lg { width: 72px; height: 72px; font-size: 1.6rem; }

/* ---------- Global search ---------- */
.global-search { position: relative; width: 260px; }
.global-search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--app-text-muted); font-size: .85rem; }
.global-search-input { padding-left: 32px; border-radius: var(--radius-input); }
.global-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    max-height: 420px;
    overflow-y: auto;
    z-index: 1060;
}
.gs-group-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--app-text-muted); padding: .45rem .8rem .2rem; font-weight: 700; }
.gs-item { display: block; padding: .45rem .8rem; text-decoration: none; color: inherit; }
.gs-item:hover { background: #f5f7fb; }
.gs-item .gs-title { font-weight: 600; font-size: .85rem; }
.gs-item .gs-sub { font-size: .75rem; color: var(--app-text-muted); }

/* ---------- Notifications ---------- */
.notif-dropdown { width: 340px; max-width: calc(100vw - 24px); padding: 0; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: block; padding: .6rem .85rem; text-decoration: none; color: inherit; border-bottom: 1px solid var(--app-border); }
.notif-item:hover { background: #f8fafd; }
.notif-item.unread { background: #eef4ff; }
.notif-title { font-weight: 600; font-size: .82rem; }
.notif-msg { font-size: .76rem; color: var(--app-text-muted); }
.notif-time { font-size: .7rem; color: var(--app-text-muted); margin-top: 2px; }
.notif-badge { font-size: .62rem; }

/* ---------- Cards ---------- */
.card {
    border: 1px solid var(--app-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
}
.card-header {
    background: #fff;
    border-bottom: 1px solid var(--app-border);
    padding: .8rem 1rem;
    border-radius: var(--radius-card) var(--radius-card) 0 0 !important;
}
.card-header h6 { font-size: .9rem; font-weight: 700; }

.stat-card { border-radius: var(--radius-card); transition: transform .12s ease, box-shadow .12s ease; }
a:hover .stat-card { transform: translateY(-2px); box-shadow: var(--shadow-drop); }
.stat-icon {
    width: 44px; height: 44px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}
.stat-value { font-size: 1.45rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat-label { font-size: .75rem; color: var(--app-text-muted); font-weight: 500; }

/* ---------- Badges (soft) ---------- */
.badge { font-weight: 600; }
.badge-soft-primary { background: #e7efff; color: #0d5cd6; }
.badge-soft-success { background: #e3f7ec; color: #117a4b; }
.badge-soft-danger  { background: #fde7e9; color: #c81e34; }
.badge-soft-warning  { background: #fff4db; color: #a66c00; }
.badge-soft-info     { background: #e1f4fb; color: #0a7ea8; }
.badge-soft-secondary { background: #eef0f4; color: #5b6470; }
.badge-soft-dark     { background: #e6e8eb; color: #33393f; }
.badge-soft-indigo   { background: #ece8fb; color: #5b41c9; }
.badge-soft-teal     { background: #dcf5f1; color: #0f8577; }

/* ---------- Tables ---------- */
.table { --bs-table-hover-bg: #f8fafd; }
.table thead th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--app-text-muted);
    font-weight: 700;
    border-bottom: 1px solid var(--app-border);
    white-space: nowrap;
    background: #fafbfd;
}
.table td { font-size: .87rem; }
.table-danger-light td { background-color: #fff6f6; }
.table > :not(:first-child) { border-top: 1px solid var(--app-border); }

/* ---------- Forms ---------- */
.form-control, .form-select { border-radius: var(--radius-input); font-size: .9rem; border-color: #d5dbe6; }
.form-control:focus, .form-select:focus { border-color: #7eb3ff; box-shadow: 0 0 0 .18rem rgba(13,110,253,.12); }
.form-label { font-weight: 600; font-size: .82rem; }
.input-group-text { border-radius: var(--radius-input); }

.btn { border-radius: var(--radius-input); }
.btn-sm { border-radius: 7px; }
.btn-primary { background: var(--app-primary); border-color: var(--app-primary); }
.btn-light { background: #fff; }

/* ---------- Choice cards (call outcomes) ---------- */
.choice-card {
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: .45rem .85rem;
    cursor: pointer;
    transition: all .12s ease;
    user-select: none;
    background: #fff;
}
.choice-card:hover { border-color: #9ec3ff; background: #f5f9ff; }
.choice-card input { display: none; }
.choice-card span { font-size: .85rem; font-weight: 500; }
.choice-card input:checked + span { color: var(--app-primary); font-weight: 700; }
.choice-card:has(input:checked) { border-color: var(--app-primary); background: #eef4ff; box-shadow: 0 0 0 1px var(--app-primary) inset; }

/* ---------- Info items ---------- */
.info-label { font-size: .72rem; color: var(--app-text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.info-value { font-size: .9rem; font-weight: 500; }

/* ---------- Activity timeline ---------- */
.activity-timeline { position: relative; padding-left: 8px; }
.activity-item { position: relative; display: flex; gap: .8rem; padding-bottom: 1.1rem; }
.activity-item::before {
    content: "";
    position: absolute;
    left: 19px; top: 34px; bottom: 0;
    width: 2px;
    background: var(--app-border);
}
.activity-item:last-child { padding-bottom: 0; }
.activity-item:last-child::before { display: none; }
.activity-dot {
    width: 38px; height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    flex-shrink: 0;
    z-index: 1;
}
.activity-body { min-width: 0; padding-top: 2px; }
.activity-text { font-size: .87rem; font-weight: 500; }
.activity-meta { font-size: .74rem; color: var(--app-text-muted); margin-top: 2px; }

/* ---------- Pipeline ---------- */
.pipeline-scroll { overflow-x: auto; padding-bottom: 1rem; }
.pipeline-board { display: flex; gap: .75rem; min-width: max-content; }
.pipeline-column {
    width: 240px;
    background: #eef1f6;
    border-radius: 10px;
    padding: .6rem;
    flex-shrink: 0;
}
.pipeline-col-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .6rem;
}
.pipeline-count {
    background: #fff;
    border-radius: 20px;
    padding: .1rem .5rem;
    font-size: .75rem;
    font-weight: 700;
    color: var(--app-text-muted);
}
.pipeline-cards { min-height: 80px; }
.pipeline-card { cursor: grab; border: 1px solid var(--app-border); border-radius: 9px; box-shadow: none; }
.pipeline-card:active { cursor: grabbing; }
.pipeline-card.dragging { opacity: .5; border: 1px dashed var(--app-primary); }
.pipeline-cards.drag-over { background: #e3ecff; border-radius: 8px; }
.pipeline-empty { border: 1px dashed #c6cede; border-radius: 8px; }

/* ---------- Empty state ---------- */
.empty-state .empty-icon {
    width: 60px; height: 60px;
    margin: 0 auto;
    border-radius: 16px;
    background: #eef1f6;
    color: var(--app-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
}

/* ---------- Login / Install ---------- */
.login-body {
    background: linear-gradient(135deg, #eef4ff 0%, #f6f8fd 55%, #eef7f1 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-wrap { width: 100%; max-width: 420px; }
.install-wrap { width: 100%; max-width: 520px; }
.login-card { border-radius: 16px; border: none; }
.login-logo {
    width: 56px; height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, #0d6efd, #4f8cff);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    box-shadow: 0 6px 18px rgba(13, 110, 253, .35);
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; }

.success-check {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: #198754;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    box-shadow: 0 8px 24px rgba(25, 135, 84, .35);
}

/* ---------- Bottom navigation (mobile) ---------- */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: #fff;
    border-top: 1px solid var(--app-border);
    display: flex;
    align-items: stretch;
    z-index: 1035;
}
.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--app-text-muted);
    text-decoration: none;
    font-size: .66rem;
    font-weight: 600;
    border: none;
    background: none;
    padding: 0;
}
.bottom-nav-item i { font-size: 1.15rem; }
.bottom-nav-item.active { color: var(--app-primary); }

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

/* ---------- Responsive ---------- */
@media (min-width: 992px) {
    .bottom-nav { display: none; }
    .app-content { padding-bottom: 3rem; }
}
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: var(--shadow-drop);
        width: 260px;
    }
    .app-sidebar.open { transform: translateX(0); }
    .app-content { padding-bottom: calc(var(--bottom-nav-h) + 1.5rem); }
}

/* ---------- Admin ---------- */
.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}
.admin-nav-link {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .75rem;
    border-radius: 8px;
    border: 1px solid var(--app-border);
    background: #fff;
    color: #4b5563;
    font-size: .82rem;
    font-weight: 600;
    text-decoration: none;
}
.admin-nav-link:hover { background: #f1f5ff; color: var(--app-primary); }
.admin-nav-link.active { background: var(--app-primary); border-color: var(--app-primary); color: #fff; }
.perm-matrix td, .perm-matrix th { vertical-align: middle; }

/* ---------- Utility ---------- */
.min-w-0 { min-width: 0; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-responsive { -webkit-overflow-scrolling: touch; }
::selection { background: #cfe3ff; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #c9d1de; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
