/* =====================================================================
   Coenz ERP design system
   Brand colours sampled from the Coenz Group logo:
   deep teal #0A3847 (primary) · sage teal #497774 (accent) · steel grey #A9ADB2
   One font family throughout (system UI stack – no external font download).
   ===================================================================== */
:root {
    --erp-primary: #0A3847;
    --erp-accent: #497774;
    --erp-grey: #A9ADB2;
    --erp-ink: #1d2a30;
    --erp-muted: #64737a;
    --erp-bg: #f3f5f6;
    --erp-surface: #ffffff;
    --erp-border: #e1e6e8;
    --erp-success: #2e7d57;
    --erp-warning: #b7791f;
    --erp-danger: #b42318;
    --erp-info: #2b6c8f;
    --erp-radius: 10px;
    --erp-radius-sm: 6px;
    --erp-shadow: 0 1px 2px rgba(10, 56, 71, .06), 0 2px 8px rgba(10, 56, 71, .05);
    --erp-sidebar-w: 264px;
    --erp-topbar-h: 60px;
    --erp-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --bs-body-font-family: var(--erp-font);
    --bs-primary: var(--erp-primary);
    --bs-link-color: var(--erp-primary);
    --bs-link-hover-color: var(--erp-accent);
}

html { font-size: 14.5px; }
body { font-family: var(--erp-font); color: var(--erp-ink); background: var(--erp-bg); -webkit-font-smoothing: antialiased; }
a { color: var(--erp-primary); text-decoration: none; }
a:hover { color: var(--erp-accent); }
.pre-line { white-space: pre-line; word-break: break-word; }
.skip-link { position: absolute; left: -999px; top: 0; z-index: 2000; background: #fff; padding: .5rem 1rem; }
.skip-link:focus { left: .5rem; }
:focus-visible { outline: 2px solid var(--erp-accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn { border-radius: var(--erp-radius-sm); font-weight: 500; }
.btn-primary { background: var(--erp-primary); border-color: var(--erp-primary); }
.btn-primary:hover, .btn-primary:focus { background: #0d4a5e; border-color: #0d4a5e; }
.btn-outline-primary { color: var(--erp-primary); border-color: var(--erp-primary); }
.btn-outline-primary:hover { background: var(--erp-primary); border-color: var(--erp-primary); color: #fff; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; color: var(--erp-muted); background: transparent; }
.btn-icon:hover { background: rgba(10, 56, 71, .07); color: var(--erp-primary); }
.btn-xs { padding: .1rem .45rem; font-size: .75rem; border-radius: 5px; }
.btn-profile { display: inline-flex; align-items: center; gap: .5rem; border: 0; background: transparent; color: var(--erp-ink); max-width: 240px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--erp-primary); color: #fff; font-size: .8rem; font-weight: 600; flex: none; }
.avatar-lg { width: 72px; height: 72px; font-size: 1.4rem; object-fit: cover; }

/* ---------- shell ---------- */
.erp-shell { display: flex; min-height: 100vh; }
.erp-sidebar { position: fixed; inset: 0 auto 0 0; width: var(--erp-sidebar-w); background: var(--erp-surface); border-right: 1px solid var(--erp-border); display: flex; flex-direction: column; z-index: 1040; transition: transform .2s ease, width .2s ease; }
.sidebar-brand { height: var(--erp-topbar-h); display: flex; align-items: center; padding: 0 1.1rem; border-bottom: 1px solid var(--erp-border); }
.sidebar-brand img { height: 36px; width: auto; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .6rem .5rem 2rem; scrollbar-width: thin; }
.erp-main { flex: 1; margin-left: var(--erp-sidebar-w); min-width: 0; display: flex; flex-direction: column; transition: margin .2s ease; }
.erp-topbar { position: sticky; top: 0; z-index: 1030; height: var(--erp-topbar-h); background: rgba(255, 255, 255, .96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--erp-border); display: flex; align-items: center; gap: .5rem; padding: 0 1rem; }
.erp-content { padding: 1.25rem 1.5rem 2rem; flex: 1; }
.erp-footer { padding: .8rem 1.5rem; color: var(--erp-muted); font-size: .8rem; border-top: 1px solid var(--erp-border); background: var(--erp-surface); }
.erp-sidebar-backdrop { display: none; }
body.sidebar-collapsed .erp-sidebar { width: 72px; }
body.sidebar-collapsed .erp-main { margin-left: 72px; }
body.sidebar-collapsed .sidebar-nav span, body.sidebar-collapsed .chevron, body.sidebar-collapsed .nav-sub { display: none !important; }
body.sidebar-collapsed .sidebar-brand img { width: 40px; height: auto; object-fit: cover; object-position: left; }

/* nav tree */
.nav-tree, .nav-sub { list-style: none; margin: 0; padding: 0; }
.nav-group-toggle, .nav-subgroup-toggle, .nav-link-item { display: flex; align-items: center; gap: .65rem; width: 100%; padding: .5rem .75rem; border: 0; background: transparent; color: var(--erp-ink); border-radius: 8px; font-size: .92rem; text-align: left; }
.nav-group-toggle { font-weight: 600; margin-top: .15rem; }
.nav-group-toggle i:first-child, .nav-link-item i { color: var(--erp-accent); font-size: 1.02rem; width: 1.2rem; text-align: center; }
.nav-group-toggle:hover, .nav-subgroup-toggle:hover, .nav-link-item:hover { background: rgba(10, 56, 71, .06); color: var(--erp-primary); }
.nav-sub { padding-left: .7rem; }
.nav-sub .nav-link-item, .nav-subgroup-toggle { font-size: .87rem; padding: .4rem .7rem; }
.nav-sub-2 { padding-left: .9rem; border-left: 1px dashed var(--erp-border); margin-left: 1.2rem; }
.nav-link-item.active { background: var(--erp-primary); color: #fff; }
.nav-link-item.active i { color: #fff; }
.chevron { margin-left: auto; font-size: .7rem; transition: transform .2s; }
[aria-expanded="true"] > .chevron { transform: rotate(180deg); }

/* top bar */
.topbar-search { position: relative; flex: 1; max-width: 520px; }
.topbar-search > i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--erp-muted); }
.topbar-search .form-control { padding-left: 2.2rem; background: var(--erp-bg); border-color: transparent; border-radius: 20px; }
.topbar-search .form-control:focus { background: #fff; border-color: var(--erp-accent); box-shadow: none; }
.search-suggest { width: 100%; max-height: 420px; overflow-y: auto; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .2rem; }
.count-dot { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; font-size: .68rem; line-height: 18px; text-align: center; background: var(--erp-danger); color: #fff; }
.count-dot.tone-warning { background: var(--erp-warning); }
.count-dot.tone-info { background: var(--erp-info); }
.notification-menu { width: 360px; max-height: 480px; overflow-y: auto; padding: 0; }
.notification-item { display: block; padding: .6rem 1rem; border-bottom: 1px solid var(--erp-border); color: var(--erp-ink); }
.notification-item.unread { background: rgba(73, 119, 116, .08); border-left: 3px solid var(--erp-accent); }

/* ---------- page ---------- */
.page-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: .75rem; margin-bottom: 1rem; }
.page-title { font-size: 1.35rem; font-weight: 650; margin: 0; color: var(--erp-primary); display: flex; align-items: center; gap: .5rem; }
.page-title i { color: var(--erp-accent); }
.page-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.breadcrumb { margin-bottom: .2rem; font-size: .8rem; }
.breadcrumb-item + .breadcrumb-item::before { color: var(--erp-grey); }
.erp-card { border: 1px solid var(--erp-border); border-radius: var(--erp-radius); box-shadow: var(--erp-shadow); }
.erp-card > .card-header { background: transparent; border-bottom: 1px solid var(--erp-border); padding: .8rem 1rem; }
.card-title { font-size: .98rem; font-weight: 650; margin: 0; color: var(--erp-ink); }
.section-title { font-size: .95rem; font-weight: 650; color: var(--erp-primary); border-bottom: 1px solid var(--erp-border); padding-bottom: .4rem; margin: 1.2rem 0 .8rem; }
.section-title:first-child { margin-top: 0; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .9rem 1.5rem; }
.detail-grid dt { font-size: .75rem; color: var(--erp-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .02em; }
.detail-grid dd { margin: 0; font-weight: 500; word-break: break-word; }
.nav-tabs .nav-link { color: var(--erp-muted); font-weight: 500; }
.nav-tabs .nav-link.active { color: var(--erp-primary); border-bottom-color: #fff; }

/* forms */
.form-label { font-weight: 500; font-size: .85rem; margin-bottom: .3rem; }
.form-label.required::after { content: " *"; color: var(--erp-danger); }
.form-control, .form-select { border-radius: var(--erp-radius-sm); border-color: #ccd5d8; }
.form-control:focus, .form-select:focus { border-color: var(--erp-accent); box-shadow: 0 0 0 .2rem rgba(73, 119, 116, .15); }
.form-check-input:checked { background-color: var(--erp-primary); border-color: var(--erp-primary); }
.field-error, .field-validation-error { color: var(--erp-danger); font-size: .8rem; display: block; }
.input-validation-error { border-color: var(--erp-danger) !important; }
.erp-validation-summary.validation-summary-valid { display: none; }
.erp-validation-summary.validation-summary-errors { background: #fdecea; border: 1px solid #f5c2bd; color: var(--erp-danger); border-radius: var(--erp-radius-sm); padding: .6rem .9rem; margin-bottom: 1rem; }
.erp-validation-summary ul { margin: 0; padding-left: 1.1rem; }
.form-actions { display: flex; gap: .5rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--erp-border); }
.form-actions.sticky { position: sticky; bottom: 0; background: var(--erp-surface); z-index: 5; }
.dynamic-rows .row-item { border: 1px solid var(--erp-border); border-radius: var(--erp-radius-sm); padding: .75rem; margin-bottom: .6rem; background: #fafbfb; position: relative; }
.dynamic-rows .row-remove { position: absolute; top: .4rem; right: .4rem; }

/* filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filter-field { min-width: 150px; }

/* tables */
.erp-table { margin-bottom: 0; }
.erp-table thead th { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--erp-muted); background: #f7f9f9; border-bottom: 1px solid var(--erp-border); white-space: nowrap; }
.erp-table td { vertical-align: middle; border-color: #eef1f2; }
.erp-table tbody tr:hover { background: rgba(73, 119, 116, .04); }
.w-sn { width: 48px; }
.pager-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; padding-top: .9rem; }
.pagination .page-item.active .page-link { background: var(--erp-primary); border-color: var(--erp-primary); }
.pagination .page-link { color: var(--erp-primary); }
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--erp-muted); }
.empty-state i { font-size: 2rem; color: var(--erp-grey); display: block; margin-bottom: .4rem; }

/* status badges */
.badge-status { display: inline-block; padding: .18rem .55rem; border-radius: 20px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.tone-success.badge-status { background: #e5f4ec; color: var(--erp-success); }
.tone-warning.badge-status { background: #fdf3e1; color: var(--erp-warning); }
.tone-danger.badge-status { background: #fdeceb; color: var(--erp-danger); }
.tone-info.badge-status { background: #e6f1f7; color: var(--erp-info); }
.tone-muted.badge-status { background: #eef0f1; color: #5b6870; }
.tone-neutral.badge-status { background: #edf2f2; color: var(--erp-primary); }
.flag-red { color: var(--erp-danger); }
.flag-brown { color: #8b5a2b; }

/* kpi */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .9rem; margin-bottom: 1rem; }
.kpi-card { display: flex; gap: .8rem; align-items: center; background: var(--erp-surface); border: 1px solid var(--erp-border); border-radius: var(--erp-radius); padding: .9rem 1rem; box-shadow: var(--erp-shadow); color: var(--erp-ink); transition: transform .15s ease, box-shadow .15s ease; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(10, 56, 71, .1); color: var(--erp-ink); }
.kpi-card.no-link { pointer-events: none; }
.kpi-icon { width: 44px; height: 44px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem; flex: none; }
.kpi-card.tone-primary .kpi-icon { background: rgba(10, 56, 71, .1); color: var(--erp-primary); }
.kpi-card.tone-success .kpi-icon { background: #e5f4ec; color: var(--erp-success); }
.kpi-card.tone-warning .kpi-icon { background: #fdf3e1; color: var(--erp-warning); }
.kpi-card.tone-danger .kpi-icon { background: #fdeceb; color: var(--erp-danger); }
.kpi-card.tone-info .kpi-icon { background: #e6f1f7; color: var(--erp-info); }
.kpi-body { display: flex; flex-direction: column; min-width: 0; }
.kpi-value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.kpi-label { font-size: .78rem; color: var(--erp-muted); }
.kpi-hint { font-size: .7rem; color: var(--erp-grey); }
.chart-box { position: relative; min-height: 280px; }
.chart-box canvas { max-height: 300px; }
.alert-strip { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.alert-item { background: #fdf3e1; border: 1px solid #f3dcae; color: #7a5212; border-radius: var(--erp-radius-sm); padding: .5rem .8rem; font-size: .88rem; }
.activity-item { position: relative; }
.activity-item .badge-status { position: absolute; right: 1rem; top: .8rem; }

/* timeline */
.timeline { list-style: none; padding-left: 1rem; margin: 0; border-left: 2px solid var(--erp-border); }
.timeline-item { position: relative; padding: 0 0 .9rem .9rem; }
.timeline-item::before { content: ""; position: absolute; left: -1.42rem; top: .25rem; width: 12px; height: 12px; border-radius: 50%; background: var(--erp-info); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--erp-border); }
.timeline-item.tone-success::before { background: var(--erp-success); }
.timeline-item.tone-danger::before { background: var(--erp-danger); }
.timeline-item.tone-muted::before { background: var(--erp-grey); }
.comment-list { list-style: none; padding: 0; margin: 0 0 .8rem; max-height: 360px; overflow-y: auto; }
.comment-list li { border-bottom: 1px solid var(--erp-border); padding: .5rem 0; }
.comment-list li.is-client { background: #f2f8f7; padding-left: .5rem; border-left: 3px solid var(--erp-accent); }

/* timesheet grid */
.ts-grid input[type=number] { width: 72px; text-align: right; }
.ts-grid .day-head { text-align: center; font-size: .72rem; }
.ts-grid .leave-day { background: #fff6e5; }
.ts-total { font-weight: 700; }

/* library tree */
.category-tree { list-style: none; padding-left: 0; margin: 0; }
.category-tree ul { list-style: none; padding-left: 1rem; }
.category-tree a { display: flex; justify-content: space-between; padding: .3rem .5rem; border-radius: 6px; color: var(--erp-ink); font-size: .88rem; }
.category-tree a.active, .category-tree a:hover { background: rgba(10, 56, 71, .07); color: var(--erp-primary); }

/* toasts */
.erp-toast { border: 0; color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .15); }
.erp-toast.tone-success { background: var(--erp-success); }
.erp-toast.tone-danger { background: var(--erp-danger); }
.erp-toast.tone-info { background: var(--erp-info); }

/* idle lock */
.idle-lock { position: fixed; inset: 0; background: rgba(10, 56, 71, .92); z-index: 3000; display: flex; align-items: center; justify-content: center; }
.idle-lock[hidden] { display: none; }
.idle-lock-card { background: #fff; border-radius: 14px; padding: 2rem; width: min(380px, 92vw); text-align: center; }

/* auth */
.auth-body { min-height: 100vh; background: linear-gradient(135deg, #0A3847 0%, #13424d 55%, #497774 100%); display: flex; }
.auth-wrap { margin: auto; width: min(440px, 94vw); padding: 2rem 0; }
.auth-wrap.auth-wide { width: min(820px, 96vw); }
.auth-card { background: #fff; border-radius: 16px; padding: 2.2rem 2rem; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.auth-foot { text-align: center; color: rgba(255, 255, 255, .8); font-size: .8rem; margin-top: 1rem; }

/* public pages */
.public-header { background: var(--erp-primary); color: #fff; padding: 1rem 0; }

/* responsive */
@media (max-width: 991.98px) {
    .erp-sidebar { transform: translateX(-100%); }
    body.sidebar-open .erp-sidebar { transform: none; }
    body.sidebar-open .erp-sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 1035; }
    .erp-main, body.sidebar-collapsed .erp-main { margin-left: 0; }
    .erp-content { padding: 1rem; }
    .topbar-search { max-width: none; }
}
@media (max-width: 575.98px) {
    .topbar-search { display: none; }
    .page-header { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media print {
    .erp-sidebar, .erp-topbar, .erp-footer, .page-actions, .no-print, .filter-bar, .pager-bar { display: none !important; }
    .erp-main { margin: 0 !important; }
    .erp-card { box-shadow: none; }
}

/* timesheet grid */
.ts-grid .ts-cell { min-width: 74px; }
.ts-grid th.ts-weekend { background: #f3f5f6; }
.ts-grid th.ts-leave { background: #e6f1f7; color: var(--erp-info); }
.stat-tile { background: var(--erp-surface); border: 1px solid var(--erp-border); border-radius: var(--erp-radius); padding: .8rem 1rem; height: 100%; }
.stat-tile .kpi-value { font-size: 1.1rem; }
.erp-table tr.row-flag-late > td:first-child { box-shadow: inset 4px 0 0 #c0392b; }
.erp-table tr.row-flag-short > td:first-child { box-shadow: inset 4px 0 0 #8d5a2b; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.legend-swatch.row-flag-late { background: #c0392b; }
.legend-swatch.row-flag-short { background: #8d5a2b; }
.doc-preview { background: #fbfcfc; border: 1px solid var(--erp-border); border-radius: var(--erp-radius); padding: 1.25rem; font-family: Georgia, "Times New Roman", serif; line-height: 1.6; max-height: 70vh; overflow: auto; }
.tree-list { list-style: none; padding-left: 0; margin: 0; }
.tree-list .tree-list { padding-left: 1rem; border-left: 1px dashed var(--erp-border); margin-left: .45rem; }
.tree-list a { display: flex; align-items: center; gap: .35rem; padding: .25rem .35rem; border-radius: 6px; color: var(--erp-ink); text-decoration: none; font-size: .9rem; }
.tree-list a:hover, .tree-list a.active { background: rgba(10, 56, 71, .08); color: var(--erp-primary); }
.tree-list a .badge { margin-left: auto; }
.json-view { background: #0f2730; color: #d8e6ea; padding: 1rem; border-radius: var(--erp-radius); font-size: .8rem; max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-word; }
