:root {
  --tg-bg: var(--tg-theme-bg-color, #ffffff);
  --tg-text: var(--tg-theme-text-color, #000000);
  --tg-hint: var(--tg-theme-hint-color, #8e8e93);
  --tg-link: var(--tg-theme-link-color, #2481cc);
  --tg-btn: var(--tg-theme-button-color, #2481cc);
  --tg-btn-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --tg-destructive: var(--tg-theme-destructive-text-color, #ff3b30);
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--tg-bg);
  color: var(--tg-text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%; overflow: hidden;
}
#app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
}

/* Font Awesome sizing */
.tab-ico { font-size: 22px; line-height: 1; }
.btn-ico { margin-right: 6px; font-size: 15px; }
.cell-ico { font-size: 16px; }
.chev-ico { font-size: 13px; opacity: .45; }
.gate-ico, .empty-ico { font-size: 44px; color: var(--tg-link); }
.empty-ico { color: var(--tg-hint); }
.wallet-ico { font-size: 14px; color: var(--tg-link); width: 16px; text-align: center; }

#main {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 4px 0 calc(56px + var(--safe-b));
  padding-top: max(8px, env(safe-area-inset-top, 0px));
}

.page-heading {
  margin: 0;
  padding: 8px 16px 12px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.subpage-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 12px 8px;
}
.subpage-top .page-heading {
  flex: 1;
  padding: 0;
  font-size: 22px;
  min-width: 0;
}
.page-back {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--tg-secondary);
  color: var(--tg-link);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.page-back:active { opacity: .7; }

.profile-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 16px 16px;
}
.profile-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0; background: var(--tg-btn);
}
.profile-avatar-fallback {
  display: flex; align-items: center; justify-content: center;
  color: var(--tg-btn-text); font-size: 20px; font-weight: 600;
}
.profile-info { min-width: 0; flex: 1; text-align: left; }
.profile-name {
  font-size: 17px; font-weight: 600; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-username {
  font-size: 14px; color: var(--tg-hint); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.subpage { padding: 0 16px 20px; }
.subpage-desc {
  font-size: 14px; line-height: 1.5;
  color: var(--tg-hint); margin: 0 0 16px;
}
.stats-card { margin-bottom: 12px; }
.ref-link-box {
  font-size: 12px; word-break: break-all;
  padding: 12px; margin-bottom: 12px;
  background: var(--tg-secondary);
  border-radius: var(--radius);
  color: var(--tg-text);
}
.profile-root { padding-top: 4px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--tg-secondary);
  border-top: 1px solid rgba(127,127,127,.15);
  padding-bottom: var(--safe-b); z-index: 100;
}
.tab {
  flex: 1; border: 0; background: none;
  padding: 7px 4px 6px; color: var(--tg-hint);
  font-size: 10px; display: flex; flex-direction: column;
  align-items: center; gap: 3px; cursor: pointer;
}
.tab.active { color: var(--tg-link); }
.tab span { line-height: 1; }

.section { padding: 8px 16px 12px; }
.section.flush-top { padding-top: 0; }
.page-heading + .section,
.page-heading + .wallet-balances,
.page-heading + .empty-state {
  padding-top: 0;
}
.field-label {
  font-size: 13px; color: var(--tg-hint);
  text-transform: uppercase; letter-spacing: .03em;
  margin-bottom: 8px;
}

.card {
  background: var(--tg-secondary);
  border-radius: var(--radius); overflow: hidden;
}
.cell {
  display: flex; align-items: center;
  padding: 12px 14px; min-height: 48px;
  border-bottom: 1px solid rgba(127,127,127,.12);
  cursor: pointer;
}
.cell:last-child { border-bottom: none; }
.cell.flat { cursor: default; }
.cell:active:not(.flat) { opacity: .65; }
.cell-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-right: 12px; background: rgba(36,129,204,.14);
  color: var(--tg-link); flex-shrink: 0;
}
.cell-body { flex: 1; min-width: 0; }
.cell-title { font-size: 16px; font-weight: 500; }
.cell-sub { font-size: 13px; color: var(--tg-hint); margin-top: 2px; }
.cell-value { color: var(--tg-hint); font-size: 16px; margin-left: 8px; flex-shrink: 0; }
.cell-chevron { margin-left: 6px; display: flex; align-items: center; }

.input-wrap { padding: 0; margin-bottom: 0; }
.input-wrap.flush { padding: 0; }
.input {
  width: 100%; padding: 13px 14px;
  border: none; border-radius: var(--radius);
  background: var(--tg-secondary); color: var(--tg-text);
  font-size: 17px;
}
.input:disabled { opacity: .55; }
.input::placeholder { color: var(--tg-hint); }

/* bomber modes — accordion rows */
.mode-list {
  display: flex; flex-direction: column; gap: 8px;
}
.mode-item {
  background: var(--tg-secondary);
  border-radius: var(--radius);
  overflow: hidden;
}
.mode-row-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 14px 16px;
  border: 0; background: transparent; color: var(--tg-text);
  font-size: 16px; font-weight: 600; cursor: pointer;
  text-align: left;
}
.mode-item:has(.mode-row-btn.active) {
  background: color-mix(in srgb, var(--tg-btn) 12%, var(--tg-secondary));
}
.mode-row-btn.active {
  color: var(--tg-link);
}
.mode-row-btn:active { opacity: .75; }
.mode-emoji { font-size: 22px; line-height: 1; width: 28px; text-align: center; flex-shrink: 0; }
.mode-title { flex: 1; }
.mode-chevron { margin-left: auto; flex-shrink: 0; display: flex; align-items: center; }
.mode-chev {
  font-size: 13px; color: var(--tg-hint);
  transition: transform 0.3s ease, color 0.2s ease;
}
.mode-chev.open {
  transform: rotate(180deg);
  color: var(--tg-link);
}
.mode-desc-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.38s cubic-bezier(0.32, 0.72, 0, 1);
}
.mode-desc-wrap.open {
  grid-template-rows: 1fr;
}
.mode-desc-inner {
  overflow: hidden;
  min-height: 0;
}
.mode-desc {
  padding: 0 16px 0 56px;
  font-size: 13px; color: var(--tg-hint);
  line-height: 1.5;
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 0.32s ease,
    transform 0.38s cubic-bezier(0.32, 0.72, 0, 1),
    padding 0.38s cubic-bezier(0.32, 0.72, 0, 1);
}
.mode-desc-wrap.open .mode-desc {
  opacity: 1;
  transform: translateY(0);
  padding-bottom: 14px;
  transition-delay: 0.06s;
}
.mode-desc-wrap:not(.open) .mode-desc {
  transition-delay: 0s;
}
.mode-desc-meta {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--tg-link);
  font-weight: 500;
}

.repeats-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 8px; margin-top: 8px; padding: 0;
}
.repeats-grid.flush { margin-top: 8px; }
.rep-btn {
  padding: 11px 0; border: 0; border-radius: 10px;
  background: var(--tg-secondary);
  color: var(--tg-text); font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.rep-btn.active { background: var(--tg-btn); color: var(--tg-btn-text); }

.pay-strip {
  margin: 4px 16px 12px; padding: 14px;
  background: var(--tg-secondary); border-radius: var(--radius);
}
.pay-total {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 16px; margin-bottom: 4px;
}
.pay-total b { font-size: 20px; }
.pay-balance { font-size: 13px; color: var(--tg-hint); margin-bottom: 12px; }
.pay-strip .btn { width: 100%; margin: 8px 0 0; }

.btn {
  display: flex; align-items: center; justify-content: center;
  width: calc(100% - 32px); margin: 10px 16px;
  padding: 14px 16px; border: 0; border-radius: var(--radius);
  background: var(--tg-btn); color: var(--tg-btn-text);
  font-size: 17px; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .45; pointer-events: none; }
.btn:active:not(:disabled) { opacity: .75; }
.btn-secondary { background: var(--tg-secondary); color: var(--tg-link); }
.btn-danger {
  background: transparent; color: var(--tg-destructive);
  border: 1px solid rgba(255,59,48,.35);
}
.btn-inline { width: auto; margin: 10px 0 0; padding: 10px 16px; font-size: 15px; }
.bomber-restart-btn { margin-top: 0; }
.flush-btn { width: 100%; margin-left: 0; margin-right: 0; }

.progress-block {
  margin: 8px 16px 12px; padding: 16px;
  background: var(--tg-secondary); border-radius: var(--radius);
}
.progress-block-full {
  margin: 0 16px 20px;
}
.progress-screen .progress-actions {
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.progress-bar-lg { height: 10px; border-radius: 5px; }
.progress-fill {
  height: 100%; background: var(--tg-btn);
  border-radius: 3px;
  transition: width 0.65s cubic-bezier(0.32, 0.72, 0, 1);
}
.progress-bar-lg .progress-fill { border-radius: 5px; }
.progress-top {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px;
}
.progress-pct { font-size: 26px; font-weight: 700; }
.progress-status { font-size: 14px; color: var(--tg-hint); }
.progress-bar {
  height: 6px; background: rgba(127,127,127,.2);
  border-radius: 3px; overflow: hidden;
}
.progress-meta { font-size: 13px; color: var(--tg-hint); margin-top: 10px; }
.hidden { display: none !important; }

/* wallet */
.wallet-page { padding-bottom: 8px; }
.wallet-balances {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 12px 16px;
}
.wallet-balances.compact { padding-top: 0; }
.wallet-card {
  background: var(--tg-secondary); border-radius: var(--radius);
  padding: 14px; min-height: 84px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.wallet-card-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--tg-hint); text-transform: uppercase;
  letter-spacing: .02em;
}
.wallet-card-amount {
  font-size: 22px; font-weight: 700; line-height: 1.2;
  margin-top: 10px;
}
.wallet-section {
  padding: 4px 16px 16px;
}
.wallet-section .field-label { margin-bottom: 8px; }
.wallet-section .repeats-grid { margin-top: 0; }
.wallet-section .input-wrap { margin-top: 8px; }
.wallet-btn {
  width: 100%; margin: 12px 0 0;
}

/* history */
.history-page .empty-state {
  text-align: center; padding: 28px 16px; color: var(--tg-hint);
}
.history-page .empty-state p { margin: 10px 0 0; }
.history-list { padding: 0; }
.history-item {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid rgba(127,127,127,.12);
  gap: 12px;
}
.history-item:last-child { border-bottom: none; }
.history-item-active {
  background: color-mix(in srgb, var(--tg-btn) 8%, var(--tg-secondary));
}
.history-item-active .history-phone { font-weight: 700; }
.history-mini-bar {
  height: 4px;
  margin-top: 8px;
  background: rgba(127,127,127,.2);
  border-radius: 2px;
  overflow: hidden;
}
.history-mini-fill {
  height: 100%;
  background: var(--tg-btn);
  border-radius: 2px;
  transition: width 0.65s cubic-bezier(0.32, 0.72, 0, 1);
}
.history-active-actions { align-self: center; }
.history-stop {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 59, 48, 0.12);
  color: var(--tg-destructive);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
}
.history-stop:active { opacity: .75; }
.history-main { flex: 1; min-width: 0; }
.history-phone { font-size: 16px; font-weight: 600; }
.history-sub { font-size: 13px; color: var(--tg-hint); margin-top: 3px; }
.history-right {
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 6px; flex-shrink: 0;
}
.history-date { font-size: 11px; color: var(--tg-hint); white-space: nowrap; }

.status-badge {
  display: inline-block; padding: 3px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.status-ok { background: rgba(52,199,89,.15); color: #248a3d; }
.status-cancel { background: rgba(255,59,48,.12); color: var(--tg-destructive); }
.status-run { background: rgba(36,129,204,.15); color: var(--tg-link); }
.status-err { background: rgba(255,149,0,.15); color: #c93400; }

.gate { text-align: center; padding: 32px 24px; }
.gate-icon { margin-bottom: 16px; display: flex; justify-content: center; }
.gate-text { color: var(--tg-hint); margin-bottom: 20px; line-height: 1.5; }

.hint { padding: 8px 16px; font-size: 13px; color: var(--tg-hint); text-align: center; }
.hint.left { text-align: left; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.admin-pre {
  margin: 0 0 12px; padding: 12px;
  background: var(--tg-secondary); border-radius: var(--radius);
  font-size: 12px; white-space: pre-wrap; word-break: break-word;
  max-height: 50vh; overflow-y: auto;
}

.menu-card { margin-top: 4px; }

@media (prefers-color-scheme: dark) {
  .status-ok { color: #4cd964; }
}
