/*
 * style.css — оформление Mini App «РАН».
 * Что делает: цвета берёт из темы Telegram (--tg-theme-*) с запасными значениями, поэтому
 * приложение выглядит прилично и в обычном браузере. Мобильная вёрстка 360–430px,
 * без горизонтального скролла, крупные кнопки (≥ 44px), нижняя панель вкладок.
 */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #86868b);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --line: rgba(128, 128, 128, 0.25);
  --ok: #2e9e5b;
  --warn: #d98a00;
  --bad: #d64545;
  --radius: 14px;
  --tabbar-h: 62px;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body.modal-open {
  overflow: hidden;
}

/* ---------- каркас ---------- */

.topbar-wrap {
  position: sticky;
  top: 0;
  z-index: 5;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

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

/* плашка режима «Посмотреть глазами…» — остаётся на виду при прокрутке */
.viewbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(36, 129, 204, 0.16);
  font-size: 14px;
}

.viewbar-text {
  flex: 1 1 200px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.logo {
  font-weight: 700;
  font-size: 17px;
  white-space: nowrap;
}

.who {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--hint);
  font-size: 13px;
}

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 14px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
  min-width: 0;
}

.view {
  min-width: 0;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 0 10px;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

p {
  margin: 0 0 8px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.foot {
  margin-top: 14px;
  text-align: center;
}

.hint {
  color: var(--hint);
  font-size: 14px;
}

.hint.small {
  font-size: 12px;
}

.hint.tap {
  margin-top: 8px;
  font-size: 12px;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

/* ---------- нижние вкладки ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  max-width: 96px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: var(--hint);
  font: inherit;
  cursor: pointer;
}

.tab-ico {
  font-size: 22px;
  line-height: 1;
  filter: grayscale(0.8);
  opacity: 0.8;
}

.tab-label {
  font-size: 11px;
  font-weight: 600;
}

.tab.active {
  color: var(--btn);
}

.tab.active .tab-ico {
  filter: none;
  opacity: 1;
}

/* ---------- карточки ---------- */

.card {
  min-width: 0;
  padding: 12px 14px;
  background: var(--card);
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}

.card.dim {
  opacity: 0.6;
}

.card.clickable {
  cursor: pointer;
}

.card.clickable:active {
  filter: brightness(0.96);
}

.card-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.card-row > .grow {
  flex: 1 1 140px;
}

.title {
  font-weight: 700;
  font-size: 16px;
}

.name {
  font-weight: 600;
}

.meta {
  margin-top: 3px;
  color: var(--hint);
  font-size: 14px;
}

.meta.strong {
  color: var(--text);
  font-weight: 600;
}

.amount {
  font-weight: 800;
  font-size: 18px;
  white-space: nowrap;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.comment {
  margin: 8px 0 0;
  padding: 8px 10px;
  background: rgba(128, 128, 128, 0.12);
  border-radius: 10px;
  font-size: 14px;
}

.section-title {
  margin: 12px 0 6px;
  font-weight: 700;
  font-size: 14px;
  color: var(--hint);
  text-transform: none;
}

.card > .section-title:first-child {
  margin-top: 0;
}

.summary {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: rgba(217, 138, 0, 0.14);
  font-size: 15px;
}

.summary.ok {
  background: rgba(46, 158, 91, 0.14);
}

.person-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.section-title + .person-row {
  border-top: 0;
}

.contacts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 8px;
}

/* ---------- бейджи ---------- */

.badge {
  display: inline-block;
  max-width: 100%;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(128, 128, 128, 0.18);
  color: var(--hint);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
}

.badge.ok {
  background: rgba(46, 158, 91, 0.16);
  color: var(--ok);
}

.badge.warn {
  background: rgba(217, 138, 0, 0.16);
  color: var(--warn);
}

.badge.bad {
  background: rgba(214, 69, 69, 0.16);
  color: var(--bad);
}

.badge.info {
  background: rgba(36, 129, 204, 0.16);
  color: var(--btn);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  color: var(--text);
  background: rgba(128, 128, 128, 0.18);
}

.btn.primary {
  background: var(--btn);
  color: var(--btn-text);
}

.btn.danger {
  background: rgba(214, 69, 69, 0.16);
  color: var(--bad);
}

.btn.small {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 14px;
}

.btn.block {
  display: flex;
  width: 100%;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn:active:not(:disabled) {
  filter: brightness(0.92);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.btn-row > .btn {
  flex: 1 1 140px;
}

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: rgba(128, 128, 128, 0.14);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.link-btn,
.back-btn {
  min-height: 44px;
  padding: 8px 6px;
  border: 0;
  background: transparent;
  color: var(--btn);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.back-btn {
  margin-bottom: 6px;
  padding-left: 0;
}

a.link {
  color: var(--btn);
  text-decoration: none;
  font-weight: 600;
}

a.link.contact,
a.link.phone {
  display: inline-block;
  padding: 6px 0;
}

/* ---------- реквизиты ---------- */

.requisites {
  margin-bottom: 12px;
}

.req-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.title + .req-row {
  margin-top: 6px;
}

.req-main {
  flex: 1 1 auto;
  min-width: 0;
}

.req-val {
  display: block;
  font-weight: 600;
  user-select: all;
  -webkit-user-select: all;
  overflow-wrap: anywhere;
}

.offscreen {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ---------- формы ---------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
}

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* меньше — iOS приближает экран при вводе */
}

textarea.input {
  resize: vertical;
  min-height: 80px;
}

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

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.row2 > * {
  min-width: 0;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.check input {
  width: 22px;
  height: 22px;
  flex: none;
}

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

.cost-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
}

/* ---------- чипы и подвкладки ---------- */

.chips,
.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.chip,
.subtab {
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active,
.subtab.active {
  background: var(--btn);
  color: var(--btn-text);
}

.subbody {
  min-width: 0;
}

.subview {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.seg-group {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.seg-group > .btn {
  flex: 1 1 0;
  padding-left: 8px;
  padding-right: 8px;
}

/* ---------- состояния ---------- */

.loader,
.empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--hint);
}

.errorbox {
  text-align: center;
}

.fatal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 48px 12px;
  text-align: center;
}

.fatal-emoji {
  font-size: 56px;
}

.fatal-text {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
}

.result {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(46, 158, 91, 0.14);
}

.passport {
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: var(--card);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  user-select: all;
  -webkit-user-select: all;
  overflow-wrap: anywhere;
}

ul.plain {
  margin: 0 0 8px;
  padding-left: 20px;
}

.warnbox {
  max-height: 40vh;
  margin-bottom: 8px;
  overflow-y: auto;
  font-size: 14px;
}

/* ---------- тост и окна ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: min(92vw, 440px);
  padding: 11px 16px;
  border-radius: 14px;
  background: rgba(30, 30, 30, 0.92);
  color: #ffffff;
  font-size: 15px;
  text-align: center;
  transform: translateX(-50%);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.toast.error {
  background: rgba(190, 50, 50, 0.95);
}

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

.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  background: var(--bg);
  color: var(--text);
}

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

  .sheet {
    border-radius: 18px;
  }
}

@media (max-width: 360px) {
  .row2 {
    grid-template-columns: 1fr;
  }

  .tab-label {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .btn,
  .chip,
  .subtab {
    transition: filter 0.1s;
  }
}

/* «отправила»: ожидание подтверждения и мелкая ссылка отмены */
.pending-note { margin: 8px 0 0; color: var(--hint, #6b7280); font-size: 14px; }
.btn.link { background: none; border: 0; color: var(--hint, #6b7280); text-decoration: underline; padding: 4px 0; min-height: 0; width: auto; font-size: 13px; }

/* ---------- кнопки в шапке капитана, выбор человека ---------- */

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

.pick-list {
  display: flex;
  flex-direction: column;
  max-height: 50vh;
  margin: 8px 0;
  overflow-y: auto;
}

.pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 10px 6px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.pick-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ---------- состав расходов в карточке взноса, «Мой бюджет» ---------- */

.costs {
  margin-top: 6px;
  color: var(--hint);
  font-size: 12px;
  line-height: 1.3;
}

.balance {
  padding: 16px 14px;
  border-radius: var(--radius);
  background: rgba(217, 138, 0, 0.14);
}

.balance.ok {
  background: rgba(46, 158, 91, 0.14);
}

.balance-totals {
  margin-top: 10px;
}

.balance-main {
  margin-bottom: 4px;
  font-size: 24px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.kv {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
  font-size: 15px;
}

.kv .k {
  min-width: 0;
  color: var(--hint);
  overflow-wrap: anywhere;
}

.kv .v {
  flex: none;
  font-weight: 700;
  white-space: nowrap;
}

.kv.warn .v {
  color: var(--warn);
}

.kv.ok .v {
  color: var(--ok);
}

.ledger-event .btn {
  margin-top: 8px;
}

.ledger-details {
  margin-top: 6px;
}

.btn:disabled[title] {
  cursor: not-allowed;
}
