/* Оформление подстраивается под тему Телеграма: светлую или тёмную. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f3f4f6);
  --text: var(--tg-theme-text-color, #16202b);
  --hint: var(--tg-theme-hint-color, #78849a);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(128, 140, 160, .22);
  --danger: #e04a4a;
  --ok: #17a673;
  --warn: #e08c00;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0; padding: 0 0 76px;
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}

.head { padding: 14px 16px 6px; }
.head h1 { margin: 0; font-size: 20px; }
.head .who { color: var(--hint); font-size: 13px; margin-top: 2px; }

.wrap { padding: 0 16px; }
.hidden { display: none !important; }

/* Карточки и списки */
.card {
  background: var(--card); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px;
}
.card .title { font-weight: 600; margin-bottom: 4px; }
.card .meta { color: var(--hint); font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.amount { font-weight: 600; white-space: nowrap; }

/* Полоска этапов воронки */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: transparent; color: var(--text);
  border-radius: 16px; padding: 6px 12px; font-size: 13px;
  white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Кнопки */
button, .btn {
  font: inherit; border: none; border-radius: 10px; padding: 11px 14px;
  background: var(--accent); color: var(--accent-text); cursor: pointer;
}
.btn-line {
  background: transparent; color: var(--text); border: 1px solid var(--line);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 8px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.wide { width: 100%; }

/* Поля ввода */
label { display: block; font-size: 13px; color: var(--hint); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }

/* Нижнее меню */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--bg); border-top: 1px solid var(--line); padding: 6px 4px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; background: none; color: var(--hint);
  font-size: 11px; padding: 6px 2px; border-radius: 8px;
}
.tabs button.on { color: var(--accent); }
.tabs .ic { display: block; font-size: 18px; line-height: 1.1; }

/* Всплывающее окно карточки */
.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; z-index: 50;
}
.sheet-body {
  background: var(--bg); width: 100%; max-height: 92vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px 28px;
}
.sheet h2 { margin: 0 0 12px; font-size: 18px; }

/* Показатели и графики */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border-radius: 12px; padding: 12px 14px; }
.tile .v { font-size: 21px; font-weight: 700; }
.tile .k { color: var(--hint); font-size: 12px; margin-top: 2px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--hint); font-weight: 500; font-size: 12px; }

.tag { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: var(--line); }
.tag.won { background: rgba(23,166,115,.18); color: var(--ok); }
.tag.lost { background: rgba(224,74,74,.18); color: var(--danger); }
.overdue { color: var(--danger); }
.empty { color: var(--hint); text-align: center; padding: 34px 10px; }
.err { background: rgba(224,74,74,.12); color: var(--danger);
       padding: 12px 14px; border-radius: 10px; margin: 10px 0; }

/* Полоса режима «глазами сотрудника» */
#viewbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 16px 10px; padding: 10px 12px; border-radius: 10px;
  background: rgba(224,140,0,.14); color: var(--warn);
  font-size: 13px; line-height: 1.3;
}
#viewbar button { background: var(--warn); color: #fff; white-space: nowrap; }
