/* Telegram passes its theme as --tg-theme-* variables; the fallbacks are the light theme. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #6b6b70);
  --link: var(--tg-theme-link-color, #1f74b8);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #c62f28);
  --sep: rgba(60, 60, 67, 0.16);
  --field: rgba(118, 118, 128, 0.12);
  --seg-active: #ffffff;
  --success: #1d7a35; --success-bg: #e2f4e6;
  --warn: #7d5300; --warn-bg: #fcefd2;
  --info: #1a62a3; --info-bg: #e2eefa;
  --danger-bg: #fde7e6;
  --ai: #6a3fc4; --ai-bg: #efe8fc;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: var(--tg-theme-secondary-bg-color, #101012);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #9a9aa1);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --sep: rgba(255, 255, 255, 0.12);
  --field: rgba(118, 118, 128, 0.24);
  --seg-active: rgba(255, 255, 255, 0.16);
  --success: #5fd27f; --success-bg: rgba(95, 210, 127, 0.14);
  --warn: #f3c55a; --warn-bg: rgba(243, 197, 90, 0.14);
  --info: #79bbf5; --info-bg: rgba(121, 187, 245, 0.14);
  --danger-bg: rgba(255, 122, 112, 0.14);
  --ai: #c3a6ff; --ai-bg: rgba(195, 166, 255, 0.16);
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, Roboto, "Segoe UI", sans-serif;
  font-size: 16px; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--btn); outline-offset: 2px; }
.boot { padding: 40px; text-align: center; color: var(--hint); }

.app { min-height: 100vh; display: flex; flex-direction: column; }
.header {
  position: sticky; top: 0; z-index: 5; min-height: 56px; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; background: var(--card); border-bottom: 1px solid var(--sep);
}
.header .titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.header .title { font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header .title.big { font-size: 20px; }
.header .sub { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--link); padding: 0;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; border-radius: 12px;
}
.icon-btn.filled { background: var(--field); }
.icon-btn.back { margin-left: -10px; }
.icon-btn.muted { color: var(--hint); }

.main { flex: 1; padding: 12px 12px 24px; display: flex; flex-direction: column; gap: 10px; }
.label { font-size: 13px; color: var(--hint); padding: 8px 4px 0; text-transform: uppercase; letter-spacing: 0.02em; }
.card { background: var(--card); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.card.pad { padding: 12px; gap: 10px; }
.note { font-size: 13px; line-height: 1.4; color: var(--hint); }
.empty { padding: 20px 16px; font-size: 15px; color: var(--hint); text-align: center; }

.row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 12px;
  border: 0; background: transparent; text-align: left;
}
.row + .row, .row.sep { border-top: 1px solid var(--sep); }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .name.lg { font-size: 16px; }
.row .meta { font-size: 13px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.link { color: var(--link); font-weight: 600; font-size: 16px; }
.row:disabled { opacity: 0.45; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.avatar.md { width: 40px; height: 40px; font-size: 15px; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 52px; height: 52px; font-size: 19px; }
.avatar.ghost { background: var(--field); color: var(--hint); }
.plat { display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: #fff; }
.plats { display: flex; align-items: center; gap: 4px; min-height: 20px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 4px 8px;
  border-radius: 10px; white-space: nowrap; flex-shrink: 0;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.c-success { background: var(--success-bg); color: var(--success); }
.c-warn { background: var(--warn-bg); color: var(--warn); }
.c-info { background: var(--info-bg); color: var(--info); }
.c-danger { background: var(--danger-bg); color: var(--danger); }
.c-neutral { background: var(--field); color: var(--hint); }

.search {
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border-radius: 12px;
  background: var(--card); color: var(--hint);
}
.search input { flex: 1; min-width: 0; height: 44px; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--text); }

.seg { display: flex; background: var(--field); border-radius: 11px; padding: 2px; }
.seg button {
  flex: 1; height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--hint);
  font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.seg button.on { background: var(--seg-active); color: var(--text); box-shadow: var(--shadow); }
.seg.sm button { font-size: 13px; height: 40px; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--btn); color: var(--btn-text);
  font-size: 12px; display: inline-flex; align-items: center; justify-content: center;
}
.lang { display: flex; background: var(--field); border-radius: 10px; padding: 2px; flex-shrink: 0; }
.lang button { width: 44px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--hint); font-size: 13px; font-weight: 700; }
.lang button.on { background: var(--seg-active); color: var(--text); box-shadow: var(--shadow); }

.btn {
  height: 50px; border: 0; border-radius: 12px; background: var(--btn); color: var(--btn-text); font-size: 16px;
  font-weight: 600; width: 100%; flex-shrink: 0;
}
.btn:disabled { opacity: 0.45; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.plain { background: var(--field); color: var(--text); }
.btn.ghost { background: transparent; color: var(--danger); }
.btn.card-btn { background: var(--card); color: var(--link); display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn.card-btn.red { color: var(--danger); }
.pill {
  min-height: 36px; padding: 0 14px; border: 0; border-radius: 18px; font-size: 14px; font-weight: 600; white-space: nowrap;
  background: var(--field); color: var(--text);
}
.pill.blue { background: var(--btn); color: var(--btn-text); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.red { background: var(--danger-bg); color: var(--danger); }

.input {
  height: 46px; border: 0; border-radius: 12px; background: var(--field); color: var(--text); font-size: 16px;
  padding: 0 14px; outline: 0; width: 100%;
}
.field-label { display: flex; flex-direction: column; gap: 6px; }
.field-label > span { font-size: 13px; color: var(--hint); }

.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 132px; border: 1.5px dashed var(--link); border-radius: 12px; color: var(--link); text-align: center;
  padding: 12px 16px; cursor: pointer;
}
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.drop strong { font-size: 16px; }
.drop span { font-size: 13px; color: var(--hint); }
.thumbs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.thumb {
  position: relative; aspect-ratio: 4 / 5; border-radius: 10px; background: #56708c; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end; padding: 6px;
}
.thumb.video { aspect-ratio: 9 / 16; }
.thumb img, .thumb video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .cap {
  position: relative; font-size: 11px; color: #fff; background: rgba(0, 0, 0, 0.6); border-radius: 6px; padding: 2px 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb .bar { position: relative; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.35); margin-bottom: 4px; }
.thumb .bar i { display: block; height: 100%; border-radius: 2px; background: #fff; }
.thumb.failed { outline: 2px solid var(--danger); }

textarea.text {
  width: 100%; min-height: 120px; border: 0; outline: 0; resize: vertical; background: transparent; font-size: 16px;
  line-height: 1.4; padding: 12px; display: block;
}
.counter { padding: 0 12px 8px; font-size: 12px; color: var(--hint); text-align: right; }
.switch { width: 51px; height: 31px; border-radius: 16px; background: var(--field); position: relative; flex-shrink: 0; transition: background .2s; }
.switch i { position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .2s; }
.switch.on { background: #34c759; }
.switch.on i { left: 22px; }
.ai-icon { width: 32px; height: 32px; border-radius: 9px; background: var(--ai-bg); color: var(--ai); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.check {
  width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--hint); display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
.check.on { border-color: var(--btn); background: var(--btn); }
.radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--hint); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.radio.on { border-color: var(--btn); }
.radio.on i { width: 11px; height: 11px; border-radius: 50%; background: var(--btn); }
.time-row { display: flex; align-items: center; gap: 10px; min-height: 48px; padding-top: 8px; border-top: 1px solid var(--sep); }
.time-row input { height: 40px; border: 0; border-radius: 10px; background: var(--field); color: var(--text); font-size: 15px; padding: 0 10px; }

.footer {
  position: sticky; bottom: 0; z-index: 5; padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--sep); display: flex; flex-direction: column; gap: 6px;
}
.footer .note { text-align: center; }

.post-head { display: flex; align-items: center; gap: 10px; padding: 12px; }
.post-thumb { width: 44px; height: 44px; border-radius: 10px; background: #56708c; flex-shrink: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; color: #fff; }
.post-thumb img { width: 100%; height: 100%; object-fit: cover; }
.target { padding: 10px 12px; border-top: 1px solid var(--sep); display: flex; flex-direction: column; gap: 8px; }
.target .line { display: flex; align-items: center; gap: 10px; }
.progress { height: 6px; border-radius: 3px; background: var(--field); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--btn); border-radius: 3px; transition: width .4s; }
.target .err { flex: 1; font-size: 13px; line-height: 1.35; color: var(--danger); }
.target a { color: var(--link); text-decoration: none; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; border: 0; background: rgba(0, 0, 0, 0.45); padding: 0; }
.sheet {
  position: relative; background: var(--card); border-radius: 16px 16px 0 0; max-height: 88vh; overflow-y: auto;
  padding: 8px 16px calc(22px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px;
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--sep); align-self: center; flex-shrink: 0; }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 700; flex: 1; }
.close-x { width: 30px; height: 30px; border-radius: 50%; background: var(--field); display: flex; align-items: center; justify-content: center; }
.group { display: flex; flex-direction: column; border-radius: 14px; background: var(--field); overflow: hidden; }
.group.scroll { max-height: 300px; overflow-y: auto; }
.bullets { margin: 0; padding: 12px; list-style: none; display: flex; flex-direction: column; gap: 10px; background: var(--field); border-radius: 12px; }
.bullets li { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; line-height: 1.35; }
.num { width: 26px; height: 26px; border-radius: 50%; background: var(--btn); color: var(--btn-text); font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.center { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; }
.dots { display: flex; gap: 8px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--btn); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.info-box { padding: 12px; border-radius: 12px; background: var(--info-bg); color: var(--info); font-size: 14px; line-height: 1.4; }
p.text { margin: 0; font-size: 15px; line-height: 1.45; }

.toast {
  position: fixed; top: 66px; left: 12px; right: 12px; z-index: 30; background: #1c1c1e; color: #fff; border-radius: 12px;
  padding: 12px 14px; font-size: 14px; font-weight: 500; display: flex; gap: 10px; align-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); animation: up .2s ease-out;
}
html[data-theme="dark"] .toast { background: #f2f2f7; color: #000; }
.toast.bad svg { color: #ff7a70; }
.wait { margin: 18vh 20px 0; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
