/* Insight Mini App — ONE fixed dark theme for all users.
   No Telegram themeParams, no light mode: a single Telegram-dark-inspired look. */

:root {
  --bg: #0e0f13;
  --surface: #17181d;
  --elevated: #202127;
  --border: rgba(255, 255, 255, 0.07);
  --text: #f3f4f7;
  --muted: #8a8d97;
  --faint: #5c5f68;
  --accent: #4c9dfa;
  --accent-ink: #05121f;
  --success: #5ec26e;
  --warn: #f0b45e;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
}

.screen { animation: fade 0.25s ease; }
.screen[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 2px 10px;
}
.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.header-action {
  flex: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  background: var(--elevated);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.header-action:active { opacity: 0.8; }
.header-action[hidden] { display: none; }
.header-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.icon-action { padding: 7px 11px; font-size: 15px; }
/* Admin gear for screens without a header (unknown/blocked/error). */
.admin-float {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  right: 14px;
  z-index: 50;
}
/* Narrow viewports (~380px and below): keep title + Консультация + gear on
   one line by tightening the text button; the title truncates, never the
   actions. */
.app-title { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 380px) {
  .header-action { padding: 6px 10px; font-size: 12px; }
  .icon-action { padding: 6px 9px; font-size: 14px; }
}
/* Admin form helper text. */
.form-hint {
  margin: 6px 2px 0;
  font-size: 12px;
  color: var(--muted, #8a8a8e);
}

/* --- Admin screen --- */
.admin-block { margin-bottom: 22px; }
.admin-heading {
  font-size: 15px;
  font-weight: 700;
  margin: 8px 0 10px;
}
.admin-total { color: var(--muted); font-weight: 600; font-size: 13px; }
.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
}
.admin-table th,
.admin-table td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.admin-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--elevated);
  position: sticky;
  top: 0;
}
.admin-table td { color: var(--text); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.admin-badge.yes { background: rgba(94, 194, 110, 0.16); color: var(--success); }
.admin-badge.no { color: var(--faint); }

/* --- Admin video management --- */
.admin-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 4px 0 12px;
}
.admin-input {
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  min-width: 0;
}
.admin-add-form .admin-input { flex: 1 1 120px; }
.admin-add-form .add-order { flex: 0 0 70px; }
.admin-check { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.admin-table .admin-input { width: 100%; font-size: 12px; padding: 5px 7px; }
.admin-table .add-order,
.admin-table td .admin-input.cell-order { width: 60px; }
.btn.admin-btn-sm {
  margin-top: 0;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 8px;
  width: auto;
}
.admin-row-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  margin-right: 5px;
  background: var(--elevated);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.admin-row-btn.danger { color: var(--warn); }
.admin-row-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- Stats --- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.stats-card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stats-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  padding: 3px 0;
}
.stats-row .label { color: var(--muted); }
.stats-row .value { font-weight: 700; color: var(--text); }
.stats-note { font-size: 12px; color: var(--faint); margin: 10px 0 0; }

/* --- Settings --- */
.settings-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 14px;
}
.settings-row .label { color: var(--muted); }
.settings-row .value { font-weight: 700; color: var(--text); }
.settings-source {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--elevated);
  color: var(--muted);
  text-transform: uppercase;
}

/* --- Tabs --- */
.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 4px;
  padding: 8px 0 0;
  margin-bottom: 14px;
  background: linear-gradient(var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px 2px 10px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.tab-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--elevated);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.tab[aria-selected="true"] .tab-count {
  background: var(--accent);
  color: var(--accent-ink);
}

/* --- Video cards --- */
.video-list { display: flex; flex-direction: column; gap: 10px; }

.video-card {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform 0.1s ease, background 0.15s ease;
}
.video-card.clickable { cursor: pointer; }
.video-card.clickable:hover { background: var(--elevated); }
.video-card.clickable:active { transform: scale(0.985); }
.video-card.locked { opacity: 0.5; }

.card-icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}
.card-icon.is-watched { background: rgba(94, 194, 110, 0.14); color: var(--success); }
.card-icon.is-unlocked { background: rgba(76, 157, 250, 0.15); color: var(--accent); }

.card-body { min-width: 0; }
.card-kicker {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.card-title {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.empty {
  text-align: center;
  color: var(--faint);
  font-size: 14px;
  padding: 40px 16px;
}

/* --- Centered notice states (blocked / unknown / error) --- */
.screen-centered {
  min-height: 82vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.notice {
  text-align: center;
  padding: 24px;
  max-width: 340px;
}
.notice-icon { font-size: 44px; }
.notice-title { margin: 14px 0 8px; font-size: 20px; font-weight: 700; }
.notice-text { margin: 0; color: var(--muted); font-size: 15px; }

.btn {
  margin-top: 20px;
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn:active { opacity: 0.85; }

/* --- Skeleton loading --- */
.skeleton-tabs { display: flex; gap: 4px; padding: 26px 0 14px; }
.skeleton-list { display: flex; flex-direction: column; gap: 10px; }
.skeleton {
  display: block;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--elevated) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-tab { flex: 1; height: 34px; }
.skeleton-card { height: 68px; border-radius: var(--radius); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* --- Placeholder player modal --- */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}
.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
  animation: sheet-up 0.25s ease;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-title { margin: 0; font-size: 17px; font-weight: 700; }
.modal-text { margin: 0; color: var(--muted); font-size: 15px; }
.modal-sheet .btn { margin-top: 22px; width: 100%; }
.modal-close {
  flex: none;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: var(--elevated);
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
.modal-close:active { opacity: 0.8; }

/* --- Player --- */
.player-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}
.player-video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}
/* Drifting, low-opacity watermark showing the viewer's tg_id. It sits above the
   video, cannot be interacted with, and slowly repositions so it can't be
   cropped out of a screen recording. */
.player-watermark {
  position: absolute;
  top: 10%;
  left: 8%;
  pointer-events: none;
  user-select: none;
  color: rgba(255, 255, 255, 0.42);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  transition: top 2.5s linear, left 2.5s linear;
  z-index: 2;
}
.player-stage.is-hidden { display: none; }

/* --- Discussion thread --- */
.thread { margin-top: 20px; text-align: left; }
.thread-heading {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.thread-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.thread-empty { color: var(--faint); font-size: 14px; padding: 8px 0; }

.reply {
  padding: 10px 12px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.reply.is-team { border-color: rgba(76, 157, 250, 0.4); }
.reply.is-mine { border-color: rgba(76, 157, 250, 0.28); background: rgba(76, 157, 250, 0.06); }
.reply-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.reply-author { font-size: 13px; font-weight: 700; color: var(--text); }
.reply.is-team .reply-author { color: var(--accent); }
.reply-mine-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  margin-left: 6px;
}
.reply-time { font-size: 11px; color: var(--faint); flex: none; }
.reply-body { font-size: 14px; color: var(--text); white-space: pre-wrap; word-break: break-word; }

.thread-form { display: flex; flex-direction: column; gap: 10px; }
.thread-input {
  width: 100%;
  resize: vertical;
  min-height: 44px;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}
.thread-input:focus { outline: none; border-color: var(--accent); }
.thread-send { margin-top: 0; width: 100%; }
.thread-send:disabled { opacity: 0.5; cursor: default; }
.thread-error { margin: 0; color: var(--warn); font-size: 13px; }

/* --- Consultation form --- */
.modal-sheet .form-note { text-align: left; margin: 0 0 14px; }
.modal-sheet #consult-input { text-align: left; }
.modal-sheet #consult-send:disabled { opacity: 0.5; cursor: default; }
.form-msg { margin: 14px 0 0; font-size: 14px; color: var(--warn); text-align: left; }
.form-msg.is-success { color: var(--success); }
