:root {
  --bg: var(--tg-theme-bg-color, #f4f4f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec: var(--tg-theme-secondary-bg-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 16px;
  color-scheme: light dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.top-titles { min-width: 0; flex: 1; }
.top h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -0.02em; }
.subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.back {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: var(--sec);
  color: var(--link);
  font-size: 28px;
  line-height: 1;
  padding: 0 0 3px;
  cursor: pointer;
}
.hidden { display: none !important; }

.app { padding: 4px 16px 40px; }
.muted { color: var(--hint); }
.error { color: #e53935; margin: 0; }

.toolbar {
  display: flex;
  gap: 8px;
  margin: 4px 0 14px;
}
.toolbar .primary { margin: 0; }

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 0 12px;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 650;
  background: var(--sec);
  color: var(--text);
  cursor: pointer;
}
.chip.active { background: var(--btn); color: var(--btn-text); }

.card {
  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%;
  text-align: left;
  border: 0;
  background: var(--sec);
  color: inherit;
  border-radius: var(--radius);
  padding: 0;
  margin: 0 0 10px;
  cursor: pointer;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--hint) 12%, transparent);
  overflow: hidden;
}
.card:active { transform: scale(0.99); }
.card-accent { width: 4px; flex: 0 0 4px; }
.card-body { flex: 1; min-width: 0; padding: 14px 8px 14px 14px; }
.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.card h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.card-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--hint);
}
.chev {
  align-self: center;
  padding: 0 12px 0 4px;
  color: var(--hint);
  font-size: 22px;
  opacity: 0.55;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.meta { font-size: 12px; color: var(--hint); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 650;
  padding: 4px 9px;
  border-radius: 999px;
  color: #fff;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.9;
  flex: 0 0 6px;
}

.hero, .panel {
  background: var(--sec);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--hint) 12%, transparent);
}
.hero h2 { margin: 10px 0 14px; font-size: 22px; line-height: 1.25; letter-spacing: -0.03em; }
.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.hero-item .k {
  display: block;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--hint);
  margin-bottom: 4px;
}
.hero-item .v { font-size: 14px; font-weight: 550; }

.panel h3 {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--hint);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.panel p { margin: 0; white-space: pre-wrap; line-height: 1.45; }

.file {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: color-mix(in srgb, var(--bg) 80%, var(--sec));
  border: 0;
  border-radius: 12px;
  color: inherit;
  padding: 10px 12px;
  margin: 0 0 8px;
  font-size: 14px;
  cursor: pointer;
}
.file-ico {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--link) 14%, var(--sec));
  color: var(--link);
  display: grid;
  place-items: center;
  font-size: 14px;
  flex: 0 0 32px;
}
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg);
  flex: 0 0 44px;
}
.linkish { color: var(--text); }

.primary, .danger, .ghost {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 13px 14px;
  margin: 10px 0 0;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}
.primary { background: var(--btn); color: var(--btn-text); }
.danger { background: color-mix(in srgb, #c62828 88%, #000); color: #fff; }
.ghost {
  background: var(--sec);
  color: var(--link);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--hint) 12%, transparent);
}
.primary:disabled, .danger:disabled { opacity: 0.55; cursor: default; }
.btns { margin-top: 8px; display: flex; }
.btns .primary, .btns .danger { width: auto; flex: 1; margin: 0; }

textarea, input[type="text"] {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 0;
  font: inherit;
  background: var(--bg);
  color: var(--text);
}
textarea { resize: vertical; min-height: 84px; }

.upload {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
  padding: 14px;
  border: 1px dashed color-mix(in srgb, var(--link) 45%, var(--hint));
  border-radius: 12px;
  color: var(--link);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: color-mix(in srgb, var(--link) 6%, var(--sec));
}
.upload input { display: none; }

.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 12px;
  width: 100%;
}
.comment {
  display: flex;
  gap: 8px;
  max-width: 88%;
  width: fit-content;
  padding: 0;
  border: 0;
  align-items: flex-end;
}
.comment.them { align-self: flex-start; }
.comment.mine {
  align-self: flex-end;
  margin-left: auto;
  flex-direction: row-reverse;
}
.comment.mine .meta { text-align: right; }
.avatar {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: #5c6bc0;
}
.comment-body { min-width: 0; }
.comment-body .meta { margin: 0 0 4px; }
.comment p {
  margin: 0;
  background: var(--bg);
  border-radius: 16px 16px 16px 4px;
  padding: 10px 12px;
  line-height: 1.4;
  white-space: pre-wrap;
}
.comment.mine p {
  background: var(--btn);
  color: var(--btn-text);
  border-radius: 16px 16px 4px 16px;
}

.empty {
  text-align: center;
  padding: 36px 16px;
  background: var(--sec);
  border-radius: var(--radius);
}
.empty-ico {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--link) 12%, var(--sec));
  color: var(--link);
  font-size: 26px;
}
.empty h2 { margin: 0 0 6px; font-size: 18px; }
.empty p { margin: 0 0 16px; color: var(--hint); }
.empty .primary { width: auto; display: inline-block; padding-left: 22px; padding-right: 22px; }

.skel-card {
  height: 96px;
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: linear-gradient(90deg, var(--sec) 25%, color-mix(in srgb, var(--hint) 12%, var(--sec)) 50%, var(--sec) 75%);
  background-size: 200% 100%;
  animation: skel 1.2s ease-in-out infinite;
}
@keyframes skel {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  background: color-mix(in srgb, var(--text) 92%, #000);
  color: var(--bg);
  text-align: center;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px color-mix(in srgb, #000 25%, transparent);
}
.toast.hidden { display: none !important; }
