:root {
  --primary: #1a56db;
  --primary-dark: #1544ab;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e4e7ee;
  --green: #0e9f6e;
  --amber: #c27803;
  --red: #e02424;
  --radius: 14px;
  --nav-h: 62px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  min-height: 100%;
}

.hidden { display: none !important; }

h1 { font-size: 22px; margin-bottom: 14px; }
h2 { font-size: 17px; margin: 18px 0 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

/* --- Кнопки --- */
.btn {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:active { background: var(--primary-dark); }
.btn:disabled { opacity: 0.5; }
.btn.secondary { background: #e8edf7; color: var(--primary); }
.btn.green { background: var(--green); }
.btn.amber { background: var(--amber); }
.btn.danger { background: #fde8e8; color: var(--red); }
.btn.small { width: auto; padding: 10px 16px; font-size: 14px; display: inline-block; }

/* --- Форми --- */
input, select, textarea {
  width: 100%;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  background: var(--card);
  color: var(--text);
  margin-bottom: 10px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 5px; }

/* --- Логін --- */
.login-wrap {
  min-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-logo { text-align: center; font-size: 44px; margin-bottom: 8px; }
.login-title { text-align: center; margin-bottom: 24px; }
.login-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 16px; line-height: 1.6; }

/* --- Пошук --- */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 4px 0 10px;
}
.search-bar input { margin-bottom: 0; }

.mat-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.mat-info { flex: 1; min-width: 0; }
.mat-name { font-weight: 600; font-size: 15px; }
.mat-code { color: var(--muted); font-size: 13px; margin-top: 2px; }
.add-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.add-btn.added { background: var(--green); }

/* --- Кошик --- */
.qty-stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}
.qty-stepper button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--card);
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
}
.qty-stepper .qty {
  min-width: 44px;
  text-align: center;
  font-weight: 600;
  font-size: 16px;
}
.remove-btn {
  border: none;
  background: none;
  color: var(--red);
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
}

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--card);
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  color: var(--text);
}
.chip.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.chip .sub { display: block; font-size: 12px; opacity: 0.75; }

.slot-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot-grid .chip { padding: 12px 6px; }

/* --- Замовлення --- */
.order-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.order-num { font-weight: 700; font-size: 15px; }
.order-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }

.badge {
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.NEW { background: #e1effe; color: var(--primary); }
.badge.IN_PROGRESS { background: #fdf6b2; color: var(--amber); }
.badge.READY { background: #def7ec; color: var(--green); }
.badge.COMPLETED { background: #e5e7eb; color: #374151; }
.badge.CANCELLED { background: #fde8e8; color: var(--red); }

.item-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.item-row:last-child { border-bottom: none; }
.item-qty { white-space: nowrap; font-weight: 600; }

.filter-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.filter-tabs .chip { font-size: 13px; padding: 8px 12px; }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  line-height: 1.6;
}
.empty .icon { font-size: 42px; margin-bottom: 10px; }

.back-link {
  display: inline-block;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 12px;
  cursor: pointer;
  background: none;
  border: none;
  font-size: 15px;
  padding: 6px 0;
}

/* --- Нижня навігація --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  position: relative;
}
.nav-item.active { color: var(--primary); font-weight: 600; }
.nav-item .ico { font-size: 21px; line-height: 1; }
.nav-badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 6px);
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 30;
  max-width: 90%;
  text-align: center;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.login-greet {
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 14px;
  line-height: 1.5;
}
.login-greet small { font-weight: 400; color: var(--muted); font-size: 13px; }

.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card { text-align: center; margin-bottom: 0; }
.stat-num { font-size: 30px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.import-result { font-size: 14px; line-height: 1.7; margin-top: 10px; }

.profile-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.profile-row:last-child { border-bottom: none; }
.profile-row .k { color: var(--muted); }
