:root {
  --bg: #f4f6f8;
  --card: #fff;
  --ink: #16202c;
  --muted: #556274;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --danger: #b91c1c;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

body.modal-open { overflow: hidden; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Cairo", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.muted-row > td { color: var(--muted); }
.small { font-size: 0.8rem; }
[hidden] { display: none !important; }

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 238px;
  flex: 0 0 238px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 0.75rem;
  background: #0f172a;
  color: #e2e8f0;
  z-index: 20;
}

.sidebar-head {
  padding: 0.15rem 0.45rem 0.85rem;
  border-bottom: 1px solid #1e293b;
}

.brand { font-size: 1rem; font-weight: 700; color: #fff; }
.brand-sub { font-size: 0.72rem; color: #94a3b8; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; }

.nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.5rem 0.7rem;
  border-radius: 9px;
  color: #cbd5e1;
  font-size: 0.9rem;
  border-inline-start: 3px solid transparent;
}

.nav a:hover { background: #1e293b; color: #fff; text-decoration: none; }
.nav a.active {
  background: #1e293b;
  color: #fff;
  font-weight: 600;
  border-inline-start-color: var(--brand);
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid #1e293b;
}

.userbox { display: grid; gap: 3px; }
.userbox-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-toggle { display: none; }
.userbox-name { font-weight: 600; color: #fff; font-size: 0.9rem; }
.role-tag {
  justify-self: start;
  font-size: 0.72rem;
  color: #99f6e4;
  background: #134e4a;
  border-radius: 999px;
  padding: 1px 9px;
}

.logout-btn {
  margin-top: 6px;
  padding: 0.35rem 0.6rem;
  border: 1px solid #334155;
  border-radius: 8px;
  background: transparent;
  color: #e2e8f0;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.logout-btn:hover { background: #1e293b; }

.main { flex: 1; min-width: 0; }

.view {
  max-width: 1180px;
  margin: 1.5rem auto 3rem;
  padding: 0 1.5rem;
}

body.logged-out .sidebar { display: none; }
body.logged-out .view { max-width: none; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card { width: 100%; max-width: 360px; padding: 1.75rem; }
.login-brand { font-size: 1.2rem; font-weight: 700; color: var(--brand-dark); }
.login-card p { margin: 4px 0 1.1rem; }
.login-card form { display: grid; gap: 0.75rem; }
.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}

.loading { color: var(--muted); padding: 1.25rem 0; }

.error-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.page-head p { margin: 2px 0 0; font-size: 0.85rem; }
.page-head .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.back {
  display: inline-block;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.back:hover { color: var(--brand); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.stat .label { color: var(--muted); font-size: 0.82rem; }
.stat .value { font-size: 1.5rem; font-weight: 700; line-height: 1.3; }
.stat .hint { color: var(--muted); font-size: 0.8rem; }

.stat-group {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.stat-group-label { font-weight: 700; margin-bottom: 0.6rem; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.stat-row .stat {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 6px);
  padding: 0.55rem 0.75rem;
}

.stat-row .stat .value { font-size: 1.15rem; }

@media (max-width: 560px) {
  .stat-row { grid-template-columns: 1fr; }
}

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

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.7rem;
}

.card-head h2 { font-size: 1rem; }

.card > p.muted:first-of-type { margin-top: -0.4rem; }

.tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}

.tab {
  padding: 0.5rem 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover { color: var(--ink); text-decoration: none; }
.tab.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--brand); }

.table-wrap {
  overflow-x: auto;
  background:
    linear-gradient(to right, var(--card) 30%, transparent),
    linear-gradient(to left, var(--card) 30%, transparent),
    linear-gradient(to right, rgba(15, 23, 42, 0.12), transparent),
    linear-gradient(to left, rgba(15, 23, 42, 0.12), transparent);
  background-position: left center, right center, left center, right center;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.table th {
  text-align: start;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fafc; }
.table .col-warehouse { min-width: 10rem; }
.table tbody tr[data-href] { cursor: pointer; }
.table tbody tr[data-href]:hover { background: #eef7f5; }
.table tbody tr[data-href]:active { background: #e2f2ee; }
.table .sub { display: block; color: var(--muted); font-size: 0.8rem; }
.table .row-title { font-weight: 600; color: var(--ink); }

.table-card { padding: 0; overflow: hidden; }

.table-card .card-head { padding: 0.9rem 1rem 0; margin-bottom: 0.1rem; }

.table-card .table-wrap { padding-bottom: 0.25rem; }

.table-card > .toolbar { padding: 0.9rem 1rem 0; margin-bottom: 0.6rem; }

.table-card > .toolbar h2 { margin: 0; }

.form-section { border-top: 1px solid var(--line); padding-top: 0.9rem; margin-top: 0.9rem; }

.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }

.form-section h3 { font-size: 0.86rem; font-weight: 600; color: var(--muted); margin-bottom: 0.55rem; }

.form-section .check-row { margin-bottom: 0.75rem; }

.form-section .form-grid { gap: 0.75rem; }

.row-actions { white-space: nowrap; text-align: end; }

.row-actions .btn { margin-inline-start: 0.35rem; }

.lines-editor { display: grid; gap: 0.5rem; margin: 0.35rem 0 0.75rem; }

.line-rows { display: grid; gap: 0.5rem; }

.line-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  background: var(--bg, #fff);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
}

.line-row .picker { flex: 1 1 100%; }

.line-row input[type="number"] { flex: 0 0 6.5rem; width: 6.5rem; }

.line-row [name="line_notes"] { flex: 1 1 12rem; min-width: 0; }

.line-row [data-remove-line] { flex: 0 0 auto; margin-inline-start: auto; }

.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.toolbar input[type="search"] {
  flex: 1 1 220px;
  min-width: 220px;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 0.88rem;
  background: #fff;
}

.toolbar input[type="search"]:focus { border-color: #5eead4; }

.list-count { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.spacer { flex: 1; }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  color: var(--muted);
  font-size: 0.82rem;
}
.pager:empty { display: none; }

.coding-head { display: grid; gap: 0.5rem; margin-bottom: 0.75rem; }
.coding-head .toolbar { margin-bottom: 0; }
.coding-head .filters { flex-wrap: nowrap; overflow-x: auto; }
.coding-head .filter { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: progress; }

.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #991b1b; border-color: #991b1b; }
.btn.small { padding: 0.25rem 0.55rem; font-size: 0.8rem; }
.btn.block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.icon-btn:hover { background: #f8fafc; color: var(--ink); }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.ok { background: #ecfdf5; color: var(--ok); border-color: #a7f3d0; }
.badge.warn { background: #fffbeb; color: var(--warn); border-color: #fde68a; }
.badge.danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.badge.info { background: #ecfeff; color: #0e7490; border-color: #a5f3fc; }
.badge.muted { background: #f1f5f9; color: var(--muted); border-color: var(--line); }

.chip-list { display: flex; flex-wrap: wrap; gap: 4px; }

.field { display: flex; flex-direction: column; gap: 4px; }

.field > span { font-size: 0.8rem; color: var(--muted); }

.field input,
.field textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 0.88rem;
  background: #fff;
  color: var(--ink);
}

.field textarea { min-height: 78px; resize: vertical; }

.field input:focus,
.field textarea:focus { border-color: #5eead4; }

.field input[readonly] { background: #f8fafc; color: var(--muted); }

.field.check { flex-direction: row-reverse; align-items: center; justify-content: flex-end; gap: 8px; }
.field.check input { width: auto; }
.field.check > span { font-size: 0.86rem; color: var(--ink); }

.req { font-style: normal; color: var(--danger); margin-inline-start: 2px; }

.check-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  margin-top: 0.75rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}

.check-group-title { font-size: 0.78rem; color: var(--muted); font-weight: 600; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem; }
.form-grid .full { grid-column: 1 / -1; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2.5rem 1rem;
  overflow-y: auto;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
}

.modal-card.wide { max-width: 760px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { font-size: 1rem; }
.modal-body { padding: 1rem; display: grid; gap: 0.75rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
  margin-top: 0.2rem;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  left: 50%;
  right: auto;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  border-radius: 10px;
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
  z-index: 60;
  max-width: min(90vw, 420px);
}

.toast.error { background: var(--danger); }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.65rem 1rem;
}

.info-grid .item { min-width: 0; }
.info-grid .k { color: var(--muted); font-size: 0.8rem; }
.info-grid .v { font-size: 0.9rem; word-break: break-word; }

.empty { text-align: center; color: var(--muted); padding: 1.1rem 0.5rem; font-size: 0.85rem; }


.grant-row td { vertical-align: middle; }
.grant-row label { display: inline-flex; align-items: center; gap: 5px; font-size: 0.8rem; color: var(--muted); }
.grant-row input[type="checkbox"] { width: auto; }

.omni { display: grid; gap: 0.5rem; }

.picker { position: relative; }

.omni-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.omni-field:focus-within {
  border-color: #5eead4;
  box-shadow: 0 3px 14px rgba(13, 148, 136, 0.16);
}

.omni-icon { display: inline-flex; color: var(--muted); }

.omni-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink);
  padding: 0.25rem 0;
}

.picker .omni-input {
  width: 100%;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  padding: 0.45rem 0.6rem;
  font-size: 0.88rem;
}

.picker .omni-input:focus { border-color: #5eead4; }

.omni-list {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  z-index: 30;
  max-height: 17rem;
  overflow-y: auto;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16);
}

.omni-list[hidden] { display: none; }

.omni-list.is-up { top: auto; bottom: calc(100% + 4px); }

.omni > .omni-list { position: static; max-height: 21rem; box-shadow: none; }

.omni-hero .omni-field { padding: 0.7rem 1.1rem; box-shadow: 0 1px 6px rgba(15, 23, 42, 0.08); }

.omni-hero .omni-input { font-size: 1.02rem; }

.omni-hero > .omni-list { border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 0.25rem 0 0; }

.omni-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 0;
  border-radius: 9px;
  background: none;
  font: inherit;
  color: var(--ink);
  text-align: start;
  cursor: pointer;
}

.omni-row.is-active { background: #ecfeff; }

.omni-row:hover { background: #f1f5f9; }

.omni-code {
  flex: 0 0 auto;
  min-width: 5.5rem;
  direction: ltr;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.omni-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.omni-text { display: grid; flex: 1 1 auto; min-width: 0; line-height: 1.35; }

.omni-sub {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.omni-avatar {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #ccfbf1;
  color: #0f766e;
  font-weight: 600;
}

.omni-badge {
  flex: 0 0 auto;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 0.72rem;
}

.omni-empty { padding: 0.8rem 0.6rem; color: var(--muted); font-size: 0.85rem; text-align: center; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.detail-grid .card { margin-bottom: 0; }
.card > h2, .detail-box h2 { margin-bottom: 0.75rem; font-size: 1rem; }
.card > h2 + .form-grid, .card > h2 + .table-wrap { margin-top: 0; }
.card > .form-grid { margin-top: 0.75rem; }
.check-row { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.price-input {
  width: 8rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 0.88rem;
  background: #fff;
  text-align: center;
}
.price-input:focus { border-color: #5eead4; }

.filter-drop { position: relative; flex: 0 0 auto; }

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
}

.filter-btn:focus-visible { border-color: #5eead4; }
.filter-caret { color: var(--muted); font-size: 0.7rem; }

.filter-menu {
  position: absolute;
  inset-inline-start: 0;
  top: calc(100% + 4px);
  z-index: 20;
  width: min(18rem, 80vw);
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 28px rgb(15 23 42 / 14%);
}

.filter-search {
  width: 100%;
  flex: none;
  min-width: 0;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  background: #fff;
}

.filter-search:focus { border-color: #5eead4; }

.filter-options {
  display: grid;
  gap: 1px;
  max-height: 16rem;
  margin-top: 0.35rem;
  overflow-x: hidden;
  overflow-y: auto;
}

.filter-option {
  padding: 0.35rem 0.5rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.86rem;
  text-align: start;
  cursor: pointer;
}

.filter-option:hover { background: #f1f5f9; }
.filter-option.is-active { background: #ccfbf1; color: #0f766e; font-weight: 600; }

.detail-panel { padding-bottom: 0.5rem; }
.detail-panel .detail-grid .card { background: #f8fafc; box-shadow: none; }
.field.filter-drop { position: relative; }
.field.filter-drop .filter-btn { width: 100%; justify-content: space-between; }
.field.filter-drop .filter-menu { width: max(100%, 12rem); }
.toolbar .filter-menu input.filter-search { flex: none; min-width: 0; width: 100%; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }

  .sidebar {
    position: static;
    width: auto;
    flex: none;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.6rem 0.75rem;
  }

  .sidebar-head { border: 0; padding: 0 0.25rem; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { padding: 0.35rem 0.6rem; border-inline-start-width: 0; }
  .sidebar-foot { margin: 0; margin-inline-start: auto; border: 0; padding: 0; }
  .userbox { display: flex; align-items: center; gap: 6px; }
  .logout-btn { margin: 0; }
  .view { padding: 0 1rem; margin-top: 1rem; }
}

@media (max-width: 900px) {
  .sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; width: 100%; }
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 0.9rem;
    border: 1px solid #334155;
    border-radius: 8px;
    background: transparent;
    color: #e2e8f0;
    font: inherit;
    cursor: pointer;
  }
  .nav { display: none; width: 100%; flex-direction: column; }
  body.nav-open .nav { display: flex; }
  .sidebar-foot { order: 3; width: 100%; margin: 0; }
  .userbox { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
  .btn, .icon-btn, .nav a, .logout-btn { min-height: 40px; }
  .view { padding: 0 0.75rem; }
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .toolbar input[type="search"] { min-width: 0; }
  .modal { padding: 0; }
  .modal-card, .modal-card.wide { max-width: none; min-height: 100%; border-radius: 0; }
}

.pre { white-space: pre-wrap; }
.field.inline { flex-direction: row; align-items: center; gap: 6px; }
.field.inline input { width: auto; }
.report-filters { align-items: flex-end; }
.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 84px;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0.25rem;
  border-bottom: 1px solid var(--line);
}

.setting-row:first-child { padding-top: 0.25rem; }
.setting-row:last-child { padding-bottom: 0.25rem; border-bottom: 0; }
.setting-info { display: grid; gap: 2px; }
.setting-info label { font-weight: 600; }
.setting-info small { font-size: 0.8rem; }

.setting-row .price-input { width: 100%; }
.setting-row input[readonly] { background: #f8fafc; color: var(--muted); }

@media (max-width: 560px) {
  .setting-row { grid-template-columns: 1fr auto; }
  .setting-info { grid-column: 1 / -1; }
}

.chat {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 4.5rem);
  min-height: 24rem;
  max-width: 820px;
  margin-inline: auto;
}

.chat .page-head { flex: none; }

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 1rem;
  scrollbar-width: none;
}

.chat-log::-webkit-scrollbar { display: none; }

.chat-msg { display: flex; align-items: flex-start; gap: 0.6rem; }
.chat-msg.bot { justify-content: flex-end; }

.chat-bubble {
  max-width: 80%;
  padding: 0.55rem 0.85rem;
  background: #e6f4f1;
  border: 1px solid #cce8e2;
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}

.chat-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
}

.chat-text {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 85%;
  padding: 0.55rem 0.85rem;
  background: #eceff2;
  border: 1px solid #e3e7ec;
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}
.chat-text > :first-child { margin-top: 0; }
.chat-text > :last-child { margin-bottom: 0; }
.chat-text p, .chat-text ul, .chat-text ol, .chat-text .table-wrap { margin: 0 0 0.6rem; }
.chat-text ul, .chat-text ol { padding-inline-start: 1.3rem; }
.chat-text code { padding: 0 0.3em; background: #eef2f6; border-radius: 4px; }
.chat-text table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.chat-text th, .chat-text td { padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--line); text-align: start; }
.chat-msg.error .chat-text { color: var(--danger); }

.chat-typing { display: flex; gap: 4px; padding: 0.35rem 0; }

.chat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-blink 1.2s infinite ease-in-out;
}

.chat-typing i:nth-child(2) { animation-delay: 0.2s; }
.chat-typing i:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-typing i { animation: none; }
}

.chat-welcome { margin: auto; text-align: center; }
.chat-welcome h2 { margin-bottom: 1rem; font-size: 1.3rem; }
.chat-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }

.chat-chip {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font: inherit;
  cursor: pointer;
}

.chat-chip:hover { border-color: #5eead4; }

.chat-form {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.chat-row { display: flex; align-items: flex-end; gap: 0.5rem; }

.chat-files { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }

.chat-file {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  padding: 0.1rem 0.6rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.chat-file button { padding: 0; border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.chat-bubble .chat-files { margin-top: 0.4rem; }
.chat-thumb { display: block; max-width: 160px; max-height: 120px; border-radius: 8px; }

.chat-form:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }

.chat-form textarea {
  flex: 1;
  min-height: 2.4rem;
  max-height: 9rem;
  padding: 0.45rem 0.5rem;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  resize: none;
  field-sizing: content;
}

.chat-usage { flex: none; margin-top: 0.4rem; color: var(--muted); font-size: 0.75rem; text-align: center; }

.assistant-settings { display: grid; gap: 0.75rem; padding: 1.25rem; }
.assistant-settings textarea { padding: 0.75rem 0.9rem; line-height: 1.8; }
.assistant-settings .btn { justify-self: start; }
.setting-field { display: grid; gap: 0.3rem; }
.setting-field small { font-size: 0.8rem; }
.assistant-limits { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.75rem; }

@media (max-width: 900px) {
  .chat { height: calc(100dvh - 8rem); }
}

@media print {
  .sidebar, .no-print, .modal, .toast { display: none !important; }
  .view { max-width: none; padding: 0; }
  body { background: #fff; }
}

body.pos-terminal .sidebar { display: none; }
body.pos-terminal .view { max-width: none; margin: 0; padding: 0.6rem; }

.pos { display: flex; flex-direction: column; gap: 0.6rem; height: calc(100vh - 1.2rem); }

.pos-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}

.pos-top-info { display: flex; align-items: center; gap: 0.6rem; }
.pos-top-actions { display: flex; gap: 0.4rem; }

.pos-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 400px;
  gap: 0.6rem;
}

.pos-cats { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 0; padding-inline-end: 2px; }
.pos-catalog { display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; min-height: 0; }
.pos-bar { display: flex; gap: 0.6rem; align-items: stretch; }

.pos-cat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  flex: 0 0 auto;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--brand);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.pos-cat.hot { border-inline-start-color: var(--warn); }
.pos-cat:hover { border-color: #5eead4; }
.pos-cat.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pos-cat.active .muted { color: #ccfbf1; }

.pos-search {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}

.pos-search:focus { border-color: #5eead4; outline: none; box-shadow: 0 0 0 3px rgba(94, 234, 212, 0.35); }
.pos-pay-btn kbd { padding: 0 8px; border: 1px solid rgba(255, 255, 255, 0.4); border-radius: 6px; background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 0.75rem; }

.pos-body { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 1rem; }

.pos-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 0.6rem; }

.pos-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
  min-height: 92px;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.pos-item:hover { border-color: #5eead4; box-shadow: 0 2px 10px rgba(15, 118, 110, 0.12); }
.pos-item:active { transform: scale(0.98); }
.pos-item-name { font-weight: 600; line-height: 1.4; }
.pos-item-price { color: var(--brand-dark); font-weight: 700; }

.pos-badge {
  position: absolute;
  inset-block-start: 6px;
  inset-inline-end: 6px;
  min-width: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.78rem;
  text-align: center;
}

.pos-cart { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.pos-cart-head { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); }
.pos-lines { flex: 1; min-height: 0; overflow-y: auto; }
.pos-lines .empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }

.pos-line {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-areas: "name total remove" "qty qty qty";
  align-items: center;
  gap: 0.35rem 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
}

.pos-line-name { grid-area: name; display: flex; flex-direction: column; line-height: 1.35; }
.pos-line-total { grid-area: total; }
.pos-line > .icon-btn { grid-area: remove; }
.pos-line.gone { grid-template-areas: "name remove"; grid-template-columns: 1fr auto; color: var(--danger); }
.pos-qty-box { grid-area: qty; display: flex; align-items: center; gap: 6px; }

.pos-qty-input { width: 5rem; }

.pos-totals { display: grid; gap: 0.5rem; padding: 0.75rem 1rem; border-top: 1px solid var(--line); background: #f8fafc; }
.pos-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.pos-grand { padding-top: 0.5rem; border-top: 1px dashed var(--line); font-size: 1.25rem; }
.pos-discount input { width: 5rem; }
.pos-discount label { flex: 1; }
.pos-pay-btn { padding: 0.9rem; font-size: 1.15rem; font-weight: 700; }

.pos-pay { display: grid; gap: 0.9rem; }
.pos-pay-total { display: flex; justify-content: space-between; align-items: center; font-size: 1.1rem; }
.pos-pay-total strong { font-size: 1.8rem; color: var(--brand-dark); }
.pos-pay-quick { display: flex; flex-wrap: wrap; gap: 6px; }
#pay-in { font-size: 1.5rem; padding: 0.6rem 0.8rem; text-align: center; }

.pos-pay-change {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: #ecfdf5;
  color: var(--ok);
  font-size: 1.1rem;
}

.pos-pay-change strong { font-size: 1.6rem; }
.pos-pay-change.short { background: #fef2f2; color: var(--danger); }
.pos-pay-change.big strong { font-size: 2.4rem; }
.pos-done { display: grid; gap: 0.9rem; text-align: center; }

.check-line { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pos-bill-info { margin-bottom: 0.5rem; }
.pos-close-info { display: grid; gap: 0.4rem; padding: 0.6rem 0.8rem; border-radius: 10px; background: #f8fafc; }

#receipt { display: none; }

@media (max-width: 1100px) {
  .pos-main { grid-template-columns: 160px minmax(0, 1fr) 340px; }
}

@media (max-width: 900px) {
  .pos { height: auto; }
  .pos-main { grid-template-columns: 1fr; }
  .pos-cats { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .pos-body { max-height: 60vh; }
  .pos-cart { min-height: 380px; }
}

@media print {
  @page { size: 80mm auto; margin: 0; }
  body.printing-receipt > *:not(#receipt) { display: none !important; }
  body.printing-receipt #receipt {
    display: block;
    width: 72mm;
    margin: 0 auto;
    padding: 4mm 0;
    background: #fff;
    color: #000;
    font-size: 12px;
    line-height: 1.5;
  }
  #receipt .r-head { display: grid; text-align: center; gap: 2px; padding-bottom: 6px; border-bottom: 1px dashed #000; font-size: 14px; }
  #receipt .r-meta { display: grid; gap: 1px; padding: 6px 0; border-bottom: 1px dashed #000; }
  #receipt .r-meta div,
  #receipt .r-totals div { display: flex; justify-content: space-between; gap: 8px; }
  #receipt .r-lines { width: 100%; border-collapse: collapse; margin: 6px 0; }
  #receipt .r-lines th { text-align: start; border-bottom: 1px solid #000; font-weight: 600; }
  #receipt .r-lines td,
  #receipt .r-lines th { padding: 2px 0; vertical-align: top; }
  #receipt .r-totals { display: grid; gap: 2px; padding-top: 6px; border-top: 1px dashed #000; }
  #receipt .r-grand { font-size: 15px; font-weight: 700; }
  #receipt .r-foot { margin: 10px 0 0; text-align: center; }
}
