/* ===== Fonts ===== */
@font-face {
    font-family: "Cairo";
    font-style: normal;
    font-weight: 200 1000;
    font-display: swap;
    src: url("/lib/fonts/cairo-arabic.woff2") format("woff2");
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
    font-family: "Cairo";
    font-style: normal;
    font-weight: 200 1000;
    font-display: swap;
    src: url("/lib/fonts/cairo-latin.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ===== Tokens ===== */
:root {
    --brand: #4a9b26;
    --brand-600: color-mix(in srgb, var(--brand) 82%, black);
    --brand-50: color-mix(in srgb, var(--brand) 9%, white);
    --brand-100: color-mix(in srgb, var(--brand) 16%, white);
    --accent: #f59e0b;
    --surface: #ffffff;
    --surface-2: #f4f6f8;
    --surface-3: #eef1f4;
    --text: #1d2433;
    --muted: #6b7280;
    --border: #e5e8ed;
    --sidebar: #ffffff;
    --sidebar-text: #4b5563;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .05);
    --shadow-lg: 0 10px 30px rgba(16, 24, 40, .10);
    --ok: #16a34a;
    --warn: #d97706;
    --bad: #dc2626;
    --bs-primary: var(--brand);
    --bs-primary-rgb: 74, 155, 38;
    --bs-body-font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
    --bs-body-bg: var(--surface-2);
    --bs-body-color: var(--text);
    --bs-border-color: var(--border);
    --bs-border-radius: 10px;
    --bs-link-color: var(--brand);
    --bs-link-hover-color: var(--brand-600);
}

[data-bs-theme="dark"] {
    --brand-50: color-mix(in srgb, var(--brand) 18%, #161b22);
    --brand-100: color-mix(in srgb, var(--brand) 28%, #161b22);
    --surface: #161b22;
    --surface-2: #0d1117;
    --surface-3: #1f262f;
    --text: #e6edf3;
    --muted: #8b949e;
    --border: #2a313b;
    --sidebar: #161b22;
    --sidebar-text: #c9d1d9;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --bs-body-bg: var(--surface-2);
    --bs-body-color: var(--text);
    --bs-border-color: var(--border);
    --bs-secondary-bg: var(--surface-3);
    --bs-tertiary-bg: var(--surface-3);
}

html, body { min-height: 100%; }
body { font-family: var(--bs-body-font-family); background: var(--surface-2); color: var(--text); -webkit-tap-highlight-color: transparent; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.text-muted, .text-body-secondary { color: var(--muted) !important; }

/* ===== Bootstrap tuning ===== */
.btn { border-radius: 10px; font-weight: 600; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand-600); --bs-btn-hover-border-color: var(--brand-600); --bs-btn-active-bg: var(--brand-600); --bs-btn-active-border-color: var(--brand-600); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-active-bg: var(--brand); --bs-btn-active-border-color: var(--brand); }
.btn-icon { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; color: var(--text); }
.btn-icon:hover { background: var(--surface-3); }
.form-control, .form-select { border-radius: 10px; background-color: var(--surface); border-color: var(--border); }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--brand) 20%, transparent); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-label { font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--surface); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); font-weight: 700; padding: .9rem 1.1rem; }
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .6rem .75rem; border-color: var(--border); }
.table thead th { font-size: .82rem; color: var(--muted); font-weight: 700; white-space: nowrap; background: var(--surface-3); }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: var(--brand-50); }
.table tfoot td, .table tfoot th { font-weight: 800; background: var(--surface-3); }
.badge { font-weight: 600; border-radius: 8px; padding: .35em .6em; }
.modal-content { border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.dropdown-menu { border-radius: 12px; border-color: var(--border); box-shadow: var(--shadow); background: var(--surface); }
.nav-tabs .nav-link.active, .nav-pills .nav-link.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.nav-pills .nav-link { color: var(--text); font-weight: 600; border-radius: 10px; }
.page-link { color: var(--brand); }
.active > .page-link { background: var(--brand); border-color: var(--brand); }
.alert { border-radius: 12px; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-600); }
a.text-reset:hover { color: var(--brand) !important; }
.list-group-item { background-color: var(--surface); border-color: var(--border); color: var(--text); }
.list-group-item.active { background-color: var(--brand); border-color: var(--brand); color: #fff; }
.list-group-item.active a { color: #fff; }
/* On/off switches read as "enabled" in green; plain checkboxes keep the brand color. */
.form-switch .form-check-input:checked { background-color: var(--ok); border-color: var(--ok); }
.form-check-input:focus { box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--brand) 20%, transparent); border-color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:focus-visible { box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--brand) 30%, transparent); }

/* ===== App shell ===== */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 264px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text); position: fixed; inset-block: 0; inset-inline-start: 0; overflow-y: auto; z-index: 1040; transition: transform .25s ease; scrollbar-width: thin; scrollbar-color: var(--border) transparent; border-inline-end: 1px solid var(--border); }
.sidebar-brand { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.1rem 1rem; border-bottom: 1px solid var(--border); }
.brand-mark { width: 42px; height: 42px; border-radius: 12px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: 1.3rem; box-shadow: 0 4px 12px color-mix(in srgb, var(--brand) 35%, transparent); }
.brand-logo { width: 42px; height: 42px; object-fit: contain; border-radius: 10px; background: #fff; border: 1px solid var(--border); }
.brand-name { color: var(--text); font-weight: 800; line-height: 1.2; }
.brand-sub { font-size: .75rem; color: var(--muted); }
.sidebar-nav { padding: .6rem .7rem 2rem; }
.sidebar-nav .nav-section { font-size: .72rem; letter-spacing: .02em; color: #9aa3af; padding: 1rem .8rem .35rem; font-weight: 700; }
.sidebar-nav .nav-link { color: var(--sidebar-text); display: flex; align-items: center; gap: .7rem; padding: .55rem .8rem; border-radius: 10px; font-size: .93rem; font-weight: 600; position: relative; }
.sidebar-nav .nav-link i { font-size: 1.08rem; width: 1.2rem; text-align: center; color: #9aa3af; }
.sidebar-nav .nav-link:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav .nav-link.active { background: var(--brand-50); color: var(--brand-600); font-weight: 700; }
.sidebar-nav .nav-link.active i { color: var(--brand); }
.sidebar-nav .nav-link.active::before { content: ""; position: absolute; inset-inline-start: -.7rem; top: .45rem; bottom: .45rem; width: 4px; border-radius: 0 4px 4px 0; background: var(--brand); }
.sidebar-nav .nav-pos { background: var(--brand); color: #fff !important; margin: .35rem 0; box-shadow: 0 4px 12px color-mix(in srgb, var(--brand) 30%, transparent); }
.sidebar-nav .nav-pos i { color: #fff !important; }
.sidebar-nav .nav-pos:hover { background: var(--brand-600); }
.main { flex: 1; min-width: 0; margin-inline-start: 264px; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 1030; display: flex; align-items: center; gap: .75rem; padding: .6rem 1.25rem; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.scan-box { position: relative; flex: 0 1 420px; }
.scan-box i { position: absolute; inset-inline-start: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.scan-box input { width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: .5rem 2.4rem .5rem .8rem; color: var(--text); outline: none; }
.scan-box input:focus { border-color: var(--brand); background: var(--surface); }
.station-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .7rem; border-radius: 999px; background: var(--brand-50); color: var(--brand); font-size: .82rem; font-weight: 700; text-decoration: none; }
.user-btn { display: inline-flex; align-items: center; gap: .5rem; color: var(--text); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-grid; place-items: center; font-weight: 800; }
.content { padding: 1.4rem 1.5rem 3rem; }
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(100%); }
    .sidebar-open .sidebar { transform: none; }
    .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1035; }
    .main { margin-inline-start: 0; }
    .content { padding: 1rem 1rem 3rem; }
    .topbar { padding: .5rem .75rem; }
}

/* ===== Page parts ===== */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.2rem; }
.page-head h1 { font-size: 1.45rem; font-weight: 800; margin: 0; }
.page-head .sub { color: var(--muted); font-size: .9rem; }
.page-head .actions { margin-inline-start: auto; display: flex; flex-wrap: wrap; gap: .5rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; padding: .9rem 1rem; }
/* Bootstrap cards are flex columns; these card variants lay out in a row. */
.card.filters, .card.stat { flex-direction: row; }
.filters .form-control, .filters .form-select { min-width: 150px; }
.stat { padding: 1rem 1.1rem; display: flex; gap: .9rem; align-items: center; height: 100%; }
.stat .ico { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0; background: var(--brand-50); color: var(--brand); }
.stat .lbl { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat .val { font-size: 1.45rem; font-weight: 800; line-height: 1.2; }
.stat .hint { font-size: .78rem; color: var(--muted); }
.ico.green { background: color-mix(in srgb, var(--ok) 13%, transparent); color: var(--ok); }
.ico.amber { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--warn); }
.ico.blue { background: color-mix(in srgb, #0369a1 13%, transparent); color: #0369a1; }
.ico.red { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty i { font-size: 2.5rem; opacity: .4; display: block; margin-bottom: .5rem; }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-3); }
.color-dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.barcode { width: 100%; max-width: 260px; height: auto; display: block; margin-inline: auto; }
.pos-amount { color: var(--ok); }
.neg-amount { color: var(--bad); }
.toast { border-radius: 12px; border: 0; box-shadow: var(--shadow); }
.list-check { list-style: none; padding: 0; margin: 0; }
.list-check li { padding: .25rem 0; }
.perm-group { border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem; height: 100%; }
.perm-group h6 { font-weight: 800; }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: .75rem 1rem; border-radius: 0 0 var(--radius) var(--radius); }
.table-responsive { border-radius: 0 0 var(--radius) var(--radius); }
.card > .table-responsive:first-child { border-radius: var(--radius); }

.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .75rem; }
.quick-actions .quick span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-actions .quick { display: flex; align-items: center; gap: .55rem; padding: .75rem .85rem; line-height: 1.25; font-size: .95rem; min-width: 0; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 700; box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease; }
.quick-actions .quick i { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); font-size: 1.15rem; flex-shrink: 0; }
.quick-actions .quick:first-child { background: var(--brand); border-color: var(--brand); color: #fff; }
.quick-actions .quick:first-child i { background: rgba(255, 255, 255, .18); color: #fff; }
.quick-actions .quick:hover { transform: translateY(-2px); border-color: var(--brand); color: inherit; }
.quick-actions .quick:first-child:hover { color: #fff; }
.discover-card { border-color: var(--brand-100); }
.discover-card .card-header { background: var(--brand-50); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); animation: live 1.6s infinite; display: inline-block; }
@keyframes live { 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.report-card { transition: transform .15s ease, border-color .15s ease; }
.report-card:hover { transform: translateY(-2px); border-color: var(--brand); }

/* Motion: gentle entrance, disabled for users who prefer reduced motion */
.content > * { animation: rise .28s ease both; }
.content > *:nth-child(2) { animation-delay: .03s; }
.content > *:nth-child(3) { animation-delay: .06s; }
.content > *:nth-child(4) { animation-delay: .09s; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ===== Auth ===== */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at 12% 8%, var(--brand-100), transparent 40%), radial-gradient(circle at 88% 92%, var(--brand-50), transparent 45%), var(--surface-2); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-lg); padding: 2.2rem 1.9rem; }
.auth-mark { width: 76px; height: 76px; margin: auto; border-radius: 22px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: 2rem; box-shadow: 0 8px 24px color-mix(in srgb, var(--brand) 35%, transparent); }
.auth-logo { max-width: 120px; max-height: 90px; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.pin-pad button { height: 54px; font-size: 1.3rem; font-weight: 700; }

/* ===== Print (A4 reports) ===== */
.print-only { display: none; }
@media print {
    .sidebar, .topbar, .no-print, .filters, .page-head .actions, .toast-container, .btn { display: none !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
    .print-only { display: block !important; }
    body { background: #fff !important; color: #000 !important; }
    .table thead th { background: #eee !important; color: #000 !important; }
    a { text-decoration: none; color: #000; }
}
