/* Дизайн-система Mini App: Telegram-native, обе темы через --tg-theme-*.
   Профиль ui-ux-pro-max: high-end utility — плотно, точно, читаемо. */

:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --fg: var(--tg-theme-text-color, #16181c);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --card: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-fg: var(--tg-theme-button-text-color, #fff);
  --link: var(--tg-theme-link-color, var(--accent));
  --sep: color-mix(in srgb, var(--hint) 25%, transparent);
  --ok: #34c759;
  --warn: #e8a33d;
  --crit: #d34f4f;
  --radius: 12px;
  --radius-sm: 8px;
  --fs-title: 16px;
  --fs-body: 15px;
  --fs-meta: 13px;
  --fs-nav: 11px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: calc(56px + var(--safe-bottom));
}

/* Тёмная тема для браузера без Telegram (?dark=1 ставит data-theme) */
:root[data-theme="dark"] {
  --bg: #17181c;
  --fg: #e8e9ed;
  --hint: #8e8e93;
  --card: #24262c;
  --accent: #4da3e0;
  --accent-fg: #fff;
}

* { box-sizing: border-box; margin: 0; }
html { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: var(--fs-body)/1.5 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  padding-bottom: var(--nav-h);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
main { padding: 12px; max-width: 640px; margin: 0 auto; outline: none; }
h1 { font-size: 20px; font-weight: 700; margin: 4px 0 12px; }
h2 {
  font-size: 13px; font-weight: 600; margin: 16px 0 8px; color: var(--hint);
  text-transform: uppercase; letter-spacing: .4px;
  display: flex; align-items: center; gap: 6px;
}
h2 .count { color: var(--hint); font-weight: 500; font-variant-numeric: tabular-nums; }
a { color: var(--link); }

svg.icon { width: 20px; height: 20px; flex: 0 0 auto; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }
svg.icon.sm { width: 16px; height: 16px; vertical-align: -3px; }

/* --- Нижняя навигация --- */
nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card);
  border-top: 1px solid var(--sep);
  padding-bottom: var(--safe-bottom);
}
nav button {
  flex: 1; min-height: 52px; padding: 6px 2px;
  background: none; border: 0; cursor: pointer;
  color: var(--hint); font-size: var(--fs-nav); font-weight: 500; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  position: relative; transition: color .15s ease-out;
}
nav button.active { color: var(--accent); font-weight: 600; }
nav button:active { opacity: .6; }
nav .badge {
  position: absolute; top: 3px; left: calc(50% + 6px);
  min-width: 17px; height: 17px; padding: 0 4px;
  background: var(--crit); color: #fff; border-radius: 9px;
  font-size: 11px; font-weight: 600; line-height: 17px; text-align: center;
  font-variant-numeric: tabular-nums;
}

/* --- Карточки --- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px;
  border-left: 3px solid transparent;
  position: relative;
}
.card.tappable { cursor: pointer; transition: transform .12s ease-out, opacity .12s ease-out; }
.card.tappable:active { transform: scale(.97); opacity: .85; }
.card .title { font-weight: 600; font-size: var(--fs-title); overflow-wrap: anywhere; }
.card .meta {
  color: var(--hint); font-size: var(--fs-meta); margin-top: 3px;
  display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center;
}
.card .body { margin-top: 6px; font-size: 14px; overflow-wrap: anywhere; }
.card .actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.card.st-todo { border-left-color: var(--hint); }
.card.st-doing { border-left-color: var(--accent); }
.card.st-blocked { border-left-color: var(--warn); }
.card.st-done { border-left-color: var(--ok); }
.card.st-failed { border-left-color: var(--crit); }
.card.st-cancelled { border-left-color: var(--sep); opacity: .7; }
.card.attention { background: color-mix(in srgb, var(--warn) 12%, var(--card)); border-left-color: var(--warn); }
.card.attention.risk { background: color-mix(in srgb, var(--crit) 10%, var(--card)); border-left-color: var(--crit); }

.chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--hint) 14%, transparent);
  font-size: 12px; font-weight: 500; color: var(--fg);
  white-space: nowrap;
}
.chip.accent { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.chip.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip.crit { background: color-mix(in srgb, var(--crit) 14%, transparent); color: var(--crit); }

.pill-timer {
  font-size: 12px; font-weight: 600; color: var(--warn);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* --- Кнопки --- */
button.btn {
  min-height: 44px; padding: 10px 16px;
  background: var(--accent); color: var(--accent-fg);
  border: 0; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: opacity .12s ease-out, transform .12s ease-out;
}
button.btn:active { opacity: .75; transform: scale(.98); }
button.btn:disabled { opacity: .45; cursor: default; }
button.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.btn.danger { background: transparent; color: var(--crit); border: 1px solid var(--crit); }
button.btn.ok { background: var(--ok); color: #fff; }
button.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; }
button.btn.block { width: 100%; }

/* --- Формы --- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: var(--fs-meta); font-weight: 500; color: var(--hint); margin-bottom: 5px; }
.field label .req { color: var(--crit); }
.field input[type="text"], .field textarea, .field select {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--card); color: var(--fg);
  border: 1px solid var(--sep); border-radius: var(--radius-sm);
  font: var(--fs-body)/1.45 inherit; font-family: inherit;
}
.field textarea { min-height: 96px; resize: vertical; }
.field textarea.mono { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent;
}
.field .error { color: var(--crit); font-size: var(--fs-meta); margin-top: 4px; }
.field .helper { color: var(--hint); font-size: var(--fs-meta); margin-top: 4px; }
.field .counter { text-align: right; font-variant-numeric: tabular-nums; }
.field .counter.over { color: var(--crit); font-weight: 600; }

.chips-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-row .chip.selectable { cursor: pointer; min-height: 32px; padding: 5px 12px; border: 1px solid transparent; }
.chips-row .chip.selectable.selected { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); border-color: var(--accent); font-weight: 600; }

.seg { display: flex; background: var(--card); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button {
  flex: 1; min-height: 38px; border: 0; background: transparent; color: var(--hint);
  border-radius: 6px; font-size: 13px; font-weight: 500; font-family: inherit; cursor: pointer;
}
.seg button.selected { background: var(--bg); color: var(--fg); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button:disabled { opacity: .4; cursor: default; }

.answer-row { display: flex; gap: 8px; margin-top: 10px; }
.answer-row input { flex: 1; min-height: 44px; padding: 10px 12px; background: var(--bg);
  color: var(--fg); border: 1px solid var(--sep); border-radius: var(--radius-sm); font-family: inherit; font-size: 14px; }
.answer-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* --- Разное --- */
.bar { height: 8px; background: color-mix(in srgb, var(--hint) 18%, transparent); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; transition: width .3s ease-out; }
.bar i.warn { background: var(--warn); }
.bar i.crit { background: var(--crit); }

pre {
  white-space: pre-wrap; overflow-wrap: anywhere;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: color-mix(in srgb, var(--hint) 8%, transparent);
  border-radius: var(--radius-sm); padding: 8px 10px; margin-top: 6px;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.empty { color: var(--hint); text-align: center; padding: 36px 16px; }
.empty .btn { margin-top: 12px; }

details summary { cursor: pointer; color: var(--hint); font-size: var(--fs-meta); min-height: 28px; display: flex; align-items: center; }
details[open] summary { margin-bottom: 4px; }

.timeline { margin-top: 6px; border-left: 2px solid var(--sep); padding-left: 12px; }
.timeline .tl-item { margin-bottom: 8px; font-size: 13px; }
.timeline .tl-time { color: var(--hint); font-size: 12px; font-variant-numeric: tabular-nums; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
  min-height: 52px; cursor: pointer; border: 0; width: 100%; text-align: left;
  color: var(--fg); font: inherit;
  transition: transform .12s ease-out, opacity .12s ease-out;
}
.list-item:active { transform: scale(.98); opacity: .85; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 10px 12px; }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--hint); margin-top: 2px; }

/* --- Скелетоны (резервируют высоту — нет layout shift) --- */
.skeleton-list { display: flex; flex-direction: column; gap: 8px; }
.skeleton {
  height: 72px; border-radius: var(--radius);
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--hint) 10%, transparent) 25%,
    color-mix(in srgb, var(--hint) 18%, transparent) 50%,
    color-mix(in srgb, var(--hint) 10%, transparent) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- Toast --- */
#toasts {
  position: fixed; bottom: calc(var(--nav-h) + 10px); left: 12px; right: 12px; z-index: 40;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.toast {
  background: color-mix(in srgb, var(--fg) 88%, transparent); color: var(--bg);
  border-radius: 10px; padding: 10px 14px; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  animation: toast-in .2s ease-out; pointer-events: auto;
  max-width: 640px; margin: 0 auto; width: 100%;
}
.toast button { background: none; border: 0; color: inherit; font-weight: 700; font-family: inherit; font-size: 14px; cursor: pointer; padding: 4px 6px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- Модалка подтверждения --- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: toast-in .15s ease-out;
}
.sheet {
  background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(16px + var(--safe-bottom));
  width: 100%; max-width: 640px;
  animation: sheet-in .22s ease-out;
}
.sheet .title { font-size: var(--fs-title); font-weight: 600; margin-bottom: 6px; }
.sheet .msg { color: var(--hint); font-size: 14px; margin-bottom: 16px; }
.sheet .actions { display: flex; gap: 8px; }
.sheet .actions .btn { flex: 1; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

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