:root {
  /* Тёмная палитра «на уровне» (не зависит от светлой темы Telegram). */
  --bg: #0f1116;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, #1a1f2e 0%, #0f1116 55%);
  --surface: #171a21;
  --surface-2: #1e222b;
  --surface-3: #252a35;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --faint: #6b7280;
  --accent: #7c83ff;
  --accent-2: #a26bff;
  --accent-grad: linear-gradient(135deg, #7c83ff 0%, #a26bff 100%);
  --success: #34d399;
  --danger: #ff6b6b;
  --warning: #fbbf24;
  --radius: 16px;
  --radius-sm: 11px;
  --c1: #7c83ff;
  --c2: #34d399;
  --c3: #fbbf24;
  --c4: #ff6b9d;
  --c5: #22d3ee;
  --c6: #a26bff;
  --c7: #f97316;
  --c8: #4ade80;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 14px 48px;
}

/* ---- Шапка + табы ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-top: 6px;
}
.brand {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.2px;
}
.brand .dot {
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.who {
  font-size: 12px;
  color: var(--muted);
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 5px;
  margin-bottom: 18px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.18s ease;
}
.tab.active {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 6px 18px -8px var(--accent);
}

/* ---- Поля формы ---- */
.title {
  font-size: 20px;
  font-weight: 800;
  margin: 4px 0 4px;
}
.subtitle {
  color: var(--muted);
  font-size: 13.5px;
  margin: 0 0 18px;
  line-height: 1.45;
}
.field {
  display: flex;
  flex-direction: column;
  margin-bottom: 13px;
}
.field > label {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
input[type="text"],
input[type="date"],
select,
textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 16px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s ease;
}
input::placeholder,
textarea::placeholder {
  color: var(--faint);
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}
input[type="date"] {
  color-scheme: dark;
}
textarea {
  resize: none;
  font-family: inherit;
}
.row {
  display: flex;
  gap: 10px;
}
.grow {
  flex: 1;
}
.currency {
  width: 122px;
}

/* Фото */
.photo-field {
  display: block;
  cursor: pointer;
  margin-bottom: 8px;
}
.photo-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 156px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
  padding: 16px;
  transition: border-color 0.15s ease;
}
.photo-empty:hover {
  border-color: var(--accent);
}
.photo-icon {
  font-size: 32px;
  opacity: 0.9;
}
.photo-preview {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface);
  display: block;
  border: 1px solid var(--border);
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13.5px;
  padding: 6px 0;
  cursor: pointer;
  margin-bottom: 14px;
  font-weight: 600;
}
.submit-fallback {
  width: 100%;
  background: var(--accent-grad);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
  box-shadow: 0 10px 24px -12px var(--accent);
}
.submit-fallback:disabled {
  opacity: 0.45;
  box-shadow: none;
}
body.has-mainbutton .submit-fallback {
  display: none;
}

/* ---- Дашборд ---- */
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip.active {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}
.chips-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  align-self: center;
  white-space: nowrap;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
}
.card .k {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 7px;
}
.card .v {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.1;
}
.card .v small {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.card.accent {
  background: var(--accent-grad);
  border: none;
}
.card.accent .k,
.card.accent .v small {
  color: rgba(255, 255, 255, 0.8);
}
.card.accent .v {
  color: #fff;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.panel h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel h3 .muted {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

/* Донат */
.donut-wrap {
  display: flex;
  gap: 16px;
  align-items: center;
}
.donut {
  flex: 0 0 132px;
}
.donut-center {
  font-size: 13px;
  fill: var(--text);
  font-weight: 800;
}
.donut-center-sub {
  font-size: 9px;
  fill: var(--muted);
}
.legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
}
.legend-row .sw {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.legend-row .lbl {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.legend-row .val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Горизонтальные бары (люди) */
.hbar {
  margin-bottom: 13px;
}
.hbar:last-child {
  margin-bottom: 0;
}
.hbar-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}
.hbar-top .nm {
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbar-top .vl {
  color: var(--muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  padding-left: 10px;
}
.hbar-track {
  height: 9px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.hbar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent-grad);
  width: 0;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Вертикальные бары (динамика) */
.vbars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 110px;
  padding-top: 6px;
}
.vbar {
  flex: 1;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: 4px 4px 2px 2px;
  min-height: 2px;
  height: 0;
  transition: height 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  opacity: 0.92;
}
.vbar.empty {
  background: var(--surface-2);
  opacity: 1;
}
.vbars-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--faint);
  margin-top: 7px;
}

/* Лента */
.feed {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.feed-item {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.feed-item:active {
  background: var(--surface-2);
}
.feed-thumb {
  width: 46px;
  height: 46px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--surface-2);
  flex: 0 0 auto;
}
.feed-thumb.ph {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.feed-main {
  flex: 1;
  min-width: 0;
}
.feed-cat {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.feed-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.feed-amt {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  text-align: right;
}
.feed-amt small {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
}
.feed-conv {
  font-size: 10px;
  color: var(--faint);
  font-weight: 500;
  margin-top: 1px;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 26px 10px;
}
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: sk 1.3s infinite;
  border-radius: var(--radius);
  height: 90px;
  margin-bottom: 12px;
}
@keyframes sk {
  to {
    background-position: -200% 0;
  }
}

/* Модалка чека */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.modal-card {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border);
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh;
  overflow-y: auto;
  animation: up 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}
.modal-photo {
  width: 100%;
  max-height: 52vh;
  object-fit: contain;
  border-radius: 12px;
  background: var(--bg);
  margin-bottom: 14px;
}
.modal-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.modal-row:last-child {
  border-bottom: none;
}
.modal-row .mk {
  color: var(--muted);
}
.modal-row .mv {
  font-weight: 600;
  text-align: right;
}
.modal-close {
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

/* Плавающая кнопка «＋ Чек» */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 14px 20px 14px 17px;
  border: none;
  border-radius: 999px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 30px -8px var(--accent), 0 4px 10px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
}
.fab:active {
  transform: scale(0.95);
}
.fab-plus {
  font-size: 20px;
  line-height: 1;
  margin-top: -1px;
}

/* Отдельное окно «Новый чек» */
.screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  overflow-y: auto;
  animation: screenIn 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes screenIn {
  from {
    transform: translateY(28px);
    opacity: 0;
  }
}
.screen-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px;
  background: rgba(15, 17, 22, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.screen-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
}
.head-spacer {
  width: 38px;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.screen-body {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px calc(40px + env(safe-area-inset-bottom));
}

.noaccess {
  text-align: center;
  padding: 60px 16px;
  color: var(--muted);
}
.na-emoji {
  font-size: 48px;
  margin-bottom: 12px;
}

.success-actions {
  display: flex;
  gap: 10px;
  max-width: 360px;
  margin: 0 auto;
}
.btn-primary,
.btn-ghost {
  flex: 1;
  padding: 13px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary {
  border: none;
  background: var(--accent-grad);
  color: #fff;
}
.btn-ghost {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* Успех */
.success {
  text-align: center;
  padding: 46px 16px;
}
.success-check {
  font-size: 58px;
  margin-bottom: 12px;
}
.success h2 {
  margin: 0 0 6px;
}
.success p {
  color: var(--muted);
  margin: 0 0 22px;
}
