:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #8a8a8a);
  --card: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --link: var(--tg-theme-link-color, #2ea6ff);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 560px; margin: 0 auto; padding: 14px 14px 80px; }
.hint { color: var(--hint); font-size: 13px; }
.hidden { display: none !important; }

#head { padding: 6px 4px 14px; }
#hname { font-size: 22px; font-weight: 700; }
#hstatus { margin-top: 2px; }

.tab { display: none; }
.tab.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.card { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px; padding: 13px 15px; margin-bottom: 9px; }
.card .k { color: var(--hint); font-size: 14px; flex-shrink: 0; }
.card .v { font-weight: 600; text-align: right; word-break: break-word; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: 14px; padding: 16px; text-align: center; }
.stat .num { font-size: 28px; font-weight: 800; }
.stat .lbl { color: var(--hint); font-size: 12px; margin-top: 4px; }

.funnel-title { margin: 22px 4px 10px; font-weight: 700; font-size: 16px; }
.fbar { background: var(--card); border-radius: 12px; margin-bottom: 8px; overflow: hidden;
  position: relative; height: 38px; display: flex; align-items: center; }
.fbar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent);
  opacity: .22; border-radius: 12px; transition: width .5s ease; }
.fbar .ftext { position: relative; padding: 0 14px; display: flex; justify-content: space-between;
  width: 100%; font-size: 14px; }
.fbar .ftext b { font-weight: 700; }

.feat-hint { margin: 2px 4px 14px; }
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 14px;
  background: var(--card); border-radius: 14px; padding: 14px 15px; margin-bottom: 10px; cursor: pointer; }
.toggle span { display: flex; flex-direction: column; }
.toggle b { font-size: 15px; }
.toggle small { color: var(--hint); font-size: 12px; margin-top: 2px; }
.toggle input { display: none; }
.toggle i { flex-shrink: 0; width: 48px; height: 28px; border-radius: 999px; background: #9993;
  position: relative; transition: background .2s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px #0003; }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(20px); }
.toggle.busy { opacity: .5; pointer-events: none; }

#tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--bg);
  border-top: 1px solid #8881; padding: 6px 4px env(safe-area-inset-bottom); }
#tabs button { flex: 1; background: none; border: none; color: var(--hint); font-size: 12px;
  padding: 8px 0; cursor: pointer; }
#tabs button.active { color: var(--accent); font-weight: 700; }

#err { position: fixed; left: 14px; right: 14px; bottom: 70px; background: #e0394a;
  color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; text-align: center; }

.sec-title { margin: 22px 4px 10px; font-weight: 700; font-size: 16px; }

/* тренд-график */
#trend .chart { width: 100%; height: 110px; }
#trend .chart path { stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
#trend .chart circle { fill: var(--accent); }
.chart-x { display: flex; justify-content: space-between; color: var(--hint);
  font-size: 11px; padding: 2px 2px 0; }

/* отклики/диалоги */
.dlg { background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 9px; }
.dlg-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.dlg-st { font-size: 13px; font-weight: 600; }
.dlg-date { color: var(--hint); font-size: 12px; }
.dlg-title { font-weight: 600; font-size: 15px; }
.dlg-emp { color: var(--hint); font-size: 13px; margin-top: 2px; }

/* редактируемые настройки */
.cfg { margin-bottom: 6px; }
.cfgrow { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px; padding: 11px 15px; margin-bottom: 9px; }
.cfgrow span { font-size: 14px; }
.cfgrow input, .cfgrow select { background: transparent; border: none; color: var(--text);
  font-size: 15px; font-weight: 600; text-align: right; max-width: 55%; outline: none;
  font-family: inherit; }
.cfgrow input.busy, .cfgrow select.busy { opacity: .5; }

#tabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 18px; }
#tabs button span { font-size: 11px; }

.hint.pad { padding: 8px 4px; }
.fval em { color: var(--hint); font-style: normal; font-size: 12px; margin-left: 4px; }

/* отклики: панель сортировки + кликабельность */
.dlg-bar { display: flex; justify-content: space-between; align-items: center;
  margin: 2px 2px 12px; }
#dlg-sort { background: var(--card); color: var(--text); border: none; border-radius: 10px;
  padding: 7px 10px; font-size: 13px; font-family: inherit; }
.dlg { cursor: pointer; transition: transform .1s; }
.dlg:active { transform: scale(.985); }

/* группа функции (тумблер + под-настройка) */
.featgroup { background: var(--card); border-radius: 14px; margin-bottom: 10px; padding: 2px; }
.featgroup .toggle { background: transparent; margin: 0; }
.cfgrow.sub { background: transparent; border-top: 1px solid #8881; border-radius: 0;
  margin: 0; padding: 11px 15px; }

/* модалка диалога */
#modal { position: fixed; inset: 0; background: #0008; display: flex; align-items: flex-end;
  z-index: 50; }
.modal-card { background: var(--bg); width: 100%; max-width: 560px; margin: 0 auto;
  border-radius: 18px 18px 0 0; max-height: 85vh; display: flex; flex-direction: column;
  animation: slideup .22s ease; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head { padding: 14px 16px 10px; border-bottom: 1px solid #8881; position: relative; }
#m-close { position: absolute; right: 12px; top: 12px; background: var(--card); border: none;
  color: var(--text); width: 30px; height: 30px; border-radius: 50%; font-size: 14px; cursor: pointer; }
.modal-title { font-weight: 700; font-size: 16px; padding-right: 36px; }
.modal-emp { margin-top: 3px; }
#m-body { overflow-y: auto; padding: 14px 16px; flex: 1; }
.msg { margin-bottom: 10px; display: flex; flex-direction: column; }
.msg.me { align-items: flex-end; }
.msg .bub { max-width: 80%; padding: 9px 13px; border-radius: 14px; font-size: 14px;
  white-space: pre-wrap; word-break: break-word; }
.msg.them .bub { background: var(--card); border-bottom-left-radius: 4px; }
.msg.me .bub { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg .mt { font-size: 10px; color: var(--hint); margin-top: 3px; }
.modal-hh { display: block; text-align: center; padding: 14px; color: var(--link);
  text-decoration: none; border-top: 1px solid #8881; font-weight: 600; }
