/* Мини-приложение CRM. Цвета берём из темы Telegram, чтобы приложение
   выглядело родным и в светлой, и в тёмной теме. Своё — только чек сделки. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #15171a);
  --hint: var(--tg-theme-hint-color, #7b818c);
  --link: var(--tg-theme-link-color, #2a78d6);
  --accent: var(--tg-theme-button-color, #2a78d6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d33b3b);
  --line: color-mix(in srgb, var(--hint) 28%, transparent);
  --paper: color-mix(in srgb, var(--surface) 92%, #e9c46a 8%);
  --gain: #2f8f5b;
  --radius-group: 14px;
  --radius-control: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-secondary-bg-color, #0f1114);
    --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1b1e23));
    --text: var(--tg-theme-text-color, #eef0f3);
    --hint: var(--tg-theme-hint-color, #8d939d);
    --gain: #5cc48a;
  }
}
:root[data-theme="dark"] { --gain: #5cc48a; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 16px 6px; }
.tabs { display: flex; gap: 4px; background: var(--surface); border-radius: var(--radius-control); padding: 3px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 7px 4px; border-radius: 8px;
  font-size: 14px; color: var(--hint); cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }

main { padding: 6px 16px 16px; max-width: 640px; margin: 0 auto; }

h2 { font-size: 13px; font-weight: 500; color: var(--hint); margin: 18px 4px 6px; }
.lead-title { font-size: 21px; font-weight: 650; margin: 8px 4px 2px; line-height: 1.2; }
.lead-sub { color: var(--hint); margin: 0 4px 10px; }

.group { background: var(--surface); border-radius: var(--radius-group); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; min-height: 48px;
  border: 0; background: transparent; width: 100%; text-align: left; cursor: pointer;
}
.row + .row { border-top: 1px solid var(--line); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 560; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.row .meta { color: var(--hint); font-size: 14px; }
.row .end { text-align: right; font-size: 14px; white-space: nowrap; align-self: flex-start; padding-top: 1px; }
.row .end .stage { display: flex; justify-content: flex-end; margin-top: 2px; }
.row.static { cursor: default; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv span:first-child { color: var(--hint); }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; }

.stage { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--hint); }
.stage.hot { color: var(--accent); }
.late { color: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }

.btn {
  display: block; width: 100%; border: 0; border-radius: var(--radius-control);
  background: var(--accent); color: var(--accent-text); padding: 12px; font-weight: 600; cursor: pointer;
}
.btn.quiet { background: var(--surface); color: var(--link); font-weight: 500; }
.btn.danger { background: var(--surface); color: var(--danger); font-weight: 500; }
.btn + .btn { margin-top: 8px; }
.actions { display: grid; gap: 8px; margin-top: 10px; }
.actions.two { grid-template-columns: 1fr 1fr; }
.btn:disabled { opacity: .55; }

label.field { display: block; padding: 8px 14px; }
label.field + label.field, .group > .chips-field + label.field, label.field + .chips-field { border-top: 1px solid var(--line); }
label.field > span { display: block; font-size: 13px; color: var(--hint); margin-bottom: 2px; }
label.field input, label.field select, label.field textarea {
  width: 100%; border: 0; background: transparent; padding: 2px 0; outline: none; font-size: 16px;
}
label.field textarea { resize: vertical; min-height: 44px; }
label.field ::placeholder { color: var(--hint); opacity: .55; }
.chips-field { padding: 8px 14px 4px; }
.chips-field > span { display: block; font-size: 13px; color: var(--hint); }
.split { display: grid; grid-template-columns: 1fr 1fr; }
.split > label.field + label.field { border-top: 0; border-left: 1px solid var(--line); }

/* Текст заявки — ровно как он уйдёт в общий чат. */
.message {
  white-space: pre-wrap; background: var(--surface); border-radius: var(--radius-group);
  padding: 12px 14px; margin: 0; font: inherit; line-height: 1.45;
  border-left: 3px solid var(--accent);
}

/* Чек сделки: откуда взялась каждая копейка. */
.receipt {
  background: var(--paper); border-radius: 4px; padding: 14px 16px 18px; position: relative;
  box-shadow: 0 1px 0 var(--line);
  --zig: radial-gradient(circle at 6px 0, transparent 5px, var(--paper) 5.5px);
}
.receipt::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 6px;
  background: var(--zig); background-size: 12px 6px;
}
.receipt .line { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; }
.receipt .line .name { white-space: nowrap; }
.receipt .line .dots { flex: 1; border-bottom: 1px dotted var(--hint); transform: translateY(-4px); min-width: 12px; }
.receipt .line .sum { white-space: nowrap; }
.receipt .total { font-weight: 700; font-size: 18px; border-top: 1px dashed var(--hint); margin-top: 6px; padding-top: 8px; }
.receipt .share .sum { font-weight: 650; color: var(--gain); }
.receipt .note { color: var(--hint); font-size: 13px; margin-top: 8px; }
.receipt .warn { color: var(--danger); font-weight: 600; }

.wallet-head { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px 4px; }
.wallet-head strong { font-size: 17px; }
.wallet-free { font-size: 26px; font-weight: 700; padding: 0 14px 10px; }
.wallet-free small { font-size: 13px; font-weight: 400; color: var(--hint); margin-left: 6px; }

.empty { text-align: center; color: var(--hint); padding: 28px 16px; }
.empty .btn { margin-top: 12px; }
.muted { color: var(--hint); font-size: 14px; }
.gain { color: var(--gain); }
.space { height: 10px; }

.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; padding: 10px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet .inner { max-width: 640px; margin: 0 auto; }
.sheet .bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sheet .bar button { border: 0; background: none; color: var(--link); padding: 8px 4px; cursor: pointer; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); border-radius: var(--radius-control); padding: 12px 14px;
  max-width: 560px; margin: 0 auto;
}
.toast.error { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: no-preference) {
  .sheet:not([hidden]) { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(14px); } to { transform: none; } }
}

input.markup { width: 84px; text-align: right; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--bg); font-size: 16px; }
label.row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
