/* =====================================================================
   SupermarketPOS — Design system (Bootstrap 5.3 RTL + tokens)
   Read DESIGN.md before styling a page. Prefer these classes over
   ad-hoc inline styles.
   ===================================================================== */

/* ---------- Font (bundled, works offline) ---------- */
@font-face { font-family: "Tajawal"; src: url("../fonts/Tajawal-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Tajawal"; src: url("../fonts/Tajawal-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

/* ---------- Tokens ---------- */
:root {
  --app-font: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;

  --brand-50:  #ecfdf7;
  --brand-100: #d1fae9;
  --brand-200: #a7f0d4;
  --brand-500: #10a37f;
  --brand-600: #0d8a6b;
  --brand-700: #0b6f57;
  --brand-800: #095a47;

  --accent-500: #f59e0b;

  --ink-900: #0f172a;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-400: #94a3b8;
  --line:    #e6e9ef;
  --line-strong: #d5dae3;
  --surface: #ffffff;
  --canvas:  #f4f6f9;

  --sidebar-bg: #0f1d2b;
  --sidebar-ink: #a9b6c6;
  --sidebar-ink-strong: #ffffff;
  --sidebar-hover: rgba(255,255,255,.06);
  --sidebar-active: rgba(16,163,127,.18);
  --sidebar-width: 256px;
  --topbar-h: 60px;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 12px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.12);

  /* Bootstrap overrides */
  --bs-body-font-family: var(--app-font);
  --bs-body-color: var(--ink-900);
  --bs-body-bg: #ffffff; /* inputs, dropdowns, modals stay white; page canvas set on body */
  --bs-border-color: var(--line);
  --bs-border-radius: var(--radius-sm);
  --bs-border-radius-lg: var(--radius);
  --bs-primary: var(--brand-600);
  --bs-primary-rgb: 13,138,107;
  --bs-link-color: var(--brand-700);
  --bs-link-color-rgb: 11,111,87;
  --bs-link-hover-color: var(--brand-800);
  --bs-link-hover-color-rgb: 9,90,71;
  --bs-primary-text-emphasis: var(--brand-800);
  --bs-primary-bg-subtle: var(--brand-50);
  --bs-primary-border-subtle: var(--brand-200);
  --bs-secondary-color: var(--ink-500);
  --bs-focus-ring-color: rgba(16,163,127,.25);
}

html, body { font-family: var(--app-font); }
body { background: var(--canvas); color: var(--ink-900); font-size: .95rem; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { font-weight: 700; color: var(--ink-900); }
.text-muted, .text-secondary { color: var(--ink-500) !important; }
a { text-decoration: none; }
.num { direction: ltr; unicode-bidi: embed; font-variant-numeric: tabular-nums; }
.bi { line-height: 1; vertical-align: -.125em; }
::selection { background: var(--brand-100); }

/* ---------- Buttons ---------- */
.btn { font-weight: 500; border-radius: var(--radius-sm); display: inline-flex; align-items: center; justify-content: center; gap: .4rem; }
.btn-primary {
  --bs-btn-bg: var(--brand-600); --bs-btn-border-color: var(--brand-600);
  --bs-btn-hover-bg: var(--brand-700); --bs-btn-hover-border-color: var(--brand-700);
  --bs-btn-active-bg: var(--brand-800); --bs-btn-active-border-color: var(--brand-800);
  --bs-btn-disabled-bg: var(--brand-600); --bs-btn-disabled-border-color: var(--brand-600);
  --bs-btn-focus-shadow-rgb: 16,163,127;
}
.btn-outline-primary {
  --bs-btn-color: var(--brand-700); --bs-btn-border-color: var(--brand-200);
  --bs-btn-hover-bg: var(--brand-50); --bs-btn-hover-color: var(--brand-800); --bs-btn-hover-border-color: var(--brand-500);
  --bs-btn-active-bg: var(--brand-100); --bs-btn-active-color: var(--brand-800); --bs-btn-active-border-color: var(--brand-500);
}
.btn-light, .btn-outline-secondary {
  --bs-btn-color: var(--ink-700); --bs-btn-bg: var(--surface); --bs-btn-border-color: var(--line-strong);
  --bs-btn-hover-bg: #f1f4f8; --bs-btn-hover-color: var(--ink-900); --bs-btn-hover-border-color: var(--line-strong);
  --bs-btn-active-bg: #e9edf3; --bs-btn-active-color: var(--ink-900); --bs-btn-active-border-color: var(--line-strong);
}
.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: var(--radius-sm); color: var(--ink-700); }
.btn-icon:hover { background: #eef1f5; }
.btn-sm.btn-icon { width: 32px; height: 32px; }

/* ---------- Forms ---------- */
.form-label { font-weight: 500; color: var(--ink-700); font-size: .875rem; margin-bottom: .35rem; }
.form-control, .form-select { border-color: var(--line-strong); border-radius: var(--radius-sm); }
.form-control:focus, .form-select:focus { border-color: var(--brand-500); box-shadow: 0 0 0 .2rem rgba(16,163,127,.15); }
.form-check-input:checked { background-color: var(--brand-600); border-color: var(--brand-600); }
.form-text { color: var(--ink-500); }
.input-group-text { background: #f6f8fb; border-color: var(--line-strong); color: var(--ink-500); }
.form-section { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1rem; }
.form-section-title { font-weight: 700; font-size: .95rem; margin-bottom: .75rem; color: var(--ink-900); display: flex; align-items: center; gap: .5rem; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-start; padding-top: 1rem; border-top: 1px solid var(--line); margin-top: 1.25rem; }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); background: var(--surface); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); padding: .9rem 1.1rem; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.card-header .card-actions { margin-inline-start: auto; display: flex; gap: .4rem; }
.card-body { padding: 1.1rem; }
@media (max-width: 575.98px) { .card-header { flex-wrap: wrap; } }
.card-footer { background: #fafbfc; border-top: 1px solid var(--line); }
.card-title { font-weight: 700; }

/* ---------- Tables ---------- */
.table { --bs-table-hover-bg: #f7f9fb; --bs-table-striped-bg: #fafbfc; margin-bottom: 0; }
.table > thead > tr > th, .table > thead th {
  background: #f7f9fb; color: var(--ink-500); font-weight: 600; font-size: .8rem;
  border-bottom: 1px solid var(--line); white-space: nowrap; padding-top: .7rem; padding-bottom: .7rem;
}
.table > :not(caption) > * > * { padding: .65rem .85rem; border-bottom-color: var(--line); }
.table td, .table th { vertical-align: middle; }
.table tfoot td, .table tfoot th { background: #f7f9fb; font-weight: 700; }
.table-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.table-card .table-responsive { margin: 0; }
.table-card .card-footer, .table-card .table-footer { padding: .75rem 1rem; border-top: 1px solid var(--line); background: #fafbfc; }
.table .actions { white-space: nowrap; text-align: end; }
.table td.num, .table th.num { white-space: nowrap; }
.table-card > nav, .table-card > .pager, .table-card > .pagination-wrap { border-top: 1px solid var(--line); padding: .75rem 1rem; background: #fafbfc; }
.table-sticky thead th { position: sticky; top: 0; z-index: 1; }

/* ---------- Badges ---------- */
.badge { font-weight: 600; border-radius: 999px; padding: .35em .7em; }
.badge-soft { border: 1px solid transparent; }
.badge-soft.success   { color: #0a6b4d; background: #e3f7ee; border-color: #c4ecda; }
.badge-soft.warning   { color: #8a5a00; background: #fff4dc; border-color: #fde3a7; }
.badge-soft.danger    { color: #a4262c; background: #fde8e8; border-color: #f8cccc; }
.badge-soft.info      { color: #0b5a8a; background: #e5f2fb; border-color: #c6e1f4; }
.badge-soft.secondary { color: #475569; background: #eef1f5; border-color: #dde2e9; }
.badge-soft.primary   { color: var(--brand-800); background: var(--brand-50); border-color: var(--brand-200); }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.4rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: .6rem; }
.page-title > .bi { color: var(--brand-600); font-size: 1.25rem; background: var(--brand-50); width: 40px; height: 40px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
.page-title .badge { font-size: .75rem; }
.page-subtitle { color: var(--ink-500); margin: .25rem 0 0; font-size: .9rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.breadcrumb { font-size: .8rem; margin-bottom: .25rem; --bs-breadcrumb-divider: "‹"; }

/* ---------- Filter bar ---------- */
.filter-bar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1rem; box-shadow: var(--shadow-sm); }
.filter-bar .form-label { font-size: .8rem; margin-bottom: .2rem; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi-grid.compact { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem; }
@media (max-width: 575.98px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; } .kpi-card { padding: .75rem; gap: .6rem; } .kpi-icon { width: 36px; height: 36px; font-size: 1rem; } .kpi-value { font-size: 1.15rem; } }
.kpi-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; gap: .9rem; align-items: flex-start; box-shadow: var(--shadow-sm); color: inherit; transition: box-shadow .15s, transform .15s; }
a.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); color: inherit; }
.kpi-icon { width: 44px; height: 44px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; background: var(--brand-50); color: var(--brand-600); }
.kpi-label { color: var(--ink-500); font-size: .82rem; font-weight: 500; }
.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; margin-top: .15rem; }
.kpi-sub { color: var(--ink-500); font-size: .78rem; margin-top: .2rem; }
.kpi-card.success .kpi-icon { background: #e3f7ee; color: #0a8a5f; }
.kpi-card.warning .kpi-icon { background: #fff4dc; color: #b77900; }
.kpi-card.danger  .kpi-icon { background: #fde8e8; color: #c2333a; }
.kpi-card.info    .kpi-icon { background: #e5f2fb; color: #1773b0; }
.kpi-card.violet  .kpi-icon { background: #f1ebfd; color: #6d3fd1; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--ink-500); }
.empty-state .bi { font-size: 2.4rem; color: var(--ink-400); display: block; margin-bottom: .6rem; }
.empty-state .empty-title { font-weight: 700; color: var(--ink-700); margin-bottom: .25rem; }

/* ---------- Stat list (label / value rows) ---------- */
.stat-list { margin: 0; }
.stat-list .stat-row { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px dashed var(--line); }
.stat-list .stat-row:last-child { border-bottom: 0; }
.stat-list .stat-row dt { font-weight: 500; color: var(--ink-500); white-space: nowrap; }
.stat-list .stat-row dd { margin: 0; font-weight: 600; text-align: end; }

/* ---------- Tabs / nav pills ---------- */
.nav-tabs { border-bottom-color: var(--line); }
.nav-tabs .nav-link { color: var(--ink-500); border: 0; border-bottom: 2px solid transparent; font-weight: 500; }
.nav-tabs .nav-link.active { color: var(--brand-700); border-bottom-color: var(--brand-600); background: transparent; }
.nav-pills .nav-link.active { background: var(--brand-600); }
.nav-pills .nav-link { color: var(--ink-700); }

/* ---------- Pagination ---------- */
.pagination { --bs-pagination-active-bg: var(--brand-600); --bs-pagination-active-border-color: var(--brand-600); --bs-pagination-color: var(--ink-700); --bs-pagination-border-color: var(--line); margin: 0; }

/* ---------- Dropdowns, modals ---------- */
.dropdown-menu { border-color: var(--line); border-radius: var(--radius); padding: .4rem; box-shadow: var(--shadow-lg); }
.dropdown-item { border-radius: 6px; padding: .45rem .7rem; display: flex; align-items: center; gap: .5rem; }
.dropdown-item:active { background: var(--brand-600); }
.modal-content { border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-header, .modal-footer { border-color: var(--line); }

/* ---------- Toasts (flash messages) ---------- */
.flash-stack { position: fixed; top: calc(var(--topbar-h) + 12px); left: 16px; z-index: 1080; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 32px)); }
.flash { display: flex; gap: .6rem; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-inline-start: 4px solid var(--brand-500); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: .75rem .9rem; animation: flash-in .2s ease-out; }
.flash .bi { font-size: 1.15rem; margin-top: .1rem; }
.flash.success { border-inline-start-color: #10a37f; } .flash.success .bi { color: #10a37f; }
.flash.error   { border-inline-start-color: #dc3545; } .flash.error .bi { color: #dc3545; }
.flash .flash-close { margin-inline-start: auto; background: none; border: 0; color: var(--ink-400); padding: 0 .1rem; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Alerts ---------- */
.alert { border-radius: var(--radius); border-width: 1px; }

/* =====================================================================
   App shell (sidebar on the right in RTL)
   ===================================================================== */
.app { min-height: 100vh; }
.app-sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar-width);
  background: var(--sidebar-bg); color: var(--sidebar-ink); display: flex; flex-direction: column;
  z-index: 1040; transition: transform .2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: .7rem; padding: 1rem 1.1rem; height: var(--topbar-h); border-bottom: 1px solid rgba(255,255,255,.06); color: #fff; }
.sidebar-brand:hover { color: #fff; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem; color: #fff; flex-shrink: 0; }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; object-fit: contain; background: #fff; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: .72rem; color: var(--sidebar-ink); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .6rem .6rem 1rem; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.sidebar-nav .nav-group { font-size: .7rem; font-weight: 700; color: #6b7c90; letter-spacing: .02em; padding: 1rem .75rem .35rem; }
.app-sidebar .nav-item { display: flex; align-items: center; gap: .7rem; padding: .5rem .75rem; margin: 1px 0; border-radius: var(--radius-sm); color: var(--sidebar-ink); font-size: .9rem; font-weight: 500; transition: background .12s, color .12s; }
.app-sidebar .nav-item .bi { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .9; }
.app-sidebar .nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-strong); }
.app-sidebar .nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset -3px 0 0 var(--brand-500); }
.app-sidebar .nav-item.active .bi { color: #34d3a6; opacity: 1; }
.app-sidebar .nav-item-cta { background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff; margin: .4rem 0 .2rem; font-weight: 700; }
.app-sidebar .nav-item-cta:hover { filter: brightness(1.08); color: #fff; background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); }
.sidebar-footer { padding: .6rem; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-backdrop { display: none; }

.app-main { margin-inline-start: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; }
.app-topbar {
  position: sticky; top: 0; z-index: 1030; height: var(--topbar-h);
  background: rgba(255,255,255,.92); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .75rem; padding: 0 1.5rem;
}
.topbar-toggle { display: none; }
.topbar-title { font-weight: 700; color: var(--ink-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .6rem; }
.user-chip { display: flex; align-items: center; gap: .55rem; background: none; border: 1px solid transparent; border-radius: 999px; padding: .25rem .5rem .25rem .25rem; }
.user-chip:hover { background: #f1f4f8; border-color: var(--line); }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-100); color: var(--brand-800); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.user-meta { flex-direction: column; align-items: flex-start; line-height: 1.15; }
.user-name { font-weight: 600; font-size: .85rem; color: var(--ink-900); }
.user-role { font-size: .72rem; color: var(--ink-500); }
.app-content { padding: 1.5rem; flex: 1; max-width: 1600px; width: 100%; }

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(100%); box-shadow: var(--shadow-lg); }
  body.sidebar-open .app-sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 1035; }
  .app-main { margin-inline-start: 0; }
  .topbar-toggle { display: inline-flex; }
  .app-topbar { padding: 0 1rem; }
  .app-content { padding: 1rem; }
}

/* ---------- Print: hide the shell ---------- */
@media print {
  .app-sidebar, .app-topbar, .sidebar-backdrop, .flash-stack, .page-actions, .filter-bar { display: none !important; }
  .app-main { margin: 0 !important; }
  .app-content { padding: 0 !important; max-width: none; }
  body { background: #fff; }
  .card, .table-card, .kpi-card { box-shadow: none !important; }
}
