:root {
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  padding-bottom: calc(86px + var(--safe-bottom));
  background: #f4f5f7;
  -webkit-tap-highlight-color: transparent;
}

/* Top bar */
.top-bar {
  position: sticky;
  top: 0;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1020;
}
.top-bar h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 600;
}
.btn-logout {
  border: none;
  background: #f1f3f5;
  color: #495057;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  list-style: none;
}
.menu-wrap { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  min-width: 180px;
  overflow: hidden;
  z-index: 1040;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a, .dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 16px;
  border: none;
  background: none;
  color: #212529;
  text-decoration: none;
  font-size: 0.95rem;
}
.dropdown-menu a:active, .dropdown-menu button:active { background: #f1f3f5; }

/* Bottom tab bar */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid #e5e5e5;
  padding-bottom: var(--safe-bottom);
  z-index: 1030;
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 12px 4px 10px;
  color: #495057;
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 64px;
  justify-content: center;
}
.bottom-nav a.active {
  color: #0d6efd;
  font-weight: 700;
}
.bottom-nav .icon {
  font-size: 1.7rem;
  line-height: 1;
  padding: 3px 16px;
  border-radius: 14px;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.bottom-nav a.active .icon {
  background: #e7f1ff;
}
.bottom-nav a:active .icon {
  transform: scale(0.9);
}

/* Floating action button */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(94px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #212529;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.28);
  text-decoration: none;
  z-index: 1025;
}
.fab:hover, .fab:active { color: #fff; background: #000; }

/* Group headers (order list: grouped by date, then district/pickup) */
.group-header {
  max-width: 720px;
  margin: 18px auto 0;
  padding: 0 16px;
  font-size: 1rem;
  font-weight: 700;
  color: #212529;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.group-header:first-of-type { margin-top: 12px; }
.group-header .jars-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #0d6efd, #0a58ca);
  padding: 3px 11px;
  border-radius: 20px;
  white-space: nowrap;
}
.group-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Collapsible date-group headers share the same card look as the
   Обработанные/Архив nav-link-cards below - one consistent style for
   anything the user can expand/collapse or drill into. */
.group-toggle {
  max-width: 720px;
  margin: 10px auto 0;
  padding: 14px 16px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.group-chevron {
  transition: transform 0.2s ease;
  display: inline-block;
}
.group-toggle:not(.is-collapsed) .group-chevron {
  transform: rotate(90deg);
}
.group-body.collapsed {
  display: none;
}
.subgroup-header {
  max-width: 720px;
  margin: 10px auto 0;
  padding: 0 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #868e96;
}

/* Card list */
.card-list { padding: 8px 12px 4px; display: flex; flex-direction: column; gap: 10px; max-width: 720px; margin: 0 auto; }

/* Client order-history summary line */
.history-stats {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
  color: #495057;
  font-size: 0.88rem;
}
.item-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
  text-decoration: none;
  color: inherit;
  display: block;
}
.item-card:active { background: #f8f9fa; }
.item-card .row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.item-card .title {
  font-weight: 600;
  font-size: 1.02rem;
  color: #212529;
}
.item-card .subtitle {
  color: #6c757d;
  font-size: 0.9rem;
}
.item-card .meta {
  color: #868e96;
  font-size: 0.85rem;
  margin-top: 6px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Status badges */
.badge-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
}
.badge-status-REQUESTED { background: #fd7e14; }
.badge-status-NEW { background: #0d6efd; }
.badge-status-DONE { background: #198754; }
.badge-status-CANCELLED { background: #adb5bd; }

.empty-state {
  text-align: center;
  padding: 70px 24px;
  color: #adb5bd;
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 10px; }

/* Forms */
.form-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 24px;
}
.form-control, .form-select {
  min-height: 48px;
  font-size: 1rem;
  width: 100%;
  padding: 10px 14px;
  color: #212529;
  box-sizing: border-box;
}
textarea.form-control { min-height: 84px; }
/* Placeholders must read as hints, not as text you already typed. */
.form-control::placeholder { color: #adb5bd; opacity: 1; }
.form-control::-webkit-input-placeholder { color: #adb5bd; opacity: 1; }
.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: #495057;
  margin-bottom: 6px;
  cursor: pointer;
}
.btn {
  min-height: 48px;
  font-size: 1rem;
  border-radius: 10px;
}

/* Segmented control */
.segmented {
  display: flex;
  background: #e9ecef;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  flex: 1;
  text-align: center;
  padding: 12px 0;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  margin: 0;
}
.segmented input:checked + label {
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

/* Sticky save bar at bottom of forms */
.sticky-save-bar {
  position: sticky;
  bottom: calc(0px + var(--safe-bottom));
  background: rgba(244,245,247,.92);
  backdrop-filter: blur(6px);
  padding: 12px 16px calc(12px + var(--safe-bottom));
  margin: 16px -16px -16px;
  display: flex;
  gap: 10px;
}
.sticky-save-bar .btn { flex: 1; }

/* Quick actions (call / map) */
.quick-actions { display: flex; gap: 8px; margin-top: 10px; }
.quick-actions a {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  border-radius: 9px;
  background: #f1f3f5;
  color: #212529;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Public shop page */
body.shop-body {
  padding-bottom: 90px;
  background: linear-gradient(180deg, #eef7ee 0%, #f4f5f7 220px);
}
.shop-hero {
  text-align: center;
  padding: 22px 20px 16px;
  position: relative;
}
.shop-lang-switch {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #adb5bd;
  margin-bottom: 8px;
}
.shop-lang-switch a { color: #adb5bd; text-decoration: none; }
.shop-lang-switch a.active { color: #2f6b3a; }
.shop-hero-emoji { font-size: 2.4rem; margin-bottom: 2px; }
.shop-hero h1 { font-size: 1.3rem; font-weight: 700; margin: 0 0 4px; color: #1b4332; }
.shop-hero p { color: #52796f; margin: 0; font-size: 0.88rem; }
.shop-welcome-back {
  margin-top: 8px;
  padding: 8px 12px;
  background: #eef7ee;
  color: #1b4332;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
}
.shop-address-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #2f6b3a;
  text-decoration: none;
  border-bottom: 1px dashed #2f6b3a;
}

.shop-wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }

.shop-alert {
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 0.95rem;
  font-weight: 500;
}
.shop-alert-success { background: #d1f0da; color: #14532d; }
.shop-alert-error { background: #fde2e1; color: #7f1d1d; }

.shop-product-card {
  background: #fff;
  border-radius: 16px;
  padding: 12px 16px;
  margin-bottom: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  display: flex;
  gap: 12px;
  align-items: center;
  border: 2px solid transparent;
  transition: border-color 0.15s ease;
}
.shop-product-card-in-cart { border-color: #2f6b3a; }
.shop-product-photo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: #eef7ee;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
  overflow: hidden;
}
.shop-product-photo img { width: 100%; height: 100%; object-fit: cover; }
.shop-product-info { flex: 1; min-width: 0; }
.shop-product-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.shop-product-name { font-size: 1rem; font-weight: 700; color: #212529; }
.shop-product-price { font-size: 0.95rem; font-weight: 600; color: #2f6b3a; white-space: nowrap; }
.shop-stock-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 600;
}
.shop-stock-in { background: #d1f0da; color: #14532d; }
.shop-stock-out { background: #f1f3f5; color: #6c757d; }
.shop-stock-ondemand { background: #ede7f6; color: #4a2f7a; }

.shop-section-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #868e96;
  margin: 18px 2px 8px;
}
.shop-product-card-compact { padding: 10px 16px; }

.shop-qty-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.shop-qty-btn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: none;
  background: #f1f3f5;
  font-size: 1.1rem;
  font-weight: 700;
  color: #212529;
  line-height: 1;
  flex-shrink: 0;
}
.shop-qty-btn:active { background: #e9ecef; }
.shop-qty-value { min-width: 18px; text-align: center; font-size: 1rem; font-weight: 700; }

.shop-reserve {
  background: #fff;
  border-radius: 18px;
  padding: 22px 20px 20px;
  margin-top: 22px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.shop-reserve h2 { font-size: 1.15rem; font-weight: 700; margin: 0 0 4px; }
.shop-reserve .hint { color: #868e96; font-size: 0.85rem; margin-bottom: 16px; }

.qty-cap { font-size: 0.78rem; color: #868e96; margin-top: 4px; text-align: center; }

.shop-cart-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #eef7ee;
  border-radius: 12px;
  padding: 12px 16px;
  margin-top: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  color: #1b4332;
}

.shop-submit {
  width: 100%;
  min-height: 52px;
  border-radius: 12px;
  border: none;
  background: #2f6b3a;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 12px;
}
.shop-submit:active { background: #24512c; }
.shop-submit:disabled { background: #ced4da; color: #868e96; }

.shop-footer {
  text-align: center;
  color: #adb5bd;
  font-size: 0.78rem;
  margin-top: 28px;
}

/* Sticky cart bar - hidden until at least one item is added, then jumps to checkout on tap. */
.shop-cart-bar {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: -80px;
  z-index: 1040;
  background: #1b4332;
  color: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
  transition: bottom 0.2s ease;
}
.shop-cart-bar-visible { bottom: 16px; }
.shop-cart-bar span { font-size: 0.92rem; font-weight: 700; }
.shop-cart-bar button {
  background: #fff;
  color: #1b4332;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Swipe-to-archive / swipe-to-restore */
.swipe-item {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
}
.swipe-action {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  color: #fff;
}
.swipe-action button {
  all: unset;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  height: 100%;
  justify-content: center;
  font-size: 1.3rem;
  cursor: pointer;
}
.swipe-action button span { font-size: 0.72rem; font-weight: 600; }
.swipe-action-archive { background: #495057; }
.swipe-action-restore { background: #198754; }
.swipe-content {
  position: relative;
  background: #fff;
  touch-action: pan-y;
  will-change: transform;
}

/* Call/map row under an order card - a sibling of .swipe-item (not nested inside its <a>, which
   would make an invalid nested anchor), so it isn't affected by the swipe transform. */
.order-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.order-card-actions a {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  border-radius: 9px;
  background: #f1f3f5;
  color: #212529;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Search bar (top of orders / clients lists) */
.search-bar {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px 0;
}
.search-bar .form-control {
  border-radius: 12px;
  background: #fff;
}

/* Stats summary (top of orders) - grid auto-wraps so a 3rd card doesn't get
   cramped on narrow phones (falls back to 2-per-row instead of 3-across). */
.stats-block {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
  padding: 12px 12px 4px;
  max-width: 720px;
  margin: 0 auto;
}
.stats-card {
  border-radius: 14px;
  padding: 14px 16px;
  color: #fff;
}
.stats-card.sold { background: linear-gradient(135deg, #198754, #146c43); }
.stats-card.expected { background: linear-gradient(135deg, #0d6efd, #0a58ca); }
.stats-card.tips { background: linear-gradient(135deg, #f59f00, #e8590c); }
.stats-card.owed { background: linear-gradient(135deg, #dc3545, #a71d2a); }
.stats-card .stats-label { font-size: 0.78rem; opacity: 0.9; font-weight: 600; }
.stats-card .stats-value { font-size: 1.35rem; font-weight: 700; margin-top: 2px; }
.stats-card .stats-sub { font-size: 0.72rem; opacity: 0.85; margin-top: 2px; }

/* Bottom nav-link cards (Обработанные / Архив) */
.nav-link-list { padding: 6px 12px 16px; max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.nav-link-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  text-decoration: none;
  color: #212529;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
}
.nav-link-card .nav-link-icon { font-size: 1.3rem; }
.nav-link-card .nav-link-label { flex: 1; font-weight: 600; }
.nav-link-card .count-badge {
  background: #f1f3f5;
  color: #495057;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}
.chevron { color: #adb5bd; font-size: 1.1rem; }

/* Form validation error banner */
.form-error-banner {
  background: #fde2e1;
  color: #7f1d1d;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  font-weight: 500;
}
.form-error-banner div { padding: 2px 0; }

/* Text-only "+ add" action under a select (replaces the old open-in-new-tab links). */
.btn-link-action {
  display: inline-block;
  margin-top: 8px;
  padding: 0;
  border: none;
  background: none;
  color: #0d6efd;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

/* A select with a small icon button (e.g. edit) beside it. */
.input-with-action {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.input-with-action select { flex: 1; }
.btn-icon-action {
  flex: 0 0 auto;
  min-height: 48px;
  min-width: 48px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid #ced4da;
  background: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}
.btn-icon-action:disabled { opacity: 0.35; cursor: default; }

/* Bottom-sheet style modal used for quick add/edit forms (client, district, payment method)
   launched from within another form - these live outside that form in the DOM so an accidental
   Enter keypress inside the modal never submits the page underneath. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1060;
}
.modal-box {
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box h3 { margin: 0 0 14px; font-size: 1.1rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }
@media (min-width: 560px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: 16px; }
}
