:root {
  --bg: #0d1017;
  --bg2: #141926;
  --card: #1a2030;
  --card2: #212a3f;
  --border: #2c3550;
  --text: #eef1f7;
  --muted: #9aa4bb;
  --accent: #7c6bff;
  --accent2: #ff6b9d;
  --accent3: #38bdf8;
  --green: #2ecc8f;
  --red: #ff5c5c;
  --radius: 16px;
  --shadow: 0 12px 32px rgba(0, 0, 0, .4);
  --grad: linear-gradient(135deg, var(--accent), var(--accent3));
  --grad2: linear-gradient(135deg, var(--accent2), var(--accent));
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(800px 400px at 85% -10%, rgba(124, 107, 255, .18), transparent 60%),
    radial-gradient(700px 400px at -10% 30%, rgba(56, 189, 248, .12), transparent 60%),
    radial-gradient(700px 500px at 50% 110%, rgba(255, 107, 157, .1), transparent 60%);
  background-attachment: fixed;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header.top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

header.top h1 {
  font-size: 20px;
  font-weight: 700;
  flex: 1;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  transition: transform .15s ease, background .15s ease;
}

.btn-back:active { transform: scale(.96); }

.btn-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  background: var(--grad);
  color: #fff;
  text-decoration: none;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(124, 107, 255, .4);
  transition: transform .15s ease, filter .15s ease;
}

.btn-plus:active { transform: scale(.94); filter: brightness(1.1); }

a {
  color: var(--accent3);
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: .7;
}

input:focus::placeholder, textarea:focus::placeholder {
  opacity: .45;
}

input, textarea, select {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 107, 255, .25);
}

textarea { resize: vertical; min-height: 96px; line-height: 1.5; }

/* ── Кнопки ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border: none;
  border-radius: 14px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .2px;
  transition: transform .15s ease, box-shadow .2s ease, filter .15s ease;
  user-select: none;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 8px 24px rgba(124, 107, 255, .35);
}
.btn-primary:not(:disabled):hover { filter: brightness(1.1); }

.btn-pink {
  background: var(--grad2);
  color: #fff;
  box-shadow: 0 8px 24px rgba(255, 107, 157, .3);
}
.btn-pink:not(:disabled):hover { filter: brightness(1.1); }

.btn-ghost {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:not(:disabled):hover { background: var(--card2); }

.btn-danger {
  background: rgba(255, 92, 92, .12);
  border: 1px solid rgba(255, 92, 92, .35);
  color: var(--red);
}
.btn-danger:not(:disabled):hover { background: rgba(255, 92, 92, .2); }

.btn-sm { min-height: 40px; padding: 0 14px; font-size: 15px; border-radius: 10px; }

/* ── Главная ─────────────────────────────── */
.hero {
  text-align: center;
  padding: 56px 0 44px;
  animation: fadeUp .5s ease both;
}

.hero .logo {
  width: 88px;
  height: 88px;
  margin: 0 auto 22px;
  border-radius: 26px;
  background: var(--grad);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 16px 40px rgba(124, 107, 255, .45);
  font-size: 40px;
  font-weight: 800;
  color: #fff;
}

.hero h2 { font-size: 26px; font-weight: 800; margin-bottom: 10px; }

.hero p { color: var(--muted); font-size: 16px; line-height: 1.6; }

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 12px;
}

.home-actions .btn { min-height: 64px; font-size: 18px; border-radius: 18px; }

/* ── Номер продажи ───────────────────────── */
.num-badge {
  text-align: center;
  padding: 18px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(124, 107, 255, .16), rgba(56, 189, 248, .12));
  border: 1px solid rgba(124, 107, 255, .4);
  margin-bottom: 20px;
  animation: fadeUp .4s ease both;
}

.num-badge .label { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
.num-badge .value { font-size: 44px; font-weight: 800; line-height: 1.15;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ── Карточки/секции ─────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  animation: fadeUp .4s ease both;
}

.section { margin-bottom: 18px; }
.section:last-child { margin-bottom: 0; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
}

/* ── Строки товаров ──────────────────────── */
.item-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  animation: fadeUp .3s ease both;
}

.item-row .item-name {
  width: 100%;
  flex-shrink: 0;
}

.item-row .item-qty { width: 72px; text-align: center; }
.item-row .item-price { flex: 1; min-width: 110px; text-align: center; }

.item-del {
  width: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: rgba(255, 92, 92, .1);
  color: var(--red);
  font-size: 18px;
  font-weight: 700;
  transition: background .15s ease;
}
.item-del:active { background: rgba(255, 92, 92, .25); }

.btn-add {
  width: 100%;
  min-height: 48px;
  border: 1px dashed var(--accent);
  background: rgba(124, 107, 255, .08);
  color: var(--accent3);
  border-radius: 12px;
  font-weight: 700;
  transition: background .15s ease;
}
.btn-add:active { background: rgba(124, 107, 255, .18); }

/* ── Итоговая сумма ──────────────────────── */
.total-box {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px;
  border-radius: 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
}

.total-box .t-label { color: var(--muted); font-size: 14px; font-weight: 600; }

.total-box .t-amount { font-size: 26px; font-weight: 800;
  background: var(--grad2); -webkit-background-clip: text; background-clip: text; color: transparent; }

.total-box .t-old {
  font-size: 15px;
  color: var(--muted);
  text-decoration: line-through;
  margin-right: 8px;
  font-weight: 600;
}

/* ── Радио оплаты ────────────────────────── */
.pay-opts { display: flex; flex-direction: column; gap: 10px; }

.pay-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}

.pay-opt:active { background: var(--card2); }

.pay-opt input { width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--accent); margin: 0; }

.pay-opt span { font-size: 16px; font-weight: 600; }

.pay-opt.selected { border-color: var(--accent); background: rgba(124, 107, 255, .1); }

/* раздельная оплата */
.split-fields { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--card2); border: 1px solid var(--border); }

.split-field { margin-bottom: 12px; }
.split-field:last-child { margin-bottom: 0; }
.split-field label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }

.split-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  background: rgba(255, 92, 92, .1);
  color: var(--red);
  border: 1px solid rgba(255, 92, 92, .3);
  transition: all .2s ease;
}

.split-status.ok { background: rgba(46, 204, 143, .1); color: var(--green); border-color: rgba(46, 204, 143, .3); }

.split-status .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; flex-shrink: 0; animation: pulse 1.4s ease infinite; }

/* ── Список продаж ───────────────────────── */
.sale-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  animation: fadeUp .35s ease both;
}

.sale-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.sale-num {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent3);
  background: rgba(56, 189, 248, .1);
  border: 1px solid rgba(56, 189, 248, .3);
  padding: 4px 10px;
  border-radius: 8px;
}

.sale-date { font-size: 13px; color: var(--muted); }

.sale-products {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.sale-desc {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg2);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.sale-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 14px;
}

.sale-meta .pay-chip {
  color: var(--green);
  background: rgba(46, 204, 143, .1);
  border: 1px solid rgba(46, 204, 143, .25);
  padding: 3px 9px;
  border-radius: 8px;
  font-weight: 600;
  word-break: break-word;
}

.sale-final {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 14px;
}

.sale-final .old {
  font-size: 14px;
  color: var(--muted);
  text-decoration: line-through;
  font-weight: 600;
  margin-left: 8px;
}

.sale-actions { display: flex; gap: 10px; }
.sale-actions .btn { flex: 1; }

.total-revenue {
  text-align: center;
  padding: 20px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(124, 107, 255, .18), rgba(255, 107, 157, .14));
  border: 1px solid rgba(124, 107, 255, .4);
  margin-top: 8px;
  margin-bottom: 14px;
  animation: fadeUp .4s ease both;
}

.total-revenue .r-label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.5px; }
.total-revenue .r-value { font-size: 30px; font-weight: 800;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

.rev-breakdown {
  margin-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, .1);
  padding-top: 12px;
}

.rev-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  font-size: 15px;
  color: var(--muted);
  border-bottom: 1px dashed rgba(255, 255, 255, .06);
}

.rev-row b { color: var(--text); font-size: 16px; }

.rev-items {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(56, 189, 248, .08);
  border: 1px solid rgba(56, 189, 248, .25);
  font-size: 15px;
  color: var(--muted);
}

.rev-items b { color: var(--accent3); font-size: 18px; }

/* ── Спиннер / пусто ─────────────────────── */
.spinner {
  text-align: center;
  padding: 60px 0;
  color: var(--muted);
}
.spinner::before {
  content: '';
  display: block;
  width: 42px;
  height: 42px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty .e-icon { font-size: 44px; margin-bottom: 14px; }

/* ── Toast ───────────────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--card2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 14px 20px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 999;
  max-width: calc(100vw - 32px);
  text-align: center;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--red); background: rgba(255, 92, 92, .15); color: #ffd9d9; }
#toast.success { border-color: var(--green); background: rgba(46, 204, 143, .14); color: #d9fff0; }

/* ── Confirm-модалка ─────────────────────── */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  opacity: 0;
  transition: opacity .2s ease;
}

.modal-mask.show { display: flex; opacity: 1; }

.modal {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow);
  transform: scale(.94);
  transition: transform .2s ease;
}

.modal-mask.show .modal { transform: scale(1); }

.modal h3 { font-size: 18px; margin-bottom: 10px; }
.modal p { color: var(--muted); font-size: 15px; line-height: 1.5; margin-bottom: 20px; word-break: break-word; }
.modal .modal-btns { display: flex; gap: 10px; }
.modal .modal-btns .btn { flex: 1; }

/* ── Анимации ────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
