:root {
    --ffm-primary: #003f7f;
    --ffm-primary-hover: #002e5d;
    --ffm-primary-soft: #eaf1fa;
    --ffm-accent: #ed1c24;
    --ffm-bg: #f5f7fb;
    --ffm-border: #e5e9f0;
    --ffm-text: #1f2937;
    --ffm-muted: #6b7280;
    --ffm-sidebar: #003f7f;
    --ffm-sidebar-text: #d3deee;
    --ffm-radius: 12px;

    --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --bs-body-font-size: .9rem;
    --bs-body-color: var(--ffm-text);
    --bs-body-bg: var(--ffm-bg);
    --bs-primary: #003f7f;
    --bs-primary-rgb: 0, 63, 127;
    --bs-link-color: #003f7f;
    --bs-link-color-rgb: 0, 63, 127;
    --bs-link-hover-color: #002e5d;
    --bs-border-color: var(--ffm-border);
    --bs-border-radius: .5rem;
}

body { background: var(--ffm-bg); -webkit-font-smoothing: antialiased; }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.app-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-main { padding: 1.5rem; flex: 1; }
@media (min-width: 1400px) { .app-main { padding: 1.75rem 2.25rem; } }

/* ---------- Sidebar ---------- */
.app-sidebar {
    --bs-offcanvas-width: 256px;
    --bs-offcanvas-bg: var(--ffm-sidebar);
    width: 256px;
    background: var(--ffm-sidebar);
    color: var(--ffm-sidebar-text);
    flex-shrink: 0;
}
@media (min-width: 992px) {
    /* Bootstrap's .offcanvas-lg forces a transparent background on large screens */
    .app-sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; background: var(--ffm-sidebar) !important; }
}
.app-brand { display: flex; align-items: center; height: 64px; padding: 0 1.25rem; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.app-logo {
    width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #ed1c24 0%, #ed1c24 48%, #003f7f 52%, #003f7f 100%); color: #fff; font-size: 1.05rem; box-shadow: 0 0 0 2px rgba(255, 255, 255, .85);
}
.app-brand-name { color: #fff; font-weight: 600; font-size: .95rem; letter-spacing: -.01em; }
.app-nav { padding: .75rem .75rem 1.5rem; }
.app-nav-section {
    font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
    color: #8fb0d9; padding: 1rem .75rem .4rem;
}
.app-nav-link {
    display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem; margin-bottom: 2px;
    color: var(--ffm-sidebar-text); text-decoration: none; border-radius: 8px; font-weight: 500; font-size: .875rem;
    transition: background .15s, color .15s;
}
.app-nav-link i { font-size: 1.05rem; width: 1.1rem; text-align: center; opacity: .85; }
.app-nav-link:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.app-nav-link.active { background: #ed1c24; color: #fff; box-shadow: 0 2px 6px rgba(237, 28, 36, .35); }
.app-nav-link.active i { color: #fff; opacity: 1; }
.app-nav-group .app-nav-caret { margin-left: auto; font-size: .75rem; width: auto; transition: transform .2s; }
.app-nav-group.collapsed .app-nav-caret { transform: rotate(-90deg); }
.app-nav-sub { margin: 0 0 .25rem 1.3rem; padding-left: .6rem; border-left: 1px solid rgba(255, 255, 255, .1); }
.app-nav-sub .app-nav-link { padding: .42rem .75rem; font-size: .84rem; }

/* ---------- Top bar ---------- */
.app-topbar {
    position: sticky; top: 0; z-index: 1020; height: 64px; display: flex; align-items: center; gap: .75rem;
    padding: 0 1.5rem; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--ffm-border);
}
.app-topbar-title { font-weight: 600; font-size: 1rem; color: var(--ffm-text); }
.btn-icon { border: 1px solid var(--ffm-border); background: #fff; width: 38px; height: 38px; padding: 0; font-size: 1.2rem; }
.app-user { display: flex; align-items: center; gap: .6rem; color: var(--ffm-text); text-decoration: none; padding: .25rem .5rem; border-radius: 10px; }
.app-user:hover { background: var(--ffm-bg); color: var(--ffm-text); }
.app-avatar {
    width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    background: var(--ffm-primary-soft); color: var(--ffm-primary); font-weight: 600; font-size: .8rem;
}
.dropdown-menu { border-color: var(--ffm-border); border-radius: 10px; padding: .35rem; font-size: .875rem; }
.dropdown-item { border-radius: 6px; padding: .45rem .75rem; }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-header .text-muted { font-size: .85rem; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--ffm-border); border-radius: var(--ffm-radius); box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.card > .card-header:first-child { border-radius: var(--ffm-radius) var(--ffm-radius) 0 0; }
.card-header { background: #fff; border-bottom-color: var(--ffm-border); font-weight: 600; padding: .9rem 1.1rem; }
.card-footer { background: #fafbfc; border-top-color: var(--ffm-border); }
.card > .table-responsive:first-child, .card > .table-responsive:first-child .table { border-radius: var(--ffm-radius); }

.stat-card { transition: transform .15s, box-shadow .15s; }
a.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16, 24, 40, .08); }
.stat-card .card-body { padding: 1.15rem 1.25rem; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.stat-card .stat-label { color: var(--ffm-muted); font-size: .82rem; margin-top: .2rem; }
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.3rem; color: var(--ffm-primary); background: var(--ffm-primary-soft);
}

/* ---------- Tables ---------- */
.table { --bs-table-hover-bg: #f8fafc; margin-bottom: 0; }
.table > :not(caption) > * > * { vertical-align: middle; padding: .7rem 1rem; border-bottom-color: #eef1f5; }
.table > thead > tr > th, .table .table-light th {
    background: #f8fafc; color: var(--ffm-muted); font-size: .72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--ffm-border);
}
.table-sm > :not(caption) > * > * { padding: .5rem .75rem; }
.table tbody tr:last-child > * { border-bottom: 0; }
.table-primary { --bs-table-bg: var(--ffm-primary-soft); }

/* ---------- Forms & buttons ---------- */
.form-label { font-weight: 500; font-size: .82rem; color: #374151; margin-bottom: .3rem; }
.form-control, .form-select { border-color: #d6dbe3; padding: .5rem .75rem; font-size: .875rem; }
.form-control:focus, .form-select:focus { border-color: #003f7f; box-shadow: 0 0 0 .2rem rgba(0, 63, 127, .15); }
.btn { font-weight: 500; font-size: .875rem; padding: .5rem 1rem; border-radius: 8px; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; border-radius: 6px; }
.btn-primary { --bs-btn-bg: var(--ffm-primary); --bs-btn-border-color: var(--ffm-primary); --bs-btn-hover-bg: var(--ffm-primary-hover); --bs-btn-hover-border-color: var(--ffm-primary-hover); --bs-btn-active-bg: var(--ffm-primary-hover); --bs-btn-disabled-bg: var(--ffm-primary); --bs-btn-disabled-border-color: var(--ffm-primary); }
.btn-outline-primary { --bs-btn-color: var(--ffm-primary); --bs-btn-border-color: #c7d4f0; --bs-btn-hover-bg: var(--ffm-primary-soft); --bs-btn-hover-color: var(--ffm-primary); --bs-btn-hover-border-color: #a9bde8; --bs-btn-active-bg: var(--ffm-primary-soft); --bs-btn-active-color: var(--ffm-primary); }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: #d6dbe3; --bs-btn-hover-bg: #f3f5f8; --bs-btn-hover-border-color: #c9cfd8; }

.badge { font-weight: 500; padding: .38em .65em; border-radius: 6px; }
.alert { border-radius: 10px; border-width: 1px; font-size: .875rem; }
.pagination { --bs-pagination-color: var(--ffm-primary); --bs-pagination-active-bg: var(--ffm-primary); --bs-pagination-active-border-color: var(--ffm-primary); }
.nav-tabs .nav-link { font-weight: 500; }
.list-group-item { border-color: #eef1f5; }

/* ---------- Maps / tracking ---------- */
.map-box { height: 70vh; min-height: 420px; border-radius: var(--ffm-radius); border: 1px solid var(--ffm-border); }
.map-box.small { height: 320px; min-height: 0; }
.tracking-pulse { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: #198754; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(25,135,84,.6); } 70% { box-shadow: 0 0 0 10px rgba(25,135,84,0); } 100% { box-shadow: 0 0 0 0 rgba(25,135,84,0); } }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: flex; background: #fff; }
.login-aside {
    flex: 1 1 50%; display: none; flex-direction: column; justify-content: space-between; padding: 3rem;
    color: #fff; position: relative; overflow: hidden;
    background: radial-gradient(circle at 15% 15%, rgba(237, 28, 36, .35), transparent 45%),
                radial-gradient(circle at 85% 90%, rgba(0, 63, 127, .55), transparent 45%),
                var(--ffm-sidebar);
}
@media (min-width: 992px) { .login-aside { display: flex; } }
.login-aside h2 { font-size: 2rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; max-width: 440px; }
.login-aside p { color: #b8c2d6; max-width: 420px; }
.login-feature { display: flex; gap: .85rem; align-items: flex-start; margin-bottom: 1.1rem; max-width: 420px; }
.login-feature i { width: 36px; height: 36px; flex-shrink: 0; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, .08); color: #ff9a9e; }
.login-feature b { display: block; font-weight: 600; font-size: .9rem; }
.login-feature span { color: #9aa6bd; font-size: .82rem; }
.login-form-wrap { flex: 1 1 50%; display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; }
.login-form { width: 100%; max-width: 380px; }
.login-form h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.login-form .form-control { padding: .65rem .85rem; }
.login-form .btn { padding: .65rem 1rem; }

/* ---------- Forms in popups ---------- */
.form-section { padding-bottom: 1.25rem; margin-bottom: 1.25rem; border-bottom: 1px solid #eef1f5; }
.form-section.mb-0 { border-bottom: 0; padding-bottom: 0; }
.form-section-title { font-weight: 600; font-size: .9rem; margin-bottom: .9rem; display: flex; align-items: center; gap: .5rem; }
.form-section-title i { color: var(--ffm-primary); }
.modal-content { border: 0; border-radius: 14px; }
.modal-header, .modal-footer { border-color: var(--ffm-border); }
.modal-title { font-weight: 600; }
.photo-pick { width: 112px; height: 112px; border-radius: 50%; overflow: hidden; background: var(--ffm-primary-soft); display: flex; align-items: center; justify-content: center; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--ffm-border); }
.photo-pick img { width: 100%; height: 100%; object-fit: cover; }
.photo-pick i { font-size: 3rem; color: #93a8d8; }

/* ---------- Employees ---------- */
.avatar-img { border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.app-avatar { flex-shrink: 0; }
.row-link { cursor: pointer; }
.detail-list { display: grid; grid-template-columns: 160px 1fr; row-gap: .65rem; margin: 0; }
.detail-list dt { font-weight: 500; color: var(--ffm-muted); }
.detail-list dd { margin: 0; }

/* Roles & permissions */
.access-table td { padding-top: .85rem; padding-bottom: .85rem; }
.access-table .btn-group .btn { min-width: 64px; }
.btn-check:checked + .btn-outline-primary { background: var(--ffm-primary); border-color: var(--ffm-primary); color: #fff; }

/* ---------- Attendance ---------- */
.today-card { border-left: 4px solid var(--ffm-primary); }
.today-icon { width: 52px; height: 52px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; background: var(--ffm-primary-soft); color: var(--ffm-primary); }
.today-icon.is-on { background: #dcfce7; color: #15803d; }
.today-photo { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--ffm-border); }
.field-preview { max-width: 100%; max-height: 220px; border-radius: 10px; }
.att-badge.att-present { background: #dcfce7; color: #166534; }
.att-badge.att-late { background: #fef3c7; color: #92400e; }
.att-badge.att-half { background: #ffedd5; color: #9a3412; }
.att-cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--ffm-border); border-radius: var(--ffm-radius); overflow: hidden; }
.att-head { background: #f8fafc; padding: .5rem; font-size: .75rem; font-weight: 600; text-transform: uppercase; color: var(--ffm-muted); text-align: center; }
.att-day { background: #fff; min-height: 96px; padding: .45rem .55rem; font-size: .8rem; border-top: 3px solid transparent; }
.att-num { font-weight: 600; }
.att-label { font-weight: 600; font-size: .75rem; margin-top: .15rem; }
.att-meta { font-size: .72rem; color: var(--ffm-muted); line-height: 1.3; }
.att-day.att-present { border-top-color: #22c55e; } .att-day.att-present .att-label { color: #15803d; }
.att-day.att-late { border-top-color: #f59e0b; background: #fffbeb; } .att-day.att-late .att-label { color: #b45309; }
.att-day.att-half { border-top-color: #f97316; background: #fff7ed; } .att-day.att-half .att-label { color: #c2410c; }
.att-day.att-absent { border-top-color: #ef4444; background: #fef2f2; } .att-day.att-absent .att-label { color: #b91c1c; }
.att-day.att-holiday { border-top-color: #8b5cf6; background: #f5f3ff; } .att-day.att-holiday .att-label { color: #6d28d9; }
.att-day.att-off { background: #f8fafc; } .att-day.att-off .att-label { color: var(--ffm-muted); }
.att-day.att-pending .att-label { color: var(--ffm-primary); }
.att-day.att-future, .att-day.att-empty { background: #fcfcfd; color: #c0c6d0; }
.att-day.att-today { box-shadow: inset 0 0 0 2px var(--ffm-primary); }
.att-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.att-dot.att-present { background: #22c55e; } .att-dot.att-late { background: #f59e0b; } .att-dot.att-half { background: #f97316; }
.att-dot.att-absent { background: #ef4444; } .att-dot.att-holiday { background: #8b5cf6; } .att-dot.att-off { background: #cbd5e1; }
.att-stat { border-top: 3px solid var(--ffm-border); }
.att-stat-present { border-top-color: #22c55e; } .att-stat-late { border-top-color: #f59e0b; } .att-stat-absent { border-top-color: #ef4444; }
.att-stat-off { border-top-color: #8b5cf6; } .att-stat-field { border-top-color: var(--ffm-accent); }
@media (max-width: 575.98px) { .att-day { min-height: 64px; padding: .3rem; } .att-meta { display: none; } }

/* ---------- Letters ---------- */
.company-img { max-height: 70px; max-width: 100%; object-fit: contain; border: 1px solid var(--ffm-border); border-radius: 8px; padding: 6px; background: #fff; }
.letter-editor { min-height: 420px; font-size: .95rem; background: #fff; }
.letter-editor .ql-editor { min-height: 420px; line-height: 1.6; }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: var(--ffm-border); }
.ql-toolbar.ql-snow { border-radius: 8px 8px 0 0; background: #f8fafc; }
.ql-container.ql-snow { border-radius: 0 0 8px 8px; }
/* Leave on the calendar */
.att-day.att-leave { border-top-color: #0ea5e9; background: #f0f9ff; } .att-day.att-leave .att-label { color: #0369a1; }
.att-day.att-unpaid { border-top-color: #e11d48; background: #fff1f2; } .att-day.att-unpaid .att-label { color: #be123c; }
.att-dot.att-leave { background: #0ea5e9; } .att-dot.att-unpaid { background: #e11d48; }
.att-stat-leave { border-top-color: #0ea5e9; }
.att-note-pending { color: #b45309; font-weight: 500; }
.leave-bal { border-left: 3px solid #0ea5e9; }
/* Attendance HR views */
.att-badge.att-absent { background: #fee2e2; color: #991b1b; }
.att-badge.att-leave { background: #e0f2fe; color: #075985; }
.att-badge.att-unpaid { background: #ffe4e6; color: #9f1239; }
.att-badge.att-holiday { background: #ede9fe; color: #5b21b6; }
.att-badge.att-off, .att-badge.att-future { background: #f1f5f9; color: #475569; }
.att-badge.att-pending { background: #eaf1fa; color: var(--ffm-primary); }
.att-stat-on { box-shadow: 0 0 0 2px var(--ffm-primary); }
.sheet-wrap { max-height: 72vh; }
.sheet { font-size: .78rem; white-space: nowrap; }
.sheet th, .sheet td { padding: .3rem .35rem; vertical-align: middle; }
.sheet thead th { position: sticky; top: 0; z-index: 2; background: #f8fafc; font-weight: 600; color: var(--ffm-muted); }
.sheet .sheet-name { position: sticky; left: 0; z-index: 1; background: #fff; min-width: 170px; }
.sheet thead .sheet-name { z-index: 3; background: #f8fafc; }
.sheet-dow { font-size: .65rem; font-weight: 400; }
.sheet-sun { color: #b91c1c !important; }
.sheet-tot { background: #eef2f7 !important; }
.sheet-cell { font-weight: 600; min-width: 30px; }
.sheet-click { cursor: pointer; } .sheet-click:hover { outline: 2px solid var(--ffm-primary); outline-offset: -2px; }
.sheet-field { font-size: .55rem; color: var(--ffm-accent); margin-left: 1px; }
.sheet-code { display: inline-block; min-width: 26px; text-align: center; font-weight: 700; border-radius: 4px; padding: 0 3px; border: 1px solid var(--ffm-border); }
.sheet .sheet-present { --bs-table-color: #15803d; }
.sheet .sheet-late { --bs-table-color: #b45309; --bs-table-bg: #fef3c7; }
.sheet .sheet-half { --bs-table-color: #c2410c; --bs-table-bg: #ffedd5; }
.sheet .sheet-absent { --bs-table-color: #b91c1c; --bs-table-bg: #fee2e2; }
.sheet .sheet-leave { --bs-table-color: #0369a1; --bs-table-bg: #e0f2fe; }
.sheet .sheet-unpaid { --bs-table-color: #be123c; --bs-table-bg: #ffe4e6; }
.sheet .sheet-holiday { --bs-table-color: #6d28d9; --bs-table-bg: #ede9fe; }
.sheet .sheet-off { --bs-table-color: #94a3b8; --bs-table-bg: #f1f5f9; }
.sheet .sheet-pending { --bs-table-color: var(--ffm-primary); }
.sheet-code.sheet-present { color: #15803d; } .sheet-code.sheet-late { color: #b45309; background: #fef3c7; } .sheet-code.sheet-half { color: #c2410c; background: #ffedd5; }
.sheet-code.sheet-absent { color: #b91c1c; background: #fee2e2; } .sheet-code.sheet-leave { color: #0369a1; background: #e0f2fe; } .sheet-code.sheet-unpaid { color: #be123c; background: #ffe4e6; }
.sheet-code.sheet-holiday { color: #6d28d9; background: #ede9fe; } .sheet-code.sheet-off { color: #94a3b8; background: #f1f5f9; }
/* Stock */
.stock-soon { background: #ffedd5; color: #9a3412; }
.receive-lines td { min-width: 110px; }
/* Orders */
.order-lines td { vertical-align: top; }
.order-steps { list-style: none; padding: 0; margin: 0; }
.order-steps li { position: relative; padding: 0 0 .9rem 1.6rem; color: var(--ffm-muted); }
.order-steps li::before { content: ''; position: absolute; left: .3rem; top: .3rem; width: .7rem; height: .7rem; border-radius: 50%; border: 2px solid #cbd5e1; background: #fff; }
.order-steps li:not(:last-child)::after { content: ''; position: absolute; left: .62rem; top: 1.1rem; bottom: .1rem; width: 2px; background: #e5e9f0; }
.order-steps li.done { color: var(--ffm-text); } .order-steps li.done::before { background: #22c55e; border-color: #22c55e; }
.order-steps li.bad::before { background: #ef4444; border-color: #ef4444; }
/* Payroll */
.payslip-table thead th { background: #f8fafc; }
.payslip-net { display: flex; justify-content: space-between; align-items: center; padding: .85rem 1rem; border-radius: 10px; background: var(--ffm-primary-soft); font-weight: 700; font-size: 1.15rem; color: var(--ffm-primary); }
/* Collapsible menu sections */
.app-nav-section-toggle { display: flex; align-items: center; gap: .4rem; text-decoration: none; cursor: pointer; border-radius: 6px; margin-top: .25rem; }
.app-nav-section-toggle:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.app-nav-section-toggle .app-nav-caret { margin-left: auto; font-size: .7rem; transition: transform .2s; }
.app-nav-section-toggle.collapsed .app-nav-caret { transform: rotate(-90deg); }
.app-nav-section-badge { font-size: .65rem; letter-spacing: 0; }
.app-nav-section-toggle:not(.collapsed) .app-nav-section-badge { display: none; }
