/* SavdoCRM design system.
   Server-rendered Django templates, no client framework -- this file is
   the entire visual layer. Everything is driven by the CSS custom
   properties below so a future rebrand only has to change values here. */

:root {
  color-scheme: light;
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;

  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-soft: #eef2ff;
  --color-secondary: #7c3aed;

  --color-sidebar: #0f2540;
  --color-sidebar-surface: #15304f;
  --color-sidebar-hover: #1c3d63;
  --color-sidebar-active: #26507f;
  --color-sidebar-border: #1e3a5c;
  --color-sidebar-text: #b7c4d6;
  --color-sidebar-text-active: #ffffff;
  --color-sidebar-muted: #7e93ad;

  --color-success: #16a34a;
  --color-success-bg: #ecfdf3;
  --color-success-text: #166534;
  --color-warning: #d97706;
  --color-warning-bg: #fffaeb;
  --color-warning-text: #92400e;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-danger-bg: #fef2f2;
  --color-danger-text: #991b1b;
  --color-info-bg: #eef2ff;
  --color-info-text: #3730a3;
  --color-neutral-bg: #f1f3f6;
  --color-neutral-text: #475467;

  --color-background: #f4f5f8;
  --color-surface: #ffffff;
  --color-border: #e3e6ec;
  --color-input-border: #ccd2db;
  --color-text: #1c2333;
  --color-muted: #64748b;
  --color-heading: #101828;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 16px 36px rgba(16, 24, 40, 0.14);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --sidebar-width: 264px;
  --topbar-height: 64px;
  --content-max: 1600px;
  --form-max: 820px;

  --focus-ring: 3px solid #4f46e5;
  --focus-ring-offset: 2px;

  background: var(--color-background);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3, h4 { color: var(--color-heading); line-height: 1.25; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 28px 0 12px; }
h3 { font-size: 1rem; margin: 20px 0 10px; }
p { margin: 0 0 12px; }
a { color: var(--color-primary); }
code { background: var(--color-neutral-bg); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }

@media (prefers-reduced-motion: no-preference) {
  .app-sidebar, .dropdown-menu, .alert { transition: transform 0.15s ease, opacity 0.15s ease; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

.icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: -0.15em;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 200;
  padding: 12px 16px;
  background: var(--color-sidebar);
  color: #fff;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }
:focus-visible { outline: var(--focus-ring); outline-offset: var(--focus-ring-offset); }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------------
   Application shell: sidebar + topbar + content, CSS grid based so it
   scales to the full viewport instead of a fixed narrow column.
   --------------------------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  grid-template-areas: "sidebar topbar" "sidebar main";
  min-height: 100vh;
}

.app-sidebar {
  grid-area: sidebar;
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}
.app-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-height);
  padding: 0 20px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  border-bottom: 1px solid var(--color-sidebar-border);
  flex-shrink: 0;
}
.app-sidebar-brand .icon { color: var(--color-secondary); }
.app-sidebar-nav { flex: 1; padding: 12px 12px 12px; overflow-y: auto; }
.app-sidebar-section {
  margin: 18px 0 6px;
  padding: 0 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-sidebar-muted);
}
.app-sidebar-section:first-child { margin-top: 4px; }
.app-sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
}
.app-sidebar-link .icon { flex-shrink: 0; width: 18px; height: 18px; }
.app-sidebar-link:hover { background: var(--color-sidebar-hover); color: var(--color-sidebar-text-active); }
.app-sidebar-link[aria-current="page"] {
  background: var(--color-sidebar-active);
  color: var(--color-sidebar-text-active);
  font-weight: 600;
}
.app-sidebar-footer {
  border-top: 1px solid var(--color-sidebar-border);
  padding: 12px;
  flex-shrink: 0;
}
.app-sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; color: var(--color-sidebar-text-active); font-size: 0.88rem; }
.app-sidebar-user-meta { min-width: 0; }
.app-sidebar-user-meta strong { display: block; font-size: 0.88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-sidebar-user-meta span { display: block; font-size: 0.76rem; color: var(--color-sidebar-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-sidebar .app-sidebar-link.is-logout { width: 100%; background: transparent; border: 0; text-align: left; cursor: pointer; font: inherit; }

.app-topbar {
  grid-area: topbar;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.app-topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.app-topbar-title { font-size: 1.05rem; font-weight: 700; color: var(--color-heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-topbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.sidebar-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px;
  color: var(--color-text);
}
.env-badge {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.env-badge--dev { background: var(--color-warning-bg); color: var(--color-warning-text); }
.env-badge--prod { background: var(--color-success-bg); color: var(--color-success-text); }

.app-main {
  grid-area: main;
  padding: 28px 32px 56px;
  min-width: 0;
}
.app-main-inner { max-width: var(--content-max); }
.app-main-inner.is-narrow { max-width: var(--form-max); }

/* Unauthenticated / standalone shell: login, error pages, and any page
   rendered without a request context (see tests/test_accessibility_and_error_pages.py). */
.bare-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.bare-shell-inner { width: min(440px, 100%); }

.site-header { display: none; } /* legacy selector kept so any un-migrated fragment doesn't error */

/* ---------------------------------------------------------------------
   Page header, breadcrumbs
   --------------------------------------------------------------------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-header h1 { margin-bottom: 2px; }
.page-header-text p { color: var(--color-muted); margin: 0; }
.page-header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 0.85rem; color: var(--color-muted); margin-bottom: 14px; }
.breadcrumbs a { color: var(--color-muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--color-primary); text-decoration: underline; }
.breadcrumbs .icon { width: 13px; height: 13px; margin: 0 2px; }
.breadcrumbs .is-current { color: var(--color-text); font-weight: 600; }

/* ---------------------------------------------------------------------
   Surfaces / cards
   --------------------------------------------------------------------- */
.card { padding: clamp(18px, 3vw, 28px); border-radius: var(--radius-lg); background: var(--color-surface); box-shadow: var(--shadow-sm); border: 1px solid var(--color-border); }
.card + .card { margin-top: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-header h2 { margin: 0; }
.narrow { max-width: 440px; margin: auto; }
.panel { padding: 14px 16px; margin: 10px 0; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); }
.section-stack > * + * { margin-top: 20px; }

/* ---------------------------------------------------------------------
   Metric cards + distribution bars (dependency-free "charts")
   --------------------------------------------------------------------- */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card { padding: 18px 20px; border-radius: var(--radius-lg); background: var(--color-surface); border: 1px solid var(--color-border); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 10px; }
.metric-card-top { display: flex; align-items: center; justify-content: space-between; }
.metric-card-icon { width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--color-primary-soft); color: var(--color-primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.metric-card-icon .icon { width: 18px; height: 18px; }
.metric-card-label { font-size: 0.82rem; color: var(--color-muted); font-weight: 600; }
.metric-card-value { font-size: 1.7rem; font-weight: 700; color: var(--color-heading); line-height: 1; }
.metric-card-note { font-size: 0.78rem; color: var(--color-muted); }

.distribution-list { display: flex; flex-direction: column; gap: 10px; }
.distribution-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; align-items: center; gap: 12px; font-size: 0.86rem; }
.distribution-label { color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.distribution-track { height: 8px; border-radius: var(--radius-pill); background: var(--color-neutral-bg); overflow: hidden; }
.distribution-fill { height: 100%; border-radius: var(--radius-pill); background: var(--color-primary); }
.distribution-value { color: var(--color-muted); font-variant-numeric: tabular-nums; text-align: right; min-width: 2.5em; }

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */
.btn, button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.2;
}
.btn .icon, button .icon, .button .icon { width: 16px; height: 16px; }
.btn:hover, button:hover, .button:hover { background: var(--color-primary-hover); }
.btn:disabled, button:disabled, .button[aria-disabled="true"] { background: var(--color-neutral-bg); color: var(--color-muted); cursor: not-allowed; border-color: var(--color-border); }
form > button:not(.btn-sm) { margin-top: 18px; }

.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-input-border); }
.btn-secondary:hover { background: var(--color-neutral-bg); }
.btn-outline { background: transparent; color: var(--color-primary); border-color: var(--color-primary); }
.btn-outline:hover { background: var(--color-primary-soft); }
.btn-ghost { background: transparent; color: var(--color-text); border-color: transparent; }
.btn-ghost:hover { background: var(--color-neutral-bg); }
.btn-success { background: var(--color-success); }
.btn-success:hover { background: #12833e; }
.btn-warning { background: var(--color-warning); }
.btn-warning:hover { background: #b45f04; }
.btn-danger, .danger { background: var(--color-danger); }
.btn-danger:hover, .danger:hover { background: var(--color-danger-hover); }
.btn-icon { padding: 8px; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 13px 22px; font-size: 0.95rem; }
.link-button { padding: 0; background: transparent; color: var(--color-primary); font-weight: 500; border: 0; }
.link-button:hover { background: transparent; text-decoration: underline; color: var(--color-primary-hover); }

.button-row, .actions, .title-row, .subnav, .pagination {
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.actions { justify-content: flex-start; }
.actions form, .actions button, .inline { margin: 0; }
.inline { display: inline; }
.inline button, .actions button { padding: 7px 12px; }

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */
label { display: block; margin: 16px 0 6px; font-weight: 600; font-size: 0.88rem; color: var(--color-text); }
.required-mark { color: var(--color-danger); margin-left: 2px; }
.help-text { font-size: 0.8rem; color: var(--color-muted); margin: 4px 0 0; }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-input-border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}
input:focus, select:focus, textarea:focus { border-color: var(--color-primary); }
input[type="checkbox"], input[type="radio"] { width: auto; margin-right: 8px; vertical-align: middle; }
textarea { min-height: 100px; resize: vertical; }
input[type="file"] { border-style: dashed; padding: 18px 12px; }
.field-error { color: var(--color-danger-text); font-size: 0.8rem; margin: 4px 0 0; }
.field-error::before { content: "⚠ "; }
.is-invalid input, .is-invalid select, .is-invalid textarea, input.is-invalid { border-color: var(--color-danger); }
.errorlist { list-style: none; margin: 4px 0 0; padding: 0; color: var(--color-danger-text); font-size: 0.8rem; }
.password-field { position: relative; }
.password-field input { padding-right: 42px; }
.password-toggle { position: absolute; right: 4px; top: 4px; bottom: 4px; background: transparent; color: var(--color-muted); padding: 0 10px; border: 0; }
.password-toggle:hover { background: transparent; color: var(--color-text); }

.form-card { max-width: var(--form-max); }
.form-section + .form-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--color-border); }
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--color-border); flex-wrap: wrap; }
.form-actions .danger-zone { margin-left: auto; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.checkbox-row label { margin: 0; font-weight: 500; }

.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.filter-panel { padding: 16px 18px; border-radius: var(--radius-lg); background: var(--color-surface); border: 1px solid var(--color-border); margin: 0 0 20px; }
.filter-panel label { margin: 0 0 6px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-muted); }
.filter-panel .filter-actions { display: flex; gap: 8px; align-self: end; }
.search-field { position: relative; }
.search-field .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--color-muted); width: 16px; height: 16px; }
.search-field input { padding-left: 36px; }

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--color-border); text-align: left; vertical-align: middle; }
thead th { background: var(--color-neutral-bg); color: var(--color-muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: var(--color-primary-soft); }
tbody tr:last-child td { border-bottom: 0; }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }
td.actions-cell { text-align: right; white-space: nowrap; }
.table-empty-row td { padding: 0; border-bottom: 0; }
.thumb { width: 42px; height: 42px; object-fit: cover; vertical-align: middle; margin-right: 8px; border-radius: var(--radius-sm); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.85em; color: var(--color-muted); }

/* ---------------------------------------------------------------------
   Badges
   --------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.5;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger-text); }
.badge-info { background: var(--color-info-bg); color: var(--color-info-text); }
.badge-neutral { background: var(--color-neutral-bg); color: var(--color-neutral-text); }

/* ---------------------------------------------------------------------
   Alerts / Django messages
   --------------------------------------------------------------------- */
.error { padding: 12px 14px; border-radius: var(--radius-md); background: var(--color-danger-bg); color: var(--color-danger-text); }
.message, .alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--color-info-bg);
  color: var(--color-info-text);
  margin: 0 0 14px;
  border: 1px solid transparent;
}
.message .icon, .alert .icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.message-body { flex: 1; min-width: 0; }
.alert-close { background: transparent; color: inherit; padding: 2px; margin: -2px 0 0; opacity: 0.7; flex-shrink: 0; }
.alert-close:hover { background: transparent; opacity: 1; }
.message.success, .alert-success { background: var(--color-success-bg); color: var(--color-success-text); }
.message.error, .alert-error { background: var(--color-danger-bg); color: var(--color-danger-text); }
.message.warning, .alert-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.message.info, .alert-info { background: var(--color-info-bg); color: var(--color-info-text); }

/* ---------------------------------------------------------------------
   Empty states
   --------------------------------------------------------------------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 24px; color: var(--color-muted); }
.empty-state .icon { width: 40px; height: 40px; color: var(--color-input-border); margin-bottom: 4px; }
.empty-state h3 { margin: 0; color: var(--color-text); }
.empty-state p { margin: 0; max-width: 40ch; }
.empty-state .btn, .empty-state .button { margin-top: 8px; }

/* ---------------------------------------------------------------------
   Pagination
   --------------------------------------------------------------------- */
.pagination { font-size: 0.85rem; color: var(--color-muted); }
.pagination a, .pagination span.current { padding: 6px 11px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); color: var(--color-text); text-decoration: none; }
.pagination span.current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------------------------------------------------------------------
   Misc legacy-compatible primitives
   --------------------------------------------------------------------- */
.container { width: min(var(--content-max), 94vw); margin: 32px auto; }
.wide-card { width: min(var(--content-max), 96vw); margin-left: 50%; transform: translateX(-50%); }
.image-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.image-grid img { width: 100%; max-height: 180px; object-fit: cover; border-radius: var(--radius-sm); }
.store-list { display: grid; gap: 12px; }
.store-list form, .store-list button { width: 100%; text-align: left; }
.store-list button { display: flex; justify-content: space-between; }
dl { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 10px 16px; margin: 0; }
dl.dl-tight { grid-template-columns: 140px minmax(0, 1fr); }
dt { font-weight: 600; color: var(--color-muted); font-size: 0.86rem; }
dd { margin: 0; overflow-wrap: break-word; word-break: break-word; }

/* ---------------------------------------------------------------------
   Auth pages
   --------------------------------------------------------------------- */
.auth-card { text-align: left; }
.auth-logo { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 6px; color: var(--color-heading); font-weight: 700; font-size: 1.2rem; }
.auth-logo .icon { color: var(--color-primary); width: 26px; height: 26px; }
.auth-card h1 { text-align: center; }
.auth-subtitle { text-align: center; color: var(--color-muted); margin-bottom: 4px; }

/* ---------------------------------------------------------------------
   Error pages
   --------------------------------------------------------------------- */
.error-page { text-align: center; }
.error-page .icon { width: 44px; height: 44px; color: var(--color-warning); margin-bottom: 10px; }
.error-page .error-code { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; color: var(--color-muted); text-transform: uppercase; }
.error-page .request-id { font-size: 0.78rem; color: var(--color-muted); margin-top: 16px; }

/* ---------------------------------------------------------------------
   POS: standalone fullscreen page shell (no sidebar/topbar chrome --
   templates/base_pos.html). The POS itself needs the whole viewport.
   --------------------------------------------------------------------- */
html:has(body.pos-body), body.pos-body { height: 100%; }
.pos-page { display: flex; flex-direction: column; height: 100vh; }
.pos-page-topbar {
  flex-shrink: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--color-sidebar);
  color: var(--color-sidebar-text-active);
}
.pos-exit-link { display: flex; align-items: center; gap: 6px; color: inherit; text-decoration: none; font-weight: 600; opacity: 0.9; }
.pos-exit-link:hover { opacity: 1; }
.pos-exit-link .icon { width: 16px; height: 16px; }
.pos-page-title { font-weight: 700; }
.pos-page-meta { margin-left: auto; color: var(--color-sidebar-muted); font-size: 0.85rem; }
.pos-page-main { flex: 1; overflow-y: auto; padding: 16px 20px 32px; }

/* ---------------------------------------------------------------------
   POS operational layout
   --------------------------------------------------------------------- */
.pos-shell { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); gap: 20px; align-items: start; }
.pos-search-bar { display: flex; gap: 10px; margin-bottom: 14px; }
#pos-search-form { margin-bottom: 14px; }
.pos-main-search input { font-size: 1.05rem; padding: 13px 40px 13px 40px; }
.pos-search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  color: var(--color-muted);
  padding: 8px;
}
.pos-search-clear:hover { background: var(--color-neutral-bg); color: var(--color-text); }
.pos-search-clear .icon { width: 14px; height: 14px; }

.pos-results-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.pos-results-category { font-weight: 700; color: var(--color-heading); }
.pos-back-icon { transform: scaleX(-1); }

.pos-category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; max-height: calc(100vh - 220px); overflow-y: auto; padding: 2px; }
.pos-category-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 22px 12px;
  background: var(--color-surface);
  cursor: pointer;
  font: inherit;
  color: var(--color-text);
}
.pos-category-card:hover { border-color: var(--color-primary); background: var(--color-primary-soft); }
.pos-category-card .icon { width: 28px; height: 28px; color: var(--color-primary); }
.pos-category-name { font-weight: 600; font-size: 0.92rem; }

.pos-product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; max-height: calc(100vh - 250px); overflow-y: auto; padding: 2px; }
.pos-product-card {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--color-text);
}
.pos-product-card:hover { border-color: var(--color-primary); box-shadow: var(--shadow-sm); }
.pos-product-card img { width: 100%; height: 80px; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-neutral-bg); }
.pos-product-name { font-weight: 600; font-size: 0.86rem; }
.pos-product-price { color: var(--color-primary); font-weight: 700; }
[data-pos-add] { margin: 0; }

.pos-customer-chip { display: flex; align-items: center; gap: 8px; padding: 8px 12px; margin-bottom: 14px; border-radius: var(--radius-md); background: var(--color-primary-soft); color: var(--color-primary); font-weight: 600; }
.pos-customer-chip form { margin-left: auto; }
.pos-customer-search { position: relative; margin-bottom: 14px; }
#pos-customer-results { position: relative; }
.pos-customer-result-list {
  position: absolute;
  z-index: 10;
  top: 4px;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 220px;
  overflow-y: auto;
}
.pos-customer-result-list form { margin: 0; }
.pos-customer-result {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: transparent;
  color: var(--color-text);
  text-align: left;
  border-radius: 0;
  font: inherit;
}
.pos-customer-result:hover { background: var(--color-neutral-bg); }
.pos-customer-result .icon { color: var(--color-muted); width: 16px; height: 16px; }

.pos-cart { position: sticky; top: 16px; max-height: calc(100vh - 90px); overflow-y: auto; }
.pos-cart-lines { max-height: 32vh; overflow-y: auto; }
.pos-cart-line { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--color-border); font-size: 0.86rem; }
.pos-totals { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--color-border); font-size: 0.9rem; }
.pos-totals .grand-total { font-size: 1.3rem; font-weight: 700; color: var(--color-heading); }
.pos-payment-form { margin-top: 12px; }
.pos-payment-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pos-payment-row select, .pos-payment-row input { width: auto; flex: 1 1 100px; min-width: 84px; padding: 8px 10px; }
.pos-payment-row button { flex-shrink: 0; }
.pos-complete-btn { width: 100%; padding: 15px; font-size: 1rem; margin-top: 14px; }
#pos-error-slot:empty { display: none; }
#pos-error-slot { margin-bottom: 12px; }
.pos-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}

/* ---------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .pos-shell { grid-template-columns: 1fr; }
  .pos-cart { position: static; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "topbar" "main"; }
  .app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-width), 82vw);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .app-shell.sidebar-open .app-sidebar { transform: translateX(0); }
  .app-shell.sidebar-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 39;
  }
  .sidebar-toggle { display: inline-flex; }
  .app-main { padding: 20px 16px 40px; }
  .metric-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

@media (max-width: 640px) {
  .app-topbar { padding: 0 14px; }
  .env-badge { display: none; }
  dl { grid-template-columns: 1fr; }
  .distribution-row { grid-template-columns: 1fr; gap: 4px; }
  .distribution-value { text-align: left; }
  .filter-panel .filter-actions { width: 100%; }
  .filter-panel .filter-actions .btn { flex: 1; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .danger-zone { margin-left: 0; }
}

@media print {
  .app-sidebar, .app-topbar, .skip-link, .pagination, .actions form, form button, .page-header-actions { display: none; }
  .app-shell { display: block; }
  .app-main { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
