:root {
  --brand: #9d3c59;
  --brand-dark: #7c2943;
  --brand-soft: #f8e7ec;
  --accent: #d99a5b;
  --ink: #2b2227;
  --muted: #7b6e74;
  --surface: #f6f1ee;
  --card: #ffffff;
  --line: #e9e0dc;
  --sidebar: #241a20;
  --sidebar-2: #1a1216;
  --success: #1f7a5c;
  --danger: #b23a48;
  --warning: #b47a24;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: .925rem;
}

a { color: var(--brand); }
a:hover { color: var(--brand-dark); }

.btn { border-radius: .55rem; font-weight: 600; }
.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark);
  --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-dark);
  --bs-btn-active-border-color: var(--brand-dark);
  --bs-btn-disabled-bg: #c9aab5;
  --bs-btn-disabled-border-color: #c9aab5;
}
.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-dark);
  --bs-btn-active-border-color: var(--brand-dark);
}
.text-brand { color: var(--brand) !important; }
.btn-icon {
  width: 38px; height: 38px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: .55rem; color: var(--ink);
}
.btn-icon:hover { background: #f3ece8; }

/* ------------------------------- App shell ------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 264px;
  flex: 0 0 264px;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #f8ece6;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 1040;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 6px; }

.sidebar-brand {
  display: flex; align-items: center; gap: .7rem;
  padding: 1rem 1rem .8rem;
}
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  display: grid; place-items: center; font-size: 1.25rem; color: #fff;
  box-shadow: 0 6px 18px rgba(157,60,89,.35);
}
.brand-name { font-size: 1.02rem; font-weight: 800; letter-spacing: .02em; }
.brand-sub { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; color: #c8b4bb; }

.sidebar-location {
  margin: .15rem .8rem .7rem;
  padding: .65rem .75rem;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.045);
  border-radius: .65rem;
  font-size: .8rem;
}

.sidebar-nav { display: flex; flex-direction: column; padding: 0 .55rem 1rem; gap: .1rem; }
.nav-heading {
  margin: 1rem .65rem .35rem;
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  font-weight: 700;
  color: #b99da7;
}
.sidebar .nav-link {
  display: flex; align-items: center; gap: .7rem;
  color: #e7d9de; text-decoration: none;
  padding: .55rem .7rem; border-radius: .55rem;
  font-size: .86rem; font-weight: 500;
  border-left: 3px solid transparent;
}
.sidebar .nav-link i { font-size: 1.02rem; width: 1.2rem; text-align: center; color: #c9aab5; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav-link.active {
  background: linear-gradient(90deg, rgba(157,60,89,.45), rgba(157,60,89,.12));
  border-left-color: var(--accent);
  color: #fff;
}
.sidebar .nav-link.active i { color: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding: .85rem 1rem;
  font-size: .7rem;
  color: #ab929c;
  border-top: 1px solid rgba(255,255,255,.07);
}

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 64px;
  padding: 0 1.15rem;
  display: flex; align-items: center; gap: .75rem;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1020;
}
.topbar-title h1 { font-weight: 700; color: var(--ink); }
.location-switch { min-width: 190px; border-color: var(--line); background: #fbf8f6; }
.user-pill {
  display: flex; align-items: center; gap: .5rem;
  background: #fbf8f6; border: 1px solid var(--line);
  padding: .3rem .55rem; border-radius: 3rem; color: var(--ink);
}
.user-pill:hover { background: #f6efeb; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 800;
}

.app-content { flex: 1; padding: 1.15rem; }
.app-footer {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .8rem 1.15rem; border-top: 1px solid var(--line);
  color: var(--muted); font-size: .76rem;
}

/* -------------------------------- Surfaces ------------------------------- */
.card {
  border: 1px solid var(--line);
  border-radius: .9rem;
  background: var(--card);
  box-shadow: 0 2px 12px rgba(54,35,43,.035);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  padding: .85rem 1rem;
}
.card-body { padding: 1rem; }
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.page-head h1, .page-head h2 { margin: 0; font-weight: 800; font-size: 1.35rem; }
.page-head .subtitle { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.stat-card { height: 100%; }
.stat-card .stat-icon {
  width: 42px; height: 42px; border-radius: .75rem;
  display: grid; place-items: center; font-size: 1.15rem;
  background: var(--brand-soft); color: var(--brand);
}
.stat-card .stat-value { font-size: 1.35rem; font-weight: 800; line-height: 1.1; }
.stat-card .stat-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.stat-card .stat-meta { color: var(--muted); font-size: .78rem; }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .62rem .65rem; }
.table thead th {
  color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  font-weight: 700; border-bottom-width: 1px; white-space: nowrap;
}
.table-hover > tbody > tr:hover > * { background: #fcf7f4; }
.table-stack td { vertical-align: middle; }

.badge-soft { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.badge-success-soft { background: #e2f3ec; color: var(--success); }
.badge-danger-soft { background: #fbe5e8; color: var(--danger); }
.badge-warning-soft { background: #fbf0dc; color: var(--warning); }
.badge-muted-soft { background: #eeeae8; color: #6e6268; }

.empty-state { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.empty-state i { font-size: 2.2rem; color: #cbb8b2; display: block; margin-bottom: .5rem; }

.form-label { font-weight: 600; font-size: .8rem; color: #5b4e54; }
.form-control, .form-select {
  border-color: #ded2cd; border-radius: .55rem; padding: .5rem .7rem;
  background-color: #fffdfc;
}
.form-control:focus, .form-select:focus {
  border-color: #c98b9e; box-shadow: 0 0 0 .2rem rgba(157,60,89,.12);
}
.form-text { font-size: .74rem; }
.input-group-text { background: #f8f2ef; border-color: #ded2cd; font-size: .8rem; }
.required::after { content: " *"; color: var(--danger); }

.alert { border: 0; border-radius: .75rem; }
.alert-success { background: #e4f4ed; color: #145c45; }
.alert-danger { background: #fbe6e9; color: #8c2635; }
.alert-warning { background: #fbf0dc; color: #7b5314; }
.alert-info { background: #e8f0f7; color: #29536f; }

.pagination { margin: 0; }
.page-link { color: var(--brand); border-color: var(--line); }
.page-item.active .page-link { background: var(--brand); border-color: var(--brand); }

.nav-tabs { border-color: var(--line); }
.nav-tabs .nav-link { color: var(--muted); font-weight: 600; border: 0; border-bottom: 2px solid transparent; }
.nav-tabs .nav-link.active { color: var(--brand); background: transparent; border-bottom-color: var(--brand); }

.list-group-item { border-color: var(--line); }
.progress { background: #f0e8e4; }

.detail-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.detail-value { font-weight: 600; }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-lg { font-weight: 800; font-size: 1.2rem; }
.text-muted-sm { color: var(--muted); font-size: .78rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.code-chip { background: #f4eeeb; border-radius: .35rem; padding: .1rem .35rem; font-size: .78rem; }

/* --------------------------------- Login --------------------------------- */
.auth-page { background: radial-gradient(1100px 600px at 15% 10%, #4a2737 0, #241a20 55%, #160f13 100%); min-height: 100vh; }
.auth-backdrop { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(600px 300px at 85% 85%, rgba(217,154,91,.15), transparent 70%); }
.auth-shell { position: relative; min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.auth-card {
  width: 100%; max-width: 430px; background: #fff; border-radius: 1.1rem;
  padding: 1.6rem; box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.auth-card .brand-mark { width: 52px; height: 52px; font-size: 1.6rem; }
.auth-alert { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 2000; max-width: 420px; width: calc(100% - 2rem); }
.demo-box { background: #fbf5f2; border: 1px dashed #e0cfc8; border-radius: .65rem; padding: .65rem .75rem; font-size: .75rem; }

/* ---------------------------------- POS ---------------------------------- */
.pos-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 1rem;
  height: calc(100vh - 64px - 2.3rem - 44px);
  min-height: 580px;
}
.pos-products, .pos-cart {
  background: #fff; border: 1px solid var(--line); border-radius: .95rem;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.pos-toolbar { padding: .8rem .9rem; border-bottom: 1px solid var(--line); }
.pos-toolbar .form-control { background: #fff; }
.category-pills { display: flex; gap: .4rem; overflow-x: auto; padding-top: .6rem; scrollbar-width: none; }
.category-pills::-webkit-scrollbar { display: none; }
.category-pill {
  border: 1px solid #e5d8d2; background: #fff; color: #6f5f66;
  font-size: .76rem; font-weight: 600; white-space: nowrap;
  padding: .32rem .7rem; border-radius: 2rem;
}
.category-pill.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.product-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: .6rem; padding: .8rem; overflow-y: auto; align-content: start;
}
.product-tile {
  border: 1px solid #ece2de; border-radius: .75rem; background: #fff;
  padding: .65rem; text-align: left; display: flex; flex-direction: column; gap: .25rem;
  min-height: 112px; transition: transform .08s ease, box-shadow .12s ease, border-color .12s ease;
}
.product-tile:hover { border-color: #d3a7b4; box-shadow: 0 6px 18px rgba(157,60,89,.1); transform: translateY(-1px); }
.product-tile:active { transform: scale(.99); }
.product-tile.out { opacity: .55; }
.product-tile .p-name { font-weight: 700; font-size: .82rem; line-height: 1.2; }
.product-tile .p-sku { font-size: .66rem; color: var(--muted); }
.product-tile .p-price { margin-top: auto; font-weight: 800; color: var(--brand); font-size: .92rem; }
.stock-pill { font-size: .64rem; font-weight: 700; border-radius: 1rem; padding: .12rem .4rem; }
.stock-ok { background: #e4f4ed; color: #1f7a5c; }
.stock-low { background: #fbf0dc; color: #9a6715; }
.stock-out { background: #fbe6e9; color: #a33140; }

.pos-cart-head { padding: .75rem .9rem; border-bottom: 1px solid var(--line); }
.cart-lines { overflow-y: auto; flex: 1; min-height: 90px; }
.cart-line { padding: .55rem .8rem; border-bottom: 1px solid #f1e9e5; }
.cart-line .cl-name { font-weight: 700; font-size: .8rem; line-height: 1.2; }
.cart-line .cl-meta { color: var(--muted); font-size: .7rem; }
.cart-line .cl-total { font-weight: 700; font-size: .82rem; }
.qty-group { display: flex; align-items: center; gap: .2rem; }
.qty-group .btn { width: 26px; height: 26px; padding: 0; font-size: .75rem; line-height: 1; }
.qty-input { width: 58px; text-align: center; padding: .15rem .2rem; font-size: .76rem; }
.line-discount { width: 58px; text-align: right; padding: .15rem .25rem; font-size: .72rem; }
.payment-panel { border-top: 1px solid var(--line); padding: .75rem .9rem; background: #fdfaf8; }
.payment-mode { display: grid; grid-template-columns: repeat(4, 1fr); gap: .3rem; margin-bottom: .6rem; }
.payment-mode .btn { font-size: .7rem; padding: .35rem .2rem; }
.totals-row { display: flex; justify-content: space-between; align-items: baseline; font-size: .8rem; margin-bottom: .18rem; }
.totals-row.total { font-size: 1.1rem; font-weight: 800; color: var(--ink); border-top: 1px dashed #dccbc4; padding-top: .4rem; margin-top: .35rem; }
.change-box { background: #e8f4ee; border: 1px solid #c9e5d8; border-radius: .5rem; padding: .4rem .6rem; font-size: .8rem; }
.pos-cart-body { overflow-y: auto; }
.pos-hint { font-size: .7rem; color: var(--muted); }
.pos-error { font-size: .78rem; }

/* ------------------------------- Utilities ------------------------------- */
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.toolbar .form-control, .toolbar .form-select { min-width: 130px; }
.table-actions { display: flex; gap: .25rem; flex-wrap: wrap; }
.metric-strip { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.metric-strip .metric { min-width: 120px; }
.metric-strip .metric .label { font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; }
.metric-strip .metric .value { font-size: 1.1rem; font-weight: 800; }
.chart-bars { display: flex; align-items: flex-end; gap: .5rem; height: 150px; padding-top: .5rem; }
.chart-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .35rem; justify-content: flex-end; height: 100%; }
.chart-bar .bar { width: 100%; max-width: 42px; background: linear-gradient(180deg, var(--brand), #c97b91); border-radius: .35rem .35rem 0 0; min-height: 3px; }
.chart-bar .bar-label { font-size: .64rem; color: var(--muted); }
.chart-bar .bar-value { font-size: .62rem; color: var(--muted); }
.dashboard-hero {
  background: linear-gradient(115deg, #fff 0%, #fdf6f2 55%, #f9e9ef 100%);
  border: 1px solid var(--line); border-radius: 1rem; padding: 1.1rem 1.2rem;
}
.receipt-preview { max-width: 360px; background: #fff; border: 1px dashed #d7c5bd; padding: 1rem; border-radius: .5rem; }
.purchase-total-box { background: #fdf8f5; border: 1px solid var(--line); border-radius: .65rem; padding: .8rem; }
.purchase-line-grid { display: grid; grid-template-columns: minmax(160px,2fr) 90px 110px 100px 110px 42px; gap: .4rem; align-items: end; }
.role-permissions { max-height: 520px; overflow-y: auto; border: 1px solid var(--line); border-radius: .6rem; padding: .75rem; }
.role-permissions .form-check { font-size: .82rem; }
.perm-group { border-bottom: 1px dashed var(--line); padding-bottom: .65rem; margin-bottom: .65rem; }
.perm-group:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.perm-group-title { font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .35rem; }
.audit-json { max-width: 380px; max-height: 120px; overflow: auto; background: #f7f2ef; border-radius: .35rem; padding: .4rem; font-size: .68rem; white-space: pre-wrap; word-break: break-word; }
.product-thumb { width: 38px; height: 38px; object-fit: cover; border-radius: .45rem; border: 1px solid var(--line); background: #f8f4f1; }
.product-thumb-lg { width: 100%; max-height: 230px; object-fit: cover; border-radius: .7rem; border: 1px solid var(--line); }

/* ------------------------------- Guide ---------------------------------- */
.guide-section { margin-bottom: 1rem; scroll-margin-top: 1rem; }
.guide-section .card-header { font-weight: 700; }
.guide-toc { position: sticky; top: 1rem; }
.guide-toc .list-group-item { border-left: 0; border-right: 0; padding: .5rem .85rem; }
.guide-toc .list-group-item:first-child { border-top: 0; }
.guide-code {
  background: #1f1720;
  color: #f3e9e4;
  border: 1px solid #342630;
  border-radius: .65rem;
  padding: .75rem .9rem;
  font-size: .78rem;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  margin-bottom: 0;
}
.guide-code code { color: inherit; font-size: inherit; }
.guide-section code:not(.guide-code code) { color: var(--brand-dark); }

@media (max-width: 991.98px) {
  .sidebar { height: 100vh; position: fixed; }
  .app-content { padding: .9rem; }
  .pos-page { grid-template-columns: 1fr; height: auto; }
  .pos-products { min-height: 52vh; max-height: 70vh; }
  .pos-cart { min-height: 420px; }
}
@media (max-width: 767.98px) {
  .topbar { padding: 0 .7rem; }
  .app-content { padding: .75rem; }
  .app-footer { flex-direction: column; gap: .2rem; }
  .page-head h1, .page-head h2 { font-size: 1.15rem; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .purchase-line-grid { grid-template-columns: 1fr 1fr; }
  .purchase-line-grid .line-product { grid-column: 1 / -1; }
  .table-responsive { border-radius: .5rem; }
  .metric-strip { gap: 1rem; }
}
@media (max-width: 479.98px) {
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .payment-mode { grid-template-columns: repeat(2, 1fr); }
}

@media print {
  .sidebar, .topbar, .app-footer, .no-print { display: none !important; }
  .app-content { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}
