:root {
  --navy-950: #081121;
  --navy-900: #0d1a33;
  --navy-800: #162749;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-50: #eff6ff;
  --teal-600: #0d9488;
  --emerald-600: #059669;
  --emerald-50: #ecfdf5;
  --amber-600: #d97706;
  --amber-50: #fffbeb;
  --rose-600: #e11d48;
  --rose-50: #fff1f2;
  --slate-900: #0f172a;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --bg-canvas: #f3f6fb;
  --surface: #ffffff;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif; background: var(--bg-canvas); color: var(--slate-900); font-size: 14px; line-height: 1.5; }
a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 700; color: var(--slate-900); }
.muted { color: var(--slate-500); }
.num, .text-right { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

/* Auth Pages */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #071022 0%, #102a52 60%, #0f4c81 100%); padding: 1.5rem; }
.auth-container { width: 100%; max-width: 560px; }
.auth-card { background: #fff; border-radius: 14px; padding: 2rem; box-shadow: 0 20px 50px rgba(0,0,0,.35); width: 100%; }
.auth-brand { display: flex; align-items: center; gap: .9rem; margin-bottom: 1rem; }
.auth-brand h1 { font-size: 1.35rem; margin: 0; }
.brand-badge { width: 46px; height: 46px; border-radius: 10px; background: linear-gradient(135deg, #2563eb, #0d9488); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: .95rem; letter-spacing: .5px; flex-shrink: 0; }
.auth-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.25rem; }
.auth-tags .tag { font-size: 11px; font-weight: 600; background: var(--blue-50); color: var(--blue-700); padding: .2rem .55rem; border-radius: 999px; border: 1px solid #bfdbfe; }
.divider { display: flex; align-items: center; text-align: center; margin: 1.25rem 0 .9rem; color: var(--slate-500); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--slate-200); }
.divider span { padding: 0 .75rem; }
.demo-role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: .5rem; }
.demo-role-btn { width: 100%; text-align: left; padding: .55rem .7rem; border: 1px solid var(--slate-200); background: #f8fafc; border-radius: 8px; cursor: pointer; transition: .15s; display: flex; flex-direction: column; }
.demo-role-btn:hover { border-color: var(--blue-600); background: var(--blue-50); }
.demo-role-btn strong { font-size: 12px; color: var(--slate-900); }
.demo-role-btn span { font-size: 11px; color: var(--slate-500); }

/* App Shell */
.erp-shell { display: flex; min-height: 100vh; }
.sidebar { width: 258px; background: var(--navy-950); color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid rgba(255,255,255,.07); transition: width .2s; }
.sidebar.collapsed { width: 0; overflow: hidden; border: none; }
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-title { font-weight: 800; font-size: .95rem; color: #fff; letter-spacing: .6px; }
.brand-sub { font-size: 11px; color: #94a3b8; }
.sidebar-nav { padding: .6rem .75rem 1rem; flex: 1; }
.nav-group-label { font-size: 10px; font-weight: 700; letter-spacing: .8px; color: #64748b; margin: .85rem .45rem .3rem; }
.nav-link { display: flex; align-items: center; gap: .6rem; padding: .52rem .75rem; border-radius: 8px; color: #cbd5e1; font-size: 13px; font-weight: 500; transition: .15s; margin-bottom: 2px; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active { background: linear-gradient(90deg, #2563eb, #1d4ed8); color: #fff; font-weight: 600; box-shadow: 0 2px 8px rgba(37,99,235,.35); }
.nav-icon { font-size: 15px; width: 20px; text-align: center; }
.sidebar-footer { padding: .85rem 1rem; border-top: 1px solid rgba(255,255,255,.08); background: rgba(0,0,0,.2); }
.user-chip { display: flex; align-items: center; gap: .65rem; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--blue-600); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.user-name { font-size: 12.5px; font-weight: 600; color: #f8fafc; line-height: 1.2; }
.user-role { font-size: 11px; color: #94a3b8; }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid var(--slate-200); padding: .75rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; position: sticky; top: 0; z-index: 20; }
.topbar-left { display: flex; align-items: center; gap: .85rem; }
.page-heading { font-size: 1.05rem; margin: 0; color: var(--slate-900); }
.page-crumb { font-size: 11.5px; color: var(--slate-500); }
.topbar-right { display: flex; align-items: center; gap: .6rem; }
.quick-search-wrap input { width: 220px; }
.role-pill { font-size: 11.5px; font-weight: 600; background: var(--slate-100); color: var(--slate-700); padding: .3rem .65rem; border-radius: 999px; border: 1px solid var(--slate-200); }

.content-wrap { padding: 1.35rem 1.5rem 2.5rem; max-width: 1560px; width: 100%; margin: 0 auto; }

/* Cards & Grids */
.card { background: var(--surface); border: 1px solid var(--slate-200); border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow-sm); margin-bottom: 1.1rem; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .9rem; flex-wrap: wrap; }
.card-title { font-size: .95rem; font-weight: 700; margin: 0; color: var(--slate-900); }
.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1150px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-2-1, .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } .topbar { flex-wrap: wrap; } .quick-search-wrap { display: none; } }

/* KPI Tiles */
.kpi-card { background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.kpi-card::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--blue-600); }
.kpi-card.kpi-green::before { background: var(--emerald-600); }
.kpi-card.kpi-amber::before { background: var(--amber-600); }
.kpi-card.kpi-rose::before { background: var(--rose-600); }
.kpi-card.kpi-teal::before { background: var(--teal-600); }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--slate-500); text-transform: uppercase; letter-spacing: .4px; }
.kpi-value { font-size: 1.45rem; font-weight: 800; color: var(--slate-900); margin: .25rem 0; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--slate-500); }

/* Interactive ERP Flow Pipeline */
.flow-pipeline { display: flex; align-items: stretch; gap: .5rem; overflow-x: auto; padding: .4rem 0 .6rem; }
.flow-node { flex: 1 0 135px; background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%); border: 1px solid var(--slate-200); border-radius: 10px; padding: .75rem .7rem; text-align: left; cursor: pointer; transition: .18s; position: relative; display: flex; flex-direction: column; justify-content: space-between; text-decoration: none; color: inherit; }
.flow-node:hover { border-color: var(--blue-600); transform: translateY(-2px); box-shadow: var(--shadow-md); text-decoration: none; }
.flow-step { font-size: 10px; font-weight: 700; color: var(--blue-600); text-transform: uppercase; letter-spacing: .5px; }
.flow-title { font-size: 12.5px; font-weight: 700; color: var(--slate-900); margin: .2rem 0; }
.flow-metric { font-size: 11.5px; color: var(--slate-600); font-weight: 600; }
.flow-arrow { display: flex; align-items: center; color: var(--slate-400); font-weight: 700; font-size: 16px; flex-shrink: 0; }

/* Tabs */
.tabs { display: flex; gap: .35rem; border-bottom: 2px solid var(--slate-200); margin-bottom: 1rem; overflow-x: auto; }
.tab-btn { padding: .58rem 1rem; background: transparent; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 600; font-size: 13px; color: var(--slate-600); cursor: pointer; white-space: nowrap; }
.tab-btn:hover { color: var(--blue-600); }
.tab-btn.active { color: var(--blue-600); border-bottom-color: var(--blue-600); }
.tab-panel.hidden { display: none; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.erp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.erp-table th { background: #f8fafc; color: var(--slate-600); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .35px; padding: .62rem .75rem; border-bottom: 2px solid var(--slate-200); text-align: left; white-space: nowrap; }
table.erp-table td { padding: .6rem .75rem; border-bottom: 1px solid var(--slate-100); vertical-align: middle; }
table.erp-table tbody tr:hover { background: #f8fafc; }
table.erp-table tfoot td, table.erp-table tfoot th { background: #f1f5f9; font-weight: 700; border-top: 2px solid var(--slate-300); padding: .65rem .75rem; }
table.erp-table th.num, table.erp-table td.num { text-align: right; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: .18rem .55rem; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-primary { background: var(--blue-50); color: var(--blue-700); border: 1px solid #bfdbfe; }
.badge-success { background: var(--emerald-50); color: var(--emerald-600); border: 1px solid #a7f3d0; }
.badge-warning { background: var(--amber-50); color: var(--amber-600); border: 1px solid #fde68a; }
.badge-danger { background: var(--rose-50); color: var(--rose-600); border: 1px solid #fecdd3; }
.badge-neutral { background: var(--slate-100); color: var(--slate-700); border: 1px solid var(--slate-200); }

/* Buttons & Forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .48rem .9rem; border-radius: 7px; border: 1px solid transparent; font-size: 13px; font-weight: 600; cursor: pointer; transition: .15s; white-space: nowrap; text-decoration: none; }
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: .32rem .65rem; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--blue-600); color: #fff; }
.btn-success { background: var(--emerald-600); color: #fff; }
.btn-warning { background: var(--amber-600); color: #fff; }
.btn-danger { background: var(--rose-600); color: #fff; }
.btn-outline { background: #fff; border-color: var(--slate-300); color: var(--slate-700); }
.btn-outline-light { background: transparent; border-color: rgba(255,255,255,.25); color: #e2e8f0; }
.btn-icon { background: transparent; border: 1px solid var(--slate-200); border-radius: 7px; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 15px; color: var(--slate-700); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
@media (max-width: 720px) { .form-grid, .form-grid-3 { grid-template-columns: 1fr; } }
.form-stack { display: flex; flex-direction: column; gap: .8rem; }
.form-group { display: flex; flex-direction: column; gap: .28rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--slate-700); }
.form-control { width: 100%; padding: .48rem .68rem; border: 1px solid var(--slate-300); border-radius: 7px; font-size: 13px; background: #fff; color: var(--slate-900); font-family: inherit; }
.form-control:focus { outline: none; border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-control-sm { padding: .34rem .58rem; font-size: 12.5px; }

/* Alerts & Lists */
.alert { padding: .75rem 1rem; border-radius: 8px; font-size: 13px; margin-bottom: .9rem; border: 1px solid transparent; }
.alert-danger { background: var(--rose-50); color: #9f1239; border-color: #fecdd3; }
.alert-warning { background: var(--amber-50); color: #92400e; border-color: #fde68a; }
.alert-success { background: var(--emerald-50); color: #065f46; border-color: #a7f3d0; }
.alert-info { background: var(--blue-50); color: #1e40af; border-color: #bfdbfe; }

.kv-row { display: flex; justify-content: space-between; align-items: center; padding: .42rem 0; border-bottom: 1px dashed var(--slate-200); font-size: 13px; gap: .5rem; }
.kv-row:last-child { border-bottom: none; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-backdrop.hidden { display: none; }
.modal-dialog { background: #fff; border-radius: 12px; width: 100%; max-width: 780px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 25px 50px rgba(0,0,0,.3); }
.modal-dialog.modal-xl { max-width: 1080px; }
.modal-header { padding: .95rem 1.25rem; border-bottom: 1px solid var(--slate-200); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-body { padding: 1.25rem; overflow-y: auto; }

/* Toast */
.toast-stack { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; max-width: 380px; }
.toast { background: var(--navy-900); color: #fff; padding: .75rem 1rem; border-radius: 8px; box-shadow: var(--shadow-md); font-size: 13px; border-left: 4px solid var(--blue-600); animation: slideIn .2s ease; }
.toast.toast-success { border-left-color: var(--emerald-600); }
.toast.toast-error { border-left-color: var(--rose-600); }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Printable Invoice Sheet */
.invoice-sheet { background: #fff; border: 1px solid var(--slate-200); border-radius: 10px; padding: 1.75rem; max-width: 860px; margin: 0 auto; }
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--slate-900); padding-bottom: 1rem; margin-bottom: 1.25rem; gap: 1rem; }
.inv-status-stamp { display: inline-block; padding: .25rem .75rem; border: 2px solid; border-radius: 6px; font-weight: 800; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }

/* Timeline */
.timeline { border-left: 2px solid var(--blue-600); margin-left: .5rem; padding-left: 1rem; }
.timeline-item { position: relative; margin-bottom: .9rem; }
.timeline-item::before { content: ''; position: absolute; left: -1.35rem; top: .25rem; width: 10px; height: 10px; border-radius: 50%; background: var(--blue-600); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--blue-600); }
