/* BlackSea Rockfishing — Telegram Mini App SPA.
   Тёмная «морская» палитра, задаётся принудительно независимо от themeParams:
   фон #0b1520/#0f1e2b, карточки #13293a, акцент #2e9e6b (морская зелень),
   текст #e8f1f6, приглушённый #8fa8b8. Системные шрифты, без внешних ресурсов. */

:root {
  --bg: #0b1520;
  --bg-elev: #0f1e2b;
  --card: #13293a;
  --card-2: #10222f;
  --accent: #2e9e6b;
  --accent-press: #26875a;
  --danger: #d9534f;
  --danger-press: #b94643;
  --text: #e8f1f6;
  --muted: #8fa8b8;
  --line: #1d3648;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 18px rgba(0, 0, 0, .35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
          "PT Sans", "Open Sans", sans-serif;
}

* { box-sizing: border-box; }

/* Component display declarations must never override the semantic hidden state. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 12px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Шапка ---------- */

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

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

.brand__logo { width: 40px; height: 20px; flex: 0 0 auto; }

.brand__text { display: flex; flex-direction: column; min-width: 0; }

.brand__title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .3px;
  color: var(--text);
}

.brand__sub { font-size: 11px; color: var(--muted); }

.topbar__controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  min-width: 0;
  max-width: 220px;
  margin-left: auto;
}

.channel-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.channel-picker__label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.channel-picker__select-wrap {
  position: relative;
  display: block;
  min-width: 0;
}

.channel-picker__select {
  width: 100%;
  max-width: 170px;
  min-height: 30px;
  padding: 5px 27px 5px 9px;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(46, 158, 107, .55);
  border-radius: 999px;
  background: var(--card);
  color: var(--accent);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.channel-picker__select:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 1px;
}

.channel-picker__select:disabled { opacity: .6; cursor: wait; }

.channel-picker__chevron {
  position: absolute;
  top: 50%;
  right: 9px;
  width: 10px;
  height: 7px;
  color: var(--accent);
  transform: translateY(-50%);
  pointer-events: none;
}

.chips { display: flex; justify-content: flex-end; gap: 6px; flex: 0 0 auto; }

.chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.chip--mode { color: var(--accent); border-color: rgba(46, 158, 107, .45); }

/* ---------- Дев-режим ---------- */

.devbar {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.devbar__label { font-size: 12px; color: var(--muted); }

.devbar__input {
  flex: 1 1 120px;
  min-width: 0;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font: inherit;
}

.devbar__hint {
  flex-basis: 100%;
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- Вкладки ---------- */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  margin: 4px 0 12px;
  position: sticky;
  top: 4px;
  z-index: 5;
}

.tabs__btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.tabs__btn[aria-selected="true"] {
  background: var(--accent);
  color: #06120c;
}

.tabs__btn:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }

/* ---------- Контент ---------- */

.content { flex: 1 1 auto; display: flex; flex-direction: column; }

.view__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.view__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.view__hint { margin: 0 0 10px; font-size: 12px; color: var(--muted); }

.view__tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

.empty {
  margin: 18px 0;
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
  background: var(--bg-elev);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}

/* ---------- Кнопки ---------- */

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--card);
  flex: 0 0 auto;
  transition: background .15s, transform .05s;
}

.btn:active { transform: translateY(1px); }

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--accent { background: var(--accent); color: #06120c; }
.btn--accent:hover:not(:disabled) { background: var(--accent-press); }

.btn--ghost { background: var(--card); border-color: var(--line); color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: var(--card-2); }

.btn--danger { background: transparent; border-color: rgba(217, 83, 79, .55); color: #e79390; }
.btn--danger:hover:not(:disabled) { background: rgba(217, 83, 79, .14); }

.btn--sm { padding: 6px 10px; font-size: 12px; }

.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }

/* ---------- Карточки отчётов ---------- */

.cards { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

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

.card__meta { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.card__source { color: #7fc7e8; text-decoration: none; border-bottom: 1px dashed rgba(127, 199, 232, .5); }

.card__id { color: var(--muted); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge--new       { color: #9db7c6; background: rgba(143, 168, 184, .12); border-color: rgba(143, 168, 184, .35); }
.badge--queued    { color: #7fc7e8; background: rgba(127, 199, 232, .1); border-color: rgba(127, 199, 232, .35); }
.badge--approved  { color: #6fd39a; background: rgba(46, 158, 107, .12); border-color: rgba(46, 158, 107, .45); }
.badge--rejected  { color: #e79390; background: rgba(217, 83, 79, .1); border-color: rgba(217, 83, 79, .4); }
.badge--published { color: #b7a36b; background: rgba(183, 163, 107, .1); border-color: rgba(183, 163, 107, .4); }
.badge--postponed { color: #c3a8d6; background: rgba(195, 168, 214, .1); border-color: rgba(195, 168, 214, .35); }
.badge--video     { color: #8fd0e8; background: rgba(80, 170, 200, .12); border-color: rgba(80, 170, 200, .4); }
.card__video video { width: 100%; max-width: 420px; border-radius: 10px; background: #000; }

.card__photos { margin-bottom: 10px; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.photo-item {
  position: relative;
  margin: 0;
  border: 0;
  padding: 0;
  background: var(--card-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 1 / 1;
}

.photo-item__preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: zoom-in;
}

.photo-item__preview:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

.photo-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-item__select {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 20px;
  height: 20px;
  cursor: pointer;
  z-index: 2;
}

.photo-item__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.photo-item__check {
  position: absolute;
  inset: 0;
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 1.5px solid rgba(232, 241, 246, .8);
  background: rgba(11, 21, 32, .55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-item__check svg { width: 12px; height: 12px; opacity: 0; }

.photo-item__input:focus-visible + .photo-item__check {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.photo-item.selected .photo-item__check {
  background: var(--accent);
  border-color: var(--accent);
}

.photo-item.selected .photo-item__check svg { opacity: 1; }

.photo-item__num {
  position: absolute;
  bottom: 4px; right: 6px;
  font-size: 10px;
  color: var(--text);
  background: rgba(11, 21, 32, .6);
  border-radius: 4px;
  padding: 1px 5px;
}

.photo-hint { margin: 6px 0 0; font-size: 11px; color: var(--muted); }

/* ---------- Редактор подписи ---------- */

.caption-wrap { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Варианты заголовка поста ---------- */

.title-wrap { display: flex; flex-direction: column; gap: 6px; }
.title-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.title-chips .chip { cursor: pointer; font-size: 12px; padding: 5px 10px; }
.title-chips .chip:active { transform: scale(.97); }
.chip--on { color: var(--accent); border-color: rgba(46, 158, 107, .55); background: rgba(46, 158, 107, .12); }
.title-input {
  flex: 1 1 100%;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  padding: 5px 12px;
}

.caption-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}

.caption {
  width: 100%;
  min-height: 150px;
  height: 150px;
  resize: vertical;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px;
}

.caption:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

/* ---------- Действия ---------- */

.card__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.card__actions .btn--span2 { grid-column: span 2; }

@media (min-width: 480px) {
  .card__actions { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .card__actions .btn--span2 { grid-column: span 2; }
}

.card__schedule {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Источники ---------- */

.addform {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}

.addform__input, .addform__select {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  min-width: 0;
}

.addform__input { flex: 1 1 200px; }
.addform__input--title { flex: 1 1 140px; }
.addform__select { flex: 0 0 130px; }

.addform__hint { margin: 0 0 12px; font-size: 11px; color: var(--muted); }

.tablewrap {
  overflow-x: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 560px; }

.table th, .table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.table thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.table tbody tr:last-child td { border-bottom: 0; }

.src-title { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.src-url { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }

.src-controls { display: flex; flex-direction: column; gap: 4px; }

.src-controls input[type="text"], .src-controls select {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 7px;
  font: inherit;
  font-size: 12px;
  width: 100%;
  min-width: 110px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 38px; height: 22px;
  flex: 0 0 auto;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch__track {
  position: absolute;
  inset: 0;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background .15s;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .15s, background .15s;
}

.switch input:checked + .switch__track { background: rgba(46, 158, 107, .35); border-color: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--text); outline-offset: 2px; }

.src-actions { display: flex; gap: 4px; flex-wrap: wrap; }

.src-last { font-size: 11px; color: var(--muted); white-space: nowrap; }
.src-last.ok { color: var(--accent); }
.src-last.err { color: #e79390; }

.src-error { color: #e79390; font-size: 11px; overflow-wrap: anywhere; max-width: 220px; }

.table__actions { width: 1%; white-space: nowrap; }

/* ---------- Результаты сканирования ---------- */

.scanresults {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.scanresults__title { margin: 0 0 6px; font-size: 13px; font-weight: 700; }

.scanresults__total { margin: 0 0 8px; font-size: 12px; color: var(--muted); }

.scanresults__list { display: flex; flex-direction: column; gap: 5px; margin: 0; padding: 0; list-style: none; }

.scanresults__item {
  font-size: 12px;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.scanresults__item .scan-name { font-weight: 600; overflow-wrap: anywhere; }
.scanresults__item .scan-stats { color: var(--muted); }
.scanresults__item.is-error { border-color: rgba(217, 83, 79, .45); }
.scanresults__item .scan-error { color: #e79390; overflow-wrap: anywhere; }

/* ---------- Диалог планирования ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 16, .72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  padding: 12px;
}

@media (min-width: 480px) { .overlay { align-items: center; } }

.dialog {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  max-height: 86vh;
  overflow-y: auto;
}

.dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

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

.dialog__close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}

.dialog__close:hover { color: var(--text); background: var(--card-2); }

.dialog__meta { margin: 0 0 10px; font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }

.field__label { font-size: 11px; color: var(--muted); font-weight: 600; }

.field__input {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
  color-scheme: dark;
}

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

.slots__empty { font-size: 12px; color: var(--muted); }

.slot {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.slot:hover { border-color: var(--accent); color: var(--accent); }
.slot.is-active { background: var(--accent); color: #06120c; border-color: var(--accent); }

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 16, .92);
  display: flex;
  align-items: center;
  justify-content:center;
  z-index: 80;
  padding: 16px;
}

.lightbox__img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.lightbox__close {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(11, 21, 32, .8);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 100;
  overflow-wrap: anywhere;
}

.toast.is-error { border-left-color: var(--danger); }

/* ---------- Загрузка ---------- */

.loading {
  margin: 14px 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.loading::after {
  content: "";
  display: block;
  width: 22px; height: 22px;
  margin: 8px auto 0;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Футер ---------- */

.footer { margin-top: 18px; }

.footer__wave { width: 100%; height: 12px; display: block; opacity: .6; }

/* ---------- Мелкие экраны ---------- */

@media (max-width: 440px) {
  .topbar__controls { max-width: 205px; }
  .channel-picker { width: 100%; }
  .channel-picker__label { display: none; }
  .channel-picker__select-wrap { width: 100%; }
  .channel-picker__select { max-width: none; }
  .chips { flex-wrap: wrap; row-gap: 4px; }
}

@media (max-width: 359px) {
  .topbar { flex-wrap: wrap; }
  .topbar__controls {
    flex: 1 1 100%;
    max-width: none;
    align-items: stretch;
    margin-left: 50px;
  }
  .chips { justify-content: flex-start; }
  .card__actions { grid-template-columns: 1fr; }
  .card__actions .btn--span2 { grid-column: span 1; }
  .photo-grid { grid-template-columns: repeat(2, 1fr); }
  .tabs__btn { font-size: 12px; padding: 8px 2px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
