/*!
 * Bahjat ERP — shared styles.
 * Visual design ported from Tabler (https://tabler.io) — Copyright (c) 2018-2025 codecalm.net (Paweł Kuna), MIT License.
 * Tabler's design tokens (--tblr-*) and component rules (navbar-vertical, page-header, card, card-table,
 * btn, form-control, badge *-lt, alert, avatar, dropdown-menu, nav-segmented, empty) are re-applied here
 * onto this app's own class names. Icons: Tabler Icons (MIT), inlined from views/icons/.
 * Logical properties (inline-start/end) keep RTL (Arabic) and LTR (English) both correct.
 */

/* ---------- Tabler design tokens ---------- */
:root {
  --tblr-primary: #066fd1;
  --tblr-primary-rgb: 6, 111, 209;
  --tblr-primary-darken: #0564bc;
  --tblr-primary-lt: #e6f1fa;
  --tblr-secondary: #6b7280;
  --tblr-success: #2fb344;
  --tblr-success-text: #1f7a2e;
  --tblr-warning: #f59f00;
  --tblr-warning-text: #a35f00;
  --tblr-danger: #d63939;
  --tblr-danger-text: #b42828;
  --tblr-info: #4299e1;
  --tblr-azure: #4299e1;
  --tblr-blue: #066fd1;
  --tblr-green: #2fb344;
  --tblr-orange: #f76707;
  --tblr-orange-darken: #de5c06;
  --tblr-red: #d63939;
  --tblr-purple: #ae3ec9;
  --tblr-teal: #0ca678;
  --tblr-yellow: #f59f00;
  --tblr-gray-50: #f9fafb;
  --tblr-gray-100: #f3f4f6;
  --tblr-gray-200: #e5e7eb;
  --tblr-gray-300: #d1d5db;
  --tblr-gray-400: #9ca3af;
  --tblr-gray-500: #6b7280;
  --tblr-gray-600: #4b5563;
  --tblr-gray-700: #374151;
  --tblr-gray-800: #1f2937;
  --tblr-gray-900: #111827;
  --tblr-body-color: #1f2937;
  --tblr-body-color-rgb: 31, 41, 55;
  --tblr-emphasis-color: #1f2937;
  --tblr-body-bg: #f9fafb;
  --tblr-bg-surface: #ffffff;
  --tblr-bg-surface-secondary: #f9fafb;
  --tblr-bg-surface-tertiary: #f9fafb;
  --tblr-border-color: #e5e7eb;
  --tblr-border-color-translucent: rgba(4, 32, 69, 0.1);
  --tblr-border-dark-color: #9ca3af;
  --tblr-border-radius-sm: 4px;
  --tblr-border-radius: 6px;
  --tblr-border-radius-lg: 8px;
  --tblr-border-radius-pill: 100rem;
  --tblr-shadow: rgba(var(--tblr-body-color-rgb), 0.04) 0 2px 4px 0;
  --tblr-shadow-input: 0 1px 1px rgba(var(--tblr-body-color-rgb), 0.06);
  --tblr-shadow-card: 0 0 4px rgba(var(--tblr-body-color-rgb), 0.04);
  --tblr-shadow-card-hover: rgba(var(--tblr-body-color-rgb), 0.16) 0 2px 16px 0;
  --tblr-shadow-dropdown: 0 16px 24px 2px rgba(0, 0, 0, 0.07), 0 6px 30px 5px rgba(0, 0, 0, 0.06), 0 8px 10px -5px rgba(0, 0, 0, 0.1);
  --tblr-focus-ring: 0 0 0 0.25rem rgba(var(--tblr-primary-rgb), 0.25);
  --tblr-font-weight-medium: 500;
  --tblr-font-weight-bold: 600;
  --tblr-card-spacer-y: 1rem;
  --tblr-card-spacer-x: 1.25rem;
  --tblr-page-padding: 1.5rem;
  --tblr-navbar-bg: #1f2937;           /* navbar-vertical, data-bs-theme=dark (bg-surface = gray-800) */
  --tblr-navbar-color: rgba(255, 255, 255, 0.7);
  --tblr-navbar-active-color: #ffffff;
  --tblr-navbar-border-color: #374151;
  --font: "Inter", "IBM Plex Sans Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Tahoma, sans-serif;

  /* Older names still used by page CSS (dashboard.css, sell.css) */
  --brand: var(--tblr-primary);
  --brand-2: var(--tblr-primary-darken);
  --accent: var(--tblr-orange);
  --bg: var(--tblr-body-bg);
  --card: var(--tblr-bg-surface);
  --ink: var(--tblr-emphasis-color);
  --muted: var(--tblr-secondary);
  --line: var(--tblr-border-color);
  --ok: var(--tblr-success-text);
  --ok-bg: #eaf7ec;
  --warn: var(--tblr-warning-text);
  --warn-bg: #fef5e6;
  --bad: var(--tblr-danger-text);
  --bad-bg: #fbebeb;
  --info: var(--tblr-primary);
  --info-bg: var(--tblr-primary-lt);
  --radius: var(--tblr-border-radius-lg);
  --shadow: var(--tblr-shadow-card);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.4285714286;
  color: var(--tblr-body-color);
  background: var(--tblr-body-bg);
  font-feature-settings: "cv03", "cv04", "cv11";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
[dir="rtl"] body { font-size: 0.9375rem; line-height: 1.6; }
a { color: var(--tblr-primary); text-decoration: none; }
a:hover { color: var(--tblr-primary-darken); text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; color: var(--tblr-emphasis-color); font-weight: var(--tblr-font-weight-bold); }
h1 { font-size: 1.5rem; line-height: 2rem; }
h2 { font-size: 1.25rem; line-height: 1.75rem; }
h3 { font-size: 1rem; line-height: 1.5rem; }
p { margin: 0 0 1rem; }
img { max-width: 100%; }
.muted { color: var(--tblr-secondary); }
.small { font-size: .8125rem; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; direction: ltr; unicode-bidi: isolate; }
.nowrap { white-space: nowrap; }
[dir="rtl"] .num { text-align: right; } /* .num is direction:ltr; keep blocks of numbers on the reading side */
.icon { width: 1.25rem; height: 1.25rem; flex: none; stroke-width: 1.5; vertical-align: middle; }
[hidden] { display: none !important; }

/* ---------- Shell: navbar-vertical (dark) + top header ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 15rem; flex-shrink: 0; position: relative; min-height: 100vh; z-index: 30;
  background: var(--tblr-navbar-bg); color: var(--tblr-navbar-color);
  box-shadow: inset calc(-1 * 1px) 0 0 0 var(--tblr-navbar-border-color);
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent;
}
.sidebar-inner { position: sticky; top: 0; max-height: 100vh; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
[dir="rtl"] .sidebar { box-shadow: inset 1px 0 0 0 var(--tblr-navbar-border-color); }
.sidebar .brand {
  display: flex; align-items: center; gap: .75rem; padding: .75rem 1.25rem; min-height: 3.5rem;
  color: #fff; font-weight: var(--tblr-font-weight-bold); font-size: 1rem; line-height: 1.25;
}
.sidebar .brand:hover { text-decoration: none; color: #fff; }
.brand-logo { width: 2.25rem; height: 2.25rem; border-radius: var(--tblr-border-radius); object-fit: cover; background: #fff; flex: none; }
.brand-text { min-width: 0; }
.sidebar .brand small { display: block; font-weight: 400; font-size: .75rem; color: rgba(255,255,255,.55); margin-top: 2px; }
.sidebar nav { padding: .25rem .75rem 1.5rem; display: flex; flex-direction: column; gap: 1px; }
.sidebar .group {
  padding: .625rem .75rem .25rem; font-size: .6875rem; font-weight: var(--tblr-font-weight-bold);
  line-height: 1rem; color: rgba(255,255,255,.42);
}
[dir="ltr"] .sidebar .group { text-transform: uppercase; letter-spacing: .04em; }
.sidebar a.item {
  position: relative; display: flex; align-items: center; gap: .625rem;
  padding: .40625rem .75rem; border-radius: var(--tblr-border-radius); color: var(--tblr-navbar-color);
  font-weight: var(--tblr-font-weight-medium); transition: color .15s, background-color .15s;
}
.sidebar a.item .nav-icon { width: 1.25rem; height: 1.25rem; opacity: .8; }
.sidebar a.item:hover { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }
.sidebar a.item.active { color: var(--tblr-navbar-active-color); background: rgba(255,255,255,.08); }
.sidebar a.item.active .nav-icon { opacity: 1; }
.sidebar a.item.active::before {
  content: ''; position: absolute; inset-block: .375rem; inset-inline-start: 0; width: 3px;
  border-start-end-radius: 3px; border-end-end-radius: 3px; background: var(--tblr-primary);
}
/* Sell: the one orange call-to-action in the menu */
.sidebar a.item.sell {
  margin: .375rem 0 .125rem; padding: .5rem .75rem; justify-content: center; font-weight: var(--tblr-font-weight-bold);
  color: #fff; background: var(--tblr-orange); box-shadow: 0 2px 6px rgba(247, 103, 7, .35);
}
.sidebar a.item.sell .nav-icon { opacity: 1; }
.sidebar a.item.sell:hover { background: var(--tblr-orange-darken); }
.sidebar a.item.sell.active { background: var(--tblr-orange-darken); box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.sidebar a.item.sell.active::before { display: none; }
.nav-backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .75rem; min-height: 3.5rem; padding: .375rem var(--tblr-page-padding);
  background: var(--tblr-bg-surface); box-shadow: inset 0 -1px 0 0 var(--tblr-border-color);
  position: sticky; top: 0; z-index: 20;
}
.topbar-brand { display: none; align-items: center; gap: .5rem; color: var(--tblr-emphasis-color); font-weight: var(--tblr-font-weight-bold); min-width: 0; }
.topbar-brand:hover { text-decoration: none; color: var(--tblr-emphasis-color); }
.topbar-brand img { width: 2rem; height: 2rem; border-radius: var(--tblr-border-radius); object-fit: cover; }
.topbar-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-end { margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; }
.topbar .lang-btn .icon { color: var(--tblr-secondary); }

/* User menu (Tabler nav-item dropdown with avatar) */
.usermenu { position: relative; }
.usermenu > summary {
  list-style: none; display: flex; align-items: center; gap: .625rem; cursor: pointer;
  padding: .25rem .5rem; border-radius: var(--tblr-border-radius); user-select: none;
}
.usermenu > summary::-webkit-details-marker { display: none; }
.usermenu > summary:hover, .usermenu[open] > summary { background: var(--tblr-gray-100); }
.usermenu > summary:focus-visible { outline: 0; box-shadow: var(--tblr-focus-ring); }
.avatar {
  --avatar-size: 2.25rem;
  width: var(--avatar-size); height: var(--avatar-size); flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--tblr-border-radius); font-weight: var(--tblr-font-weight-medium); font-size: 1rem; line-height: 1;
  color: var(--tblr-primary); background: var(--tblr-primary-lt); box-shadow: inset 0 0 0 1px var(--tblr-border-color-translucent);
}
.avatar .icon { width: 1.5rem; height: 1.5rem; }
.who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who-name { color: var(--tblr-emphasis-color); font-weight: var(--tblr-font-weight-medium); white-space: nowrap; }
.who-role { color: var(--tblr-secondary); font-size: .75rem; margin-top: 1px; }
.usermenu .caret { width: 1rem; height: 1rem; color: var(--tblr-secondary); transition: transform .15s; }
.usermenu[open] .caret { transform: rotate(180deg); }
.dropdown-menu {
  position: absolute; top: calc(100% + .375rem); inset-inline-end: 0; z-index: 1000; min-width: 13rem;
  padding: .25rem 0; background: var(--tblr-bg-surface); color: var(--tblr-body-color);
  border: 1px solid var(--tblr-border-color-translucent); border-radius: var(--tblr-border-radius);
  box-shadow: var(--tblr-shadow-dropdown);
}
.dropdown-menu form { margin: 0; }
.dropdown-header { display: flex; flex-direction: column; padding: .5rem .75rem .375rem; line-height: 1.3; }
.dropdown-header strong { color: var(--tblr-emphasis-color); font-weight: var(--tblr-font-weight-medium); }
.dropdown-header span { color: var(--tblr-secondary); font-size: .75rem; }
.dropdown-item {
  display: flex; align-items: center; gap: .5rem; width: 100%; padding: .5rem .75rem; border: 0; background: transparent;
  color: inherit; font: inherit; text-align: start; white-space: nowrap; cursor: pointer;
}
.dropdown-item .icon { color: var(--tblr-secondary); width: 1.125rem; height: 1.125rem; }
.dropdown-item:hover { background: rgba(107, 114, 128, .08); text-decoration: none; color: var(--tblr-emphasis-color); }
.dropdown-item.danger, .dropdown-item.danger .icon { color: var(--tblr-danger); }
.dropdown-divider { height: 0; margin: .25rem 0; border-top: 1px solid var(--tblr-border-color-translucent); }

/* Desktop: the menu button hides/shows the sidebar (remembered) */
@media (min-width: 769px) { body.nav-collapsed .sidebar { display: none; } }
.content { padding: var(--tblr-page-padding); max-width: 1320px; width: 100%; margin-inline: auto; }

/* ---------- Page header (page-pretitle + page-title + actions) ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.5rem; min-height: 2.25rem; }
.page-head > :first-child { min-width: 0; }
.page-head h1 { font-size: 1.25rem; line-height: 1.75rem; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; }
.page-head .tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.page-pretitle, .subheader {
  font-size: .75rem; font-weight: var(--tblr-font-weight-medium); line-height: 1rem; color: var(--tblr-secondary);
}
[dir="ltr"] .page-pretitle, [dir="ltr"] .subheader { text-transform: uppercase; letter-spacing: .04em; }
.page-head .muted.small, .page-head .rep-range { margin-top: .125rem; }

/* ---------- Card ---------- */
.card {
  position: relative; min-width: 0; background: var(--tblr-bg-surface); color: var(--tblr-body-color);
  border: 1px solid var(--tblr-border-color-translucent); border-radius: var(--tblr-border-radius-lg);
  box-shadow: var(--tblr-shadow-card); padding: var(--tblr-card-spacer-y) var(--tblr-card-spacer-x); margin-bottom: 1rem;
  overflow-wrap: break-word;
}
a.card { color: inherit; transition: box-shadow .3s ease-out, border-color .3s; }
a.card:hover { text-decoration: none; box-shadow: var(--tblr-shadow-card-hover); }
/* A heading as the card's first child becomes Tabler's card-header + card-title */
.card > h2:first-child, .card > h3:first-child {
  margin: calc(-1 * var(--tblr-card-spacer-y)) calc(-1 * var(--tblr-card-spacer-x)) var(--tblr-card-spacer-y);
  padding: 1rem var(--tblr-card-spacer-x); border-bottom: 1px solid var(--tblr-border-color-translucent);
  font-size: 1rem; line-height: 1.5rem; font-weight: var(--tblr-font-weight-bold);
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem;
}
.card > h2:not(:first-child), .card > h3:not(:first-child) { font-size: 1rem; line-height: 1.5rem; margin-top: 1rem; }
.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid > * { min-width: 0; }
.grid > .card, .grid > .stat { margin-bottom: 0; }
.grid .grid { margin-bottom: 0; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* Stat tile = Tabler card + subheader + h1 value */
.stat {
  position: relative; background: var(--tblr-bg-surface); border: 1px solid var(--tblr-border-color-translucent);
  border-radius: var(--tblr-border-radius-lg); box-shadow: var(--tblr-shadow-card); padding: 1rem 1.25rem; min-width: 0;
}
.stat .label { font-size: .75rem; font-weight: var(--tblr-font-weight-medium); line-height: 1rem; color: var(--tblr-secondary); }
[dir="ltr"] .stat .label { text-transform: uppercase; letter-spacing: .04em; }
[dir="rtl"] .stat .label { font-size: .8125rem; }
.stat .value {
  font-size: 1.5rem; line-height: 2rem; font-weight: var(--tblr-font-weight-bold); color: var(--tblr-emphasis-color);
  margin-top: .375rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.stat .value .sub, .stat .value small { font-size: .8125rem; font-weight: var(--tblr-font-weight-medium); color: var(--tblr-secondary); }
.stat .sub { font-size: .8125rem; color: var(--tblr-secondary); margin-top: .125rem; }
/* Label on its own line, the currency (.sub) beside the number; a long .sub note wraps under it */
.stat:not(.dash-kpi) { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: .375rem; }
.stat:not(.dash-kpi) > .label { flex: 0 0 100%; }
.stat:not(.dash-kpi) > .value { min-width: 0; }
.stat:not(.dash-kpi) > .sub { margin-top: 0; }
.grid + br { display: none; }
.stat.good .value { color: var(--tblr-success-text); }
.stat.bad .value { color: var(--tblr-danger-text); }
/* card-status-top */
.stat.accent::before, .stat.good::before, .stat.bad::before {
  content: ''; position: absolute; inset-inline: -1px; top: -1px; height: 2px; border-radius: var(--tblr-border-radius-lg) var(--tblr-border-radius-lg) 0 0;
  background: var(--tblr-orange);
}
.stat.good::before { background: var(--tblr-success); }
.stat.bad::before { background: var(--tblr-danger); }

/* ---------- Tables (Tabler .table + .card-table + .table-vcenter) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; color: inherit; background: transparent; margin: 0; }
.table th, .table td { padding: .75rem; border-bottom: 1px solid var(--tblr-border-color); text-align: start; vertical-align: middle; }
.table thead th {
  background: var(--tblr-bg-surface-tertiary); font-size: .75rem; font-weight: var(--tblr-font-weight-medium); line-height: 1rem;
  color: var(--tblr-secondary); padding-block: .5rem; white-space: nowrap; border-top: 1px solid var(--tblr-border-color);
}
[dir="ltr"] .table thead th { text-transform: uppercase; letter-spacing: .04em; }
[dir="rtl"] .table thead th { font-size: .8125rem; }
.table tbody tr { transition: background-color .15s; }
.table tbody tr:hover { background: rgba(var(--tblr-primary-rgb), .03); }
.table tbody tr[data-href] { cursor: pointer; }
.table td.num, .table th.num { text-align: end; }
[dir="rtl"] .table td.num, [dir="rtl"] .table th.num { text-align: left; } /* .num is direction:ltr, so "end" would be the right side */
.table tfoot td { font-weight: var(--tblr-font-weight-bold); color: var(--tblr-emphasis-color); background: var(--tblr-bg-surface-tertiary); border-bottom: 0; }
.table .actions { white-space: nowrap; text-align: end; }
.table .actions form { display: inline; }
.table .actions .btn + .btn, .table .actions form + .btn, .table .actions .btn + form { margin-inline-start: .25rem; }
.table td.num, .table td a[href*="/sales/"], .table td a[href*="/purchases/"], .table td a[href*="invoices/"] { white-space: nowrap; }
tr.row-cancelled td { color: var(--tblr-gray-400); }
tr.row-cancelled td:not(:has(.badge)) { text-decoration: line-through; }
/* card-table: the table runs edge to edge inside its card */
.card > .table-wrap, .card > table.table { margin-inline: calc(-1 * var(--tblr-card-spacer-x)); width: calc(100% + 2 * var(--tblr-card-spacer-x)); }
.card > .table-wrap:last-child, .card > table.table:last-child { margin-bottom: calc(-1 * var(--tblr-card-spacer-y)); }
.card > .table-wrap:first-child, .card > table.table:first-child,
.card > h2:first-child + .table-wrap, .card > h3:first-child + .table-wrap,
.card > h2:first-child + table.table, .card > h3:first-child + table.table { margin-top: calc(-1 * var(--tblr-card-spacer-y)); }
.card > .table-wrap:first-child .table thead th, .card > table.table:first-child thead th,
.card > h2:first-child + .table-wrap .table thead th, .card > h3:first-child + .table-wrap .table thead th,
.card > h2:first-child + table.table thead th { border-top: 0; }
.card.table-wrap { padding: 0; }
.card.table-wrap > table.table { margin: 0; width: 100%; }
/* Sales list: the per-flavor box split under the box count may wrap */
.sales-list .table td.num > .small { white-space: normal; min-width: 6.5rem; line-height: 1.35; margin-top: .125rem; }
.sales-list .table td, .sales-list .table th { padding-inline: .4375rem; }
.sales-list .table tbody td:first-child { white-space: normal; min-width: 7.5rem; }
.sales-list .table tbody td:first-child > a { white-space: nowrap; }
.sales-list .table tbody td:nth-child(3) { white-space: normal; min-width: 7rem; }
.card.sales-list .table tr > :first-child { padding-inline-start: 1rem; }
.card.sales-list .table tr > :last-child { padding-inline-end: 1rem; }
.sales-list .table { font-size: .8125rem; }
[dir="rtl"] .sales-list .table { font-size: .875rem; }
.table { font-size: .875rem; }
.card.table-wrap > h2:first-child, .card.table-wrap > h3:first-child { margin: 0; }
.card.table-wrap > .table thead th:first-child { border-start-start-radius: var(--tblr-border-radius-lg); }
.card.table-wrap > .table:first-child thead th { border-top: 0; }
.card.table-wrap > .empty, .card.table-wrap > p { margin: 0; padding: 2rem var(--tblr-card-spacer-x); }
.card .table tr > :first-child { padding-inline-start: var(--tblr-card-spacer-x); }
.card .table tr > :last-child { padding-inline-end: var(--tblr-card-spacer-x); }
.card .table tbody tr:last-child td { border-bottom: 0; }
.card .table tfoot td { border-top: 1px solid var(--tblr-border-color); }

/* ---------- Badges (Tabler badge + bg-*-lt) ---------- */
.badge {
  display: inline-flex; align-items: center; justify-content: center; gap: .25rem;
  padding: .25em .5em; font-size: .8125rem; font-weight: var(--tblr-font-weight-medium); line-height: 1;
  border: 1px solid transparent; border-radius: var(--tblr-border-radius); white-space: nowrap; vertical-align: middle;
  color: var(--tblr-secondary); background: #f0f1f2;
}
[dir="rtl"] .badge { line-height: 1.25; padding: .2em .55em; }
.badge.paid, .badge.ok { color: var(--tblr-success-text); background: #eaf7ec; }
.badge.partial, .badge.warn { color: var(--tblr-warning-text); background: #fef5e6; }
.badge.unpaid, .badge.bad { color: var(--tblr-danger-text); background: #fbebeb; }
.badge.cancelled { color: var(--tblr-gray-600); background: #f0f1f2; }
.badge.sample, .badge.info { color: var(--tblr-primary); background: var(--tblr-primary-lt); }
h1 .badge { font-size: .8125rem; }

/* Status dot */
.status-dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 100rem; background: var(--tblr-secondary); flex: none; }
.status-dot.green { background: var(--tblr-success); }
.status-dot.red { background: var(--tblr-danger); }
.status-dot.orange { background: var(--tblr-orange); }
.status-dot.blue { background: var(--tblr-primary); }

/* ---------- Forms (form-control / form-select / form-label / form-hint) ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .375rem; min-width: 0; }
.field.full { grid-column: 1 / -1; }
label { font-size: .875rem; font-weight: var(--tblr-font-weight-medium); color: var(--tblr-emphasis-color); }
input, select, textarea {
  display: block; width: 100%; font-family: inherit; font-size: .875rem; line-height: 1.25rem; color: var(--tblr-emphasis-color);
  padding: .5625rem .75rem; background-color: var(--tblr-bg-surface); background-clip: padding-box;
  border: 1px solid var(--tblr-border-color); border-radius: var(--tblr-border-radius); box-shadow: var(--tblr-shadow-input);
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
[dir="rtl"] input, [dir="rtl"] select, [dir="rtl"] textarea { font-size: .9375rem; }
input::placeholder, textarea::placeholder { color: var(--tblr-gray-400); }
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: color-mix(in srgb, var(--tblr-primary) 50%, var(--tblr-border-color)); box-shadow: var(--tblr-shadow-input), var(--tblr-focus-ring);
}
input:disabled, select:disabled, textarea:disabled, input[readonly] { background-color: var(--tblr-gray-50); color: var(--tblr-secondary); }
select {
  -webkit-appearance: none; appearance: none; padding-inline-end: 2.25rem; cursor: pointer;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right .75rem center; background-size: 16px 12px;
}
[dir="rtl"] select { background-position: left .75rem center; }
select[multiple] { background-image: none; padding-inline-end: .75rem; }
input[type="number"] { direction: ltr; text-align: end; }
input[type="date"] { min-height: calc(1.25rem + 1.125rem + 2px); }
input[type="checkbox"], input[type="radio"] {
  width: 1rem; height: 1rem; padding: 0; display: inline-block; vertical-align: middle; box-shadow: none; accent-color: var(--tblr-primary);
}
input[type="file"] { padding: .375rem .5rem; }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: var(--tblr-font-weight-medium); margin-inline-end: .75rem; padding: .25rem .75rem; cursor: pointer;
  border: 1px solid var(--tblr-border-color); border-radius: var(--tblr-border-radius-sm); background: var(--tblr-gray-50); color: var(--tblr-body-color);
}
textarea { min-height: 5rem; resize: vertical; }
.hint { font-size: .8125rem; color: var(--tblr-secondary); font-weight: 400; }
label .hint { font-size: .75rem; }
.req::after { content: ' *'; color: var(--tblr-danger); }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--tblr-border-color-translucent); }
.card > form > .form-actions:last-child, .card > .form-actions:last-child { margin-bottom: 0; }
.inline-form { display: inline; }

/* Filters (a card of fields in one row) */
.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { flex: 1 1 130px; min-width: 120px; max-width: 260px; }
.filters .field:has(> .btn:only-child) { flex: 0 0 auto; min-width: 0; }
.filters .filter-actions { display: flex; gap: .5rem; align-items: flex-end; margin-inline-start: auto; }
.btn.filter-toggle { display: none; }
.btn.filter-toggle[aria-expanded="true"] { color: var(--tblr-primary); border-color: var(--tblr-primary); background: var(--tblr-primary-lt); }
input[type="search"] { unicode-bidi: plaintext; }
.summary-strip { margin-bottom: 1rem; gap: 1rem; }
.summary-strip .stat { padding: .875rem 1.25rem; }
.summary-strip .stat .value { font-size: 1.25rem; line-height: 1.75rem; margin-top: .25rem; }

/* ---------- Buttons (btn, btn-primary, btn-outline-danger, btn-ghost, btn-sm) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .5625rem 1rem; font-family: inherit; font-size: .875rem; font-weight: var(--tblr-font-weight-medium); line-height: 1.25rem;
  color: var(--tblr-emphasis-color); background: var(--tblr-bg-surface); border: 1px solid var(--tblr-border-color);
  border-radius: var(--tblr-border-radius); box-shadow: var(--tblr-shadow-input); cursor: pointer; white-space: nowrap;
  text-align: center; vertical-align: middle; user-select: none; touch-action: manipulation;
  transition: color .15s, background-color .15s, border-color .15s, box-shadow .15s;
}
.btn .icon { width: 1.25rem; height: 1.25rem; margin-inline: -.25rem 0; stroke-width: 2; }
.btn:hover { color: var(--tblr-emphasis-color); background: var(--tblr-gray-50); border-color: var(--tblr-border-dark-color); text-decoration: none; }
.btn:focus-visible { outline: 0; box-shadow: var(--tblr-focus-ring); }
.btn:disabled, .btn[disabled] { opacity: .4; pointer-events: none; }
.btn.primary { color: #fff; background: var(--tblr-primary); border-color: transparent; }
.btn.primary:hover { color: #fff; background: var(--tblr-primary-darken); }
.btn.accent { color: #fff; background: var(--tblr-orange); border-color: transparent; }
.btn.accent:hover { color: #fff; background: var(--tblr-orange-darken); }
.btn.danger { color: var(--tblr-danger); background: transparent; border-color: var(--tblr-danger); box-shadow: none; }
.btn.danger:hover { color: #fff; background: var(--tblr-danger); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--tblr-body-color); }
.btn.ghost:hover { background: var(--tblr-gray-100); border-color: transparent; }
.btn.icon-btn { padding: .5rem; }
.btn.icon-btn .icon { margin: 0; }
.btn.sm { padding: .25rem .625rem; font-size: .8125rem; line-height: 1.25rem; gap: .25rem; }
.btn.sm .icon { width: 1rem; height: 1rem; }
.btn.link { border: 0; background: none; color: var(--tblr-primary); padding: 0; box-shadow: none; }
.btn.link:hover { text-decoration: underline; background: none; }

/* ---------- Alerts (Tabler alert with icon) ---------- */
.alert {
  --alert-color: var(--tblr-secondary);
  position: relative; padding: .75rem 1rem; padding-inline-start: 2.75rem; margin-bottom: 1rem;
  color: var(--tblr-emphasis-color); border: 1px solid color-mix(in srgb, var(--alert-color) 25%, transparent);
  background: color-mix(in srgb, var(--alert-color) 8%, var(--tblr-bg-surface)); border-radius: var(--tblr-border-radius);
}
.alert::before {
  content: ''; position: absolute; inset-inline-start: 1rem; top: .8rem; width: 1.25rem; height: 1.25rem; background: var(--alert-color);
  -webkit-mask: var(--alert-icon) center / contain no-repeat; mask: var(--alert-icon) center / contain no-repeat;
  --alert-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0'/%3e%3cpath d='M12 9h.01'/%3e%3cpath d='M11 12h1v4h1'/%3e%3c/svg%3e");
}
[dir="rtl"] .alert::before { top: .95rem; }
.alert.success { --alert-color: var(--tblr-success); }
.alert.success::before { --alert-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0'/%3e%3cpath d='M9 12l2 2l4 -4'/%3e%3c/svg%3e"); }
.alert.error { --alert-color: var(--tblr-danger); }
.alert.error::before { --alert-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0'/%3e%3cpath d='M12 8v4'/%3e%3cpath d='M12 16h.01'/%3e%3c/svg%3e"); }
.alert.warn { --alert-color: var(--tblr-warning); }
.alert.warn::before { --alert-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M12 9v4'/%3e%3cpath d='M10.363 3.591l-8.106 13.534a1.914 1.914 0 0 0 1.636 2.871h16.214a1.914 1.914 0 0 0 1.636 -2.87l-8.106 -13.536a1.914 1.914 0 0 0 -3.274 0z'/%3e%3cpath d='M12 16h.01'/%3e%3c/svg%3e"); }
.alert.info { --alert-color: var(--tblr-azure); }
.alert a { color: inherit; font-weight: var(--tblr-font-weight-medium); text-decoration: underline; }

/* ---------- Empty state ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--tblr-secondary); padding: 2rem 1rem; gap: .75rem; }
.empty::before {
  content: ''; width: 3rem; height: 3rem; border-radius: 50%; background: var(--tblr-gray-100) no-repeat center / 1.5rem
    url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0'/%3e%3cpath d='M21 21l-6 -6'/%3e%3c/svg%3e");
}
.card.empty { padding: 2.5rem 1rem; }

/* ---------- Pagination ---------- */
.pagination { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: center; padding: .75rem var(--tblr-card-spacer-x); border-top: 1px solid var(--tblr-border-color); }
.card.table-wrap > .pagination { position: sticky; inset-inline-start: 0; }

/* Key/value list (datagrid) */
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .625rem 1.25rem; margin: 0; }
dl.kv dt { color: var(--tblr-secondary); }
dl.kv dd { margin: 0; font-weight: var(--tblr-font-weight-medium); color: var(--tblr-emphasis-color); min-width: 0; overflow-wrap: anywhere; }

/* ---------- Attachments ---------- */
.att-list { list-style: none; margin: 0 0 .75rem; padding: 0; }
.att-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding: .625rem 0; border-bottom: 1px solid var(--tblr-border-color); }
.att-list li a { font-weight: var(--tblr-font-weight-medium); word-break: break-all; }
.att-form { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; }
.att-form input[type="file"] { width: auto; max-width: 100%; }

/* ---------- Login / error (Tabler sign-in page) ---------- */
.login-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2.5rem 1rem; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-bottom: 1.5rem; color: var(--tblr-emphasis-color); font-weight: var(--tblr-font-weight-bold); font-size: 1.125rem; text-align: center; }
.login-brand img { width: 4rem; height: 4rem; border-radius: var(--tblr-border-radius-lg); object-fit: cover; box-shadow: var(--tblr-shadow-card); background: #fff; }
.login-brand small { display: block; color: var(--tblr-secondary); font-weight: 400; font-size: .8125rem; }
.login-card { width: 100%; max-width: 26rem; padding: 2rem; margin: 0; }
.card.login-card > h2:first-child { margin: 0 0 1.5rem; padding: 0; border: 0; justify-content: center; font-size: 1.25rem; line-height: 1.75rem; }
.login-card .field + .field { margin-top: 1rem; }
.login-card .btn.primary { width: 100%; padding-block: .625rem; }
.login-card .form-actions { border-top: 0; padding-top: 0; margin-top: 1.5rem; }
.login-foot { margin-top: 1rem; text-align: center; color: var(--tblr-secondary); }
.login-foot a { display: inline-flex; align-items: center; gap: .375rem; }
.login-foot .icon { width: 1rem; height: 1rem; }
.error-page { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 3rem 1.5rem; max-width: 30rem; margin: 2rem auto; }
.error-page .btn { margin-top: .5rem; }
.error-page .error-code { font-size: 3.5rem; line-height: 1; font-weight: 300; color: var(--tblr-gray-400); margin-bottom: .75rem; font-variant-numeric: tabular-nums; }
.error-page h1 { font-size: 1.5rem; line-height: 2rem; }
.error-page p { color: var(--tblr-secondary); max-width: 32rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 991.98px) {
  :root { --tblr-page-padding: 1rem; }
}
@media (min-width: 769px) and (max-width: 1100px) {
  .grid .table thead th { white-space: normal; }
}
@media (max-width: 991.98px) {
  .grid.cols-2:not(:has(> .stat)) { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 768px) {
  :root { --tblr-card-spacer-x: 1rem; --tblr-page-padding: .75rem; }
  /* Off-canvas sidebar */
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; height: 100%; min-height: 0; width: min(17rem, 85vw); z-index: 1040;
    transform: translateX(-100%); transition: transform .25s ease-out, visibility 0s .25s; box-shadow: none; visibility: hidden;
  }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  body.nav-open .sidebar, [dir="rtl"] body.nav-open .sidebar { transform: none; box-shadow: var(--tblr-shadow-dropdown); visibility: visible; transition: transform .25s ease-out; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 1035; background: rgba(17, 24, 39, .45); }
  body.nav-open { overflow: hidden; }
  .topbar { padding: .25rem .5rem; gap: .25rem; min-height: 3.25rem; }
  .topbar-brand { display: flex; }
  .topbar .lang-btn { display: none; }
  .usermenu > summary { padding: .25rem; gap: .25rem; }
  .usermenu .who, .usermenu .caret { display: none; }
  .avatar { --avatar-size: 2rem; font-size: .875rem; }
  .content { padding: 1rem var(--tblr-page-padding) 1.5rem; }
  .page-head { margin-bottom: 1rem; }
  .page-head h1 { font-size: 1.125rem; line-height: 1.5rem; }
  .page-head .tools { width: 100%; }
  .page-head .tools .btn { flex: 1 1 auto; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .grid.cols-4.summary-strip, .grid.cols-2 > .grid.cols-2, .grid.cols-4:has(> .stat), .grid.cols-3:has(> .stat) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-4:has(> .stat), .grid.cols-3:has(> .stat) { gap: .5rem; }
  .grid.cols-4:has(> .stat) > .stat, .grid.cols-3:has(> .stat) > .stat { padding: .75rem; }
  .grid.cols-3:has(> .stat) > .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .summary-strip { gap: .5rem; }
  .summary-strip .stat { padding: .625rem .75rem; }
  .summary-strip .stat .value { font-size: 1.0625rem; line-height: 1.5rem; }
  .stat .value { font-size: 1.25rem; line-height: 1.75rem; }
  .btn { padding: .625rem 1rem; }
  .btn.sm { padding: .375rem .75rem; }
  input, select, textarea { font-size: 1rem; padding-block: .625rem; } /* 16px: no zoom on iOS */
  [dir="rtl"] input, [dir="rtl"] select, [dir="rtl"] textarea { font-size: 1rem; }
  .filters .field { max-width: none; }
  .filters .filter-actions { width: 100%; margin-inline-start: 0; }
  .filters .filter-actions .btn { flex: 1; }
  /* Filter card behind a "Filter" button (pages that add .collapsible + a [data-toggle-filters] button) */
  .btn.filter-toggle { display: inline-flex; }
  .js .filters.collapsible:not(.open) { display: none; }
  .filters.collapsible .field { flex: 1 1 calc(50% - .75rem); min-width: 0; }
}
@media (max-width: 1100px) {
  /* Wide tables scroll inside their card; a soft shadow on the cut edge shows there is more to see */
  .table-wrap:not(:has(> .table.stack)) {
    background:
      linear-gradient(to right, var(--tblr-bg-surface) 30%, rgba(255, 255, 255, 0)) left center / 2rem 100% no-repeat local,
      linear-gradient(to left, var(--tblr-bg-surface) 30%, rgba(255, 255, 255, 0)) right center / 2rem 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(31, 41, 55, .16), transparent) left center / .75rem 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(31, 41, 55, .16), transparent) right center / .75rem 100% no-repeat scroll,
      var(--tblr-bg-surface);
  }
}
@media (max-width: 768px) {
  .table td { padding-inline: .625rem; }
  /* the empty row sits on the visible (start) side of a table that is wider than the screen */
  .table td.empty.empty { text-align: start; }
  .table td.empty.empty::before { margin-inline: 0; }
  dl.kv { grid-template-columns: minmax(0, 1fr); gap: .125rem; }
  dl.kv dd { margin-bottom: .5rem; }

  /* Tables that opt in (<table class="table stack">): each row becomes a small card,
     every value labelled with its column title (data-label is filled by app.js). */
  .table-wrap:has(> .table.stack) { overflow: visible; }
  .card.table-wrap:has(> .table.stack) { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tfoot { display: block; width: 100%; }
  .table.stack tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem; padding: .875rem 1rem; margin-bottom: .625rem;
    background: var(--tblr-bg-surface); border: 1px solid var(--tblr-border-color-translucent); border-radius: var(--tblr-border-radius-lg); box-shadow: var(--tblr-shadow-card);
  }
  .table.stack tbody tr:hover { background: var(--tblr-bg-surface); }
  .card .table.stack tr > td, .table.stack td { display: block; padding: 0; border: 0; text-align: start; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
  .table.stack td.num { text-align: start; direction: inherit; }
  .table.stack td[data-label]::before {
    content: attr(data-label); display: block; font-size: .75rem; line-height: 1rem; color: var(--tblr-secondary); font-weight: var(--tblr-font-weight-medium); margin-bottom: .125rem;
  }
  .card .table.stack tr > td:empty { display: none; }
  .table.stack td.actions { grid-column: 1 / -1; text-align: start; }
  .card .table.stack tr > td.actions, .table.stack td.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
  .table.stack td.actions > .btn, .table.stack td.actions > form { flex: 1 1 0; min-width: max-content; margin: 0 !important; }
  .table.stack td.actions > form { display: flex; }
  .table.stack td.actions .btn { width: 100%; }
  .card .table.stack tr > td:first-child, .card .table.stack tr > td:last-child { padding: 0; }
  /* A card that only holds a stacked table gives way to the row cards */
  .card:has(> .table-wrap > .table.stack):not(:has(> h2, > h3, > .card-header, > form, > p, > dl, > .grid, > .alert)) { background: transparent; border: 0; box-shadow: none; padding: 0; }
  /* inside a card that keeps its header, the row cards are flat */
  .card:has(> h2, > h3, > .card-header, > form, > p, > dl) .table.stack tr, .card form .table.stack tr { box-shadow: none; background: var(--tblr-bg-surface-secondary); }
  .card:has(> h2, > h3, > .card-header, > form, > p, > dl) > .table-wrap:has(> .table.stack):last-child { margin-bottom: 0; }
  .card > .table-wrap:has(> .table.stack) { margin: 0; width: 100%; }
  .table.stack tbody td:first-child { grid-column: 1 / -1; font-weight: var(--tblr-font-weight-bold); color: var(--tblr-emphasis-color); font-size: .9375rem; }
  .table.stack tbody td:first-child::before { display: none; }
  .table.stack td.num { font-weight: var(--tblr-font-weight-medium); color: var(--tblr-emphasis-color); }
  .table.stack td.num[data-label]::before { font-weight: var(--tblr-font-weight-medium); }
  .table.stack tfoot tr { background: var(--tblr-gray-100); box-shadow: none; }
  .table.stack tfoot td { background: transparent; }
  .table.stack tr.row-cancelled { opacity: .7; }
  .card.table-wrap:has(> .table.stack) > .pagination { border: 0; padding-inline: 0; }

  /* Sales list row card: number + status / customer / figures */
  .sales-list .table.stack tr { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .625rem .75rem; }
  .sales-list .table.stack tbody td:nth-child(1) { grid-column: 1 / 3; grid-row: 1; align-self: center; }
  .sales-list .table.stack tbody td:nth-child(10) { grid-column: 3; grid-row: 1; justify-self: end; align-self: center; }
  .sales-list .table.stack tbody td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; font-size: 1rem; font-weight: var(--tblr-font-weight-bold); color: var(--tblr-emphasis-color); padding-bottom: .625rem; border-bottom: 1px solid var(--tblr-border-color); }
  .sales-list .table.stack tbody td:nth-child(1)::before, .sales-list .table.stack tbody td:nth-child(3)::before, .sales-list .table.stack tbody td:nth-child(10)::before { display: none; }
  .sales-list .table.stack tbody td:nth-child(1) a { font-weight: var(--tblr-font-weight-bold); }
  .sales-list .table.stack tbody td:nth-child(7) { color: var(--tblr-danger-text); font-weight: var(--tblr-font-weight-bold); }
  .sales-list .table.stack tfoot tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sales-list .table.stack tfoot td:first-child { grid-column: 1 / -1; }
}

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .nav-backdrop, .no-print, .page-head .tools, .alert, .filter-toggle { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .card, .stat { box-shadow: none; border: 0; padding: 0; }
  .card > h2:first-child, .card > h3:first-child { margin: 0 0 .5rem; padding: 0; border: 0; }
  .card > .table-wrap, .card > table.table { margin: 0; width: 100%; }
}
@media (min-width: 769px) { body.nav-collapsed .content { max-width: none; } }
.error-page .error-icon { --avatar-size: 3.5rem; color: var(--tblr-danger); background: #fbebeb; box-shadow: none; margin-bottom: 1rem; }
.error-page .error-icon .icon { width: 2rem; height: 2rem; }
td.empty, .table td.empty { display: table-cell; text-align: center; }
td.empty::before { display: block; margin: 0 auto .5rem; }

/* ---------- Rollout to every page: shared pieces ---------- */
/* "Back" arrows point to the reading start: flipped in Arabic */
[dir="rtl"] .icon.flip-rtl { transform: scaleX(-1); }
/* Card header with a title and tools (Tabler card-header + card-actions) */
.card > .card-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem;
  margin: calc(-1 * var(--tblr-card-spacer-y)) calc(-1 * var(--tblr-card-spacer-x)) var(--tblr-card-spacer-y);
  padding: .75rem var(--tblr-card-spacer-x); border-bottom: 1px solid var(--tblr-border-color-translucent); min-height: 3.5rem;
}
.card-header h2, .card-header h3 { margin: 0; font-size: 1rem; line-height: 1.5rem; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; }
.card-header .tools, .card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.card-header h2 > .icon, .card > h2:first-child > .icon, .card > h3:first-child > .icon { color: var(--tblr-secondary); }
.card > .card-header + .table-wrap, .card > .card-header + table.table { margin-top: calc(-1 * var(--tblr-card-spacer-y)); }
.card > .card-header + .table-wrap .table thead th, .card > .card-header + table.table thead th { border-top: 0; }
/* A card nested inside a form card is a flat section */
.card .card { box-shadow: none; }
p.hint { margin: 0 0 .75rem; }
.card > p:last-child, .card > .hint:last-child { margin-bottom: 0; }
/* Radio / checkbox choices in a row */
.choice-group { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center; }
.choice-group label, label.check { display: inline-flex; align-items: center; gap: .5rem; font-weight: 400; cursor: pointer; }
/* Receipt preview */
.receipt-img { display: block; max-width: 100%; max-height: 26rem; border-radius: var(--tblr-border-radius); border: 1px solid var(--tblr-border-color); }
/* Inputs inside a table cell */
.table td input[type="number"], .table td input[type="text"], .table td select { min-width: 6.5rem; }
.table td input.w-sm { max-width: 9rem; }
/* A hint / button under a table inside a card */
.table-wrap + .table-note, table.table + .table-note { margin: 1rem 0 0; }
.card > .table-wrap:has(+ .table-note) { margin-bottom: 0; }
.card.table-wrap > .table-note { margin: 0; padding: .75rem var(--tblr-card-spacer-x); border-top: 1px solid var(--tblr-border-color); }
.narrow-card { max-width: 32rem; }
.narrow-card .field + .field { margin-top: 1rem; }
.audit-pre { white-space: pre-wrap; max-width: 60ch; font-size: .75rem; margin: .5rem 0 0; padding: .5rem .75rem; background: var(--tblr-gray-50); border: 1px solid var(--tblr-border-color); border-radius: var(--tblr-border-radius); overflow-wrap: anywhere; }
details > summary { cursor: pointer; }
/* A titled section inside a form card */
.form-section, .card > h2.form-section, .card > h3.form-section {
  margin: 1.5rem 0 1rem; padding: 1rem 0 0; border-top: 1px solid var(--tblr-border-color-translucent);
  font-size: 1rem; line-height: 1.5rem;
}
/* Expense categories: name + active + save in one row */
.cat-edit { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin: 0; }
.cat-edit input[name="name"] { flex: 1 1 12rem; max-width: 18rem; }
.cat-edit label.check { flex: none; white-space: nowrap; }
@media (max-width: 768px) { .cat-edit input[name="name"] { max-width: none; flex-basis: 100%; } .cat-table td:first-child { font-weight: 400; } }
/* A computed figure shown in a form (totals): looks like a read-only field */
.form-figure {
  padding: .5625rem .75rem; min-height: calc(1.25rem + 1.125rem + 2px); border-radius: var(--tblr-border-radius);
  background: var(--tblr-gray-50); border: 1px solid var(--tblr-border-color); font-weight: var(--tblr-font-weight-medium); color: var(--tblr-emphasis-color);
}
.form-figure.total { background: var(--tblr-primary-lt); border-color: transparent; color: var(--tblr-primary); font-size: 1rem; }
.att-mark .icon { width: 1rem; height: 1rem; color: var(--tblr-secondary); }
/* Dates: always readable (LTR digits) */
input[type="date"], input[type="month"] { direction: ltr; min-width: 0; }
[dir="rtl"] input[type="date"], [dir="rtl"] input[type="month"] { text-align: right; }

/* File picker: the real <input type="file"> lies over a translated button (app.js wraps it) */
.file-pick {
  position: relative; display: flex; align-items: center; gap: .625rem; min-width: 0; max-width: 100%;
  padding: .3125rem; padding-inline-end: .75rem; background: var(--tblr-bg-surface);
  border: 1px dashed var(--tblr-border-dark-color); border-radius: var(--tblr-border-radius); cursor: pointer;
}
.file-pick:hover { border-color: var(--tblr-primary); background: rgba(var(--tblr-primary-rgb), .03); }
.file-pick > input[type="file"] {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; opacity: 0; cursor: pointer; border: 0; box-shadow: none;
}
.file-pick .file-pick-btn { padding: .375rem .75rem; pointer-events: none; flex: none; }
.file-pick .file-pick-name { min-width: 0; flex: 1 1 auto; color: var(--tblr-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-pick.has-file .file-pick-name { color: var(--tblr-emphasis-color); font-weight: var(--tblr-font-weight-medium); }
.file-pick:focus-within { border-color: var(--tblr-primary); box-shadow: var(--tblr-focus-ring); }
.att-form .file-pick { flex: 1 1 16rem; }
.file-pick.drag, .file-pick.pasted { border-color: var(--tblr-primary); border-style: solid; background: rgba(var(--tblr-primary-rgb), .07); }
.file-pick-preview { display: flex; align-items: center; gap: .625rem; margin-top: .5rem; }
.file-pick-preview img { max-width: 12rem; max-height: 8rem; object-fit: contain; border: 1px solid var(--tblr-border-color); border-radius: var(--tblr-border-radius); background: var(--tblr-bg-surface); }
.att-list li { flex-wrap: nowrap; }
.att-list li:last-child { border-bottom: 0; }
.att-icon { --avatar-size: 2.25rem; }
.att-icon .icon { width: 1.25rem; height: 1.25rem; }
.att-info { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.att-list li > form { flex: none; }
.att-list + .att-form, .att-none + .att-form { padding-top: 1rem; border-top: 1px solid var(--tblr-border-color-translucent); }
.att-none { margin: 0 0 1rem; }
.att-hint { flex: 1 0 100%; }
.archive-regen { margin-top: 1rem; }
.table td a > .icon { width: 1rem; height: 1rem; margin-inline-end: .25rem; vertical-align: -.125rem; }

@media (max-width: 768px) {
  .card > .card-header { padding-block: .625rem; min-height: 0; }
  /* Dates take a whole row on the phone so the date is never cut off */
  .filters.collapsible .field:has(> input[type="date"]), .filters .field:has(> input[type="date"]) { flex: 1 1 100%; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .table.stack td input, .table.stack td select { max-width: none; width: 100%; }
  .card-header .tools .btn { flex: 1 1 auto; }
  /* lists with many figures: three per line */
  .table.stack.stack-3 tr { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem .75rem; }
  .table.stack.stack-3 td[data-label]::before { font-size: .6875rem; }
}
@media (min-width: 560px) and (max-width: 768px) {
  /* tablets: row cards use the extra width */
  .table.stack tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .table.stack.stack-3 tr { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 440px) and (max-width: 768px) {
  /* wider phones / small tablets: from-to dates side by side again */
  .filters.collapsible .field:has(> input[type="date"]), .filters .field:has(> input[type="date"]) { flex: 1 1 calc(50% - .75rem); }
  .form-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}
