/* POS System — restrained, dense business UI on Bootstrap 5.3 */
:root {
    --sb-w: 240px;
    --sb-w-collapsed: 64px;
    --topbar-h: 56px;
    --app-bg: #f4f6f9;
    --app-surface: #ffffff;
    --app-border: #e3e7ee;
    --app-text: #1f2937;
    --app-muted: #6b7280;
    --app-accent: #2563eb;
    --app-accent-soft: #eaf1ff;
    --sb-bg: #0f172a;
    --sb-text: #cbd5e1;
    --sb-muted: #64748b;
    --sb-active: #1e293b;
    --bs-primary: #2563eb;
    --bs-primary-rgb: 37, 99, 235;
    --bs-link-color: #2563eb;
    --bs-link-color-rgb: 37, 99, 235;
    --bs-body-font-size: .9rem;
    --bs-border-color: #e3e7ee;
}
html, body { height: 100%; }
body.app { background: var(--app-bg); color: var(--app-text); font-size: .9rem; }
.btn-primary { --bs-btn-bg: #2563eb; --bs-btn-border-color: #2563eb; --bs-btn-hover-bg: #1d4ed8; --bs-btn-hover-border-color: #1d4ed8; --bs-btn-active-bg: #1e40af; --bs-btn-disabled-bg: #93b4f5; --bs-btn-disabled-border-color: #93b4f5; }
.btn-outline-primary { --bs-btn-color: #2563eb; --bs-btn-border-color: #2563eb; --bs-btn-hover-bg: #2563eb; --bs-btn-hover-border-color: #2563eb; }
.text-bg-primary { background-color: #2563eb !important; }
a { text-decoration: none; }
.form-label { font-weight: 500; font-size: .82rem; color: #374151; margin-bottom: .25rem; }
.form-control, .form-select { font-size: .88rem; }
.form-text { font-size: .76rem; }
.required::after { content: " *"; color: #dc3545; }

/* ---------- sidebar ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sb-w); background: var(--sb-bg); color: var(--sb-text); display: flex; flex-direction: column; z-index: 1040; transition: width .15s ease, transform .2s ease; }
.sidebar-brand { height: var(--topbar-h); display: flex; align-items: center; padding: 0 16px; border-bottom: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--app-accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.brand-mark-lg { width: 48px; height: 48px; font-size: 1.4rem; border-radius: 12px; }
.brand-text { color: #fff; font-weight: 600; max-width: 170px; }
.sidebar-nav { overflow-y: auto; padding: 8px 8px 24px; flex: 1; scrollbar-width: thin; }
.nav-group { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--sb-muted); padding: 14px 10px 4px; white-space: nowrap; }
.sidebar .nav-link { display: flex; align-items: center; gap: 10px; color: var(--sb-text); padding: 7px 10px; border-radius: 6px; font-size: .86rem; white-space: nowrap; }
.sidebar .nav-link i { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar .nav-link:hover { background: var(--sb-active); color: #fff; }
.sidebar .nav-link.active { background: var(--app-accent); color: #fff; }
.main { margin-left: var(--sb-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin .15s ease; }
body.sb-collapsed .sidebar { width: var(--sb-w-collapsed); }
body.sb-collapsed .sidebar .nav-link span, body.sb-collapsed .nav-group, body.sb-collapsed .brand-text { display: none; }
body.sb-collapsed .sidebar .nav-link { justify-content: center; }
body.sb-collapsed .main { margin-left: var(--sb-w-collapsed); }
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); width: var(--sb-w) !important; }
    body.sb-open .sidebar { transform: none; }
    body.sb-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }
    .main, body.sb-collapsed .main { margin-left: 0; }
    body.sb-collapsed .sidebar .nav-link span, body.sb-collapsed .nav-group, body.sb-collapsed .brand-text { display: initial; }
    body.sb-collapsed .sidebar .nav-link { justify-content: flex-start; }
}

/* ---------- topbar & content ---------- */
.topbar { height: var(--topbar-h); background: var(--app-surface); border-bottom: 1px solid var(--app-border); display: flex; align-items: center; gap: 10px; padding: 0 16px; position: sticky; top: 0; z-index: 1020; }
.topbar-title { font-weight: 600; font-size: 1rem; }
.btn-icon { border: 0; background: transparent; font-size: 1.3rem; line-height: 1; padding: 4px 6px; color: var(--app-text); }
.btn-icon:hover { background: var(--app-bg); border-radius: 6px; }
.branch-switch { min-width: 160px; }
.content { padding: 20px; flex: 1; max-width: 1600px; width: 100%; }
.app-full .content { max-width: none; padding: 12px; }
@media (max-width: 575.98px) { .content { padding: 12px; } }

.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.page-header h1 { font-size: 1.25rem; font-weight: 600; margin: 0; }
.page-header .subtitle { color: var(--app-muted); font-size: .85rem; }

.card { border: 1px solid var(--app-border); border-radius: 10px; box-shadow: none; }
.card-header { background: var(--app-surface); border-bottom: 1px solid var(--app-border); font-weight: 600; padding: .65rem 1rem; }
.card-header:first-child { border-radius: 10px 10px 0 0; }

/* KPI cards */
.kpi { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 10px; padding: 14px 16px; height: 100%; }
.kpi .kpi-label { color: var(--app-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.kpi .kpi-value { font-size: 1.35rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: .78rem; color: var(--app-muted); }
.kpi .kpi-icon { width: 36px; height: 36px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; background: var(--app-accent-soft); color: var(--app-accent); }

/* tables */
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .5rem .65rem; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--app-muted); font-weight: 600; background: #f8fafc; border-bottom-width: 1px; white-space: nowrap; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f5f8ff; }
.table td.num, .table th.num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-card { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 10px; overflow: hidden; }
.table-card .table-responsive { border-radius: 0 0 10px 10px; }
.table-card .card-footer, .table-footer { padding: 10px 14px; border-top: 1px solid var(--app-border); background: var(--app-surface); }
.table tfoot td { font-weight: 600; background: #f8fafc; }

/* filters */
.filter-bar { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 120px; }

/* badges */
.badge-status { font-weight: 600; font-size: .72rem; padding: .35em .6em; }
.text-bg-warning { color: #713f12 !important; background-color: #fde68a !important; }
.text-bg-success { background-color: #16a34a !important; }
.text-bg-danger { background-color: #dc2626 !important; }
.text-bg-info { background-color: #cfe8ff !important; color: #0c4a6e !important; }

.empty-state { text-align: center; color: var(--app-muted); padding: 40px 16px; }
.empty-state i { font-size: 2.2rem; display: block; margin-bottom: 8px; color: #cbd5e1; }

.amount-pos { color: #15803d; }
.amount-neg { color: #b91c1c; }
.dl-compact dt { font-weight: 500; color: var(--app-muted); font-size: .8rem; }
.dl-compact dd { margin-bottom: .5rem; }

/* auth */
.auth-body { background: linear-gradient(180deg, #eef3ff 0%, #f4f6f9 60%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-logo { display: block; width: 100%; max-width: 280px; height: auto; margin: 0 auto; mix-blend-mode: multiply; }
.auth-card { background: #fff; border: 1px solid var(--app-border); border-radius: 12px; padding: 24px; box-shadow: 0 10px 30px rgba(15,23,42,.06); }

/* loading state for buttons */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; left: 50%; top: 50%; width: 1rem; height: 1rem; margin: -.5rem 0 0 -.5rem; border: 2px solid rgba(255,255,255,.7); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-light.is-loading::after, .btn-outline-secondary.is-loading::after { border-color: #64748b; border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* line-item editors (purchases, transfers, adjustments) */
.items-table input.form-control, .items-table select.form-select { padding: .25rem .4rem; font-size: .85rem; }
.items-table td { vertical-align: middle; }
.typeahead-menu { position: absolute; z-index: 1060; background: #fff; border: 1px solid var(--app-border); border-radius: 8px; box-shadow: 0 8px 24px rgba(15,23,42,.12); max-height: 280px; overflow-y: auto; min-width: 280px; }
.typeahead-menu .ta-item { padding: 6px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; }
.typeahead-menu .ta-item:hover, .typeahead-menu .ta-item.active { background: var(--app-accent-soft); }
.typeahead-menu .ta-meta { color: var(--app-muted); font-size: .78rem; }

/* ---------- POS ---------- */
.pos-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 12px; height: calc(100vh - var(--topbar-h) - 24px); }
.pos-left, .pos-right { min-height: 0; display: flex; flex-direction: column; }
.pos-search { position: relative; }
.pos-search .form-control { font-size: 1rem; padding: .6rem .9rem .6rem 2.4rem; }
.pos-search .bi-search { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--app-muted); }
.pos-cats { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; scrollbar-width: thin; flex-shrink: 0; }
.pos-cats .btn { white-space: nowrap; }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; overflow-y: auto; padding: 2px 2px 8px; align-content: start; flex: 1; }
.pos-tile { background: #fff; border: 1px solid var(--app-border); border-radius: 8px; padding: 10px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-height: 84px; transition: border-color .1s; }
.pos-tile:hover, .pos-tile:focus { border-color: var(--app-accent); outline: none; box-shadow: 0 0 0 2px var(--app-accent-soft); }
.pos-tile .t-name { font-weight: 600; font-size: .85rem; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pos-tile .t-price { color: var(--app-accent); font-weight: 700; margin-top: auto; }
.pos-tile .t-stock { font-size: .72rem; color: var(--app-muted); }
.pos-tile.out { opacity: .55; }
.pos-cart { background: #fff; border: 1px solid var(--app-border); border-radius: 10px; display: flex; flex-direction: column; min-height: 0; flex: 1; }
.pos-cart-head { padding: 10px; border-bottom: 1px solid var(--app-border); }
.pos-lines { overflow-y: auto; flex: 1; }
.pos-line { display: grid; grid-template-columns: 1fr 92px 84px 26px; gap: 6px; align-items: center; padding: 8px 10px; border-bottom: 1px solid #f1f3f7; }
.pos-line.sel { background: #f5f8ff; }
.pos-line .l-name { font-weight: 600; font-size: .85rem; line-height: 1.2; }
.pos-line .l-meta { font-size: .74rem; color: var(--app-muted); }
.pos-line .l-meta a { color: var(--app-accent); }
.pos-line .qty-input { text-align: center; padding: .2rem; }
.pos-line .l-total { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.pos-totals { padding: 10px 12px; border-top: 1px solid var(--app-border); font-variant-numeric: tabular-nums; }
.pos-totals .row-t { display: flex; justify-content: space-between; font-size: .85rem; padding: 1px 0; }
.pos-totals .grand { font-size: 1.4rem; font-weight: 800; }
.pos-actions { padding: 10px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; border-top: 1px solid var(--app-border); }
.pos-actions .btn-pay { grid-column: 1 / -1; font-size: 1.1rem; font-weight: 700; padding: .7rem; }
.kbd { display: inline-block; font-size: .68rem; border: 1px solid #cbd5e1; border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: #475569; background: #f8fafc; font-family: ui-monospace, monospace; }
.btn .kbd { margin-left: 4px; background: rgba(255,255,255,.2); color: inherit; border-color: rgba(255,255,255,.4); }
.pay-row { display: grid; grid-template-columns: 1fr 120px 1fr 32px; gap: 6px; margin-bottom: 6px; }
.pay-methods .btn { min-width: 80px; }
.pos-summary-big { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (max-width: 1199.98px) { .pos-wrap { grid-template-columns: minmax(0, 1fr) 360px; } }
@media (max-width: 991.98px) {
    .pos-wrap { grid-template-columns: 1fr; height: auto; }
    .pos-grid { max-height: 40vh; }
    .pos-cart { min-height: 60vh; }
}
@media (max-width: 575.98px) { .pay-row { grid-template-columns: 1fr 100px; } .pay-row .pay-ref { grid-column: 1 / 2; } }

/* charts */
.chart-box { position: relative; height: 260px; }

@media print {
    .sidebar, .topbar, .no-print, .filter-bar, .btn, .pagination { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0; }
    body.app { background: #fff; }
}
