/*
 * style.css — оформление Mini App в стиле нативного Telegram.
 * Цвета берутся из темы Telegram (--tg-theme-*), поэтому светлая и тёмная темы
 * работают сами. Запасные значения (--fb-*) нужны только в обычном браузере.
 * Акцент #2AABEE — фирменный цвет Telegram.
 * Разделы: 1 переменные, 2 основа, 3 переходы, 4 общие элементы,
 *          5 экраны, 6 запасные кнопки браузера.
 */

/* ---------- 1. Переменные и тема ---------- */
:root {
  /* запасная светлая тема (используется, если Telegram не передал свою) */
  --fb-bg: #f0f2f5;
  --fb-card: #ffffff;
  --fb-text: #0f1419;
  --fb-hint: #6d7883;

  --accent: #2AABEE;
  --accent-soft: rgba(42, 171, 238, 0.14);
  --accent-press: #1f93d1;

  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));   /* фон экрана */
  --card: var(--tg-theme-bg-color, var(--fb-card));          /* фон карточек */
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --sep: rgba(127, 127, 127, 0.18);
  --press: rgba(127, 127, 127, 0.14);

  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px rgba(0, 0, 0, 0.06);

  --ok: #34c759;
  --warn: #f5a623;

  --top-inset: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom-space: 24px;      /* отступ снизу, когда кнопок нет */
  --anim: 260ms;
  color-scheme: light dark;
}

/* запасная тёмная тема для браузера (в Telegram цвета приходят от клиента) */
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #0e1621;
    --fb-card: #17212b;
    --fb-text: #f5f7fa;
    --fb-hint: #8b98a5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
  }
}

/* ---------- 2. Основа ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
}
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;     /* как приложение: текст не выделяется */
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
textarea, input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; text-align: left; }
h1, h2, p, ul, ol { margin: 0; }
.hint { color: var(--hint); }
.small { font-size: 14px; }

/* Контейнер приложения: на всю высоту видимой области Telegram, узкая колонка до 430px */
#app {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px;
  height: var(--tg-viewport-stable-height, 100%);
  overflow: hidden; background: var(--bg);
}
@media (min-width: 431px) { #app { box-shadow: 0 0 0 1px var(--sep), 0 10px 40px rgba(0, 0, 0, 0.15); } }

/* Экран — отдельный прокручиваемый слой */
.screen {
  position: absolute; left: 0; right: 0; bottom: 0;
  top: var(--top-inset);
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: var(--bg);
  padding: 8px 16px calc(var(--bottom-space) + env(safe-area-inset-bottom, 0px));
}
.has-main { --bottom-space: 104px; }          /* оставляем место под кнопки внизу */
.page { display: block; }

/* ---------- 3. Переходы между экранами (slide / fade) ---------- */
.screen.leaving { pointer-events: none; }
.enter-fwd  { animation: inFwd  var(--anim) cubic-bezier(.22, .8, .24, 1) both; z-index: 2; box-shadow: -8px 0 24px rgba(0,0,0,.12); }
.exit-fwd   { animation: outFwd var(--anim) cubic-bezier(.22, .8, .24, 1) both; z-index: 1; }
.enter-back { animation: inBack var(--anim) cubic-bezier(.22, .8, .24, 1) both; z-index: 1; }
.exit-back  { animation: outBack var(--anim) cubic-bezier(.22, .8, .24, 1) both; z-index: 2; box-shadow: -8px 0 24px rgba(0,0,0,.12); }
.enter-fade { animation: fadeIn 220ms ease both; z-index: 2; }
.exit-fade  { animation: fadeOut 220ms ease both; z-index: 1; }

@keyframes inFwd   { from { transform: translateX(100%); } to { transform: none; } }
@keyframes outFwd  { from { transform: none; opacity: 1; } to { transform: translateX(-28%); opacity: .6; } }
@keyframes inBack  { from { transform: translateX(-28%); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes outBack { from { transform: none; } to { transform: translateX(100%); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* уважаем «уменьшить движение» и слабые устройства */
@media (prefers-reduced-motion: reduce) {
  .enter-fwd, .enter-back, .exit-fwd, .exit-back { animation: fadeIn 120ms ease both; box-shadow: none; }
  .exit-fwd, .exit-back { animation-name: fadeOut; }
}

/* ---------- 4. Общие элементы ---------- */
.stack { display: flex; flex-direction: column; gap: 10px; }
.title { font-size: 26px; line-height: 1.2; font-weight: 700; margin: 8px 0 6px; }
.lead { font-size: 16px; color: var(--hint); margin-bottom: 8px; }
.block { margin-top: 20px; }
.block > h2, .next h2 { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 0 0 8px 4px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%;
}

/* Отклик на касание: нажатый элемент слегка уменьшается и темнеет */
.press { transition: transform 120ms ease, background-color 120ms ease, opacity 120ms ease; }
.press:active { transform: scale(.97); }
.card.press:active, .tile.press:active { background: color-mix(in srgb, var(--card) 88%, var(--hint)); }

/* Кнопки (минимум 48px высотой) */
.btn {
  display: flex; align-items: center; justify-content: center; text-align: center;
  width: 100%; min-height: 50px; padding: 12px 16px; border-radius: 14px;
  font-size: 16px; font-weight: 600; margin-top: 16px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { color: var(--hint); font-weight: 500; font-size: 14px; min-height: 44px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.loading::after {
  content: ""; width: 18px; height: 18px; margin-left: 10px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chip { display: inline-block; vertical-align: middle; font-size: 14px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; margin-left: 4px; }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; margin-left: 8px; }
.chev { color: var(--hint); font-size: 26px; line-height: 1; margin-left: auto; padding-left: 8px; }

.status { display: inline-block; font-size: 14px; font-weight: 600; border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.status.lg { font-size: 16px; padding: 6px 14px; }
.st-accepted    { color: var(--accent); background: var(--accent-soft); }
.st-in_progress { color: #c77d0a; background: rgba(245, 166, 35, .18); }
.st-replied     { color: #1f9d46; background: rgba(52, 199, 89, .18); }

.empty { text-align: center; padding: 40px 12px; }
.empty-icon { font-size: 56px; margin-bottom: 8px; }
.empty h2 { font-size: 20px; margin-bottom: 6px; }
.error { color: #e5484d; font-size: 14px; }

/* ---------- 5. Экраны ---------- */

/* Главная */
.hero { display: flex; align-items: center; gap: 14px; padding: 8px 4px 18px; }
.hero h1 { font-size: 22px; line-height: 1.2; font-weight: 700; }
.avatar { width: 56px; height: 56px; border-radius: 50%; flex: none; object-fit: cover; background: linear-gradient(135deg, #5ec8f8, var(--accent)); color: #fff; font-size: 24px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.svc { display: flex; align-items: center; gap: 14px; min-height: 76px; padding: 12px 14px; }
.svc-icon { width: 52px; height: 52px; flex: none; border-radius: 14px; background: var(--accent-soft); font-size: 28px; display: flex; align-items: center; justify-content: center; }
.svc-icon.sm { width: 44px; height: 44px; font-size: 24px; }
.svc-body { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.svc-title { font-weight: 600; font-size: 16px; }
.svc-sub { font-size: 14px; }
.skeleton { height: 76px; background: linear-gradient(90deg, var(--card) 25%, var(--press) 50%, var(--card) 75%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.tile { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 4px; min-height: 76px; padding: 12px 14px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); font-weight: 600; position: relative; }
.tile-icon { font-size: 22px; }
.tile .badge { position: absolute; top: 10px; right: 10px; margin: 0; }
.foot { text-align: center; margin-top: 18px; font-size: 14px; }

/* Карточка услуги */
.cover { height: 150px; border-radius: 20px; display: flex; align-items: center; justify-content: center; font-size: 68px; margin-top: 4px; background: linear-gradient(135deg, #7fd3fb, var(--accent)); box-shadow: var(--shadow); }
.cover-bots    { background: linear-gradient(135deg, #8ee0c2, #2fb7a0); }
.cover-miniapp { background: linear-gradient(135deg, #a4b0ff, #6b7cf0); }
.cover-support { background: linear-gradient(135deg, #ffd08a, #f5a623); }

.checks { list-style: none; padding: 6px 14px; }
.checks li { position: relative; padding: 10px 0 10px 30px; border-bottom: 1px solid var(--sep); font-size: 16px; }
.checks li:last-child { border-bottom: 0; }
.checks li::before { content: "✓"; position: absolute; left: 0; top: 10px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.packs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pack { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-height: 104px; padding: 12px 10px; background: var(--card); border-radius: 14px; border: 2px solid transparent; box-shadow: var(--shadow); }
.pack-name { font-size: 14px; font-weight: 600; }
.pack-from { font-size: 14px; margin-top: 6px; line-height: 1; }
.pack-price { font-size: 16px; font-weight: 700; white-space: nowrap; }
.pack-term { font-size: 14px; line-height: 1.2; }
.pack.selected { border-color: var(--accent); background: color-mix(in srgb, var(--card) 90%, var(--accent)); }
.pack-note { margin: 10px 4px 0; font-size: 14px; min-height: 20px; }

.example { padding: 14px; }
.example-title { font-weight: 700; font-size: 18px; margin-bottom: 4px; }
.price-note { margin-top: 16px; padding: 0 4px; }

/* Заявка */
.selected-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 48px; padding: 8px 14px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip-edit { font-size: 14px; font-weight: 500; opacity: .85; }
.who { font-size: 14px; margin: 8px 4px 0; }
.field-label { font-size: 14px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; margin: 20px 4px 8px; }
.input { display: block; width: 100%; min-height: 128px; padding: 12px 14px; font: inherit; font-size: 16px; color: var(--text); background: var(--card); border: 2px solid transparent; border-radius: 14px; box-shadow: var(--shadow); resize: none; outline: none; transition: border-color 150ms; }
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--hint); opacity: .8; }
.field-foot { display: flex; justify-content: space-between; gap: 8px; margin: 6px 4px 0; min-height: 20px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-btn { min-height: 56px; padding: 8px 12px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); border: 2px solid transparent; font-weight: 500; font-size: 15px; text-align: center; display: flex; align-items: center; justify-content: center; }
.seg-btn.selected { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.promise { margin-top: 16px; padding: 12px 14px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-weight: 500; font-size: 15px; }

/* Готово */
.center { text-align: center; padding-top: 24px; }
.success { width: 88px; height: 88px; border-radius: 50%; background: var(--ok); margin: 0 auto 12px; display: flex; align-items: center; justify-content: center; animation: pop 420ms cubic-bezier(.2, 1.4, .4, 1) both; }
.success svg { width: 52px; height: 52px; fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.success path { stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw 360ms 200ms ease forwards; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
.next { text-align: left; padding: 16px; margin-top: 20px; }
.next ol { padding-left: 22px; }
.next li { padding: 6px 0; font-size: 16px; }

/* Мои заявки и детали */
.req { display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 10px 12px; }
.req .svc-body { flex: 1; }
.status-big { padding: 16px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; margin-top: 12px; }
.timeline { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { display: flex; align-items: center; gap: 10px; color: var(--hint); font-size: 15px; }
.timeline li.done { color: var(--text); font-weight: 500; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--hint); flex: none; }
.timeline li.done .dot { background: var(--accent); border-color: var(--accent); }
.text-card { padding: 14px; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }

/* Как я работаю */
.step { display: flex; align-items: center; gap: 14px; padding: 12px 14px; min-height: 72px; }
.step .hint { font-size: 14px; }
.faq { padding: 0 14px; }
.faq-item { border-bottom: 1px solid var(--sep); }
.faq-item:last-child { border-bottom: 0; }
.faq-q { display: flex; align-items: center; width: 100%; min-height: 52px; padding: 8px 0; font-weight: 600; }
.faq-q .chev { transition: transform 200ms ease; }
.faq-item.open .chev { transform: rotate(90deg); }
.faq-a { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 220ms ease; }
.faq-a > div { overflow: hidden; }
.faq-a p { padding: 0 0 14px; color: var(--hint); font-size: 15px; }
.faq-item.open .faq-a { grid-template-rows: 1fr; }

/* Нижнее меню (вкладки): цвета из темы, активная вкладка — акцент */
.tabs { position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; background: var(--card); border-top: 1px solid var(--sep); padding-bottom: env(safe-area-inset-bottom, 0px); transform: translateY(100%); visibility: hidden; transition: transform 220ms ease, visibility 0s 220ms; }
.has-tabs .tabs { transform: none; visibility: visible; transition: transform 220ms ease; }
.tab { flex: 1 1 0; min-width: 0; min-height: 58px; padding: 4px 2px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 14px; font-weight: 500; line-height: 1.15; color: var(--hint); text-align: center; white-space: nowrap; }
.tab .ico { width: 56px; height: 30px; border-radius: 15px; display: flex; align-items: center; justify-content: center; transition: background-color 200ms; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: fill 200ms; }
.tab.active { color: var(--accent); }   /* жирность не меняем: текст не должен расширяться */
/* на самых узких экранах (320 px) подписи чуть мельче, иначе «Мои записи» не помещается */
@media (max-width: 350px) { .tab { font-size: 13px; } }
.tab.active .ico { background: var(--accent-soft); }
.tab.active svg { fill: rgba(42, 171, 238, 0.22); }
.screen.with-tabs { padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }

/* О мастере и Портфолио */
.avatar.big { width: 64px; height: 64px; font-size: 28px; }
.about-lead { color: var(--text); font-size: 16px; padding: 0 4px; }
.about-bonus { padding: 0 4px 10px; font-size: 16px; }
.about-closing { margin: 20px 4px 0; padding: 14px; border-radius: 14px; background: var(--accent-soft); font-size: 16px; }
.work { padding: 14px; }
.work-head { display: flex; align-items: center; gap: 14px; }
.work-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.chip.plain { margin: 0; }
.work-text { margin: 12px 0 0; font-size: 15px; }
.btn.ghost-accent { color: var(--accent); background: none; min-height: 48px; margin-top: 8px; }

/* ---------- 6. Запасные элементы для обычного браузера (в Telegram их нет) ---------- */
#app.fake { --top-inset: 52px; }
#topbar { position: absolute; top: 0; left: 0; right: 0; height: 52px; z-index: 5; display: flex; align-items: center; justify-content: center; background: var(--card); border-bottom: 1px solid var(--sep); }
.topbar-title { font-weight: 600; }
.icon-btn { position: absolute; left: 4px; top: 4px; width: 44px; height: 44px; border-radius: 50%; font-size: 34px; line-height: 1; color: var(--accent); display: flex; align-items: center; justify-content: center; text-align: center; padding-bottom: 4px; }

#bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--card); border-top: 1px solid var(--sep); display: flex; flex-direction: column; gap: 8px; }
#bar .btn { margin-top: 0; }
#fakeSecondary { order: 1; }
#fakeMain { order: 2; }
