/* =====================================================
   JBN Mobile RMS — Application Theme
   Custom admin skin on top of Bootstrap 5
   ===================================================== */

:root {
    --sidebar-w: 264px;
    --c-sidebar-bg: #0f172a;
    --c-primary: #4f46e5;
    --c-primary-2: #6366f1;
    --c-bg: #f1f5f9;
    --c-card: #ffffff;
    --c-text: #0f172a;
    --c-muted: #64748b;
    --c-border: #e2e8f0;
}

* { box-sizing: border-box; }

body.app-body {
    background: var(--c-bg);
    color: var(--c-text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: .925rem;
}

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

.app-sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--c-sidebar-bg) 0%, #111c33 100%);
    color: #cbd5e1;
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.05rem 1.2rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.02rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-brand .brand-logo {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--c-primary), #8b5cf6);
    display: grid; place-items: center;
    font-size: 1.15rem; color: #fff;
    flex-shrink: 0;
}
.sidebar-brand small {
    display: block;
    font-size: .63rem;
    color: #94a3b8;
    font-weight: 500;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.sidebar-nav { padding: .6rem .6rem; overflow-y: auto; flex: 1; }
.sidebar-section {
    font-size: .63rem;
    letter-spacing: .13em;
    text-transform: uppercase;
    color: #64748b;
    padding: .95rem .75rem .35rem;
}
.app-nav {
    display: flex;
    align-items: center;
    gap: .7rem;
    color: #cbd5e1;
    padding: .58rem .75rem;
    border-radius: .5rem;
    text-decoration: none;
    font-size: .88rem;
    margin-bottom: .12rem;
    transition: background .15s ease;
}
.app-nav i { font-size: 1.02rem; width: 1.25rem; text-align: center; color: #94a3b8; }
.app-nav:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.app-nav.active {
    background: linear-gradient(90deg, var(--c-primary), #7c3aed);
    color: #fff;
    box-shadow: 0 6px 18px rgba(79, 70, 229, .35);
}
.app-nav.active i { color: #fff; }
.app-nav.disabled-module { opacity: .42; cursor: not-allowed; }
.phase-badge {
    margin-left: auto;
    font-size: .58rem;
    background: rgba(255, 255, 255, .12);
    color: #e2e8f0;
    padding: .2rem .42rem;
    border-radius: .35rem;
    font-weight: 600;
}
.sidebar-alert {
    margin-left: auto;
    background: #ef4444;
    color: #fff;
    font-size: .62rem;
    font-weight: 700;
    padding: .12rem .4rem;
    border-radius: 999px;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, .22);
}

/* ---------- Stock level bars ---------- */
.stock-bar {
    height: 5px;
    background: #e2e8f0;
    border-radius: 3px;
    margin-top: 5px;
    overflow: hidden;
    min-width: 90px;
}
.stock-bar > div { height: 100%; border-radius: 3px; }

.sidebar-foot {
    padding: .8rem 1rem;
    font-size: .66rem;
    color: #64748b;
    border-top: 1px solid rgba(255, 255, 255, .08);
    line-height: 1.7;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

/* ---------- Topbar ---------- */
.app-topbar {
    background: #fff;
    border-bottom: 1px solid var(--c-border);
    padding: .6rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.topbar-toggle { display: none; border: 0; background: transparent; font-size: 1.35rem; color: var(--c-text); }
.topbar-title { font-weight: 600; font-size: .98rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .85rem; }

.role-chip {
    background: #eef2ff;
    color: var(--c-primary);
    font-size: .68rem;
    padding: .3rem .65rem;
    border-radius: 999px;
    font-weight: 700;
    letter-spacing: .03em;
}

.user-chip { display: flex; align-items: center; gap: .6rem; }
.user-chip::after { display: none; }
.user-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 700;
    font-size: .82rem;
    flex-shrink: 0;
}

/* ---------- Content ---------- */
.app-content { padding: 1.5rem; flex: 1; }
.app-footer {
    padding: .75rem 1.5rem;
    color: var(--c-muted);
    font-size: .73rem;
    border-top: 1px solid var(--c-border);
    background: #fff;
}

/* ---------- Cards & stats ---------- */
.panel, .stat-card {
    border: 0;
    border-radius: .9rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .08);
}
.panel .card-header {
    background: #fff;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
    font-size: .9rem;
    border-radius: .9rem .9rem 0 0 !important;
}

.stat-card .card-body {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.05rem 1.2rem;
}
.stat-icon {
    width: 52px; height: 52px;
    border-radius: .8rem;
    display: grid; place-items: center;
    font-size: 1.4rem;
    color: #fff;
    flex-shrink: 0;
}
.si-indigo { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.si-green  { background: linear-gradient(135deg, #10b981, #059669); }
.si-blue   { background: linear-gradient(135deg, #3b82f6, #0ea5e9); }
.si-amber  { background: linear-gradient(135deg, #f59e0b, #d97706); }
.si-red    { background: linear-gradient(135deg, #ef4444, #dc2626); }

.stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--c-muted); font-size: .78rem; font-weight: 600; }
.stat-sub   { font-size: .7rem; color: var(--c-muted); }

/* ---------- Bar chart ---------- */
.bar-chart { display: flex; align-items: stretch; gap: .6rem; height: 170px; padding-top: .5rem; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.bar-track {
    flex: 1; width: 100%;
    display: flex; align-items: flex-end;
    background: #f1f5f9;
    border-radius: .4rem;
    overflow: hidden;
}
.bar-fill {
    width: 100%;
    background: linear-gradient(180deg, #818cf8, var(--c-primary));
    border-radius: .4rem .4rem 0 0;
    min-height: 3px;
    transition: height .5s ease;
}
.bar-count { font-size: .72rem; color: var(--c-muted); font-weight: 600; }
.bar-label { font-size: .72rem; color: var(--c-muted); font-weight: 700; }

/* ---------- Health list / activity ---------- */
.health-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .55rem 0;
    border-bottom: 1px dashed var(--c-border);
    font-size: .84rem;
}
.health-item:last-child { border-bottom: 0; }
.health-item > span:first-child { color: var(--c-muted); }

.activity-row td { font-size: .84rem; vertical-align: middle; }

.empty-state { text-align: center; color: var(--c-muted); padding: 1.75rem .5rem; }
.empty-state i { font-size: 1.9rem; opacity: .4; display: block; margin-bottom: .4rem; }

.profile-table td { padding: .5rem .25rem; font-size: .87rem; }
.profile-table td:first-child { width: 130px; }

/* ---------- Buttons & inputs ---------- */
.btn-jbn {
    background: linear-gradient(135deg, var(--c-primary), #7c3aed);
    border: 0;
    color: #fff;
    font-weight: 600;
    padding: .6rem 1.1rem;
    border-radius: .55rem;
}
.btn-jbn:hover:not(:disabled) { color: #fff; filter: brightness(1.08); }
.btn-jbn:disabled { opacity: .65; }

.input-icon { position: relative; }
.input-icon > .bi {
    position: absolute;
    left: .85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--c-muted);
}
.input-icon > input { padding-left: 2.5rem; }

/* ---------- Login page ---------- */
.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(1100px 550px at 8% -8%, #312e81 0%, transparent 58%),
        radial-gradient(900px 480px at 108% 108%, #7c2d12 0%, transparent 55%),
        #0f172a;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 1.1rem;
    box-shadow: 0 25px 60px rgba(0, 0, 0, .45);
    overflow: hidden;
}
.login-brand {
    background: linear-gradient(135deg, var(--c-primary) 0%, #8b5cf6 100%);
    color: #fff;
    padding: 1.5rem 2rem 1.3rem;
    text-align: center;
}
.login-brand .bi { font-size: 2.1rem; }
.login-brand h1 { font-size: 1.22rem; margin: .45rem 0 0; font-weight: 700; }
.login-brand p { margin: .2rem 0 0; font-size: .7rem; opacity: .85; letter-spacing: .16em; text-transform: uppercase; }
.login-body-pad { padding: 1.6rem 2rem 1.4rem; }
.login-foot {
    padding: .75rem 2rem 1.1rem;
    text-align: center;
    font-size: .68rem;
    color: var(--c-muted);
}

/* ---------- Toasts ---------- */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 2000; }

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

/* =====================================================
   Leads — Kanban board, drawer, stage colors
   ===================================================== */
.kanban-board {
    display: flex;
    gap: .9rem;
    overflow-x: auto;
    padding-bottom: .6rem;
    align-items: flex-start;
}
.kanban-col {
    flex: 0 0 272px;
    background: #f1f5f9;
    border-radius: .9rem;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 360px);
    min-height: 260px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
}
.kanban-col-head {
    padding: .7rem .9rem;
    font-weight: 700;
    font-size: .8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid;
    border-radius: .9rem .9rem 0 0;
}
.kanban-col-head .badge { color: inherit; font-size: .68rem; }
.kanban-col-body {
    padding: .6rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .55rem;
}
.kanban-card {
    background: #fff;
    border-radius: .65rem;
    padding: .65rem .75rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
    cursor: pointer;
    border-left: 3px solid transparent;
}
.kanban-card:hover { box-shadow: 0 4px 12px rgba(15, 23, 42, .14); }
.kanban-card.flag-due_today { border-left-color: #3b82f6; }
.kanban-card.flag-overdue { border-left-color: #ef4444; }
.kanban-card .kc-name { font-weight: 600; font-size: .85rem; }
.kanban-card .kc-meta { font-size: .72rem; color: var(--c-muted); margin-top: .15rem; }
.kanban-card .kc-foot { display: flex; justify-content: space-between; align-items: center; margin-top: .55rem; gap: .4rem; }
.kanban-card .kc-assignee {
    font-size: .66rem;
    background: #eef2ff;
    color: var(--c-primary);
    border-radius: 999px;
    padding: .12rem .5rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.kanban-empty { text-align: center; color: var(--c-muted); font-size: .74rem; padding: 1.2rem .5rem; }

.stage-NEW         { background: #f1f5f9; color: #475569; border-color: #cbd5e1 !important; }
.stage-CONTACTED   { background: #eef2ff; color: #4f46e5; border-color: #c7d2fe !important; }
.stage-VISITED     { background: #ecfeff; color: #0e7490; border-color: #a5f3fc !important; }
.stage-NEGOTIATION { background: #fffbeb; color: #b45309; border-color: #fde68a !important; }
.stage-WON         { background: #ecfdf5; color: #059669; border-color: #a7f3d0 !important; }
.stage-LOST        { background: #fef2f2; color: #dc2626; border-color: #fecaca !important; }

.lead-drawer .offcanvas-body { padding: 1rem 1.1rem; }
.timeline { position: relative; padding-left: 1.1rem; }
.timeline-item { position: relative; padding-bottom: 1rem; font-size: .8rem; }
.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.05rem;
    top: .25rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-primary);
}
.timeline-item::after {
    content: '';
    position: absolute;
    left: -1.02rem;
    top: .95rem;
    bottom: 0;
    width: 1px;
    background: var(--c-border);
}
.timeline-item:last-child::after { display: none; }
.timeline-item .ti-action { font-weight: 600; }
.timeline-item .ti-time { color: var(--c-muted); font-size: .7rem; }
.timeline-item .ti-details { color: var(--c-muted); }

/* -----------------------------------------------------------
   Repairs — Kanban status colors + urgent-priority accent
   ----------------------------------------------------------- */
.rstatus-RECEIVED      { background: #f1f5f9; color: #475569; border-color: #cbd5e1 !important; }
.rstatus-DIAGNOSING    { background: #ecfeff; color: #0e7490; border-color: #a5f3fc !important; }
.rstatus-WAITING_PARTS { background: #fffbeb; color: #b45309; border-color: #fde68a !important; }
.rstatus-IN_REPAIR     { background: #eef2ff; color: #4f46e5; border-color: #c7d2fe !important; }
.rstatus-READY         { background: #ecfdf5; color: #059669; border-color: #a7f3d0 !important; }
.rstatus-DELIVERED     { background: #ecfdf5; color: #059669; border-color: #a7f3d0 !important; }
.rstatus-CANCELLED     { background: #fef2f2; color: #dc2626; border-color: #fecaca !important; }

.kanban-card.priority-urgent { border-left-color: #dc2626; }

/* -----------------------------------------------------------
   Staff KPI & SOP Tracking — checklist rows + tab bar
   ----------------------------------------------------------- */
.sop-item { transition: background-color .15s ease; }
.sop-item.done { background: #f0fdf4; }
.sop-item .btn.btn-success i { color: #fff; }

#kpi-tabs .nav-link {
    color: var(--c-muted);
    font-weight: 600;
    font-size: .85rem;
    border: none;
    border-bottom: 2px solid transparent;
}
#kpi-tabs .nav-link.active {
    color: var(--c-primary);
    border-bottom-color: var(--c-primary);
    background: transparent;
}

/* -----------------------------------------------------------
   Payroll, Attendance, Bonus & Penalty Engine — tab bar +
   payslip/detail-drawer rows
   ----------------------------------------------------------- */
#payroll-tabs .nav-link {
    color: var(--c-muted);
    font-weight: 600;
    font-size: .85rem;
    border: none;
    border-bottom: 2px solid transparent;
}
#payroll-tabs .nav-link.active {
    color: var(--c-primary);
    border-bottom-color: var(--c-primary);
    background: transparent;
}

#mine-payslip-body .table td { padding: .45rem .5rem; }
#payroll-detail-drawer .table td { padding: .45rem .5rem; vertical-align: middle; }
#payroll-detail-drawer input:disabled { background-color: #f8fafc; opacity: .8; }

/* -----------------------------------------------------------
   Settings & Backup (Module 13) — history table + restore UX
   ----------------------------------------------------------- */
#cron-url { font-size: .78rem; }
#history-body .act-restore:hover {
    background: #fef2f2;
    border-color: #fecaca !important;
}
#restore-confirm-input:focus {
    border-color: #dc2626;
    box-shadow: 0 0 0 .2rem rgba(220, 38, 38, .15);
}

/* -----------------------------------------------------------
   Business Reports & Analytics (Module 14) — tab bar + print header
   ----------------------------------------------------------- */
#reports-tabs .nav-link {
    color: var(--c-muted);
    font-weight: 600;
    font-size: .85rem;
    border: none;
    border-bottom: 2px solid transparent;
}
#reports-tabs .nav-link.active {
    color: var(--c-primary);
    border-bottom-color: var(--c-primary);
    background: transparent;
}
.print-report-header { margin-bottom: 1rem; }

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
    .app-sidebar.open { transform: none; }
    .app-main { margin-left: 0; }
    .topbar-toggle { display: block; }
    .app-content { padding: 1rem; }
    .stat-value { font-size: 1.25rem; }
    .stat-icon { width: 44px; height: 44px; font-size: 1.15rem; }
}

/* -----------------------------------------------------------
   Print-friendly layout (Module 14 — Business Reports & Analytics)
   Only ever takes effect when a page actually calls window.print()
   while the app shell is on screen — today that is reports.js alone,
   so this cannot change how any other module looks or behaves.
   ----------------------------------------------------------- */
@media print {
    .app-sidebar, .sidebar-backdrop, .app-topbar, .app-footer, .toast-container { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .app-content { padding: 0 !important; }
    .card, .panel, .stat-card { box-shadow: none !important; border: 1px solid #cbd5e1 !important; }
    .table-responsive { overflow: visible !important; }
    table { font-size: .8rem; }
}
