:root {
  --bg: #faf7f0;
  --surface: #ffffff;
  --primary: #2f7d4f;
  --primary-dark: #235f3c;
  --danger: #c0392b;
  --danger-dark: #a13124;
  --text: #232323;
  --text-muted: #5a5a5a;
  --border: #d8d2c4;
  --accent: #f2ecd9;
  --focus: #1a5cb0;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 20px;
  line-height: 1.4;
  padding-bottom: 40px;
}

.app-header {
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  max-width: 720px;
  margin: 0 auto;
}

.sync-status {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  background: rgba(255,255,255,0.15);
  cursor: default;
}

.sync-status-syncing {
  animation: sync-pulse 1s ease-in-out infinite;
}

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

@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.app-icon {
  flex: 0 0 auto;
  font-size: 1.5rem;
  line-height: 1;
}

.app-brand {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 6px 0;
  cursor: pointer;
  touch-action: manipulation;
}

.app-brand-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.2px;
}

.header-logout-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.header-logout-btn:active {
  background: rgba(255,255,255,0.28);
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 0;
}

/* ---- Auth screen ---- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-screen.hidden {
  display: none;
}

.auth-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  text-align: center;
}

.auth-icon {
  font-size: 2.6rem;
  margin-bottom: 6px;
}

.auth-title {
  font-size: 1.6rem;
  margin: 0 0 24px;
  color: var(--primary-dark);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.auth-form.hidden {
  display: none;
}

.auth-form .btn-add {
  margin-top: 8px;
}

.auth-form .btn-back {
  margin-bottom: 0;
}

.view.hidden {
  display: none;
}

/* ---- Screen header (back button + title, one compact row) ---- */
.screen-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.btn-back-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-back-icon:active {
  background: var(--accent);
  border-color: var(--primary);
}

.screen-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Store screen sub-tabs (Накладні / Закупка) — segmented control ---- */
.store-subtabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--accent);
  border-radius: 14px;
  margin-bottom: 18px;
}

.store-subtab-btn {
  flex: 1 1 0;
  min-width: 0;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 11px 6px;
  color: var(--text-muted);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.store-subtab-btn.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.store-subpanel.hidden {
  display: none;
}

/* ---- Dashboard / KPI cards ---- */
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  margin-bottom: 16px;
}

.kpi-label {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1;
}

.kpi-main-block {
  text-align: center;
}

.kpi-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.kpi-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.kpi-value-sm {
  font-size: 1.6rem;
}

.kpi-trend {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
}

.kpi-trend-sm {
  font-size: 1rem;
}

.trend-arrow {
  font-size: 1.6rem;
  line-height: 1;
}

.kpi-trend.up .trend-arrow,
.kpi-trend.up .trend-text {
  color: var(--danger);
}

.kpi-trend.down .trend-arrow,
.kpi-trend.down .trend-text {
  color: var(--primary-dark);
}

.kpi-trend.flat .trend-arrow,
.kpi-trend.flat .trend-text {
  color: var(--text-muted);
}

.kpi-sub {
  font-size: 1.1rem;
  font-weight: 600;
}

.btn-goto-list {
  margin-top: 4px;
}

/* ---- Purchases list ---- */
.purchase-list {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.purchase-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  border: 2px solid transparent;
  text-align: left;
  width: 100%;
  touch-action: manipulation;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}

.purchase-card:active {
  border-color: var(--primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transform: scale(0.99);
}

.purchase-card-static {
  cursor: default;
}

.store-card-icon {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.store-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.store-row .purchase-card {
  flex: 1 1 auto;
  min-width: 0;
}

.store-row .item-delete,
.store-row .item-edit {
  flex: 0 0 auto;
}

.purchase-card-info {
  flex: 1 1 auto;
  min-width: 0;
}

.purchase-card-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.purchase-card-meta {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.purchase-card-categories {
  font-size: 0.9rem;
  color: var(--primary-dark);
  font-weight: 600;
  margin-top: 4px;
}

.purchase-card-breakdown {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.purchase-card-breakdown b {
  color: var(--primary-dark);
  font-weight: 700;
}

.purchase-card-breakdown b.negative {
  color: var(--danger);
}

.purchase-badge {
  flex: 0 0 auto;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
}

.purchase-badge.active {
  background: var(--accent);
  color: var(--primary-dark);
}

.purchase-badge.done {
  background: #e6e6e6;
  color: var(--text-muted);
}

.purchase-arrow {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--primary-dark);
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-back {
  display: inline-block;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 12px 18px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 16px;
  touch-action: manipulation;
}

.btn-delete-purchase {
  display: block;
  width: 100%;
  font-size: 1rem;
  font-weight: 700;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  margin-top: 6px;
  touch-action: manipulation;
}

.btn-finish {
  display: block;
  width: 100%;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 16px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  margin-top: 4px;
  touch-action: manipulation;
}

.btn-finish:active {
  background: var(--primary-dark);
}

/* ---- Add form ---- */
.add-form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
  border: 2px solid transparent;
}

.add-form.glow {
  border-color: var(--primary);
  animation: glow-pulse 1.8s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08), 0 0 0 0 rgba(47,125,79,0.35);
  }
  50% {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08), 0 0 0 8px rgba(47,125,79,0);
  }
}

/* ---- Quick pick icons ---- */
.quick-pick-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.quick-pick-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 10px;
}

.quick-pick-category-header:first-child {
  margin-top: 0;
}

.quick-pick-category {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.category-edit,
.category-delete {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
}

.category-edit {
  border: 2px solid var(--primary);
  color: var(--primary-dark);
}

.category-edit:active {
  background: var(--primary);
  color: #fff;
}

.category-delete {
  border: 2px solid var(--danger);
  color: var(--danger);
}

.category-delete:active {
  background: var(--danger);
  color: #fff;
}

.add-category-row {
  display: flex;
  gap: 8px;
  margin: 4px 0 18px;
}

.add-category-row .field-input {
  flex: 1 1 auto;
}

.add-category-row .btn-inline-next {
  flex: 0 0 auto;
}

.quick-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  touch-action: manipulation;
}

.quick-item img {
  width: 36px;
  height: 36px;
}

.quick-item span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.15;
}

.quick-item:active {
  background: var(--accent);
}

.quick-item.selected {
  border-color: var(--primary);
  background: var(--accent);
}

.quick-item-custom {
  position: relative;
  cursor: default;
}

.quick-item-select-inner {
  all: unset;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  cursor: pointer;
  touch-action: manipulation;
}

.quick-item-select-inner img {
  width: 36px;
  height: 36px;
}

.quick-item-select-inner span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.15;
}

.quick-item-edit,
.quick-item-delete {
  position: absolute;
  top: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  font-size: 0.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  z-index: 2;
}

.quick-item-edit {
  left: -8px;
  border: 2px solid var(--primary);
  color: var(--primary-dark);
}

.quick-item-edit:active {
  background: var(--primary);
  color: #fff;
}

.quick-item-delete {
  right: -8px;
  border: 2px solid var(--danger);
  color: var(--danger);
}

.quick-item-delete:active {
  background: var(--danger);
  color: #fff;
}

.field-label {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ---- Add-item wizard ---- */
.wizard {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
}

.wizard.hidden {
  display: none;
}

.wizard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.wizard-back {
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
}

.wizard-back.hidden {
  visibility: hidden;
}

.wizard-step-label {
  flex: 1 1 auto;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
}

.wizard-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.wizard-step.hidden {
  display: none;
}

.inline-field-row {
  display: flex;
  gap: 10px;
}

.inline-field-row input {
  flex: 1 1 auto;
  font-size: 1.1rem;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  min-width: 0;
}

.inline-field-row input:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.btn-inline-next {
  flex: 0 0 auto;
  font-size: 1rem;
  font-weight: 700;
  padding: 0 16px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-inline-next:active {
  background: var(--primary-dark);
}

.quick-pick-grid-text {
  grid-template-columns: repeat(2, 1fr);
}

.quick-pick-grid-text .quick-item {
  flex-direction: row;
  justify-content: center;
  padding: 14px 8px;
}

.quick-pick-grid-text .quick-item span {
  font-size: 1rem;
}

.wizard-summary {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-align: center;
}

/* ---- Group / subgroup pickers ---- */
.group-pick {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group-pick.hidden {
  display: none;
}

.group-pick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.group-chip {
  flex: 0 0 auto;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
  touch-action: manipulation;
}

.group-chip.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.point-chip-wrap {
  display: inline-flex;
  align-items: stretch;
  flex: 0 0 auto;
  border: 2px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.point-chip-wrap.active {
  border-color: var(--primary);
}

.point-chip-select {
  border: none;
  background: #fff;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 12px;
  cursor: pointer;
  touch-action: manipulation;
}

.point-chip-wrap.active .point-chip-select {
  background: var(--primary);
  color: #fff;
}

.point-chip-delete {
  border: none;
  border-left: 2px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 10px 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.point-chip-wrap.active .point-chip-delete {
  background: var(--primary);
  color: #fff;
  border-left-color: rgba(255, 255, 255, 0.4);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-row.hidden {
  display: none;
}

.checkbox-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  accent-color: var(--primary);
}

.field-input {
  width: 100%;
  font-size: 1.2rem;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}

.field-input:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.field-input.shake {
  animation: shake 0.3s;
  border-color: var(--danger);
}

#itemVariant {
  width: 100%;
  font-size: 1.1rem;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}

#itemVariant:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.item-variant {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.item-point {
  font-size: 0.85rem;
  color: var(--primary-dark);
  font-weight: 600;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.qty-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.qty-btn {
  flex: 0 0 56px;
  font-size: 1.8rem;
  font-weight: 700;
  border: 2px solid var(--primary);
  background: var(--accent);
  color: var(--primary-dark);
  border-radius: 12px;
  cursor: pointer;
  line-height: 1;
  touch-action: manipulation;
}

.qty-btn:active {
  background: var(--primary);
  color: #fff;
}

#itemQty {
  flex: 1 1 70px;
  min-width: 0;
  font-size: 1.3rem;
  text-align: center;
  padding: 10px 4px;
  border: 2px solid var(--border);
  border-radius: 12px;
  -moz-appearance: textfield;
}

#itemQty::-webkit-outer-spin-button,
#itemQty::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#itemUnit {
  flex: 1 1 110px;
  font-size: 1.1rem;
  padding: 10px 8px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}

.btn-add {
  width: 100%;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 18px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-add:active {
  background: var(--primary-dark);
}

.btn-add:disabled {
  background: var(--text-muted);
  cursor: default;
}

.btn-text-action {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--primary-dark);
  cursor: pointer;
  margin-top: 4px;
  touch-action: manipulation;
}

.btn-text-action:active {
  background: var(--accent);
}

/* ---- List ---- */
.list-section {
  margin-bottom: 24px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  padding: 0 4px;
}

.list-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.counter {
  color: var(--text-muted);
  font-size: 1rem;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-row {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.07);
  transition: opacity 0.2s;
}

.item-row.available {
  opacity: 0.6;
}

.item-row.unavailable {
  background: #fdecea;
}

.item-status-group {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-status-btn {
  width: 40px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.item-status-yes {
  border-color: var(--primary);
  color: var(--primary);
}

.item-status-yes.active {
  background: var(--primary);
  color: #fff;
}

.item-status-no {
  border-color: var(--danger);
  color: var(--danger);
}

.item-status-no.active {
  background: var(--danger);
  color: #fff;
}

.item-info {
  flex: 1 1 auto;
  min-width: 0;
}

.item-name {
  font-size: 1.2rem;
  font-weight: 600;
  word-break: break-word;
}

.item-row.available .item-name {
  text-decoration: line-through;
}

.item-row.unavailable .item-name {
  color: var(--danger-dark);
}

.item-qty {
  font-size: 1.05rem;
  color: var(--primary-dark);
  font-weight: 600;
}

.item-status-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--danger);
  margin-top: 2px;
}

.item-delete {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--danger);
  background: #fff;
  color: var(--danger);
  font-size: 1.3rem;
  cursor: pointer;
  touch-action: manipulation;
}

.item-delete:active {
  background: var(--danger);
  color: #fff;
}

.item-edit {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid var(--primary);
  background: #fff;
  color: var(--primary-dark);
  font-size: 1.1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.item-edit:active {
  background: var(--primary);
  color: #fff;
}

.empty-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 30px 10px;
}

.item-list:not(:empty) + .empty-msg {
  display: none;
}

.empty-msg-inline {
  font-size: 0.95rem;
  padding: 6px 4px 0;
}

/* ---- Clear button ---- */
.btn-clear {
  display: block;
  width: 100%;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 16px;
  border: 2px solid var(--danger);
  border-radius: 12px;
  background: #fff;
  color: var(--danger);
  cursor: pointer;
  margin-top: 8px;
  touch-action: manipulation;
}

.btn-clear:active {
  background: var(--danger);
  color: #fff;
}

/* ---- Confirm overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.confirm-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.confirm-box p {
  font-size: 1.15rem;
  margin: 0 0 20px;
}

.confirm-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.confirm-box .field-input {
  margin-bottom: 20px;
}

.btn-danger, .btn-secondary {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 16px;
  border-radius: 12px;
  cursor: pointer;
  border: 2px solid transparent;
  touch-action: manipulation;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:active {
  background: var(--danger-dark);
}

.btn-secondary {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

/* ---- JSON import / copy ---- */
/* ---- List action row (export / print) ---- */
.list-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.list-action-row .btn-back {
  flex: 1 1 100px;
  margin-bottom: 0;
  padding: 12px 10px;
  font-size: 0.95rem;
  text-align: center;
}

#printArea {
  display: none;
}

@media print {
  body > *:not(#printArea) {
    display: none !important;
  }

  #printArea {
    display: block !important;
  }

  #printArea h1 {
    font-size: 1.4rem;
    margin: 0 0 4px;
  }

  #printArea .print-meta {
    color: #555;
    margin: 0 0 16px;
    font-size: 0.95rem;
  }

  #printArea .print-point-section {
    margin-bottom: 24px;
    /* Keep one order together on one page whenever it actually fits —
       splitting "Точка А" across two sheets just to save a few millimetres
       is worse than a bit of blank space. The JS side does the actual
       paper-saving work by sorting sections biggest-first (see
       sortSectionsForPrint below), so small sections land after big ones
       and slot into whatever room is left instead of forcing a fresh page.
       This is only a hint, not a hard rule — a section too tall for even a
       blank page still has to split, which is fine: its own <thead> below
       repeats on the next page automatically, so the store/point name
       isn't lost. */
    break-inside: avoid-page;
    page-break-inside: avoid;
  }

  #printArea table {
    width: 100%;
    border-collapse: collapse;
  }

  #printArea th,
  #printArea td {
    border: 1px solid #999;
    padding: 6px 10px;
    text-align: left;
    font-size: 0.95rem;
  }

  #printArea .print-section-title-row th {
    background: #eee;
    font-size: 1.05rem;
    font-weight: 700;
    text-align: left;
  }

  #printArea th:last-child,
  #printArea td:last-child {
    text-align: right;
  }

  #printArea .print-totals {
    margin-top: 14px;
    width: 100%;
    max-width: 320px;
    margin-left: auto;
  }

  #printArea .print-totals-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.95rem;
  }

  #printArea .print-totals-row.print-total-main {
    border-top: 1px solid #999;
    margin-top: 4px;
    padding-top: 8px;
    font-weight: 700;
  }
}

.import-box {
  max-width: 480px;
  text-align: left;
}

.import-box p {
  font-size: 1rem;
  margin: 0 0 10px;
}

.import-textarea {
  width: 100%;
  height: 160px;
  font-family: "Courier New", monospace;
  font-size: 0.95rem;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  resize: vertical;
  margin-bottom: 14px;
}

.import-textarea:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.import-error {
  color: var(--danger);
  font-size: 0.95rem;
  font-weight: 700;
  margin: -6px 0 14px;
}

.import-error.hidden {
  display: none;
}

/* ---- Date filter — one cohesive pill control instead of stacked boxes ---- */
.date-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 18px 0 14px;
  padding: 4px 4px 4px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.date-filter-row .field-label {
  flex: 0 0 auto;
  margin: 0;
  font-size: 0.85rem;
  white-space: nowrap;
}

.date-filter-row input[type="date"] {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.95rem;
  padding: 8px 4px;
  border: none;
  background: transparent;
  color: var(--text);
}

.date-filter-row input[type="date"]:focus {
  outline: none;
}

.date-filter-clear {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  touch-action: manipulation;
}

.date-filter-clear:active {
  background: var(--accent);
  color: var(--danger);
}

.point-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  flex-wrap: wrap;
}

.point-filter-row.hidden {
  display: none;
}

.point-filter-row .field-label {
  flex: 0 0 auto;
}

.point-filter-row select {
  flex: 1 1 auto;
  min-width: 140px;
  font-size: 1rem;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}

.point-filter-row select:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.field-select {
  width: 100%;
  font-size: 1.1rem;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  margin-bottom: 16px;
}

.field-select:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

#linkInvoiceRow .inline-field-row select {
  flex: 1 1 auto;
  min-width: 0;
  margin-bottom: 0;
}

.purchase-card-money {
  font-weight: 800;
  color: var(--primary-dark);
}

/* ---- Markup ("Tinder-style" card) ---- */
.markup-card-wrap {
  position: relative;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.markup-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  touch-action: manipulation;
  z-index: 1;
}

.markup-progress {
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
}

.markup-card {
  width: 100%;
  background: var(--surface);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.markup-item-name {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
}

.markup-item-cost {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.markup-value {
  font-size: 3rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1;
  margin: 10px 0;
}

.markup-btn-row {
  display: flex;
  gap: 14px;
  width: 100%;
}

.markup-btn {
  flex: 1 1 0;
  font-size: 1.5rem;
  font-weight: 800;
  padding: 20px 0;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  touch-action: manipulation;
  color: #fff;
}

.markup-minus {
  background: var(--danger);
}

.markup-minus:active {
  background: var(--danger-dark);
}

.markup-plus {
  background: var(--primary);
}

.markup-plus:active {
  background: var(--primary-dark);
}

.markup-extra-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-top: 4px;
}

.markup-extra-label {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 600;
}

.markup-extra-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.markup-extra-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--primary);
  background: var(--accent);
  color: var(--primary-dark);
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.markup-extra-btn:active {
  background: var(--primary);
  color: #fff;
}

.markup-extra-value {
  min-width: 64px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.markup-sell-price {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-top: 12px;
}

.markup-nav-row {
  display: flex;
  gap: 24px;
}

.markup-nav-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-size: 1.6rem;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

.markup-nav-btn:active {
  background: #fff;
}

.markup-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.markup-nav-btn-primary {
  background: var(--primary);
  color: #fff;
}

.markup-nav-btn-primary:active {
  background: var(--primary-dark);
}

.invoice-row-markup {
  font-size: 0.95rem;
  color: var(--primary-dark);
  font-weight: 600;
}

/* ---- Invoice index table ---- */
.table-scroll {
  overflow-x: auto;
  margin: 16px 0;
  -webkit-overflow-scrolling: touch;
}

.invoice-index-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  margin: 0;
}

.invoice-index-table th {
  text-align: left;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 12px 14px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.invoice-index-table td {
  padding: 14px;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.invoice-index-table tr:last-child td {
  border-bottom: none;
}

.invoice-index-table .num-col {
  text-align: right;
}

.invoice-index-table .invoice-index-chevron-col {
  width: 34px;
  padding: 14px 10px;
}

.invoice-index-table .invoice-index-chevron-col .purchase-arrow {
  width: 28px;
  height: 28px;
  font-size: 0.95rem;
}

.invoice-index-row {
  cursor: pointer;
  touch-action: manipulation;
}

.invoice-index-row:active {
  background: var(--accent);
}

.invoice-index-sum,
.invoice-index-sell {
  font-weight: 700;
  color: var(--primary-dark);
}

.invoice-index-profit {
  font-weight: 800;
  color: var(--primary-dark);
}

.invoice-index-profit.negative {
  color: var(--danger);
}

.invoice-day-header {
  cursor: pointer;
  touch-action: manipulation;
  background: var(--accent);
}

.invoice-day-header:active {
  background: var(--border);
}

.invoice-day-header td {
  font-weight: 700;
}

.invoice-day-header-name {
  color: var(--primary-dark);
}

.invoice-day-arrow {
  transition: transform 0.15s ease;
}

.invoice-day-arrow.expanded {
  transform: rotate(90deg);
}

/* ---- Invoice cost/sell/profit summary ---- */
.invoice-summary {
  background: var(--accent);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.invoice-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.invoice-summary-profit {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary-dark);
  border-top: 2px solid rgba(0,0,0,0.08);
  padding-top: 8px;
  margin-top: 2px;
}

.invoice-summary-profit.negative {
  color: var(--danger);
}

/* ---- Invoices ---- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.invoice-image-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  max-height: 320px;
  display: flex;
  justify-content: center;
  background: #000;
}

.invoice-image {
  max-width: 100%;
  max-height: 320px;
  object-fit: contain;
}

.ocr-status {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
  padding: 10px;
  min-height: 1.2em;
}

.ocr-status.error {
  color: var(--danger);
}

.invoice-table {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.invoice-row {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.07);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.invoice-row input[type="text"],
.invoice-row input[type="number"] {
  width: 100%;
  font-size: 1.05rem;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}

.invoice-row input:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.invoice-row-numbers {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.invoice-row-numbers label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}

.invoice-row-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.invoice-row-sum {
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 1.05rem;
}

.invoice-row-delete {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--danger);
  background: #fff;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.invoice-row-delete:active {
  background: var(--danger);
  color: #fff;
}

.btn-add-row {
  width: 100%;
  text-align: center;
  margin-bottom: 14px;
}

.invoice-total {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary-dark);
  padding: 14px;
  background: var(--accent);
  border-radius: var(--radius);
}

.invoice-print-row {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

.invoice-print-row .btn-inline-next {
  flex: 1 1 0;
  height: 44px;
}

/* ---- Tablet / larger screens ---- */
@media (min-width: 600px) {
  body {
    font-size: 21px;
  }
  .container {
    padding-top: 32px;
  }
  .add-form {
    padding: 28px;
  }
  .qty-row {
    align-items: center;
  }
  .quick-pick-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  .quick-pick-grid-text {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 900px) {
  .app-icon {
    font-size: 2rem;
  }
}
