/* FRK Moderator dashboard — themed via Telegram.WebApp.themeParams,
   with a light/dark fallback palette for standalone/dev viewing.
   Visual language: a plain "modern SaaS dashboard" look (generous
   whitespace, sans-serif type, a single accent color carrying emphasis)
   layered on top of whatever palette Telegram hands us at runtime. */

:root {
  --bg: #0f1115;
  --secondary-bg: #161922;
  --card-bg: #1a1e29;
  --text: #eef1f8;
  --hint: #8b93a7;
  --button: #4c8bf5;
  --button-text: #ffffff;
  --link: #6ab2ff;
  --border: rgba(255, 255, 255, 0.09);

  --accent-pending: #f0b429;
  --accent-executed: #f2542d;
  --accent-false: #7a8296;
  --accent-skipped: #4c8bf5;
  --accent-ok: #2fbf71;

  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.28);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

/* Telegram light themes report their own palette via themeParams; when it's
   applied (see app.js) these tokens get overridden inline, so this block
   only matters when running outside Telegram with a light OS theme. */
@media (prefers-color-scheme: light) {
  :root:not([data-tg-themed]) {
    --bg: #f6f7fb;
    --secondary-bg: #eef0f5;
    --card-bg: #ffffff;
    --text: #14161f;
    --hint: #6b7280;
    --border: rgba(16, 19, 26, 0.09);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 6px 18px rgba(16, 19, 26, 0.06);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

code, .mono {
  font-family: "SF Mono", "Cascadia Code", ui-monospace, "JetBrains Mono", Consolas, monospace;
  font-size: 0.93em;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

/* -- header ------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 18px;
}

.topbar__title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar__icon {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(76, 139, 245, 0.35));
}

.topbar h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.topbar__subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Live indicator: the panel refreshes itself, so there is no refresh button. */
.live {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent-ok) 45%, var(--border));
  background: color-mix(in srgb, var(--accent-ok) 10%, var(--card-bg));
  color: var(--accent-ok);
  font-size: 12px;
  font-weight: 700;
}

.live__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent);
  animation: live-pulse 1.8s ease-out infinite;
}

.live.is-offline {
  color: var(--accent-pending);
  border-color: color-mix(in srgb, var(--accent-pending) 45%, var(--border));
  background: color-mix(in srgb, var(--accent-pending) 10%, var(--card-bg));
}

.live.is-offline .live__dot {
  animation: none;
}

@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  70%, 100% { box-shadow: 0 0 0 7px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .live__dot { animation: none; }
}

/* -- tab navigation -------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 8px;
  border: none;
  border-radius: calc(var(--radius-md) - 4px);
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.tab__badge[hidden] {
  display: none;
}

.tab__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-pending);
  color: #14161f;
  font-size: 10.5px;
  font-weight: 800;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tab-panel[hidden] {
  display: none;
}

/* -- stat tiles ----------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 15px 15px 13px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.tile:hover {
  transform: translateY(-2px);
  border-color: var(--tile-accent, var(--border));
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--tile-accent, var(--button));
  opacity: 0.85;
}

.tile__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--hint);
  font-weight: 600;
  margin-bottom: 8px;
}

.tile__value {
  font-size: 25px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* -- cards ------------------------------------------------------------ */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 20px;
  box-shadow: var(--shadow);
}

.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.card__head h2 {
  font-size: 14.5px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.card__hint {
  font-size: 11.5px;
  color: var(--hint);
  white-space: nowrap;
}

.chart-wrap {
  width: 100%;
}

.chart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.bar-row {
  transition: opacity 0.15s ease;
}

.bar-rect {
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1), fill 0.15s ease;
}

.area-path {
  transition: d 0.5s ease;
}

/* -- empty states ---------------------------------------------------------- */

.empty-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--hint);
  font-size: 13px;
  padding: 22px 10px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--secondary-bg);
}

/* -- settings / controls ---------------------------------------------------- */

.settings {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.switch-row__label {
  font-size: 13.5px;
  font-weight: 500;
}

.switch {
  position: relative;
  display: inline-block;
  flex: none;
  width: 42px;
  height: 24px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch__track {
  position: absolute;
  inset: 0;
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.switch__track::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--hint);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1), background 0.2s ease;
}

.switch input:checked + .switch__track {
  background: var(--button);
  border-color: var(--button);
}

.switch input:checked + .switch__track::before {
  transform: translateX(18px);
  background: #ffffff;
}

.switch input:disabled + .switch__track {
  opacity: 0.5;
  cursor: not-allowed;
}

.settings__rules {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rule-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  user-select: none;
}

.rule-chip input {
  accent-color: var(--button);
  cursor: pointer;
}

.rule-chip:has(input:checked) {
  border-color: var(--button);
  background: color-mix(in srgb, var(--button) 16%, var(--secondary-bg));
}

.settings__field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  font-weight: 500;
}

.settings__field input[type="number"] {
  width: 72px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font: inherit;
  text-align: center;
}

.save-btn {
  margin-top: 2px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--button);
  color: var(--button-text);
  font: inherit;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.save-btn--compact {
  margin-top: 0;
  flex: none;
  padding: 10px 16px;
}

.save-btn:active {
  transform: scale(0.98);
}

.save-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.save-btn.is-saved {
  background: var(--accent-ok);
}

/* -- privileged-user exclusions --------------------------------------------- */

.exclusions-add {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.exclusions-add input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}

.exclusions-add input[type="text"]:disabled {
  opacity: 0.6;
}

.exclusions-error {
  color: var(--accent-executed);
  font-size: 12px;
  margin-top: 8px;
  min-height: 1px;
}

.exclusion-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--secondary-bg);
  border: 1px solid var(--border);
}

.exclusion-item__label {
  font-size: 13.5px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.exclusion-item__id {
  font-size: 11.5px;
  color: var(--hint);
}

.exclusion-item__remove {
  flex: none;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--accent-executed);
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

.exclusion-item__remove:disabled {
  opacity: 0.5;
  cursor: default;
}

/* -- generic item lists (pending / history) --------------------------------- */

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list:not(:empty) {
  max-height: 420px;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}

.history-item {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 11px;
  align-items: start;
  padding: 11px 12px 11px 0;
  border-radius: var(--radius-sm);
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  transition: background 0.15s ease, transform 0.15s ease;
}

.history-item:hover {
  transform: translateX(2px);
  background: color-mix(in srgb, var(--secondary-bg) 80%, var(--item-accent, var(--button)) 20%);
}

.history-item__bar {
  align-self: stretch;
  border-radius: 4px;
  background: var(--item-accent, var(--hint));
}

.history-item__body {
  min-width: 0;
}

.history-item__top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.history-item__rule {
  font-weight: 700;
  font-size: 12.5px;
}

.history-item__status {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  color: #0b0d12;
  background: var(--item-accent, var(--hint));
  white-space: nowrap;
}

.history-item__snippet {
  font-size: 13px;
  color: var(--text);
  opacity: 0.92;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item__reason {
  font-size: 11.5px;
  color: var(--hint);
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.history-item__time {
  font-size: 11px;
  color: var(--hint);
  white-space: nowrap;
  text-align: right;
  padding-top: 1px;
}

/* -- bulk actions ------------------------------------------------------------ */

.bulk-bar[hidden] {
  display: none;
}

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--button) 12%, var(--secondary-bg));
  border: 1px solid color-mix(in srgb, var(--button) 35%, var(--border));
}

.bulk-bar__count {
  font-size: 12.5px;
  font-weight: 700;
}

.bulk-bar__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.history-item--selectable {
  grid-template-columns: auto 4px 1fr auto;
}

.history-item__checkbox {
  align-self: start;
  margin-top: 2px;
  width: 17px;
  height: 17px;
  accent-color: var(--button);
  cursor: pointer;
}

.history-item__username {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

/* -- user history modal ------------------------------------------------------ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 720px;
  max-height: 82vh;
  background: var(--card-bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.modal__head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.modal__close {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.modal__body {
  overflow-y: auto;
  padding: 16px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal__section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.modal__section .list:not(:empty) {
  max-height: none;
  overflow-y: visible;
  margin: 0;
  padding: 0;
}

/* -- pending-review actions ------------------------------------------------ */

.pending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.alert-action-btn {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.alert-action-btn:active {
  transform: scale(0.97);
}

.alert-action-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.alert-action-btn--execute {
  border-color: color-mix(in srgb, var(--accent-executed) 55%, var(--border));
  color: var(--accent-executed);
}

.alert-action-btn--skip {
  border-color: color-mix(in srgb, var(--accent-skipped) 55%, var(--border));
  color: var(--accent-skipped);
}

.alert-action-btn--false {
  border-color: color-mix(in srgb, var(--accent-false) 55%, var(--border));
  color: var(--accent-false);
}

/* -- footer ------------------------------------------------------------- */

.footer {
  text-align: center;
  color: var(--hint);
  font-size: 11px;
  padding-top: 18px;
  opacity: 0.7;
}

/* -- small screens (Telegram Mini Apps on phones) ------------------------ */

@media (max-width: 400px) {
  #app {
    padding: 12px 12px 26px;
  }
  .tiles {
    grid-template-columns: repeat(2, 1fr);
  }
  .tile__value {
    font-size: 21px;
  }
  .topbar h1 {
    font-size: 16px;
  }
  .tab {
    font-size: 12px;
    padding: 8px 4px;
  }
}

@media (max-width: 340px) {
  .tiles {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
}

/* -- multi-chat additions ------------------------------------------------------ */

.pause-banner {
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent-pending) 18%, var(--card-bg));
  border: 1px solid color-mix(in srgb, var(--accent-pending) 55%, var(--border));
  font-size: 13px;
  font-weight: 600;
}

.pause-banner[hidden] {
  display: none;
}

.chips {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chips[hidden] {
  display: none;
}

.chip {
  flex: none;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--hint);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip.is-active {
  background: var(--button);
  border-color: var(--button);
  color: var(--button-text);
}

.history-item__chat {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--hint);
  white-space: nowrap;
}

.history-item__cmd {
  margin-top: 3px;
  font-family: "SF Mono", "Cascadia Code", ui-monospace, Consolas, monospace;
  font-size: 11.5px;
  color: var(--hint);
  overflow-wrap: anywhere;
}

.alert-action-btn--delete {
  border-color: var(--border);
  color: var(--hint);
}

.profile-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 20px;
  box-shadow: var(--shadow);
}

.profile-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.profile-card__head h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--secondary-bg);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--button);
  transition: width 0.4s ease;
}

.exclusions-add select {
  flex: none;
  max-width: 34%;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.exclusions-add select[hidden] {
  display: none;
}

.warning-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  font-size: 12.5px;
}

.warning-item__rule {
  font-weight: 700;
}

.warning-item__count {
  color: var(--hint);
}

#profileSettings {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
