/* ============================================================
   WorkFlow AI — Mini App (Telegram WebApp)
   Стиль наследует лендинг: тот же фиолетовый бренд, мягкие тени,
   Inter, пилюли-чипы. Адаптирован под узкий Telegram-viewport и
   тёмную тему Telegram (через telegram-web-app theme params).
   ============================================================ */

:root {
  --primary: #533afd;
  --primary-deep: #4434d4;
  --primary-soft: #665efd;
  --primary-subdued: #b9b9f9;
  --brand-dark-900: #1c1e54;
  --ruby: #ea2261;
  --magenta: #f96bee;
  --amber: #c98a1a;
  --teal: #0ea5a4;
  --green: #17a45f;

  /* Поверхности — переопределяются из Telegram theme (см. .tg-dark). */
  --canvas: #ffffff;
  --surface: #f6f9fc;
  --surface-2: #eef3f9;
  --hairline: #e3e8ee;

  --ink: #0d253d;
  --ink-2: #273951;
  --ink-mute: #64748d;
  --on-primary: #ffffff;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 9999px;

  --shadow-1: 0 1px 3px rgba(0, 55, 112, .08);
  --shadow-2: 0 8px 24px rgba(0, 55, 112, .10), 0 2px 6px rgba(0, 55, 112, .04);
  --nav-h: 62px;

  --ease: cubic-bezier(.2, .7, .2, 1);
}

/* Тёмная тема Telegram: приглушаем поверхности, сохраняем бренд. */
body.tg-dark {
  --canvas: #17181f;
  --surface: #1f2129;
  --surface-2: #262933;
  --hairline: #2f3340;
  --ink: #f0f2f6;
  --ink-2: #c7cdd8;
  --ink-mute: #8a92a4;
  --shadow-2: 0 8px 24px rgba(0, 0, 0, .35);
  --primary-subdued: #3a3a72;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  overscroll-behavior-y: contain;
}

/* ---- App shell --------------------------------------------------- */
.app { max-width: 640px; margin: 0 auto; }

.screen { display: none; padding: 16px 16px 24px; animation: fadeUp .3s var(--ease); }
.screen.is-active { display: block; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---- Header ------------------------------------------------------ */
.head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--canvas) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.head__logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--magenta));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
  flex: 0 0 auto;
}
.head__title { font-weight: 600; font-size: 15px; }
.head__sub { font-size: 12px; color: var(--ink-mute); }
.head__spacer { flex: 1; }
.chip-mini {
  font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--hairline);
}

/* ---- Section titles --------------------------------------------- */
.s-title { font-size: 19px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 4px; }
.s-sub { font-size: 13px; color: var(--ink-mute); margin-bottom: 16px; }

.eyebrow {
  display: inline-block;
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--primary); margin-bottom: 8px;
}

/* ---- Cards ------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 16px;
  transition: transform .2s var(--ease), box-shadow .2s ease, border-color .2s ease;
}
.card + .card { margin-top: 12px; }
.card--tap { cursor: pointer; }
.card--tap:active { transform: scale(.985); }
.card__row { display: flex; align-items: center; gap: 12px; }
.card__icon {
  width: 40px; height: 40px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 20px;
  background: var(--surface-2);
}
.card__body { flex: 1; min-width: 0; }
.card__title { font-weight: 600; font-size: 15px; }
.card__meta { font-size: 12.5px; color: var(--ink-mute); margin-top: 2px; }
.card__chevron { color: var(--ink-mute); flex: 0 0 auto; }

/* ---- Buttons ----------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--r-md);
  padding: 12px 18px; transition: transform .12s var(--ease), background-color .18s, box-shadow .2s;
  width: 100%;
}
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-1); }
.btn--primary:hover { background: var(--primary-deep); }
.btn--ghost { background: var(--surface); color: var(--ink); border-color: var(--hairline); }
.btn--sm { padding: 9px 14px; font-size: 14px; width: auto; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

/* ---- Segmented control ------------------------------------------- */
.seg {
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-pill); margin-bottom: 16px;
}
.seg__item {
  flex: 1; text-align: center; font-size: 13.5px; font-weight: 600;
  padding: 9px 8px; border-radius: var(--r-pill); color: var(--ink-mute);
  cursor: pointer; transition: color .2s, background-color .2s, box-shadow .2s;
}
.seg__item.is-active { background: var(--canvas); color: var(--primary); box-shadow: var(--shadow-1); }

/* ---- Chips (topics/tabs) ----------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-pill); padding: 8px 14px; cursor: pointer;
  transition: transform .12s var(--ease), border-color .2s, color .2s, background-color .2s;
}
.chip:active { transform: scale(.95); }
.chip.is-on { background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.chip__count { color: var(--ink-mute); font-weight: 400; }

/* ---- Topic / source list rows ------------------------------------ */
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-md); padding: 12px 14px; cursor: pointer;
  transition: transform .12s var(--ease), border-color .2s, box-shadow .2s;
}
.row:active { transform: scale(.99); }
.row:hover { border-color: color-mix(in srgb, var(--primary) 30%, var(--hairline)); }
.row__dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--green); }
.row__dot--pause { background: var(--ink-mute); }
.row__dot--err { background: var(--ruby); }
.row__body { flex: 1; min-width: 0; }
.row__title { font-size: 14.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__meta { font-size: 12px; color: var(--ink-mute); }
.row__badge {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink-mute); flex: 0 0 auto;
}

/* ---- Draft / post bubble ----------------------------------------- */
.draft {
  background: var(--canvas); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow-1);
}
.draft__cover {
  width: 100%; aspect-ratio: 16/10; border-radius: var(--r-md);
  background: linear-gradient(135deg, #c7d8ff, #e7d3ff);
  display: grid; place-items: center; color: #4434d4; font-weight: 700; margin-bottom: 12px;
  overflow: hidden;
}
.draft__text { font-size: 14.5px; color: var(--ink); white-space: pre-wrap; }
.draft__text b { font-weight: 700; }
.draft__src { font-size: 12.5px; color: var(--ink-mute); margin-top: 10px; }
.draft__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.draft__actions .btn { font-size: 14px; padding: 11px; }
.draft__actions .btn--full { grid-column: 1 / -1; }

/* ---- Stat tiles -------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-md); padding: 14px 12px; text-align: center;
}
.tile__num { font-size: 22px; font-weight: 700; color: var(--ink); }
.tile__label { font-size: 11.5px; color: var(--ink-mute); margin-top: 3px; }

/* ---- Field ------------------------------------------------------- */
.field { margin-bottom: 14px; }
.field__label { font-size: 13px; font-weight: 600; margin-bottom: 6px; display: block; }
.input, .textarea {
  width: 100%; font-family: inherit; font-size: 15px; color: var(--ink);
  background: var(--canvas); border: 1px solid var(--hairline);
  border-radius: var(--r-md); padding: 12px 14px; transition: border-color .2s, box-shadow .2s;
}
.input:focus, .textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.textarea { resize: vertical; min-height: 96px; }

/* ---- Bottom navigation ------------------------------------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--canvas) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(12px);
  border-top: 1px solid var(--hairline);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--ink-mute); cursor: pointer; font-size: 11px; font-weight: 600;
  transition: color .2s;
}
.tab__icon { font-size: 20px; line-height: 1; transition: transform .25s var(--ease); }
.tab.is-active { color: var(--primary); }
.tab.is-active .tab__icon { transform: translateY(-2px) scale(1.08); }

.tab__icon { position: relative; }
.tab__badge {
  position: absolute; top: -6px; right: -10px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--r-pill); background: var(--ruby); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
.tab__badge:empty, .tab__badge.is-zero { display: none; }

.chip-mini--tap { cursor: pointer; }
.chip-mini--tap:active { transform: scale(.95); }

.gen-note { font-size: 12.5px; text-align: center; margin-top: 8px; }

/* ---- Draft badges (формат/длина) --------------------------------- */
.draft__badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.badge {
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: var(--r-pill);
  background: var(--surface-2); color: var(--ink-2);
}
.badge--ok { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.badge--warn { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.draft__actions { grid-template-columns: 1fr 1fr 1fr; }

/* ---- Toast ------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px);
  transform: translate(-50%, 20px); z-index: 60;
  background: var(--brand-dark-900); color: #fff;
  font-size: 13.5px; font-weight: 500; padding: 11px 18px; border-radius: var(--r-pill);
  box-shadow: var(--shadow-2); opacity: 0; pointer-events: none;
  transition: opacity .25s ease, transform .25s var(--ease); max-width: 90%;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Sheet bar (back / close) ------------------------------------ */
.sheet__bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; min-height: 24px; }
.sheet__back, .sheet__close {
  background: none; border: none; font-family: inherit; cursor: pointer;
  color: var(--ink-mute); font-size: 15px; padding: 4px 6px;
}
.sheet__back { font-weight: 600; color: var(--primary); }

/* ---- Onboarding overlay ------------------------------------------ */
.onb {
  position: fixed; inset: 0; z-index: 70;
  background: color-mix(in srgb, var(--canvas) 96%, transparent);
  backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 24px;
}
.onb__card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-xl); padding: 28px 22px; box-shadow: var(--shadow-2);
  animation: fadeUp .35s var(--ease);
}
.onb__emoji { font-size: 44px; margin-bottom: 12px; }
.onb__step h2 { font-size: 20px; margin-bottom: 8px; }
.onb__step p { color: var(--ink-mute); font-size: 14px; margin-bottom: 18px; }
.onb__dots { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.onb__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--hairline); }
.onb__dot.is-on { background: var(--primary); }

/* ---- Sheet (modal from bottom) ----------------------------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(13, 37, 61, .45);
  opacity: 0; pointer-events: none; transition: opacity .28s ease;
}
.sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 640px; margin: 0 auto;
  background: var(--canvas); border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%); transition: transform .32s var(--ease);
  max-height: 86vh; overflow-y: auto;
}
.sheet.is-open { transform: none; }
.sheet__grip { width: 40px; height: 4px; border-radius: 2px; background: var(--hairline); margin: 6px auto 14px; }
.sheet__title { font-size: 17px; font-weight: 700; margin-bottom: 12px; }

/* ---- Calendar (mini) --------------------------------------------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 10px 0; }
.cal__wd { text-align: center; font-size: 11px; color: var(--ink-mute); padding: 4px 0; }
.cal__day {
  aspect-ratio: 1; display: grid; place-items: center; font-size: 13px;
  border-radius: 9px; cursor: pointer; transition: background-color .15s, color .15s;
}
.cal__day:hover { background: var(--surface-2); }
.cal__day.is-off { color: var(--ink-mute); opacity: .4; pointer-events: none; }
.cal__day.is-sel { background: var(--primary); color: #fff; font-weight: 600; }

/* ---- Empty state ------------------------------------------------- */
.empty { text-align: center; padding: 40px 20px; color: var(--ink-mute); }
.empty__emoji { font-size: 34px; margin-bottom: 10px; }

/* ---- Utility ----------------------------------------------------- */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.muted { color: var(--ink-mute); }
.reveal { opacity: 0; transform: translateY(12px); transition: opacity .5s var(--ease), transform .5s var(--ease); }
.reveal.is-in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
  .reveal { opacity: 1; transform: none; transition: none; }
}
