:root {
    --brand: #0d3b66;
    --brand-dark: #082946;
    --accent: #f59e0b;
    --surface: #f5f7fb;
    --sidebar-width: 250px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--surface);
    color: #1f2937;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overflow-x: hidden;
}
body.menu-open { overflow: hidden; }
.min-w-0 { min-width: 0; }
.app-shell { min-height: 100vh; display: flex; }

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1045;
    box-shadow: 12px 0 35px rgba(8, 41, 70, .12);
}
.brand-box {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: 76px;
    padding: 1rem;
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.brand-mark {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--accent);
    color: #111827;
    font-weight: 900;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
}
.brand-name { font-weight: 800; line-height: 1.1; }
.sidebar-logo-wrap {
    flex: 0 0 auto;
    width: 58px;
    height: 46px;
    padding: 4px;
    border-radius: 10px;
    background: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
}
.sidebar-logo { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.login-logo {
    display: block;
    width: min(270px, 82%);
    height: auto;
    margin-left: auto;
    margin-right: auto;
    object-fit: contain;
}

.sidebar-nav { padding: .75rem; overflow-y: auto; overscroll-behavior: contain; }
.sidebar-nav .nav-link {
    color: rgba(255,255,255,.80);
    display: flex;
    gap: .75rem;
    align-items: center;
    min-height: 44px;
    padding: .68rem .8rem;
    border-radius: .65rem;
    margin-bottom: .15rem;
}
.sidebar-nav .nav-link i { width: 20px; text-align: center; }
.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link.active { background: rgba(255,255,255,.14); color: white; }
.sidebar-user { margin-top: auto; padding: 1rem; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-backdrop { display: none; border: 0; padding: 0; }

.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
}
.topbar {
    min-height: 82px;
    background: rgba(255,255,255,.97);
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: .85rem 1.35rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 1.35rem; margin: 0; font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.icon-button, .notification-button { width: 44px; height: 44px; display: grid; place-items: center; }
.notification-count {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    background: #dc3545;
    color: white;
    font-size: .68rem;
    line-height: 20px;
    font-weight: 800;
    padding: 0 5px;
}
.content-area { padding: 1.25rem; }

.card {
    border: 1px solid #e7ebf2;
    border-radius: .9rem;
    box-shadow: 0 4px 16px rgba(15,23,42,.04);
}
.card-header { border-bottom-color: #edf0f5; }
.stat-card { border: 0; border-radius: 1rem; box-shadow: 0 6px 20px rgba(15,23,42,.06); overflow: hidden; }
.stat-card .icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.25rem; }
.table-responsive { border-radius: inherit; }
.table thead th {
    background: #eef3f8;
    color: #475569;
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}
.table td { vertical-align: middle; }
.text-bg-purple { background-color: #7c3aed !important; color: white !important; }
.notice-card { border-left: 5px solid var(--brand); }
.assignment-card { border-left: 5px solid #16a34a; }
.missing-card { border-left: 5px solid #dc3545; }
.completed-card { border-left: 5px solid #198754; }
.login-page { min-height: 100vh; background: linear-gradient(135deg, #082946 0%, #0d3b66 55%, #1f5f8b 100%); display: grid; place-items: center; padding: 1rem; }
.login-card { max-width: 430px; width: 100%; border: none; border-radius: 1.25rem; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.form-label { font-weight: 650; }
.form-control, .form-select { min-height: 44px; }
textarea.form-control { min-height: auto; }
.btn { min-height: 40px; }
.btn-touch { min-height: 48px; font-weight: 700; }
.mobile-status-actions .btn { min-height: 46px; }
.sticky-mobile-actions { position: sticky; bottom: 0; z-index: 1000; background: rgba(245,247,251,.96); padding: .65rem 0 calc(.65rem + env(safe-area-inset-bottom)); }
.break-word { overflow-wrap: anywhere; }
.whatsapp-message-box { white-space: pre-wrap; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: .75rem; padding: .85rem; font-size: .88rem; }
.notification-item.unread { background: #eef6ff; border-left: 4px solid #0d6efd; }
.empty-state { padding: 3rem 1rem; text-align: center; color: #6c757d; }

@media (max-width: 1199.98px) {
    .content-area { padding: 1rem; }
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-102%); transition: transform .22s ease; }
    .sidebar.show { transform: translateX(0); }
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 1040;
        background: rgba(15,23,42,.5);
    }
    .sidebar-backdrop.show { display: block; }
    .main-content { margin-left: 0; width: 100%; }
    .topbar { min-height: 70px; padding: .7rem .85rem; }
    .content-area { padding: .85rem; }
}

@media (max-width: 767.98px) {
    .topbar { align-items: center; gap: .55rem; }
    .topbar h1 { font-size: 1.05rem; }
    .topbar-title .small { font-size: .7rem; }
    .topbar-actions { gap: .35rem; }
    .topbar-actions .btn span { display: none; }
    .topbar-actions .btn { width: 42px; padding-left: 0; padding-right: 0; }
    .content-area { padding: .65rem; }
    .card { border-radius: .75rem; }
    .card-body { padding: .9rem; }
    .stat-card .card-body { padding: .85rem; }
    .stat-card .display-6 { font-size: 1.65rem; }
    .stat-card .icon { width: 40px; height: 40px; }
    .table { min-width: 680px; }
    .table.table-compact-mobile { min-width: 560px; }
    .mobile-stack > [class*="col-"] { width: 100%; }
    .position-sticky { position: static !important; }
    .modal-dialog { margin: .5rem; }
    .btn-mobile-full { width: 100%; }
    h2 { font-size: 1.45rem; }
    h4 { font-size: 1.15rem; }
}

@media (max-width: 420px) {
    .topbar { padding-left: .55rem; padding-right: .55rem; }
    .topbar-actions .notification-button { display: none; }
    .content-area { padding: .5rem; }
    .card-body { padding: .8rem; }
}

@media print {
    .sidebar, .sidebar-backdrop, .topbar, .no-print, .btn, .sticky-mobile-actions { display: none !important; }
    .main-content { margin: 0; width: 100%; }
    .content-area { padding: 0; }
    body { background: white; }
    .card { box-shadow: none; border: 0; }
    .table { min-width: 0 !important; }
}

/* Version 5 communications */
.communication-tabs { gap: .4rem; }
.communication-tabs .nav-link { font-weight: 700; border-radius: .7rem; }
.communication-card { transition: border-color .15s ease, box-shadow .15s ease; }
.communication-card.communication-unread { border-left: 5px solid #0d6efd; background: #fbfdff; box-shadow: 0 7px 22px rgba(13,110,253,.08); }
.communication-type-icon { width: 46px; height: 46px; min-width: 46px; border-radius: .85rem; display: grid; place-items: center; font-size: 1.15rem; }
.communication-body { line-height: 1.65; white-space: normal; overflow-wrap: anywhere; }
.communication-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .65rem; max-width: 760px; }
.communication-photo { display: block; border-radius: .75rem; overflow: hidden; border: 1px solid #e2e8f0; background: #f8fafc; aspect-ratio: 4 / 3; }
.communication-photo img { width: 100%; height: 100%; display: block; object-fit: cover; transition: transform .18s ease; }
.communication-photo:hover img { transform: scale(1.025); }
.programme-link { display: flex; align-items: center; gap: .7rem; padding: .8rem .9rem; border-radius: .75rem; border: 1px solid #bbf7d0; background: #f0fdf4; color: #166534; text-decoration: none; }
.programme-link:hover { background: #dcfce7; color: #14532d; }
.employee-multi { min-height: 210px; }
.communication-help-card { position: sticky; top: 100px; }
.communication-rule { display: flex; gap: .8rem; padding: .9rem 0; border-bottom: 1px solid #edf0f5; }
.communication-rule:last-child { border-bottom: 0; }
.communication-rule > i { width: 38px; height: 38px; min-width: 38px; display: grid; place-items: center; border-radius: .7rem; background: #eef3f8; color: var(--brand); font-size: 1.05rem; }

@media (max-width: 767.98px) {
    .communication-card .card-body { padding: .85rem; }
    .communication-card .d-flex.align-items-start.gap-3 { gap: .65rem !important; }
    .communication-type-icon { width: 38px; height: 38px; min-width: 38px; border-radius: .65rem; font-size: .95rem; }
    .communication-photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .communication-help-card { position: static; }
}

/* Version 5.3 Client Follow-Up CRM */
.client-avatar {
    width: 38px; height: 38px; min-width: 38px; border-radius: 50%;
    display: grid; place-items: center; font-weight: 800; color: var(--brand);
    background: #e8f1fb; border: 1px solid #cfe0f2;
}
.client-avatar-lg { width: 58px; height: 58px; min-width: 58px; font-size: 1.35rem; }
.client-followup-table td { padding-top: .8rem; padding-bottom: .8rem; }
.client-row-overdue { background: #fff7f7; }
.client-row-overdue:hover { background: #fff0f0 !important; }
.client-pipeline-card .btn { white-space: nowrap; }
.client-followup-side-card { top: 98px; }
.client-notes { white-space: normal; overflow-wrap: anywhere; line-height: 1.65; }
.client-detail-row { display: flex; gap: 1rem; justify-content: space-between; padding: .75rem 0; border-bottom: 1px solid #edf0f5; }
.client-detail-row:last-child { border-bottom: 0; }
.client-detail-row > span { color: #64748b; font-size: .86rem; flex: 0 0 38%; }
.client-detail-row > strong { text-align: right; font-size: .9rem; min-width: 0; }
.client-timeline { position: relative; }
.client-timeline::before { content: ''; position: absolute; left: 20px; top: 6px; bottom: 6px; width: 2px; background: #e2e8f0; }
.client-timeline-item { display: flex; gap: .9rem; position: relative; padding-bottom: 1.2rem; }
.client-timeline-item:last-child { padding-bottom: 0; }
.client-timeline-icon { z-index: 1; width: 42px; height: 42px; min-width: 42px; border-radius: 50%; display: grid; place-items: center; background: #fff; border: 2px solid #cbd5e1; color: var(--brand); }
.client-timeline-content { flex: 1; min-width: 0; border: 1px solid #e5e7eb; border-radius: .75rem; padding: .8rem .9rem; background: #fff; }
.client-mini-stat { min-height: 72px; display: flex; flex-direction: column; justify-content: center; align-items: center; border-radius: .75rem; background: #f8fafc; border: 1px solid #e5e7eb; }
.client-mini-stat strong { font-size: 1.6rem; line-height: 1; }
.client-mini-stat span { color: #64748b; font-size: .78rem; font-weight: 700; margin-top: .35rem; }
.client-due-card { border: 1px solid #e5e7eb; border-radius: .75rem; padding: .75rem; min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: .75rem; background: #fff; }
.client-due-card:hover { border-color: #bfdbfe; box-shadow: 0 4px 14px rgba(15,23,42,.06); }

@media (max-width: 767.98px) {
    .client-followup-side-card { position: static !important; }
    .client-avatar-lg { width: 48px; height: 48px; min-width: 48px; }
    .client-timeline::before { left: 17px; }
    .client-timeline-icon { width: 36px; height: 36px; min-width: 36px; }
}
