:root {
  --bg: #ffffff;
  --bg-soft: #f5f9ff;
  --bg-panel: #ffffff;
  --ink: #0f2744;
  --muted: #5a6f8a;
  --blue: #1e8fff;
  --blue-deep: #0b66d6;
  --blue-soft: #e8f3ff;
  --sun: #f5b400;
  --sun-deep: #e88900;
  --sun-soft: #fff6db;
  --danger: #d64545;
  --ok: #1f9d6a;
  --line: #d9e6f5;
  --shadow: 0 10px 30px rgba(15, 70, 140, 0.08);
  --radius: 16px;
  --font: "IBM Plex Sans Arabic", sans-serif;
  --display: "IBM Plex Sans Arabic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  background:
    radial-gradient(900px 420px at 100% -10%, rgba(245, 180, 0, 0.12), transparent 55%),
    radial-gradient(800px 480px at -5% 0%, rgba(30, 143, 255, 0.12), transparent 50%),
    var(--bg);
}

/* لا تعتمد على [hidden] وحده — display في .app-shell كان يُظهر التطبيق تحت صفحة الدخول */
[hidden] { display: none !important; }
.screen { min-height: 100vh; }
#view-login,
#view-app {
  display: none !important;
}
body.is-auth #view-login {
  display: block !important;
}
body.is-app #view-app {
  display: flex !important;
}
body.is-auth {
  overflow: auto;
  background:
    radial-gradient(900px 420px at 100% -10%, rgba(245, 180, 0, 0.12), transparent 55%),
    radial-gradient(800px 480px at -5% 0%, rgba(30, 143, 255, 0.12), transparent 50%),
    var(--bg);
}
body.is-app #view-login,
body.is-auth #view-app {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
  height: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
.login-shell {
  max-width: 440px;
  margin: 0 auto;
  padding: 8vh 1.25rem 3rem;
  animation: rise 0.6s ease both;
  text-align: center;
}
.login-logo {
  width: min(280px, 78vw);
  height: auto;
  display: block;
  margin: 0 auto 1rem;
  filter: drop-shadow(0 10px 24px rgba(11, 102, 214, 0.18));
}
.brand-block { margin-bottom: 1.25rem; }
.brand, .brand-sm {
  font-family: var(--display);
  color: var(--blue-deep);
  letter-spacing: 0.01em;
  margin: 0 0 0.25rem;
  font-weight: 700;
}
.brand { font-size: 1.15rem; }
.brand-sm { font-size: 0.95rem; }
.top-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.top-brand img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}
h1 {
  font-family: var(--display);
  font-size: clamp(1.55rem, 3.5vw, 2rem);
  margin: 0 0 0.45rem;
  color: var(--ink);
}
.lead { color: var(--muted); margin: 0 0 1.5rem; line-height: 1.7; }
.stack { display: grid; gap: 0.85rem; text-align: right; }
label { display: grid; gap: 0.35rem; font-size: 0.92rem; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  box-shadow: inset 0 1px 2px rgba(15, 70, 140, 0.03);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(30, 143, 255, 0.25);
  border-color: var(--blue);
}
textarea { min-height: 80px; resize: vertical; }
.btn {
  border: 0;
  border-radius: 14px;
  padding: 0.85rem 1.2rem;
  min-height: 48px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff;
  box-shadow: 0 8px 18px rgba(11, 102, 214, 0.25);
}
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost {
  background: #fff;
  color: var(--blue-deep);
  border: 1px solid var(--line);
}
.btn-block { width: 100%; }
.btn.icon-btn {
  padding: 0.55rem 0.85rem;
  min-height: 44px;
  border-radius: 12px;
  background: var(--blue-soft);
  color: var(--blue-deep);
  border: 0;
}
.error { color: var(--danger); margin: 0; }

/* —— App shell —— */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 100%;
  background: var(--bg-soft);
}
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  box-shadow: 0 2px 12px rgba(15, 70, 140, 0.06);
}
.top-brand-text { text-align: right; }
.top-brand-text strong {
  display: block;
  font-size: 0.95rem;
  line-height: 1.3;
  max-width: 52vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.55rem 0.85rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.admin-tabs::-webkit-scrollbar { display: none; }
.admin-tabs button {
  flex: 0 0 auto;
  border: 0;
  background: var(--bg-soft);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.admin-tabs button.active {
  background: var(--blue-deep);
  color: #fff;
}
.app-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 0.35rem 0.15rem calc(0.35rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(15, 70, 140, 0.08);
  backdrop-filter: blur(12px);
}
.app-tabbar[hidden] { display: none !important; }
.tab-item {
  border: 0;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.35rem 0.15rem;
  min-height: 56px;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 12px;
}
.tab-item .tab-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
}
.tab-badge {
  position: absolute;
  top: -6px;
  left: -8px;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: var(--sun);
  color: #1a1200;
  font-size: 0.68rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  line-height: 1;
}
.tab-badge[hidden] { display: none !important; }
.sticky-checkout {
  position: sticky;
  bottom: calc(72px + env(safe-area-inset-bottom));
  background: #fff;
  padding: 0.75rem 0 0.25rem;
  z-index: 2;
}
.cart-fab { display: none !important; }
.tab-item.active {
  color: var(--blue-deep);
  background: var(--blue-soft);
}
.tab-item.active .tab-icon {
  transform: translateY(-1px);
}

body.role-customer .main {
  padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
}
body.role-customer .main.has-order-footer {
  padding-bottom: calc(11.5rem + env(safe-area-inset-bottom));
}
body.role-customer .order-footer {
  bottom: calc(60px + env(safe-area-inset-bottom));
  padding-bottom: 0.65rem;
}
body.role-customer .toast {
  bottom: calc(5.25rem + env(safe-area-inset-bottom));
}
body.role-customer.order-footer-on .toast {
  bottom: calc(10.5rem + env(safe-area-inset-bottom));
}
body.role-admin .app-tabbar {
  display: none !important;
}
body.role-admin .main {
  padding-bottom: 2rem;
}

/* legacy topbar kept for safety */
.topbar {
  display: flex; align-items: center; gap: 1rem; justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 18px rgba(15, 70, 140, 0.05);
}
.nav { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.nav button {
  background: transparent; color: var(--muted); border: 0; border-radius: 999px;
  padding: 0.45rem 0.85rem; font: inherit; cursor: pointer;
}
.nav button.active {
  background: var(--blue-soft);
  color: var(--blue-deep);
  font-weight: 600;
}
.main { padding: 1rem 1rem 1.5rem; max-width: 1400px; margin: 0 auto; width: 100%; animation: rise 0.35s ease both; flex: 1; }
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.15rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.panel h2 {
  font-family: var(--display);
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  color: var(--blue-deep);
}
.auth-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.15rem 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  text-align: right;
}
.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.linkish {
  border: 0;
  background: transparent;
  color: var(--blue-deep);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0.35rem 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.auth-title {
  margin: 0 0 0.35rem;
  color: var(--blue-deep);
  font-size: 1.15rem;
}
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; min-width: 1100px; }
.catalog-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.catalog-empty {
  padding: 1.25rem 0.5rem;
  text-align: center;
}
.catalog-sort-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.catalog-sort-bar label {
  flex: 1 1 160px;
  margin: 0;
}
.catalog-sort-bar select {
  margin-top: 0.25rem;
}
.catalog-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem 0.95rem 1rem;
  box-shadow: 0 4px 14px rgba(15, 70, 140, 0.05);
}
.catalog-card.is-unavailable {
  opacity: 0.78;
  background: #fafbfc;
}
.cat-title {
  margin: 0 0 0.25rem;
  font-size: 1.02rem;
  line-height: 1.45;
  color: var(--ink);
  font-weight: 700;
}
.cat-meta {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  margin-bottom: 0.55rem;
}
.cat-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0.55rem 0 0.75rem;
}
.cat-stat {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.45rem 0.55rem;
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}
.cat-stat span {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.3;
}
.cat-stat strong {
  font-size: 1rem;
  color: var(--blue-deep);
  font-variant-numeric: tabular-nums;
}
.cat-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.cat-price-tag {
  flex: 0 0 auto;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--blue-deep);
  white-space: nowrap;
}
.cat-price-tag span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}
.shop-card .cat-card-foot {
  justify-content: flex-end;
}
.btn-add {
  min-width: 8.5rem;
  border-radius: 12px;
}
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--blue-soft);
  border-radius: 999px;
  padding: 0.2rem;
}
.step-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--blue-deep);
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  flex: 0 0 auto;
}
.step-input {
  width: 3.4rem;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--blue-deep);
  background: #fff;
  padding: 0.2rem 0.15rem;
  -moz-appearance: textfield;
}
.step-input::-webkit-outer-spin-button,
.step-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.add-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.add-row .add-qty {
  width: 4.5rem;
  min-height: 44px;
}
.step-val {
  min-width: 1.75rem;
  text-align: center;
  font-weight: 800;
  color: var(--blue-deep);
}
.cart-fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(72px + env(safe-area-inset-bottom));
  z-index: 28;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff;
  box-shadow: 0 10px 28px rgba(11, 102, 214, 0.35);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  max-width: min(92vw, 420px);
  width: auto;
}
.cart-fab,
.cart-fab[hidden] { display: none !important; }
body.has-cart-fab.role-customer .main {
  padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
}
.cart-list {
  display: grid;
  gap: 0.75rem;
  margin: 1rem 0;
}
.cart-line {
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.cart-line-main { flex: 1; min-width: 0; }
.cart-line-main h3 {
  margin: 0 0 0.25rem;
  font-size: 0.98rem;
  line-height: 1.4;
}
.cart-line-side {
  display: grid;
  gap: 0.35rem;
  justify-items: end;
}
.cart-line-total { color: var(--blue-deep); }
.cart-note { display: grid; gap: 0.35rem; margin: 1rem 0; }
.cart-checkout {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.cart-grand {
  display: block;
  font-size: 1.35rem;
  color: var(--blue-deep);
}
.order-cards {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.85rem;
}
.order-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  background: #fff;
}
.order-card.compact { padding: 0.75rem; }
.order-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.order-card-meta { margin-top: 0.25rem; font-size: 0.85rem; }
.cat-avail {
  display: flex;
  align-items: center;
  min-height: 2rem;
}
.cat-qty {
  flex: 1 1 140px;
  margin: 0;
  font-size: 0.85rem;
}
.cat-qty .qty {
  width: 100%;
  max-width: none;
  margin-top: 0.3rem;
  min-height: 48px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  border-radius: 12px;
}
.catalog-card .qty-err {
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 0.35rem;
}
.catalog-card .qty-invalid {
  border-color: var(--danger) !important;
  background: #fff5f5;
}

@media (min-width: 720px) {
  .cat-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .catalog-list {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    align-items: start;
  }
}

/* جدول الكتالوج القديم (إن وُجد) */
table.catalog-table {
  width: max(100%, 1350px);
  table-layout: auto;
}
table.catalog-table th {
  white-space: nowrap;
  line-height: 1.35;
  font-size: 0.88rem;
  padding: 0.75rem 0.7rem;
  vertical-align: bottom;
}
table.catalog-table th.sortable {
  cursor: pointer;
  user-select: none;
}
table.catalog-table th.sortable:hover {
  background: #dcebff;
}
table.catalog-table th.sortable.sorted {
  color: var(--blue-deep);
  background: #e8f3ff;
}
table.catalog-table th .sort-ind {
  font-size: 0.75em;
  opacity: 0.85;
}
table.catalog-table td {
  white-space: nowrap;
  vertical-align: middle;
  padding: 0.7rem 0.7rem;
}
table.catalog-table td.col-title {
  white-space: normal;
  min-width: 220px;
  max-width: 340px;
}
table.catalog-table .col-prev,
table.catalog-table .col-ordered,
table.catalog-table .col-remain {
  min-width: 120px;
  text-align: center;
}
table.catalog-table .col-avail {
  min-width: 90px;
  text-align: center;
}
table.catalog-table .col-price {
  min-width: 90px;
  text-align: center;
}
table.catalog-table .col-qty {
  min-width: 110px;
  text-align: center;
}
table.catalog-table .qty {
  width: 5.5rem;
  margin: 0 auto;
  display: block;
}
th, td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-size: 0.92rem;
}
th {
  color: var(--blue-deep);
  font-weight: 600;
  background: var(--bg-soft);
  position: sticky;
  top: 0;
}
tr:hover td { background: #f8fbff; }
.qty { width: 5.5rem; }
.badge {
  display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.78rem; background: var(--bg-soft); color: var(--ink);
}
.badge.pending { background: var(--sun-soft); color: #9a6400; }
.badge.confirmed { background: #e5f8ef; color: #147a52; }
.badge.rejected { background: #fdecec; color: #b42318; }
.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.85rem; }
.stmt-adjust {
  font-size: 0.8rem;
  margin-top: 0.2rem;
  line-height: 1.35;
}
.pdf-size-label .pdf-size {
  min-width: 7.5rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.btn.active { outline: 2px solid var(--accent, #2563eb); }
.muted { color: var(--muted); }
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: #fff; border: 1px solid var(--line); color: var(--ink);
  padding: 0.75rem 1.1rem;
  border-radius: 14px; box-shadow: var(--shadow); z-index: 40;
  animation: rise 0.25s ease both;
  max-width: min(92vw, 420px);
  text-align: center;
}
.toast.bad { border-color: rgba(214, 69, 69, 0.45); color: var(--danger); }
.stat {
  font-size: 1.6rem; font-family: var(--display); color: var(--blue-deep); margin: 0;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.filters-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: end;
  margin-top: 1rem;
}
.filters-bar .filter-company {
  min-width: 220px;
  flex: 0 1 280px;
}
.filters-bar #filter {
  flex: 1;
  min-width: 180px;
}
.finance-box {
  margin: 0.85rem 0 0.35rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--bg-soft), #fff);
}
.finance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem 1rem;
}
.finance-grid div {
  display: grid;
  gap: 0.2rem;
}
.finance-grid strong {
  font-size: 1.05rem;
  color: var(--ink);
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 39, 68, 0.45);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  text-align: right;
}
.modal-card h2 {
  margin: 0 0 0.5rem;
  color: var(--blue-deep);
  font-family: var(--display);
  font-size: 1.2rem;
}
.bulk-result {
  max-height: 360px;
  overflow: auto;
  margin-top: 0.75rem;
  font-size: 0.88rem;
}
.order-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 28px rgba(15, 70, 140, 0.1);
  backdrop-filter: blur(10px);
  padding: 0.75rem 1.25rem calc(0.75rem + env(safe-area-inset-bottom));
}
.order-footer[hidden] { display: none !important; }
.order-footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: minmax(160px, 1.2fr) minmax(220px, 1fr);
  align-items: end;
}
.order-footer-note {
  margin: 0;
}
.order-footer-note textarea {
  min-height: 44px;
  resize: vertical;
}
.order-footer-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.order-footer-sum {
  display: grid;
  gap: 0.15rem;
  text-align: left;
  min-width: 140px;
}
.order-footer-sum strong {
  color: var(--blue-deep);
  font-size: 1.05rem;
}
.order-footer .btn.primary {
  min-width: 160px;
  padding: 0.85rem 1.4rem;
  font-size: 1.05rem;
}
.main.has-order-footer {
  padding-bottom: 7rem;
}
body.order-footer-on .toast {
  bottom: 5.5rem;
}
@media (max-width: 700px) {
  .login-shell { padding-top: 4vh; }
  .login-logo { width: min(220px, 70vw); }
  .top-brand img { width: 44px; height: 44px; }
  .icon-btn-label { display: none; }
  table { min-width: 960px; }
  table.catalog-table { min-width: 1100px; }
  .order-footer-inner {
    grid-template-columns: 1fr;
  }
  .order-footer-actions {
    justify-content: stretch;
  }
  .order-footer-sum {
    text-align: right;
    flex: 1;
  }
  .order-footer .btn.primary {
    flex: 1;
    width: 100%;
  }
  .panel { border-radius: 16px; padding: 1rem; }
  .filters-bar .filter-company,
  .filters-bar #filter {
    min-width: 100%;
    flex: 1 1 100%;
  }
}

@media (min-width: 901px) {
  body.role-customer .app-tabbar {
    max-width: 520px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    border-radius: 18px 18px 0 0;
    border: 1px solid var(--line);
    border-bottom: 0;
  }
  body.role-customer .order-footer {
    max-width: 900px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }
}

.explain-box {
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  text-align: right;
}
.explain-box h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.explain-list { margin: 0; padding-inline-start: 1.25rem; }
.explain-list li { margin: 0.35rem 0; line-height: 1.45; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}
.stat-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  background: #fff;
}
.stat-label { font-weight: 700; margin-bottom: 0.5rem; color: var(--blue-deep, #1e3a5f); }
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.2rem 0;
  font-size: 0.95rem;
}
.stat-row.ok b { color: #147a52; }
.stat-row.warn b { color: #9a6400; }
.issue-list { display: grid; gap: 0.65rem; }
.issue-card {
  border-radius: 12px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  text-align: right;
}
.issue-card.issue-error { border-color: #f0b4b4; background: #fff5f5; }
.issue-card.issue-warn { border-color: #f0d9a0; background: #fffaf0; }
.issue-card.issue-info { border-color: #c5d4f0; background: #f5f8ff; }

.edit-panel {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  text-align: right;
}
.cred-box {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: #fff;
}
.cred-box h4 { margin: 0 0 0.5rem; }
.cred-preview {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  white-space: pre-wrap;
  direction: ltr;
  text-align: left;
  font-size: 0.9rem;
}

.qty-invalid {
  border-color: #b42318 !important;
  background: #fff5f5;
}
.qty-err {
  color: #b42318;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.match-table-panel {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.5rem;
}
.match-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}
.match-toolbar .match-search {
  flex: 1 1 16rem;
  min-width: 12rem;
  max-width: 28rem;
  margin: 0;
}
.match-table-scroll {
  max-height: min(58vh, 560px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.match-table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef4fb;
  box-shadow: 0 1px 0 var(--line);
}
.match-table-scroll table {
  min-width: 900px;
}
.auth-links {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
  align-items: center;
}
.auth-links .linkish,
button.linkish {
  background: none;
  border: none;
  color: var(--blue-deep, #1d4ed8);
  cursor: pointer;
  text-align: center;
  padding: 0.45rem 0.25rem;
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.auth-title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}
.ok-msg {
  color: #027a48;
  background: #ecfdf3;
  border: 1px solid #abefc6;
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  margin: 0;
}
.name-with-prefix {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.name-with-prefix .name-prefix {
  display: flex;
  align-items: center;
  padding: 0 0.85rem;
  background: #eef4fb;
  color: var(--blue-deep, #1d4ed8);
  font-weight: 700;
  white-space: nowrap;
  border-left: 1px solid var(--line);
}
.name-with-prefix input {
  border: none !important;
  border-radius: 0 !important;
  flex: 1;
  min-width: 0;
}
.name-with-prefix:focus-within {
  outline: 2px solid color-mix(in srgb, var(--blue-deep, #1d4ed8) 35%, transparent);
}
.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted, #64748b);
}
.address-preview {
  margin: 0;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px dashed var(--line);
}
.unlinked-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}
.unlinked-col h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}
.unlinked-col .match-table-scroll {
  max-height: min(52vh, 480px);
}
.unlinked-col .match-table-scroll table {
  min-width: 520px;
}
@media (max-width: 960px) {
  .unlinked-grid {
    grid-template-columns: 1fr;
  }
}
