/* Шахта — мини-апп ручного прогрева.
   Чёрный фон, сгруппированные карточки, системный синий акцент — как в
   нативных списках iOS. Цвет несёт только статус: зелёный жив, красный бан,
   оранжевый — аккаунт в работе. */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* Скрытое остаётся скрытым: у листов и стадий свой display, который иначе
   перебивает атрибут hidden. */
[hidden] { display: none !important; }

:root {
  --bg:         #000000;
  --card:       #1C1C1E;
  --card-2:     #2C2C2E;
  --sep:        rgba(255, 255, 255, .09);

  --text:       #FFFFFF;
  --text-2:     #8E8E93;
  --text-3:     #636366;

  --blue:       #0A84FF;
  --green:      #30D158;
  --red:        #FF453A;
  --orange:     #FF9F0A;

  --r:    12px;
  --r-sm: 8px;

  --ease: cubic-bezier(.25, .1, .25, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

button, input, textarea, select {
  font: inherit; color: inherit;
  background: none; border: none; outline: none;
}
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
b, strong, .num { font-variant-numeric: tabular-nums; }

.ic {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}
.ic.big { width: 32px; height: 32px; stroke-width: 2; }
.ic.sm  { width: 16px; height: 16px; }

/* ─────────── Шапка ─────────── */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 6px;
}
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--blue);
  transition: opacity .15s var(--ease);
}
.icon-btn:active { opacity: .5; }
.icon-btn.is-busy .ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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

.tabs {
  position: relative;
  display: flex; gap: 24px;
  padding: 0 16px;
  border-bottom: .5px solid var(--sep);
}
.tab {
  padding: 8px 0 12px;
  font-size: 16px; font-weight: 500;
  color: var(--text-2);
  transition: color .2s var(--ease);
}
.tab.is-active { color: var(--text); font-weight: 600; }
.tab-underline {
  position: absolute; bottom: -.5px; left: 0;
  height: 2.5px; border-radius: 2px;
  background: var(--blue);
  transition: transform .3s var(--ease), width .3s var(--ease);
}

.progress { height: 2px; background: transparent; }
.progress-fill {
  display: block; height: 100%; width: 0;
  background: var(--blue);
  transition: width .3s var(--ease);
}

/* Полоска состояния: видно, что идёт проверка, а не «просто висит» */
.status-bar {
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px;
  background: var(--card);
  font-size: 14px; color: var(--text-2);
  animation: statusIn .2s var(--ease);
}
@keyframes statusIn { from { opacity: 0; transform: translateY(-4px); } }

.spinner {
  width: 14px; height: 14px; flex: none;
  border: 2px solid var(--card-2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ─────────── Экраны ─────────── */

.screens {
  position: absolute; inset: 0;
  top: calc(var(--safe-top) + 100px);
  overflow: hidden;
  transition: top .2s var(--ease);
}
/* Полоса состояния занимает место в потоке — экраны уезжают вниз ровно на неё */
body.has-status .screens { top: calc(var(--safe-top) + 140px); }
.screen {
  position: absolute; inset: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(var(--safe-bottom) + 24px);
  opacity: 0; visibility: hidden;
  transition: opacity .2s var(--ease), visibility .2s;
}
.screen.is-active { opacity: 1; visibility: visible; }

/* ─────────── Выбор аккаунта ─────────── */

.account-picker {
  width: 100%;
  display: flex; align-items: center; gap: 9px;
  padding: 14px 15px;
  background: var(--card);
  border-radius: var(--r);
  text-align: left;
  transition: opacity .15s var(--ease);
}
.account-picker:active { opacity: .7; }
.picker-name { font-weight: 600; letter-spacing: -.01em; }
.picker-user { color: var(--text-2); }
.account-picker .chev {
  margin-left: auto; color: var(--text-2);
  transition: transform .25s var(--ease);
}
.account-picker.is-open .chev { transform: rotate(180deg); }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-3); flex: none;
}
.dot.alive, .dot.live { background: var(--green); }
.dot.dead { background: var(--red); }
.dot.live { animation: breathe 2.2s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(48, 209, 88, .5); }
  55%      { box-shadow: 0 0 0 6px rgba(48, 209, 88, 0); }
}

.dropdown {
  margin-top: 6px;
  background: var(--card);
  border-radius: var(--r);
  overflow: hidden;
  animation: dropIn .2s var(--ease);
}
@keyframes dropIn { from { opacity: 0; transform: translateY(-8px); } }
.dropdown-item {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 15px;
  text-align: left;
}
.dropdown-item + .dropdown-item { box-shadow: inset 0 .5px 0 var(--sep); }
.dropdown-item:active { background: var(--card-2); }
.dropdown-item .muted { color: var(--text-2); }
.dropdown-item .check { margin-left: auto; color: var(--blue); }
.dropdown-item.action .ic { color: var(--blue); }

/* Сводка по аккаунту — одна строка вместо блока плиток */
.summary {
  padding: 10px 4px 0;
  font-size: 14px; color: var(--text-2);
}
.summary b { color: var(--text); font-weight: 600; }
.summary b.ok { color: var(--green); }

/* ─────────── Сгруппированные списки ─────────── */

.list {
  display: flex; flex-direction: column;
  margin-top: 10px;
  background: var(--card);
  border-radius: var(--r);
  overflow: hidden;
}
.list:empty { display: none; }
.list.scroll { overflow-y: auto; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  text-align: left;
  background: transparent;
  transition: background .12s var(--ease);
}
.row + .row { box-shadow: inset 0 .5px 0 var(--sep); }
.row:active { background: var(--card-2); }

.row-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 1px;
}
.row-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 17px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-sub {
  display: block;
  color: var(--text-2); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-sub.dim { color: var(--text-3); }
.row-meta {
  display: block;
  font-size: 13px; color: var(--text-2); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-meta b { color: var(--text); font-weight: 600; }
.row-meta .ok { color: var(--green); }

.row-side {
  display: flex; align-items: center; gap: 8px;
  flex: none; color: var(--text-3);
}
.row-time { font-size: 13px; color: var(--text-2); }
.row-side .chev { width: 16px; height: 16px; }
.row.is-connecting .row-meta { color: var(--blue); }


.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: var(--blue); color: #fff;
  font-size: 12px; font-weight: 600;
}

.tag { font-size: 13px; font-weight: 500; }
.tag.dead { color: var(--red); }
.tag.spam { color: var(--orange); }

.row-add { color: var(--text-2); }
.row-add .ic { color: var(--blue); }
.row-add span { font-size: 17px; }


.empty, .hint {
  text-align: center; color: var(--text-2);
  padding: 44px 24px; font-size: 15px;
}
.empty p { margin-bottom: 16px; }

.btn-ghost {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--card-2);
  color: var(--blue);
  font-size: 15px; font-weight: 500;
}
.btn-ghost:active { opacity: .6; }

.btn-primary {
  width: 100%;
  padding: 15px;
  border-radius: var(--r);
  background: var(--blue);
  color: #fff;
  font-size: 17px; font-weight: 600;
  transition: opacity .15s var(--ease), transform .1s var(--ease);
}
.btn-primary:active { transform: scale(.99); opacity: .85; }
.btn-primary:disabled { opacity: .32; }

/* ─────────── Полноэкранные листы ─────────── */

.sheet {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; flex-direction: column;
  z-index: 40;
  animation: sheetIn .28s var(--ease);
}
.sheet.closing { animation: sheetOut .22s var(--ease) forwards; }
@keyframes sheetIn  { from { opacity: 0; transform: translateX(26px); } }
@keyframes sheetOut { to   { opacity: 0; transform: translateX(26px); } }

.sheet-head {
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  border-bottom: .5px solid var(--sep);
}
.sheet-head .icon-btn { color: var(--blue); }
.sheet-title { min-width: 0; }
.sheet-title strong {
  display: block; font-size: 17px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sheet-title span { font-size: 13px; color: var(--text-2); }
.sheet .list { margin: 12px; }

/* ─────────── Переписка ─────────── */

.thread {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 12px 8px;
  display: flex; flex-direction: column; gap: 5px;
}
.day {
  align-self: center; margin: 12px 0 6px;
  font-size: 12px; color: var(--text-3);
}
.bubble {
  max-width: 76%;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 16px; line-height: 1.35;
  word-wrap: break-word;
  animation: bubbleIn .22s var(--ease);
}
@keyframes bubbleIn { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.bubble.them {
  align-self: flex-start;
  background: var(--card);
  border-bottom-left-radius: 6px;
}
.bubble.me {
  align-self: flex-end;
  background: var(--blue);
  border-bottom-right-radius: 6px;
}
.bubble .kind { opacity: .75; font-style: italic; }
.bubble time { display: block; margin-top: 2px; font-size: 11px; opacity: .6; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(var(--safe-bottom) + 10px);
  border-top: .5px solid var(--sep);
}
.composer textarea {
  flex: 1; max-height: 120px;
  padding: 10px 15px;
  background: var(--card);
  border-radius: 20px;
  resize: none;
}
.send {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--blue); color: #fff;
  transition: transform .12s var(--ease), opacity .15s var(--ease);
}
.send:disabled { background: var(--card-2); color: var(--text-3); }
.send:not(:disabled):active { transform: scale(.9); }

/* ─────────── Первое сообщение ─────────── */

.start-body { padding: 16px 14px calc(var(--safe-bottom) + 18px); }
.start-note { color: var(--text-2); font-size: 14px; margin-bottom: 14px; }
.start-note b { color: var(--text); font-weight: 600; }
#startInput {
  width: 100%;
  padding: 14px;
  background: var(--card);
  border-radius: var(--r);
  resize: none;
  margin-bottom: 16px;
}

/* ─────────── Авторизация ─────────── */

.auth-stage {
  flex: 1;
  padding: 56px 22px calc(var(--safe-bottom) + 22px);
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  animation: stageIn .32s var(--ease);
}
@keyframes stageIn { from { opacity: 0; transform: translateY(12px); } }
.auth-stage h2 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.auth-sub { color: var(--text-2); font-size: 15px; margin: 8px 0 26px; max-width: 32ch; }
.auth-sub b { color: var(--text); font-weight: 600; }

.auth-art {
  position: relative;
  width: 92px; height: 92px; margin: 14px 0 18px;
  display: grid; place-items: center;
}
  25%  { opacity: .8; }
  100% { transform: scale(1); opacity: 0; }
}
  50%      { transform: scale(.82); box-shadow: 0 0 0 16px rgba(10, 132, 255, 0); }
}
.auth-art.done { color: var(--green); }
.auth-art.done .ic { animation: popIn .38s var(--ease); }
@keyframes popIn { from { transform: scale(.4); opacity: 0; } }

.auth-field { position: relative; width: 100%; }
.paste {
  position: absolute; right: 6px; top: 50%;
  transform: translateY(-50%);
  padding: 8px 12px;
  color: var(--blue);
  font-size: 15px; font-weight: 500;
  border-radius: var(--r-sm);
  transition: opacity .15s var(--ease);
}
.paste:active { opacity: .5; }

.auth-input {
  width: 100%;
  padding: 16px 92px 16px 16px;
  text-align: center;
  font-size: 22px; font-weight: 600; letter-spacing: .03em;
  font-variant-numeric: tabular-nums;
  background: var(--card);
  border-radius: var(--r);
}
.auth-input::placeholder { color: var(--text-3); font-weight: 500; }

.auth-pack {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  margin: 10px 0 22px; padding: 14px 16px;
  background: var(--card);
  border-radius: var(--r);
  color: var(--text-2); font-size: 15px;
}
.auth-pack select { color: var(--blue); text-align: right; font-weight: 500; }

.code-cells { display: flex; gap: 10px; margin-bottom: 24px; }
.code-cell {
  width: 44px; height: 56px;
  display: grid; place-items: center;
  font-size: 26px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--card);
  border-radius: var(--r-sm);
  border: 1.5px solid transparent;
  transition: border-color .18s var(--ease), transform .18s var(--ease);
}
.code-cell.filled { animation: cellPop .2s var(--ease); }
.code-cell.active { border-color: var(--blue); }
@keyframes cellPop { 50% { transform: scale(1.08); } }
.code-hidden { position: absolute; opacity: 0; pointer-events: none; height: 0; }

.auth-error {
  margin-top: 16px; color: var(--red); font-size: 14px;
  animation: shake .32s var(--ease);
}
@keyframes shake {
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(3px); }
}

/* ─────────── Тост ─────────── */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 26px);
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 12px 20px;
  background: var(--card-2);
  border-radius: 999px;
  font-size: 15px;
  z-index: 90;
  animation: toastIn .24s var(--ease);
}
.toast.err { color: #FF8A80; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } }

.skeleton {
  height: 64px;
  background: linear-gradient(100deg, var(--card) 30%, var(--card-2) 50%, var(--card) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -120% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
