@font-face {
  font-family: Vazirmatn;
  src: url("../fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Vazirmatn;
  src: url("../fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root,
html[data-theme="day"] {
  color-scheme: light;
  --ink: #1b2d5a;
  --muted: #5a6d8c;
  --paper: #fff3d6;
  --card: #fffdf8;
  --surface: #fffdf8;
  --wine: #ef6a2f;
  --wine-hot: #d4531c;
  --wine-deep: #1f5ed8;
  --gold: #e39b12;
  --line: #f3d7a2;
  --green: #12a36a;
  --shadow: 0 16px 40px rgba(31, 94, 216, 0.12);
  --side-text: #fff8e8;
  --photo: #ffe6b8;
  --picked: #fff1c9;
  --glow: rgba(227, 155, 18, 0.34);
  --mist: rgba(31, 94, 216, 0.12);
}
html[data-theme="night"] {
  color-scheme: dark;
  --ink: #fff6e4;
  --muted: #d2c4ae;
  --paper: #121a33;
  --card: #1c2748;
  --surface: #26345c;
  --wine: #ff8d4a;
  --wine-hot: #ffb07a;
  --wine-deep: #0e1630;
  --gold: #ffc857;
  --line: #3a4d7a;
  --green: #3dce86;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  --side-text: #fff6e4;
  --photo: #2a3b68;
  --picked: #3a3118;
  --glow: rgba(255, 200, 87, 0.18);
  --mist: rgba(255, 141, 74, 0.1);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, var(--glow), transparent 32%),
    radial-gradient(circle at bottom left, var(--mist), transparent 28%),
    var(--paper);
  font-family: Vazirmatn, Tahoma, sans-serif;
}
a { color: var(--wine); text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
h1, h2 { margin: 0 0 .6rem; font-weight: 700; }
[x-cloak] { display: none !important; }

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: linear-gradient(180deg, #2a6bff 0%, var(--wine-deep) 70%);
  color: var(--side-text);
  padding: 1.2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}
.brand { display: block; color: inherit; }
.brand-logo, .login-logo { display: block; width: 100%; height: auto; }
.login-logo { width: min(240px, 78%); margin: 0 auto .8rem; }
.brand small, .side-user small, .muted, .form-text { color: var(--muted); display: block; }
.side .brand small, .side .side-user small { color: #ffe7b0; }
.live-clock {
  display: block; font-weight: 700; text-align: center;
  font-variant-numeric: tabular-nums;
}
.side .live-clock {
  color: #fff6e4; background: rgba(255, 214, 102, .22);
  border-radius: 12px; padding: .45rem .7rem;
}
.login-card .live-clock { color: var(--ink); margin: 0 0 .8rem; }
.night-note { display: grid; gap: .8rem; }
.night-body { font-size: 1.15rem; line-height: 1.8; }
.night-note audio, .night-note video { width: 100%; max-height: 360px; border-radius: 12px; background: #000; }
.night-slot { display: grid; gap: .55rem; padding-top: .8rem; margin-top: .8rem; border-top: 1px solid var(--line); }
.night-slot h2 { font-size: 1.05rem; }
.broadcast + .broadcast { border-top: 1px solid var(--line); margin-top: .8rem; padding-top: .8rem; }
.category-add, .category-edit {
  display: grid; grid-template-columns: minmax(0, 1.4fr) 110px auto; gap: .45rem; align-items: end;
}
.purchase-add { grid-template-columns: minmax(0, 1fr) auto; }
.category-add { margin-bottom: 1rem; }
.category-row {
  display: flex; flex-wrap: wrap; gap: .45rem; align-items: flex-end;
  margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--line);
}
.category-edit { flex: 1 1 280px; }
.category-row .muted, .category-add .btn, .category-row .btn { margin-bottom: .15rem; }
.side-nav { display: flex; flex-direction: column; gap: .25rem; }
.side-nav a {
  color: var(--side-text); border-radius: 12px; padding: .7rem .8rem;
}
.side-nav a.active, .side-nav a:hover { background: rgba(255, 214, 102, .28); }
.side-user { margin-top: auto; display: flex; justify-content: space-between; gap: .55rem; align-items: center; }
.side-user-name { min-width: 0; flex: 1; }
.side-user-name strong, .side-user-name small {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-avatar {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: none;
  background: #ffc857; color: #1b2d5a; display: inline-grid; place-items: center;
  font-weight: 700; font-size: 1.15rem;
}
.user-avatar-lg { width: 84px; height: 84px; margin-bottom: .8rem; font-size: 2rem; }
.main { padding: 1.4rem 1.4rem 2rem; }
.page-head, .btn-row, .filter-bar, .type-row, .sum-row, .pay-row {
  display: flex; gap: .6rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.page-head { margin-bottom: 1rem; }
.eyebrow { letter-spacing: .08em; color: var(--gold); margin: 0; }
.page-card, .stat, .report-card, .filter-card, .login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.page-card { padding: 1rem 1.1rem; margin-bottom: 1rem; }
.page-card.narrow, .login-card { max-width: 520px; }
.stat-grid, .report-grid, .split {
  display: grid; gap: .8rem; margin-bottom: 1rem;
}
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
.report-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.split { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.stat, .report-card, .filter-card { padding: 1rem; }
.stat span, .report-card span { color: var(--muted); }
.stat strong { display: block; font-size: 1.35rem; margin: .3rem 0; }
a.stat { color: inherit; text-decoration: none; cursor: pointer; }
a.stat:hover { border-color: var(--gold); }
.report-card, .filter-card { color: inherit; display: flex; flex-direction: column; gap: .35rem; min-height: 120px; }
.report-card, .filter-card > a { cursor: pointer; text-decoration: none; }
.report-card:hover, .filter-card:hover, .report-card.is-open, .filter-card:has(> a.is-open) { border-color: var(--gold); }
.filter-card a { color: inherit; display: flex; flex: 1; flex-direction: column; gap: .35rem; }
.panel-report { scroll-margin-top: 1rem; }
.filter-card [hidden] { display: none !important; }
.btn-wine, .btn-line {
  border-radius: 12px; padding: .55rem 1rem; border: 1px solid transparent;
}
.btn-wine { background: var(--wine); color: white; }
.btn-wine:hover, .btn-wine:active { background: var(--wine-hot); color: white; }
html[data-theme="night"] .btn-wine:hover,
html[data-theme="night"] .btn-wine:active { color: #1b2d5a; }
.btn-line { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-line:hover, .btn-line:active { border-color: var(--gold); color: var(--ink); }
.btn:disabled, .btn.disabled { opacity: .55; }
.filter-bar { margin-bottom: 1rem; align-items: end; }
.filter-bar .form-control, .filter-bar .form-select { min-width: 150px; }
.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--ink);
  --bs-table-border-color: var(--line);
  --bs-table-hover-bg: var(--picked);
  --bs-table-hover-color: var(--ink);
}
.gain { color: var(--green); }
.loss { color: var(--wine); }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.app-foot { color: var(--muted); margin-top: 1rem; font-size: .85rem; }
.alert-error { background: #f8d7da; color: #842029; border-radius: 12px; padding: .7rem 1rem; }
html[data-theme="night"] .alert-success { background: #143528; color: #b6f3d0; border-color: #1f6b48; }
html[data-theme="night"] .alert-danger,
html[data-theme="night"] .alert-error { background: #3a1820; color: #ffc9d0; border-color: #7a3040; }
html[data-theme="night"] .alert-warning { background: #3a3118; color: #ffe7b0; border-color: #8a6a20; }
html[data-theme="night"] .alert-info { background: #1a2748; color: #d6e4ff; border-color: #3a4d7a; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: .35rem; margin-bottom: 1rem; }
.form-check {
  display: flex; align-items: center; gap: .55rem;
  min-height: 44px; margin: 0; padding: .25rem 0;
}
.form-check .form-check-input { width: 1.2rem; height: 1.2rem; margin: 0; flex: none; float: none; }
.photo-field { display: grid; gap: .45rem; }
.photo-current, .photo-pick, .photo-clear { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.photo-clear { min-height: 44px; }
.photo-pick { position: relative; }
.photo-chosen { color: var(--muted); }
.photo-native {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; min-height: 0;
}
.total-preview { background: var(--picked); color: var(--ink); border-radius: 12px; padding: .7rem 1rem; }
.form-control, .form-select, .form-control:focus, .form-select:focus {
  background: var(--surface); color: var(--ink); border-color: var(--line);
}
.form-control::placeholder { color: var(--muted); }
input[data-group="3"] { direction: ltr; text-align: left; }
.qty-input { width: 8rem; }
.table { color: var(--ink); }
.theme-toggle {
  border: 0; border-radius: 999px; padding: .45rem .9rem; min-height: 44px;
  background: #ffc857; color: #1b2d5a; font-weight: 700;
}
.side .theme-toggle { width: 100%; margin-top: .4rem; }
.login-tools { display: flex; justify-content: flex-end; margin-bottom: .4rem; }

.login-body {
  min-height: 100vh; display: grid; place-items: center;
  background:
    linear-gradient(145deg, #2f74ff 0%, #7aa2ff 42%, #ffc857 100%);
}
html[data-theme="night"] .login-body {
  background: linear-gradient(160deg, #0c1226 0%, #1a2750 55%, #24386e 100%);
}
html[data-theme="night"] .side {
  background: linear-gradient(180deg, #1a2750 0%, #0c1226 80%);
}
.login-card { padding: 1.6rem; width: min(440px, calc(100% - 2rem)); }
.login-lead { color: var(--muted); }

.pos-layout { display: grid; grid-template-columns: 1fr 360px; gap: 1rem; align-items: start; }
.pos-layout.single { grid-template-columns: minmax(0, 560px); }
.table-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .8rem; }
.table-card {
  display: grid; grid-template-columns: 76px 1fr; gap: .8rem; align-items: center;
  padding: .9rem; background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  color: inherit; box-shadow: var(--shadow);
}
.table-card:hover { border-color: var(--gold); }
.table-card .customer-photo { width: 76px; height: 76px; }
.table-card-body { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.table-total { color: var(--wine); font-size: 1.15rem; }
.settle-person { display: flex; gap: .75rem; align-items: center; margin-bottom: .4rem; }
.settle-person .customer-photo { width: 72px; height: 72px; }
.cat-row, .type-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip, .type-row button, .product-card {
  border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 14px;
}
.chip, .type-row button { padding: .55rem .9rem; }
.chip.on, .type-row button.on { background: var(--wine); color: white; border-color: var(--wine); }
.search-box { margin: .8rem 0; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: .8rem; }
.product-card {
  min-height: 210px; padding: 0 0 .85rem; overflow: hidden; text-align: right;
  display: flex; flex-direction: column; align-items: stretch; gap: .35rem;
  box-shadow: var(--shadow);
}
.product-card:disabled { opacity: .45; }
.product-card strong, .product-card .product-price { padding: 0 .85rem; }
.product-photo {
  height: 132px; background: var(--photo); overflow: hidden; display: grid;
}
.product-photo > * { grid-area: 1 / 1; }
.product-photo img { width: 100%; height: 132px; object-fit: cover; display: block; }
.product-price { color: var(--wine); font-weight: 700; font-size: 1.05rem; }
.prize-block { margin-top: 1.2rem; }
.prize-block h2 { font-size: 1.15rem; margin-bottom: .6rem; }
.customer-photo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; background: var(--photo); display: inline-grid; place-items: center; }
.customer-photo-empty { color: var(--wine); font-weight: 700; font-size: 1.6rem; }
.profile-line { display: flex; gap: .9rem; align-items: center; }
.portal-product { display: flex; gap: .8rem; align-items: center; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.portal-photo { width: 64px; height: 64px; border-radius: 12px; flex: none; }
.portal-photo img { width: 64px; height: 64px; object-fit: cover; }
.qty-label { margin-right: auto; }
.qty-label input { width: 88px; }
.menu-thumb, .form-preview, .cart-thumb { object-fit: cover; border-radius: 10px; background: var(--photo); }
.menu-thumb, .cart-thumb { width: 42px; height: 42px; }
.form-preview { width: 140px; height: 100px; margin-bottom: .8rem; }
.cart-name { display: flex; gap: .45rem; align-items: center; }
.pos-cart {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: .9rem; position: sticky; top: .8rem;
}
.cart-line, .pay-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: .4rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.qty { display: flex; gap: .3rem; align-items: center; }
.qty button, .icon-x {
  width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.sum-row.final { font-size: 1.15rem; color: var(--wine); }
.error { color: var(--wine); }
.open-list { display: grid; gap: .35rem; margin-bottom: .7rem; }
.open-link { display: block; padding: .25rem 0; }
.customer-box { position: relative; margin-bottom: .7rem; display: grid; gap: .4rem; }
.customer-hits {
  position: absolute; z-index: 5; top: 2.6rem; right: 0; left: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 220px; overflow: auto;
}
.customer-hits button {
  width: 100%; text-align: right; background: var(--card); color: var(--ink); border: 0;
  border-bottom: 1px solid var(--line); padding: .45rem .7rem;
  display: flex; justify-content: space-between; gap: .5rem;
}
.customer-picked {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  background: var(--picked); color: var(--ink); border-radius: 12px; padding: .45rem .7rem;
}
.customer-define { display: grid; gap: .4rem; }
.modal-mask {
  position: fixed; inset: 0; background: rgba(36, 20, 16, .46);
  display: grid; place-items: center; padding: 1rem; z-index: 20;
}
.pay-modal {
  background: var(--card); border-radius: 18px; padding: 1rem;
  width: min(640px, 100%); max-height: min(92vh, 100%); overflow: auto;
}
.mobile-total {
  position: fixed; bottom: 12px; left: 12px; right: 12px; z-index: 15;
  background: var(--wine); color: white; border: 0; border-radius: 14px; padding: .9rem;
}
.count-form { display: grid; gap: .6rem; margin-top: 1rem; }

@media (max-width: 991px) {
  .app-shell { grid-template-columns: 1fr; }
  .side {
    position: sticky; top: 0; z-index: 30;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "who who" "brand tools" "clock clock" "nav nav";
    align-items: center;
    gap: .35rem .55rem;
    padding: max(.45rem, env(safe-area-inset-top)) .7rem .4rem;
  }
  .side-user { grid-area: who; margin: 0; }
  .side .live-clock { grid-area: clock; }
  .brand { grid-area: brand; }
  .brand-logo { width: 52px; height: 52px; object-fit: contain; }
  .btn:not(.btn-link), .chip, .form-control, .form-select { min-height: 44px; }
  .table .btn-link, .filter-card .btn-link { min-height: 40px; display: inline-flex; align-items: center; }
  .side-nav {
    mask-image: linear-gradient(to left, transparent, #000 14px, #000 calc(100% - 14px), transparent);
  }
  .page-card .table th:first-child,
  .page-card .table td:first-child {
    position: sticky; inset-inline-start: 0; background: var(--card); z-index: 1;
    box-shadow: -8px 0 8px rgba(27, 45, 90, 0.06);
  }
  .side .theme-toggle { grid-area: tools; justify-self: end; width: auto; margin: 0; min-height: 44px; }
  .side-nav {
    grid-area: nav;
    flex-direction: row; flex-wrap: nowrap; overflow-x: auto;
    gap: .15rem; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav a {
    white-space: nowrap; flex: 0 0 auto;
    min-height: 40px; display: inline-flex; align-items: center;
  }
  .main { padding: .85rem .7rem calc(5.2rem + env(safe-area-inset-bottom)); min-width: 0; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-head .btn { min-height: 44px; }
  .page-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .page-card .table { width: max-content; min-width: 100%; }
  .category-add, .category-edit, .purchase-add { grid-template-columns: 1fr; }
  .category-edit { flex-basis: 100%; }
  .filter-bar { display: grid; grid-template-columns: 1fr; align-items: stretch; }
  .filter-bar .form-control, .filter-bar .form-select, .filter-bar .btn { width: 100%; min-width: 0; }
  .filter-bar label { display: grid; gap: .25rem; }
  input, select, textarea { font-size: 16px; }
  .pos-layout { grid-template-columns: 1fr; }
  .table-grid { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
  .product-card { min-height: 0; }
  .product-photo, .product-photo img { height: 96px; }
  .product-card strong { overflow-wrap: anywhere; }
  .pos-cart { display: none; }
  .pos-cart.open {
    display: block; position: fixed; inset: auto 0 0 0; z-index: 40;
    border-radius: 18px 18px 0 0; max-height: calc(100dvh - 12.2rem); overflow: auto;
    padding-bottom: max(.9rem, env(safe-area-inset-bottom));
  }
  .pos-layout.single .pos-cart { display: block; position: static; max-height: none; border-radius: 18px; }
  .cart-line { grid-template-columns: minmax(0, 1fr) auto auto; }
  .cart-line .cart-name { grid-column: 1 / -1; }
  .pay-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .pay-row .form-select, .pay-row .form-control { width: 100%; min-width: 0; }
  .pay-row .icon-x { justify-self: end; }
  .portal-product { flex-wrap: wrap; }
  .qty-label { margin-right: 0; width: 100%; }
  .qty-label input { width: 100%; }
  .mobile-total { bottom: max(12px, env(safe-area-inset-bottom)); min-height: 48px; }
  .modal-mask { align-items: end; padding: 0; }
  .pay-modal { width: 100%; border-radius: 18px 18px 0 0; }
  .login-card { width: calc(100% - 1.2rem); padding: 1.1rem; }
  .login-logo { width: min(180px, 64%); }
  .profile-line .customer-photo { width: 64px; height: 64px; flex: none; }
  h1 { font-size: 1.35rem; }
}

@media (min-width: 640px) and (max-width: 991px) {
  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .table-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

input.photo-native {
  position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}
.portal-photo { display: grid; place-items: center; }
.portal-photo-empty { font-weight: 700; color: var(--wine); font-size: 1.25rem; }
.print-only { display: none; }

@media print {
  .side, .no-print, .filter-bar, .flash-stack, .app-foot, .theme-toggle { display: none !important; }
  .print-only { display: block !important; }
  body.print-panel .main > :not(#panel-report) { display: none !important; }
  body, .app-shell, .main, .page-card { background: #fff !important; color: #111 !important; box-shadow: none !important; }
  .app-shell { display: block; }
  .main { width: auto; padding: 0; }
  a { color: #111; text-decoration: none; }
  @page { margin: 12mm; }
}
