/* =====================================================================
   Стили приложения лояльности.

   ГЛАВНОЕ ПРАВИЛО: сначала телефон, потом всё остальное.
   Админ работает стоя, одной рукой, у стойки с клиентом. Поэтому:
     * кнопки не ниже 56px, поля ввода не ниже 56px — попадать пальцем;
     * размер шрифта в полях >= 16px, иначе iOS зумит страницу при фокусе;
     * НИКАКИХ таблиц для данных — на 360px они разъезжают. Только карточки;
     * ничего не вылезает по горизонтали: box-sizing + max-width + перенос слов.
   ===================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #14161a;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #1558e8;
  --accent-dark: #0f47bd;
  --green: #0b7a3e;
  --green-bg: #e7f6ed;
  --red: #c62828;
  --red-bg: #fdecec;
  --amber: #a35c00;
  --amber-bg: #fff5e3;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

html {
  /* Не даём странице ездить вбок ни при каких обстоятельствах. */
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  overflow-x: hidden;
  /* Учитываем «чёлку» и нижнюю панель на iPhone */
  padding-bottom: env(safe-area-inset-bottom);
}

/* Длинные телефоны/номера/комментарии не должны рвать вёрстку */
h1, h2, h3, p, span, div, td, li, label {
  overflow-wrap: anywhere;
}

img { max-width: 100%; height: auto; }

/* ------------------------------------------------------------- Шапка */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar a { color: inherit; text-decoration: none; }

.topbar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}

/* На узких экранах (320-400px) название целиком не влезает и обрезается
   многоточием. Прячем слово, оставляем иконку — ссылка «на главную» узнаётся. */
.topbar .brand-text { display: none; }

@media (min-width: 400px) {
  .topbar .brand-text { display: inline; }
}

.topbar nav {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.topbar nav a {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
  color: var(--muted);
}

.topbar nav a:active { background: var(--bg); }

/* ---------------------------------------------------------- Контейнер */

.container {
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: 14px 14px 40px;
}

h1 { font-size: 1.35rem; margin: 0 0 14px; }
h2 { font-size: 1.05rem; margin: 22px 0 10px; color: var(--muted); font-weight: 600; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.muted { color: var(--muted); font-size: 0.92rem; }
.center { text-align: center; }

/* ------------------------------------------------------ Поля и кнопки */

.field { margin-bottom: 14px; }

.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

.input {
  width: 100%;
  min-height: 56px;           /* палец, а не курсор */
  padding: 12px 14px;
  font-size: 1.15rem;         /* >16px — iOS не зумит при фокусе */
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  outline: none;
}

.input:focus { border-color: var(--accent); }

/* Крупный ввод сумм и телефона — самое частое действие */
.input-lg {
  min-height: 66px;
  font-size: 1.6rem;
  font-weight: 600;
  text-align: center;
}

/* Числовые поля: убираем стрелки, они мешают на тач-экране */
.input[type="number"]::-webkit-outer-spin-button,
.input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 58px;
  padding: 14px 16px;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn + .btn { margin-top: 10px; }

.btn-green { background: var(--green); }
.btn-red { background: var(--red); }

.btn-ghost {
  background: #fff;
  color: var(--text);
  border: 2px solid var(--line);
}

.btn-sm {
  min-height: 44px;
  width: auto;
  padding: 8px 14px;
  font-size: 0.92rem;
}

/* Три главные кнопки на первом экране */
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions .btn { min-height: 66px; font-size: 1.15rem; }

/* --------------------------------------------------------- Уведомления */

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
  font-size: 0.98rem;
  border: 1px solid transparent;
}

.alert-ok { background: var(--green-bg); color: var(--green); border-color: #bfe4cd; }
.alert-err { background: var(--red-bg); color: var(--red); border-color: #f3c7c7; }
.alert-warn { background: var(--amber-bg); color: var(--amber); border-color: #f0dcb4; }

/* Плашка «примените скидку вручную» — её нельзя не заметить */
.banner {
  background: var(--amber-bg);
  border: 3px solid var(--amber);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 16px;
  text-align: center;
}

.banner .banner-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--amber);
  margin-bottom: 8px;
}

.banner .banner-value {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
}

/* ------------------------------------------------------------- Баланс */

.balance-box {
  text-align: center;
  padding: 18px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.balance-label {
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.balance-value {
  font-size: 3.2rem;
  font-weight: 800;
  line-height: 1.05;
  margin: 4px 0 0;
  /* Огромный баланс (100 000+) не должен вылезать за экран */
  overflow-wrap: anywhere;
}

.balance-value.zero { color: var(--muted); }
.balance-value.negative { color: var(--red); }

/* Итог расчёта на формах: «начислим 40 баллов» */
.calc-box {
  background: var(--green-bg);
  border: 2px solid #bfe4cd;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  text-align: center;
}

.calc-box .calc-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--green);
  line-height: 1.15;
}

.calc-box.neutral { background: var(--bg); border-color: var(--line); }
.calc-box.neutral .calc-value { color: var(--text); }

/* --------------------------------------------- Список операций (карточки) */

.tx-list { display: flex; flex-direction: column; gap: 8px; }

.tx {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.tx-info { min-width: 0; flex: 1; }   /* min-width:0 — иначе flex не даёт тексту сжаться */

.tx-title { font-weight: 600; font-size: 0.98rem; }
.tx-sub { color: var(--muted); font-size: 0.86rem; margin-top: 2px; }

.tx-points {
  flex-shrink: 0;
  font-size: 1.2rem;
  font-weight: 800;
  white-space: nowrap;
}

.tx-points.plus { color: var(--green); }
.tx-points.minus { color: var(--red); }

.tx.reversed { opacity: 0.55; }
.tx.reversed .tx-points { text-decoration: line-through; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
}

.badge-reversed { background: var(--red-bg); color: var(--red); border-color: #f3c7c7; }

/* --------------------------------------------------------- Список авто */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
}

.chip.invalid { background: var(--amber-bg); border-color: #f0dcb4; color: var(--amber); }

/* ------------------------------------------------------------ Фильтры */

.filters { display: flex; flex-direction: column; gap: 10px; }

.filters .row2 { display: flex; gap: 10px; }
.filters .row2 > * { flex: 1; min-width: 0; }

/* --------------------------------------------------------- Разделитель */

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

.link { color: var(--accent); text-decoration: none; font-weight: 600; }

/* ------------------------------------------------- Планшет / десктоп */

@media (min-width: 640px) {
  body { font-size: 16px; }
  .container { padding: 22px 20px 60px; }
  .actions { flex-direction: row; }
  .actions .btn { flex: 1; }
  h1 { font-size: 1.6rem; }
}
