/* Цвета берутся из темы Telegram (светлая/тёмная), в браузере — запасные значения */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --card: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --border: rgba(127, 127, 127, 0.25);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.has-cartbar { padding-bottom: 76px; }
#app { max-width: 640px; margin: 0 auto; padding: 16px 16px 40px; }
h1 { font-size: 22px; line-height: 1.25; margin: 4px 0 6px; }
h2 { font-size: 18px; margin: 0 0 8px; }
p { margin: 6px 0; }
a { color: var(--link); text-decoration: none; }
.hint { color: var(--hint); font-size: 14px; }
.small { font-size: 14px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 12px; }

/* браузерная панель «Назад» (в Telegram используется его кнопка) */
#browser-bar { position: sticky; top: 0; z-index: 5; background: var(--bg2); border-bottom: 1px solid var(--border); }
#browser-bar[hidden] { display: none; }
#browser-back { border: 0; background: none; color: var(--link); font: inherit; font-size: 16px; padding: 10px 16px; cursor: pointer; }

/* загрузка, ошибки, пустые состояния */
.loader { width: 28px; height: 28px; margin: 60px auto; border: 3px solid var(--border); border-top-color: var(--btn); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { text-align: center; padding: 40px 8px; }
.empty { color: var(--hint); text-align: center; padding: 18px 8px; font-size: 14px; }

/* главная */
.hero { margin-bottom: 14px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  min-height: 112px; padding: 14px; border: 0; border-radius: var(--radius);
  background: var(--card); color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.tile:active, .item:active, .card.clickable:active { opacity: .7; }
.tile-emoji { font-size: 28px; line-height: 1; margin-bottom: 4px; }
.tile-name { font-weight: 600; font-size: 17px; }
.tile-sub { color: var(--hint); font-size: 13px; }
.contacts { white-space: pre-line; }
.contacts div { margin-top: 4px; }

/* кнопки */
.btn {
  display: block; width: 100%; margin-top: 10px; padding: 13px 16px;
  border: 0; border-radius: 12px; background: var(--btn); color: var(--btn-text);
  font: inherit; font-weight: 600; text-align: center; cursor: pointer;
}
.btn:disabled { opacity: .55; }
.btn-secondary { background: var(--card); color: var(--link); }
.btn-danger { background: var(--card); color: var(--danger); }
.btn-small {
  padding: 7px 12px; border: 0; border-radius: 10px; background: var(--btn); color: var(--btn-text);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.link-danger { border: 0; background: none; padding: 6px 0 0; color: var(--danger); font: inherit; font-size: 14px; cursor: pointer; }
.badge-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; }
.badge-count:empty { display: none; }

/* секции и формы */
.section { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--hint); margin: 0 0 10px; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }
input, textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; outline: none;
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input:focus, textarea:focus, select:focus { border-color: var(--btn); }
input[type="checkbox"] { width: 20px; height: 20px; padding: 0; margin: 0; flex: 0 0 auto; -webkit-appearance: checkbox; appearance: auto; accent-color: var(--btn); }
textarea { resize: vertical; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > * { min-width: 0; }
.grow { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }

/* выбор даты и времени */
.days { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin: 0 -14px 12px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.days::-webkit-scrollbar { display: none; }
.day {
  flex: 0 0 auto; width: 58px; padding: 8px 0; display: flex; flex-direction: column; align-items: center;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
}
.day b { font-size: 18px; }
.day-wd, .day-m { font-size: 12px; color: var(--hint); }
.day.active { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }
.day.active .day-wd, .day.active .day-m { color: var(--btn-text); }
.day:disabled { opacity: .35; cursor: default; }
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.slot { padding: 10px 0; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; cursor: pointer; }
.slot.active { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }
.slot:disabled { opacity: .35; text-decoration: line-through; cursor: default; }

/* списки и карточки */
.list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px;
  border: 0; border-radius: var(--radius); background: var(--card); color: var(--text); font: inherit; text-align: left;
}
button.item { cursor: pointer; }
.item.inactive { opacity: .5; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; }
.item-sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.item-side { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; font-size: 14px; }
.chev { color: var(--hint); font-size: 22px; }
.price { font-weight: 600; white-space: nowrap; }
.stock { font-size: 12px; margin-top: 4px; }
.stock.in { color: #2ea043; }
.stock.out { color: #e68a00; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 30px; height: 30px; border: 0; border-radius: 8px; background: var(--bg2); color: var(--text); font-size: 18px; cursor: pointer; }
.qty span { min-width: 22px; text-align: center; font-weight: 600; }
.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0; }
.card.clickable { cursor: pointer; }
.card > div + div { margin-top: 3px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.note { background: var(--bg2); border-radius: 10px; padding: 8px 10px; font-size: 14px; white-space: pre-line; }
.total { text-align: right; margin: 8px 2px; }
details.history summary { cursor: pointer; color: var(--link); padding: 12px 0; }

/* статусы */
.badge { flex: 0 0 auto; display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-new { background: rgba(255, 152, 0, .16); color: #e68a00; }
.st-ok { background: rgba(46, 160, 67, .16); color: #2ea043; }
.st-ready { background: rgba(36, 129, 204, .16); color: #2481cc; }
.st-done { background: rgba(127, 127, 127, .16); color: var(--hint); }
.st-cancel { background: rgba(229, 57, 53, .14); color: #e53935; }

/* фильтры-«чипсы» */
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px -16px; padding: 0 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 7px 12px; border: 0; border-radius: 16px; background: var(--card); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--btn); color: var(--btn-text); }
.tabs { margin-top: 0; }
.tabs .chip { font-weight: 600; }

/* корзина */
.cartbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--border);
}

/* экран успеха */
.success { text-align: center; padding-top: 30px; }
.success-icon { font-size: 56px; }

/* админка */
.info-row { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.info-row:last-child { border-bottom: 0; }
.info-row > span { flex: 0 0 96px; color: var(--hint); }
.info-row > div { flex: 1; min-width: 0; white-space: pre-line; overflow-wrap: anywhere; }
.actions { display: grid; grid-template-columns: 1fr; gap: 0; }
.wd-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.wd-row .check { flex: 0 0 86px; }
.wd-row input[type="time"] { flex: 1; min-width: 0; padding: 8px; }
.items-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.items-table td { padding: 6px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.items-table td:last-child { text-align: right; white-space: nowrap; padding-left: 8px; }

/* всплывающие сообщения */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: 24px; z-index: 50; max-width: 520px; margin: 0 auto;
  padding: 12px 16px; border-radius: 12px; background: rgba(30, 30, 30, .92); color: #fff; font-size: 14px; text-align: center;
  opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: rgba(200, 40, 40, .95); }
body.has-cartbar .toast { bottom: 90px; }
