/* ==========================================================
   MicroAsia Sales Management - Theme (logo red + green)
   ========================================================== */
:root {
    --brand-red: #E30613;
    --brand-red-dark: #B8040F;
    --brand-red-soft: #FDE8EA;
    --brand-green: #078A35;
    --brand-green-dark: #05682A;
    --brand-green-soft: #E3F5EA;
    --ink: #1E2430;
    --muted: #6B7280;
    --line: #E7E9EE;
    --bg: #F4F6F9;
    --card: #FFFFFF;
    --sidebar-w: 262px;
}

* { box-sizing: border-box; }
body {
    font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
    margin: 0;
}
a { color: var(--brand-green); }
a:hover { color: var(--brand-green-dark); }
.text-red { color: var(--brand-red) !important; }
.text-green { color: var(--brand-green) !important; }

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: #fff;
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    z-index: 1040;
    transition: transform .25s ease;
}
.sidebar::before {           /* red-green brand strip */
    content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--brand-red) 50%, var(--brand-green) 50%);
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 18px 14px; text-decoration: none;
    border-bottom: 1px solid var(--line);
}
.sidebar-brand img { width: 46px; height: 46px; object-fit: contain; }
.brand-title { font-weight: 700; font-size: 18px; line-height: 1.1; letter-spacing: .3px; }
.brand-sub { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; }
.sidebar-nav { padding: 10px 12px 24px; overflow-y: auto; flex: 1; }
.nav-section {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px;
    color: #9AA1AE; font-weight: 600; padding: 16px 10px 6px;
}
.nav-item-link, .nav-sub-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px;
    color: #3B4251; text-decoration: none; font-weight: 500;
    margin-bottom: 2px;
}
.nav-item-link i:first-child { font-size: 17px; width: 20px; text-align: center; }
.nav-item-link:hover, .nav-sub-link:hover { background: var(--brand-green-soft); color: var(--brand-green-dark); }
.nav-item-link.active {
    background: var(--brand-green); color: #fff;
    box-shadow: 0 4px 12px rgba(7,138,53,.25);
}
.nav-item-link.active-parent { color: var(--brand-green-dark); background: var(--brand-green-soft); }
.nav-toggle .chev { font-size: 12px; transition: transform .2s; }
.nav-toggle.collapsed .chev { transform: rotate(-90deg); }
.nav-sub-link { padding: 7px 12px 7px 40px; font-size: 13.5px; font-weight: 400; position: relative; }
.nav-sub-link i { font-size: 14px; }
.nav-sub-link.active { color: var(--brand-red); font-weight: 600; background: var(--brand-red-soft); }
.nav-sub-link.active::before {
    content: ""; position: absolute; left: 24px; top: 50%; width: 6px; height: 6px;
    border-radius: 50%; background: var(--brand-red); transform: translateY(-50%);
}

/* ---------- Main ---------- */
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    height: 64px; background: #fff; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 12px; padding: 0 24px;
    position: sticky; top: 0; z-index: 1020;
}
.topbar h1 { font-size: 18px; font-weight: 600; margin: 0; }
.btn-icon { border: 0; background: transparent; padding: 4px 8px; }
.user-chip { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.user-chip::after { margin-left: 4px; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--brand-red), var(--brand-green));
    color: #fff; font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.content { padding: 24px; flex: 1; }
.app-footer { padding: 14px 24px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); background: #fff; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header {
    background: #fff; border-bottom: 1px solid var(--line);
    padding: 14px 18px; font-weight: 600; border-radius: 12px 12px 0 0 !important;
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card-header .bi { color: var(--brand-green); }
.stat-card { padding: 18px; display: flex; align-items: center; gap: 14px; height: 100%; }
.stat-icon {
    width: 50px; height: 50px; border-radius: 12px; font-size: 22px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon.green { background: var(--brand-green-soft); color: var(--brand-green); }
.stat-icon.red { background: var(--brand-red-soft); color: var(--brand-red); }
.stat-icon.dark { background: #EEF0F4; color: #374151; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 12.5px; }

/* ---------- Buttons & badges ---------- */
.btn { border-radius: 8px; font-weight: 500; }
.btn-brand { background: var(--brand-green); border-color: var(--brand-green); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-green-dark); border-color: var(--brand-green-dark); color: #fff; }
.btn-brand-red { background: var(--brand-red); border-color: var(--brand-red); color: #fff; }
.btn-brand-red:hover, .btn-brand-red:focus { background: var(--brand-red-dark); border-color: var(--brand-red-dark); color: #fff; }
.btn-soft { background: #F1F3F6; border: 1px solid var(--line); color: var(--ink); }
.btn-soft:hover { background: #E7EAEE; }
.btn-xs { padding: 3px 8px; font-size: 12.5px; }
.badge-soft-success { background: var(--brand-green-soft); color: var(--brand-green-dark); font-weight: 600; }
.badge-soft-danger { background: var(--brand-red-soft); color: var(--brand-red-dark); font-weight: 600; }
.badge-soft-dark { background: #EEF0F4; color: #374151; font-weight: 600; }
.code-pill {
    font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; font-size: 12.5px;
    background: var(--brand-red-soft); color: var(--brand-red-dark);
    padding: 3px 8px; border-radius: 6px; white-space: nowrap;
}

/* ---------- Status tabs (All / Active / Inactive) ---------- */
.status-tabs { gap: 8px; flex-wrap: wrap; }
.status-tabs .nav-link {
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    color: #3B4251; font-weight: 500; padding: 8px 16px; display: flex; align-items: center; gap: 8px;
}
.status-tabs .nav-link .count {
    background: #EEF0F4; color: #374151; border-radius: 20px; padding: 1px 9px; font-size: 12px; font-weight: 600;
}
.status-tabs .nav-link:hover { border-color: var(--brand-green); color: var(--brand-green-dark); }
.status-tabs .nav-link.active.tab-all { background: #2E3A4D; border-color: #2E3A4D; color: #fff; }
.status-tabs .nav-link.active.tab-active { background: var(--brand-green); border-color: var(--brand-green); color: #fff; }
.status-tabs .nav-link.active.tab-inactive { background: var(--brand-red); border-color: var(--brand-red); color: #fff; }
.status-tabs .nav-link.active .count { background: rgba(255,255,255,.25); color: #fff; }

/* ---------- Notifications (bell, sidebar badge) ---------- */
.nav-badge {
    background: var(--brand-red); color: #fff; font-size: 11px; font-weight: 700;
    border-radius: 20px; padding: 1px 8px; line-height: 1.5;
}
.nav-item-link.active .nav-badge { background: #fff; color: var(--brand-red); }
.bell-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 50%; color: #3B4251; font-size: 19px; text-decoration: none;
    margin-right: 6px;
}
.bell-btn:hover { background: var(--brand-green-soft); color: var(--brand-green-dark); }
.bell-btn .bi-bell-fill { color: var(--brand-red); animation: ring 2.5s ease-in-out infinite; transform-origin: top center; }
.bell-count {
    position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px;
    background: var(--brand-red); color: #fff; border-radius: 10px; font-size: 10.5px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
}
@keyframes ring { 0%, 86%, 100% { transform: rotate(0); } 88% { transform: rotate(14deg); } 92% { transform: rotate(-12deg); } 96% { transform: rotate(6deg); } }
@media (prefers-reduced-motion: reduce) { .bell-btn .bi-bell-fill { animation: none; } }
.bell-menu { width: 340px; max-width: calc(100vw - 24px); border-radius: 12px; overflow: hidden; }
.bell-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; background: #FAFBFC; }
.bell-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; text-decoration: none; color: var(--ink); border-bottom: 1px solid #F1F3F6; min-width: 0; }
.bell-item > span.flex-grow-1 { min-width: 0; }
.bell-item:hover { background: #FAFDFB; color: var(--ink); }
.bell-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.bell-dot.red { background: var(--brand-red); } .bell-dot.green { background: var(--brand-green); }
.bell-foot { display: block; text-align: center; padding: 10px; font-weight: 600; text-decoration: none; color: var(--brand-green-dark); background: #FAFBFC; }
.row-overdue td { background: #FFF5F6; }
.followup-alert { border: 1px solid #F7C6CA; background: linear-gradient(90deg, var(--brand-red-soft), #fff); border-radius: 12px; }

/* ---------- Forms ---------- */
.form-label { font-weight: 500; font-size: 13px; margin-bottom: 4px; }
.form-control, .form-select { border-radius: 8px; border-color: #D9DDE4; font-size: 14px; }
.form-control:focus, .form-select:focus { border-color: var(--brand-green); box-shadow: 0 0 0 .2rem rgba(7,138,53,.15); }
.form-check-input:checked { background-color: var(--brand-green); border-color: var(--brand-green); }
.required::after { content: " *"; color: var(--brand-red); }
.form-section-title {
    font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px;
    color: var(--brand-green-dark); border-bottom: 2px solid var(--brand-green-soft);
    padding-bottom: 6px; margin: 8px 0 14px;
}
.dup-box { display: none; }
.logo-preview {
    width: 96px; height: 96px; border-radius: 12px; border: 2px dashed var(--line);
    display: flex; align-items: center; justify-content: center; overflow: hidden; background: #FAFBFC;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Tables ---------- */
.table { margin-bottom: 0; }
.table thead th {
    background: #F8F9FB; font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
    color: #4B5563; font-weight: 600; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background: #FAFDFB; }
.company-cell { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.company-thumb {
    width: 38px; height: 38px; border-radius: 8px; flex-shrink: 0; overflow: hidden;
    background: var(--brand-green-soft); color: var(--brand-green-dark);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.company-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pagination .page-link { color: var(--brand-green-dark); }
.pagination .active .page-link { background: var(--brand-green); border-color: var(--brand-green); }

/* ---------- Profile ---------- */
.profile-hero {
    background: linear-gradient(120deg, var(--brand-green) 0%, var(--brand-green-dark) 60%, var(--brand-red) 140%);
    color: #fff; border-radius: 12px 12px 0 0; padding: 26px; display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
}
.profile-logo {
    width: 92px; height: 92px; border-radius: 14px; background: #fff; color: var(--brand-green);
    display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 700; overflow: hidden;
    border: 3px solid rgba(255,255,255,.6);
}
.profile-logo img { width: 100%; height: 100%; object-fit: contain; }
.info-list dt { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.info-list dd { font-weight: 500; margin-bottom: 12px; word-break: break-word; }

/* ---------- Login ---------- */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
    background:
        radial-gradient(circle at 10% 10%, rgba(227,6,19,.10), transparent 40%),
        radial-gradient(circle at 90% 90%, rgba(7,138,53,.14), transparent 45%),
        var(--bg);
}
.login-card { width: 100%; max-width: 420px; border-radius: 16px; overflow: hidden; }
.login-card .top-strip { height: 5px; background: linear-gradient(90deg, var(--brand-red) 50%, var(--brand-green) 50%); }

/* ---------- Responsive ---------- */
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); box-shadow: 0 0 30px rgba(0,0,0,.15); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1035; }
    .main { margin-left: 0; }
    .content { padding: 16px; }
    .topbar { padding: 0 12px; }
}
@media (max-width: 575.98px) {
    .stat-value { font-size: 20px; }
    .topbar h1 { font-size: 16px; }
    .card-header { padding: 12px 14px; }
}

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .app-footer, .no-print, .btn, .alert { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    body { background: #fff; font-size: 12px; }
    .card { border: 0; box-shadow: none; }
    .table thead th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .print-only { display: block !important; }
    a { color: inherit; text-decoration: none; }
}
.print-only { display: none; }
.print-head {
    display: flex; align-items: center; gap: 14px; border-bottom: 3px solid var(--brand-green);
    padding-bottom: 10px; margin-bottom: 14px;
}
.print-head img { width: 64px; height: 64px; object-fit: contain; }
