/* tools/miniapp/css/app.css — Приёмка. Кадр — главное, интерфейс не спорит
   с фото. Тема — переменные --tg-theme-*, которые сам telegram-web-app.js
   ставит на :root внутри Telegram; вне Telegram (разработка в браузере)
   работают запасные значения ниже. */

:root {
  --bg: var(--tg-theme-bg-color, #14161a);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #1b1e24);
  --text: var(--tg-theme-text-color, #e6e6e6);
  --hint: var(--tg-theme-hint-color, #8b93a1);
  --link: var(--tg-theme-link-color, #5b8def);
  --button: var(--tg-theme-button-color, #3a5fa8);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --border: #2c313a;
  --ok: #3a7a45;
  --warn: #a8791f;
  --bad: #8f3030;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.screen {
  min-height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

button { font: inherit; }

.icon-btn {
  background: rgba(0,0,0,.35); color: #fff; border: none; border-radius: 50%;
  width: 38px; height: 38px; font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}

.btn {
  border: none; border-radius: 10px; padding: 12px 18px; font-size: 15px;
  font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-ghost { background: transparent; color: var(--hint); border: 1px solid var(--border); }

/* --- топбар (партии/дуэль/сводка) ------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  position: sticky; top: 0; background: var(--bg); z-index: 3;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; }
.toggle-line { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--hint); }

/* --- экран 1: партии ---------------------------------------------------- */
.pull-hint { text-align: center; padding: 8px; color: var(--hint); font-size: 12px; }
.batches-list { padding: 10px 14px; display: flex; flex-direction: column; gap: 10px; }
.batch-card {
  background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px;
}
.batch-card .name { font-size: 15px; font-weight: 600; margin-bottom: 6px; word-break: break-word; }
.batch-card .stats { display: flex; gap: 14px; font-size: 12px; color: var(--hint); margin-bottom: 8px; }
.batch-card .bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin-bottom: 8px; }
.batch-card .bar-fill { height: 100%; background: var(--ok); }
.batch-status { font-size: 11px; padding: 3px 8px; border-radius: 20px; display: inline-block; }
.status-новое, .status-не-начато { background: var(--border); color: var(--hint); }
.status-в-работе { background: rgba(168,121,31,.25); color: #d9a94a; }
.status-завершено { background: rgba(58,122,69,.25); color: #6fbf7d; }
.empty-hint { text-align: center; color: var(--hint); padding: 40px 20px; }

/* --- экран 2: лента ------------------------------------------------------ */
.feed-stage {
  position: fixed; inset: 0; background: #000; overflow: hidden;
  touch-action: none;
}
.feed-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  user-select: none; -webkit-user-drag: none;
}
.feed-flash {
  position: absolute; inset: 0; opacity: 0; pointer-events: none;
  transition: opacity .12s ease-out;
}
.feed-flash.on-a { background: rgba(58,122,69,.55); opacity: 1; }
.feed-flash.on-b { background: rgba(168,121,31,.55); opacity: 1; }
.feed-flash.on-x { background: rgba(143,48,48,.55); opacity: 1; }

.feed-topline {
  position: absolute; top: calc(var(--safe-top) + 10px); left: 10px; right: 10px;
  display: flex; align-items: center; justify-content: space-between; z-index: 4;
}
.feed-progress {
  background: rgba(0,0,0,.45); color: #fff; padding: 6px 14px; border-radius: 20px;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.feed-counters {
  position: absolute; top: calc(var(--safe-top) + 56px); left: 10px;
  display: flex; gap: 6px; z-index: 4;
}
.cnt { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: rgba(0,0,0,.45); color: #fff; }
.cnt-a { color: #8fd39c; } .cnt-b { color: #e3bd75; } .cnt-x { color: #e58f8f; }

.feed-meta {
  position: absolute; left: 10px; right: 10px; bottom: calc(var(--safe-bottom) + 16px);
  background: rgba(0,0,0,.6); color: #cbd2dd; font-size: 12px; padding: 10px 12px;
  border-radius: 10px; z-index: 4; line-height: 1.6;
}
.undo-btn {
  position: absolute; bottom: calc(var(--safe-bottom) + 16px); right: 12px; z-index: 4;
  background: rgba(0,0,0,.55); color: #fff; border: none; border-radius: 20px;
  padding: 8px 14px; font-size: 13px;
}

/* шторка причины брака */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--bg-secondary); border-radius: 16px 16px 0 0;
  padding: 10px 16px calc(16px + var(--safe-bottom));
  box-shadow: 0 -8px 24px rgba(0,0,0,.4);
}
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 4px auto 10px; }
.sheet-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  background: var(--border); color: var(--text); border: 1px solid transparent;
  border-radius: 20px; padding: 8px 14px; font-size: 13px;
}
.chip.sel { background: var(--bad); border-color: #b04040; color: #fff; }
.reason-comment {
  width: 100%; min-height: 60px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px; font: inherit; resize: vertical;
}
.sheet-actions { display: flex; gap: 10px; margin-top: 12px; }
.sheet-actions .btn { flex: 1; }

/* онбординг */
.onboarding {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 20;
  display: flex; align-items: center; justify-content: center;
}
.onb-card {
  background: var(--bg-secondary); border-radius: 16px; padding: 24px;
  width: min(320px, 86vw); text-align: left;
}
.onb-row { font-size: 15px; padding: 6px 0; display: flex; gap: 10px; align-items: center; }
.onb-arrow { width: 24px; text-align: center; font-size: 18px; color: var(--link); }
.onb-note { color: var(--hint); font-size: 12px; margin-top: 6px; }
.onb-card .btn { width: 100%; margin-top: 16px; }

/* --- экран 3: дуэль ------------------------------------------------------ */
.duel-hint { color: var(--hint); font-size: 12px; padding: 0 16px 8px; }
.duel-progress { font-size: 12px; color: var(--hint); }
.duel-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 12px;
}
.duel-tile {
  position: relative; border-radius: 10px; overflow: hidden; aspect-ratio: 1;
  border: 3px solid transparent; background: #000;
}
.duel-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.duel-tile.sel { border-color: var(--ok); }
.duel-tile .badge {
  position: absolute; top: 6px; right: 6px; background: var(--ok); color: #fff;
  border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center;
  justify-content: center; font-size: 13px; opacity: 0;
}
.duel-tile.sel .badge { opacity: 1; }

/* --- экран 4: сводка ------------------------------------------------------ */
.summary-counts { display: flex; gap: 10px; padding: 14px 16px; flex-wrap: wrap; }
.summary-counts .tile {
  flex: 1 1 70px; background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; text-align: center;
}
.summary-counts .tile .n { font-size: 22px; font-weight: 700; }
.summary-counts .tile .l { font-size: 11px; color: var(--hint); margin-top: 2px; }
.summary-reasons { padding: 0 16px 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.summary-reasons .chip { pointer-events: none; }
.summary-actions { display: flex; flex-direction: column; gap: 10px; padding: 10px 16px; }
.offline-snack {
  margin: 10px 16px; padding: 10px 14px; border-radius: 10px;
  background: rgba(168,121,31,.2); color: #d9a94a; font-size: 12px;
}

/* --- зум --------------------------------------------------------------- */
.zoom-overlay {
  position: fixed; inset: 0; background: #000; z-index: 30;
  display: flex; align-items: center; justify-content: center;
}
.zoom-overlay img { max-width: 100%; max-height: 100%; touch-action: pinch-zoom; }

/* --- тост ---------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%); background: rgba(20,22,26,.95); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 40;
  max-width: 86vw; text-align: center;
}

[hidden] { display: none !important; }
