/* JSS — app styles. Brand colour comes from Settings via --brand / --brand-rgb. */
@font-face { font-family: "Rabar"; src: url("../fonts/Rabar_021.woff") format("woff"), url("../fonts/Rabar_021.ttf") format("truetype"); font-display: swap; }

:root {
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --radius: 14px;
  --bs-font-sans-serif: "Rabar", system-ui, "Segoe UI", Tahoma, sans-serif;
  --bs-primary: var(--brand);
  --bs-primary-rgb: var(--brand-rgb);
  --bs-link-color: var(--brand);
  --bs-link-color-rgb: var(--brand-rgb);
  --bs-link-hover-color: var(--brand);
  --brand-soft: rgba(var(--brand-rgb), .10);
  --owes: #c0362c;           /* customer owes us */
  --owes-bg: rgba(192, 54, 44, .10);
  --credit: #157f4b;         /* we owe the customer */
  --credit-bg: rgba(21, 127, 75, .11);
}
[data-bs-theme="light"] { --bs-body-bg: #f4f6f9; --surface: #fff; --surface-2: #f8fafc; --line: #e6e9ef; }
[data-bs-theme="dark"]  { --bs-body-bg: #0f1318; --surface: #171c23; --surface-2: #1d232b; --line: #2a313b; --owes: #ff8a80; --owes-bg: rgba(255, 138, 128, .13); --credit: #5fd59a; --credit-bg: rgba(95, 213, 154, .13); }

body { font-family: var(--bs-font-sans-serif); font-size: 1.02rem; min-height: 100vh; }
.num, .table td.num, input.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
td.num, th.num { text-align: left; white-space: nowrap; }
a { text-decoration: none; }

/* Brand colour on Bootstrap components */
.btn-primary { --bs-btn-bg: 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); --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); }
.btn-primary:hover { filter: brightness(1.08); }
.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); }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--brand-rgb), .6); box-shadow: 0 0 0 .2rem rgba(var(--brand-rgb), .18); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.pagination { --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand); --bs-pagination-color: var(--brand); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--brand); --bs-nav-link-color: var(--bs-body-color); }
.text-brand { color: var(--brand) !important; }
.bg-brand-soft { background: var(--brand-soft) !important; }

/* ---------- Layout ---------- */
.sidebar { background: var(--surface); border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; }
@media (min-width: 992px) {
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar-w); z-index: 1030; }
  .app { margin-inline-start: var(--sidebar-w); }
}
@media (max-width: 991.98px) { .sidebar { --bs-offcanvas-width: 280px; } }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--bs-body-color); }
.brand img { width: 38px; height: 38px; object-fit: contain; border-radius: 10px; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--brand); color: #fff; font-size: 1.2rem; }
.sidebar-nav { padding: 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.sidebar-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px; color: var(--bs-body-color); font-size: 1.05rem; }
.sidebar-nav a i { font-size: 1.2rem; opacity: .75; }
.sidebar-nav a:hover { background: var(--surface-2); }
.sidebar-nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.sidebar-nav a.active i { opacity: 1; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot .who small { color: var(--bs-secondary-color); margin-inline-start: 4px; }
.sidebar-foot .logout { color: var(--owes); }

.topbar { position: sticky; top: 0; z-index: 1020; height: var(--topbar-h); display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: color-mix(in srgb, var(--bs-body-bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.page-title { font-size: 1.25rem; font-weight: 700; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-tools { display: flex; align-items: center; gap: 6px; }
.btn-icon { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; font-size: 1.25rem; color: var(--bs-body-color); }
.btn-icon:hover { background: var(--surface-2); }

.content { padding: 18px 16px 28px; max-width: 1400px; margin-inline: auto; }
.content-wide { max-width: none; }
@media (max-width: 767.98px) { .content { padding-bottom: 90px; } }

/* Rate widget in the header */
.rate-widget { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 6px 4px 10px; }
.rate-widget label { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--bs-secondary-color); font-size: .9rem; white-space: nowrap; }
.rate-widget label i { color: var(--brand); font-size: 1.05rem; }
.rate-view { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 8px; cursor: pointer; font-variant-numeric: tabular-nums; }
.rate-view b { font-size: 1.05rem; }
.rate-view i { font-size: .8rem; opacity: .6; }
.rate-view:hover { background: var(--brand-soft); }
.rate-edit { display: none; align-items: center; gap: 4px; }
.rate-edit input { width: 90px; text-align: center; direction: ltr; }
.rate-widget.editing .rate-view { display: none; }
.rate-widget.editing .rate-edit { display: inline-flex; }
.rate-widget.flash { animation: rateflash 1.2s ease; }
@keyframes rateflash { 0% { box-shadow: 0 0 0 0 rgba(var(--brand-rgb), .6); } 100% { box-shadow: 0 0 0 10px rgba(var(--brand-rgb), 0); } }
@media (max-width: 575.98px) { .rate-label { display: none; } .page-title { font-size: 1.05rem; } }

/* Bottom navigation on phones */
.bottom-nav { position: fixed; inset-inline: 0; bottom: 0; z-index: 1030; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 6px; font-size: .78rem; color: var(--bs-secondary-color); }
.bottom-nav a i { font-size: 1.35rem; }
.bottom-nav a.active { color: var(--brand); font-weight: 700; }

/* ---------- Surfaces ---------- */
.card { --bs-card-bg: var(--surface); --bs-card-border-color: var(--line); --bs-card-border-radius: var(--radius); --bs-card-cap-bg: transparent; }
.card-header { font-weight: 700; padding: 14px 16px; }
.panel-title { font-size: 1.05rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1 1 220px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; height: 100%; }
.stat .label { color: var(--bs-secondary-color); font-size: .9rem; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
.stat .sub { font-size: .85rem; color: var(--bs-secondary-color); font-variant-numeric: tabular-nums; }
.stat .ico { width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); }

/* Balances: red = customer owes us, green = we owe the customer */
.bal-owes { color: var(--owes); }
.bal-credit { color: var(--credit); }
.bal-zero { color: var(--bs-secondary-color); }
.bal-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; white-space: nowrap; }
.bal-chip.bal-owes { background: var(--owes-bg); }
.bal-chip.bal-credit { background: var(--credit-bg); }
.bal-chip.bal-zero { background: var(--surface-2); }
.balance-card { border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); background: var(--surface); }
.balance-card .cur { font-size: .9rem; color: var(--bs-secondary-color); }
.balance-card .amt { font-size: 1.8rem; font-weight: 800; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.balance-card .hint { font-size: .9rem; font-weight: 700; }
.balance-card.bal-owes { background: var(--owes-bg); border-color: transparent; }
.balance-card.bal-credit { background: var(--credit-bg); border-color: transparent; }

/* Tables: on phones, rows become cards (each cell shows its data-label). */
.table { --bs-table-bg: transparent; margin: 0; }
.table > :not(caption) > * > * { padding: .7rem .75rem; vertical-align: middle; border-color: var(--line); }
.table thead th { font-size: .85rem; color: var(--bs-secondary-color); font-weight: 600; white-space: nowrap; background: var(--surface-2); }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: var(--brand-soft); }
tr.row-cancelled td { opacity: .55; text-decoration: line-through; }
tr.row-cancelled td.keep { text-decoration: none; }
@media (max-width: 767.98px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 10px; padding: 6px 4px; background: var(--surface); }
  .table-stack td { border: 0 !important; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: .35rem .75rem !important; text-align: start !important; }
  .table-stack td::before { content: attr(data-label); color: var(--bs-secondary-color); font-size: .85rem; flex-shrink: 0; }
  .table-stack td[data-label=""]::before { content: none; }
  .table-stack td.stack-title { font-weight: 700; font-size: 1.05rem; }
  .table-stack td.stack-title::before { content: none; }
  .table-stack td.stack-actions { justify-content: flex-end; }
  .card .table-stack tr { margin: 8px; }
}

.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; background: var(--surface-2); flex-shrink: 0; }
.thumb-lg { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; }
.badge-soft { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.badge-status-packed { background: var(--credit-bg); color: var(--credit); }
.badge-status-notpacked { background: rgba(234, 160, 0, .15); color: #b07600; }
.badge-status-cancelled { background: var(--owes-bg); color: var(--owes); }
.empty { text-align: center; padding: 40px 16px; color: var(--bs-secondary-color); }
.empty i { font-size: 2.4rem; display: block; margin-bottom: 8px; opacity: .6; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn { border-radius: 10px; }
.btn-lg { border-radius: 12px; }
.form-control, .form-select { border-radius: 10px; }
.form-label { font-weight: 600; font-size: .95rem; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg input { display: none; }
.seg label { padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--bs-secondary-color); white-space: nowrap; }
.seg input:checked + label { background: var(--brand); color: #fff; }

/* ---------- Sell / POS ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
@media (max-width: 1279.98px) { .pos { grid-template-columns: minmax(0, 1fr) 330px; gap: 12px; } }
@media (max-width: 991.98px) { .pos { grid-template-columns: 1fr; } }
.pos-side { position: sticky; top: calc(var(--topbar-h) + 12px); display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 991.98px) { .pos-side { position: static; } }
.search-box { position: relative; }
.search-box > i { position: absolute; inset-inline-start: 14px; top: 50%; transform: translateY(-50%); color: var(--bs-secondary-color); }
.search-box input { padding-inline-start: 40px; height: 48px; font-size: 1.05rem; }
.search-results { position: absolute; inset-inline: 0; top: calc(100% + 4px); z-index: 1040; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.14); max-height: 60vh; overflow-y: auto; display: none; }
.search-results.open { display: block; }
.result { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.result:last-child { border-bottom: 0; }
.result:hover, .result.focus { background: var(--brand-soft); }
.result .meta { flex: 1; min-width: 0; }
.result .meta .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result .meta .s { font-size: .85rem; color: var(--bs-secondary-color); }
.result .price { font-weight: 700; direction: ltr; white-space: nowrap; }
.result.out { opacity: .5; }

.cart-line { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); align-items: start; }
.cart-line:last-child { border-bottom: 0; }
.cart-line .thumb { width: 52px; height: 52px; }
.cart-line .t { font-weight: 700; }
.cart-line .s { font-size: .85rem; color: var(--bs-secondary-color); }
.cart-inputs { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.qty-step input { min-width: 40px; }
.cart-inputs label { font-size: .78rem; color: var(--bs-secondary-color); margin-bottom: 2px; display: block; }
.cart-inputs input { text-align: center; direction: ltr; font-variant-numeric: tabular-nums; }
.cart-line .line-total { font-weight: 800; direction: ltr; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cart-line .warn { color: #b07600; font-size: .8rem; }
.qty-step { display: flex; align-items: stretch; }
.qty-step button { width: 32px; border: 1px solid var(--bs-border-color); background: var(--surface-2); color: var(--bs-body-color); }
.qty-step button:first-child { border-radius: 0 10px 10px 0; border-left: 0; }
.qty-step button:last-child { border-radius: 10px 0 0 10px; border-right: 0; }
.qty-step input { border-radius: 0 !important; min-width: 0; }

.sum-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; gap: 8px; }
.sum-row .v { font-weight: 700; direction: ltr; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum-row.total { font-size: 1.25rem; border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 10px; }
.sum-row.total .v { color: var(--brand); font-size: 1.4rem; }
.customer-pick { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; }
.customer-pick.chosen { border-style: solid; background: var(--surface-2); }

.pos-bar { display: none; }
@media (max-width: 991.98px) {
  .pos-bar { display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 1035; gap: 10px; align-items: center; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 20px rgba(0,0,0,.08); }
  .pos-bar .v { font-size: 1.25rem; font-weight: 800; direction: ltr; flex: 1; text-align: right; }
  body.page-sell .bottom-nav { display: none !important; }
  body.page-sell .content { padding-bottom: 100px; }
}

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 100% 0%, rgba(var(--brand-rgb), .18), transparent 60%), var(--bs-body-bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.08); }

/* Theme colour presets in Settings */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 40px; height: 40px; border-radius: 12px; border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--bs-body-color); }

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .bottom-nav, .no-print, .pos-bar { display: none !important; }
  .app { margin: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
  body { background: #fff !important; color: #000; }
  .card { border: 0; }
}

/* Text size (Settings → ڕووکار): everything is in rem, so changing the root size scales the whole app. */
html { font-size: 16px; }
html[data-font="large"] { font-size: 18.5px; }
html[data-font="large"] .table > :not(caption) > * > * { padding: .8rem .8rem; }
html[data-font="large"] .thumb { width: 52px; height: 52px; }
