/* ==========================================================================
   ManufactureERP — application theme (Bootstrap 5.3 based)
   ========================================================================== */
:root {
    --erp-primary: #2563eb;
    --erp-primary-dark: #1d4ed8;
    --erp-primary-soft: #eff6ff;
    --erp-bg: #f1f5f9;
    --erp-surface: #ffffff;
    --erp-border: #e2e8f0;
    --erp-text: #0f172a;
    --erp-muted: #64748b;
    --erp-sidebar: #0f172a;
    --erp-sidebar-2: #1e293b;
    --erp-sidebar-text: #94a3b8;
    --erp-sidebar-w: 262px;
    --erp-topbar-h: 62px;
    --erp-radius: 12px;
    --bs-primary: #2563eb;
    --bs-primary-rgb: 37, 99, 235;
    --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --bs-body-font-size: .875rem;
    --bs-body-color: #0f172a;
    --bs-border-color: #e2e8f0;
    --bs-link-color: #2563eb;
    --bs-link-color-rgb: 37, 99, 235;
}

body { background: var(--erp-bg); color: var(--erp-text); -webkit-font-smoothing: antialiased; }
a { text-decoration: none; }
.btn-primary { --bs-btn-bg: var(--erp-primary); --bs-btn-border-color: var(--erp-primary); --bs-btn-hover-bg: var(--erp-primary-dark); --bs-btn-hover-border-color: var(--erp-primary-dark); --bs-btn-active-bg: #1e40af; }
.btn { font-weight: 500; border-radius: 8px; font-size: .845rem; }
.btn-sm { border-radius: 6px; font-size: .8rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.btn-light { --bs-btn-bg: #fff; --bs-btn-border-color: var(--erp-border); --bs-btn-hover-bg: #f8fafc; --bs-btn-hover-border-color: #cbd5e1; }
.text-muted { color: var(--erp-muted) !important; }
.fw-medium { font-weight: 500 !important; }
.fs-13 { font-size: .8125rem !important; }
.fs-12 { font-size: .75rem !important; }

/* ---------- Layout ---------- */
.app-sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--erp-sidebar-w); z-index: 1040;
    background: var(--erp-sidebar); color: var(--erp-sidebar-text);
    display: flex; flex-direction: column; transition: transform .25s ease, width .25s ease;
}
.app-main { margin-left: var(--erp-sidebar-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin .25s ease; }
.app-content { padding: 24px 28px; flex: 1; }
.app-footer { padding: 14px 28px; color: var(--erp-muted); font-size: .78rem; border-top: 1px solid var(--erp-border); background: #fff; }

.sidebar-brand { height: var(--erp-topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 20px; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar-brand .logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #6366f1); display: grid; place-items: center; color: #fff; font-size: 1.05rem; flex-shrink: 0; }
.sidebar-brand .name { color: #fff; font-weight: 700; font-size: 1.02rem; letter-spacing: -.01em; line-height: 1.1; }
.sidebar-brand .name small { display: block; font-size: .68rem; font-weight: 500; color: var(--erp-sidebar-text); letter-spacing: .02em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 12px 24px; scrollbar-width: thin; scrollbar-color: #334155 transparent; }
.sidebar-nav .nav-section { font-size: .66rem; text-transform: uppercase; letter-spacing: .09em; color: #475569; font-weight: 600; padding: 16px 12px 6px; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: 11px; color: var(--erp-sidebar-text); padding: 8px 12px; border-radius: 8px;
    font-size: .84rem; font-weight: 500; margin-bottom: 1px; position: relative;
}
.sidebar-nav .nav-link i.nav-icon { font-size: 1.05rem; width: 20px; text-align: center; opacity: .9; }
.sidebar-nav .nav-link:hover { color: #e2e8f0; background: rgba(255,255,255,.04); }
.sidebar-nav .nav-link.active { color: #fff; background: rgba(59,130,246,.18); }
.sidebar-nav .nav-link.active::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #3b82f6; }
.sidebar-nav .nav-link .chevron { margin-left: auto; font-size: .7rem; transition: transform .2s; }
.sidebar-nav .nav-link[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.sidebar-nav .nav-link[aria-expanded="true"] { color: #e2e8f0; }
.sidebar-nav .sub-nav { padding: 2px 0 6px 31px; }
.sidebar-nav .sub-nav .nav-link { font-size: .815rem; padding: 6px 12px; font-weight: 400; }
.sidebar-nav .sub-nav .nav-link::after { content: ''; position: absolute; left: -10px; top: 50%; width: 5px; height: 5px; border-radius: 50%; background: #475569; transform: translateY(-50%); }
.sidebar-nav .sub-nav .nav-link.active { background: transparent; color: #fff; font-weight: 500; }
.sidebar-nav .sub-nav .nav-link.active::before { display: none; }
.sidebar-nav .sub-nav .nav-link.active::after { background: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.25); }
.sidebar-factory { margin: 12px; padding: 10px 12px; border-radius: 10px; background: var(--erp-sidebar-2); display: flex; gap: 10px; align-items: center; }
.sidebar-factory .ico { width: 32px; height: 32px; border-radius: 8px; background: rgba(59,130,246,.18); color: #60a5fa; display: grid; place-items: center; }
.sidebar-factory .t { color: #e2e8f0; font-weight: 600; font-size: .8rem; line-height: 1.2; }
.sidebar-factory .s { font-size: .7rem; }

.app-topbar {
    height: var(--erp-topbar-h); background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--erp-border);
    display: flex; align-items: center; gap: 12px; padding: 0 28px; position: sticky; top: 0; z-index: 1030;
}
.app-topbar .topbar-title { font-weight: 600; font-size: .95rem; }
.topbar-btn { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--erp-border); background: #fff; display: inline-grid; place-items: center; color: #334155; }
.topbar-btn:hover { background: #f8fafc; }
.factory-switch { border: 1px solid var(--erp-border); border-radius: 9px; padding: 5px 12px 5px 6px; display: flex; align-items: center; gap: 9px; background: #fff; color: var(--erp-text); }
.factory-switch .ico { width: 28px; height: 28px; border-radius: 7px; background: var(--erp-primary-soft); color: var(--erp-primary); display: grid; place-items: center; }
.factory-switch .n { font-weight: 600; font-size: .8rem; line-height: 1.1; }
.factory-switch .tp { font-size: .7rem; color: var(--erp-muted); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff; display: inline-grid; place-items: center; font-weight: 600; font-size: .8rem; flex-shrink: 0; object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: .7rem; }
.avatar-lg { width: 72px; height: 72px; font-size: 1.4rem; }
.dropdown-menu { border-color: var(--erp-border); border-radius: 10px; box-shadow: 0 10px 30px -10px rgba(15,23,42,.18); font-size: .845rem; padding: 6px; }
.dropdown-item { border-radius: 6px; padding: 7px 10px; }
.dropdown-item i { width: 18px; margin-right: 6px; color: var(--erp-muted); }

body.sidebar-collapsed .app-sidebar { transform: translateX(-100%); }
body.sidebar-collapsed .app-main { margin-left: 0; }
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-main { margin-left: 0; }
    body.sidebar-open .app-sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }
    .app-content { padding: 18px 16px; }
    .app-topbar { padding: 0 16px; }
}

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-header h1 { font-size: 1.35rem; font-weight: 700; margin: 0; letter-spacing: -.02em; }
.page-header .subtitle { color: var(--erp-muted); margin-top: 3px; font-size: .84rem; }
.breadcrumb { font-size: .76rem; margin-bottom: 4px; --bs-breadcrumb-divider-color: #94a3b8; }
.breadcrumb a { color: var(--erp-muted); }
.breadcrumb .active { color: #94a3b8; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--erp-border); border-radius: var(--erp-radius); box-shadow: 0 1px 2px rgba(15,23,42,.04); --bs-card-cap-bg: #fff; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--erp-border); display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fff; border-radius: var(--erp-radius) var(--erp-radius) 0 0 !important; }
.card-title { font-size: .92rem; font-weight: 600; margin: 0; }
.card-body { padding: 18px; }
.card-footer { background: #fafbfc; border-top: 1px solid var(--erp-border); padding: 12px 18px; }

.stat-card { padding: 18px; display: flex; gap: 14px; align-items: flex-start; height: 100%; }
.stat-card .stat-icon { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; font-size: 1.25rem; flex-shrink: 0; }
.stat-card .stat-label { color: var(--erp-muted); font-size: .76rem; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.25; margin-top: 2px; }
.stat-card .stat-meta { font-size: .76rem; color: var(--erp-muted); margin-top: 2px; }
.soft-primary { background: #eff6ff; color: #2563eb; }
.soft-success { background: #ecfdf5; color: #059669; }
.soft-warning { background: #fffbeb; color: #d97706; }
.soft-danger { background: #fef2f2; color: #dc2626; }
.soft-info { background: #ecfeff; color: #0891b2; }
.soft-purple { background: #f5f3ff; color: #7c3aed; }
.soft-slate { background: #f1f5f9; color: #475569; }

/* ---------- Tables ---------- */
.table { --bs-table-color: var(--erp-text); margin-bottom: 0; font-size: .845rem; }
.table > :not(caption) > * > * { padding: .7rem .9rem; border-bottom-color: #eef2f6; }
.table thead th { background: #f8fafc; color: var(--erp-muted); font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; border-bottom: 1px solid var(--erp-border); }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f8fafc; }
.table tfoot td, .table tfoot th { background: #fafbfc; font-weight: 600; }
.table-sm > :not(caption) > * > * { padding: .45rem .6rem; }
.card > .table-responsive:last-child .table tr:last-child td { border-bottom: 0; }
.cell-title { font-weight: 600; color: var(--erp-text); }
.cell-sub { font-size: .75rem; color: var(--erp-muted); }
.table-actions { white-space: nowrap; text-align: right; }
.table-actions .btn { padding: .2rem .45rem; }
.table-register td, .table-register th { text-align: center; padding: .35rem .3rem !important; font-size: .74rem; }

/* ---------- Filters ---------- */
.filter-bar { padding: 14px 18px; border-bottom: 1px solid var(--erp-border); background: #fcfdfe; border-radius: var(--erp-radius) var(--erp-radius) 0 0; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 140px; }

/* ---------- Forms ---------- */
.form-label { font-weight: 500; font-size: .8rem; color: #334155; margin-bottom: 5px; }
.form-label .req { color: #dc2626; margin-left: 2px; }
.form-control, .form-select { border-color: #d7dee8; border-radius: 8px; font-size: .855rem; padding: .48rem .75rem; }
.form-control-sm, .form-select-sm { font-size: .8rem; border-radius: 6px; padding: .3rem .55rem; }
.form-control:focus, .form-select:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-text { font-size: .75rem; }
.form-section-title { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--erp-muted); margin: 6px 0 14px; padding-bottom: 8px; border-bottom: 1px dashed var(--erp-border); }
.input-group-text { background: #f8fafc; border-color: #d7dee8; font-size: .82rem; color: var(--erp-muted); }

.ts-wrapper.form-select, .ts-wrapper.form-control { padding: 0; }
.ts-control { border-color: #d7dee8 !important; border-radius: 8px !important; padding: .44rem .75rem !important; font-size: .855rem; min-height: 37px; }
.ts-wrapper.form-select-sm .ts-control, .line-items .ts-control { padding: .28rem .5rem !important; min-height: 31px; font-size: .8rem; border-radius: 6px !important; }
.ts-wrapper.focus .ts-control { border-color: #93c5fd !important; box-shadow: 0 0 0 3px rgba(37,99,235,.12) !important; }
.ts-dropdown { border-radius: 8px; border-color: var(--erp-border); box-shadow: 0 10px 25px -10px rgba(15,23,42,.2); font-size: .84rem; }
.ts-dropdown .active { background: var(--erp-primary-soft); color: var(--erp-text); }

/* ---------- Line items ---------- */
.line-items { margin: 0; }
.line-items td { vertical-align: middle; }
.line-items .form-control, .line-items .form-select { font-size: .8rem; padding: .3rem .5rem; border-radius: 6px; }
.line-items .col-num { width: 34px; color: var(--erp-muted); text-align: center; }
.totals-box { background: #f8fafc; border: 1px solid var(--erp-border); border-radius: 10px; padding: 14px 16px; }
.totals-box .row-t { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.totals-box .grand { border-top: 1px dashed #cbd5e1; margin-top: 6px; padding-top: 10px; font-size: 1.05rem; font-weight: 700; }

/* ---------- Badges ---------- */
.badge { font-weight: 600; font-size: .7rem; padding: .38em .65em; border-radius: 6px; letter-spacing: .01em; }
.badge-dot::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: middle; }

/* ---------- Misc ---------- */
.empty-state { padding: 46px 20px; text-align: center; color: var(--erp-muted); }
.empty-state i { font-size: 2.2rem; color: #cbd5e1; display: block; margin-bottom: 8px; }
.detail-list { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: .85rem; margin: 0; }
.detail-list dt { color: var(--erp-muted); font-weight: 500; }
.detail-list dd { margin: 0; font-weight: 500; }
.progress { height: 7px; border-radius: 6px; background: #e2e8f0; }
.progress-sm { height: 5px; }
.list-compact .list-group-item { padding: 10px 18px; border-color: #eef2f6; font-size: .84rem; }
.nav-tabs-erp { border-bottom: 1px solid var(--erp-border); gap: 4px; padding: 0 18px; }
.nav-tabs-erp .nav-link { border: 0; border-bottom: 2px solid transparent; color: var(--erp-muted); font-weight: 500; padding: 12px 10px; font-size: .84rem; border-radius: 0; }
.nav-tabs-erp .nav-link.active { color: var(--erp-primary); border-bottom-color: var(--erp-primary); background: transparent; }
.timeline-item { position: relative; padding-left: 22px; padding-bottom: 14px; border-left: 2px solid #e2e8f0; margin-left: 6px; }
.timeline-item::before { content: ''; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--erp-primary); }
.toast-container { z-index: 1090; }
.toast { border: 0; border-radius: 10px; box-shadow: 0 12px 30px -10px rgba(15,23,42,.3); font-size: .85rem; }
.permission-matrix th, .permission-matrix td { text-align: center; vertical-align: middle; }
.permission-matrix td:first-child, .permission-matrix th:first-child { text-align: left; }
.module-card { transition: all .15s; }
.module-card:hover { border-color: #93c5fd; transform: translateY(-1px); box-shadow: 0 6px 18px -8px rgba(37,99,235,.25); }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-hero { background: radial-gradient(1200px 500px at 10% 10%, #1e3a8a 0%, transparent 60%), linear-gradient(160deg, #0f172a 0%, #111c3a 100%); color: #cbd5e1; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-hero h2 { color: #fff; font-weight: 700; font-size: 2rem; letter-spacing: -.02em; line-height: 1.2; }
.auth-hero .feature { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.auth-hero .feature i { width: 36px; height: 36px; border-radius: 9px; background: rgba(59,130,246,.18); color: #93c5fd; display: grid; place-items: center; flex-shrink: 0; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: #fff; }
.auth-form .inner { width: 100%; max-width: 400px; }
@media (max-width: 991.98px) { .auth-wrap { grid-template-columns: 1fr; } .auth-hero { display: none; } }

/* ---------- Print ---------- */
.print-doc { background: #fff; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--erp-text); padding-bottom: 14px; margin-bottom: 18px; }
.doc-title { font-size: 1.4rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
@media print {
    @page { size: A4; margin: 12mm; }
    body { background: #fff !important; font-size: 11.5px; }
    .app-sidebar, .app-topbar, .app-footer, .no-print, .toast-container { display: none !important; }
    .app-main { margin: 0 !important; }
    .app-content { padding: 0 !important; }
    .card { border: 0 !important; box-shadow: none !important; }
    .card-body { padding: 0 !important; }
    .table thead th { background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    a { color: inherit !important; }
}
