/* Лише змінні теми Telegram (із запасними значеннями); без inline-стилів (CSP). */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8f);
  --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, #f0f0f5);
  --line: color-mix(in srgb, var(--hint) 28%, transparent);
  --err: #e5484d;
  --ok: #2fa84f;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --pad: 16px;
  --bar-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, p, ul { margin: 0; }
a { color: var(--link); text-decoration: none; }
.hint { color: var(--hint); font-size: 14px; }

.app { max-width: 720px; margin: 0 auto; min-height: 100vh; transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out); }
.app.enter { opacity: 0; transform: translateY(4px); }
.screen { display: flex; flex-direction: column; min-height: 100vh; }
.screen.with-bar { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); }
.content { padding: 0 var(--pad) 24px; flex: 1; min-width: 0; }
.head { padding: 12px var(--pad) 8px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.title { font-size: 22px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.subtitle { color: var(--hint); font-size: 14px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; overflow-wrap: anywhere; }
.head.flat { position: static; }

/* верхні вкладки */
.segs { display: flex; gap: 4px; background: var(--sec); padding: 3px; border-radius: 10px; margin-bottom: 10px; }
.seg { flex: 1; text-align: center; min-height: 44px; line-height: 38px; border-radius: 8px; font-weight: 600; color: var(--hint); transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out); }
.seg.active { background: var(--bg); color: var(--text); }
.search { width: 100%; min-height: 44px; border: 0; border-radius: 10px; padding: 0 14px; background: var(--sec); color: var(--text); font: inherit; outline: none; }
.search::placeholder, .ask-input::placeholder { color: var(--hint); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 44px; padding: 0 16px; border: 0; border-radius: 22px; background: var(--sec); color: var(--text); font: inherit; font-size: 15px; cursor: pointer; transition: transform 140ms var(--ease-out), background-color 160ms var(--ease-out); }
.chip.active { background: var(--btn); color: var(--btn-text); }
.chip:active, .btn:active, .key:active, .ask-send:active { transform: scale(0.97); }

/* вкладки проєкту */
.tabs { display: flex; gap: 4px; margin-top: 10px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab { flex: none; min-height: 44px; line-height: 44px; padding: 0 14px; color: var(--hint); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--text); border-bottom-color: var(--btn); }

/* списки */
.list { display: flex; flex-direction: column; }
.row { display: block; min-height: 56px; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--text); }
.row-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-meta { color: var(--hint); font-size: 14px; flex: none; font-variant-numeric: tabular-nums; }
.row-sub { color: var(--hint); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { font-size: 12px; color: var(--hint); background: var(--sec); padding: 2px 8px; border-radius: 10px; flex: none; }
@media (hover: hover) and (pointer: fine) { a.row:hover { background: var(--sec); } }
a.row:active { background: var(--sec); }
.frow { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 6px 0; }
.frow.disabled { opacity: 0.5; }
.ficon { flex: none; width: 24px; text-align: center; }
.fname { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.fsize { flex: none; color: var(--hint); font-size: 14px; font-variant-numeric: tabular-nums; }
.repo-line { color: var(--hint); font-size: 14px; padding: 16px 0 4px; text-align: center; }
.row-link { display: block; width: 100%; min-height: 48px; margin-top: 4px; border: 0; background: none; color: var(--link); font: inherit; cursor: pointer; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; padding: 12px 0 6px; font-size: 14px; color: var(--hint); }
.crumbs a { padding: 6px 0; }
.crumbs .cur { color: var(--text); padding: 6px 0; overflow-wrap: anywhere; }
.crumbs .sep { padding: 6px 0; }

/* стани */
.loading { display: flex; align-items: center; gap: 10px; justify-content: center; color: var(--hint); padding: 32px 0; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--btn); animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--hint); padding: 40px 8px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.empty.error p:first-child { color: var(--err); }
.empty.outside { min-height: 80vh; justify-content: center; color: var(--text); }
.empty.outside h1 { font-size: 24px; }

/* кнопки */
.btn { min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px; font: inherit; font-weight: 600; cursor: pointer; transition: transform 140ms var(--ease-out), opacity 160ms var(--ease-out); }
.btn.primary { background: var(--btn); color: var(--btn-text); }
.btn.secondary { background: var(--sec); color: var(--link); }
.btn.link { background: none; color: var(--link); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* картки стану */
.card { background: var(--sec); border-radius: 14px; padding: 14px; margin-top: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.card-head h2 { font-size: 17px; }
.card-foot { margin-top: 10px; display: flex; justify-content: flex-end; }
.commits, .heavy { list-style: none; padding: 0; }
.commits li { display: flex; gap: 12px; padding: 5px 0; }
.cdate { color: var(--hint); flex: none; font-variant-numeric: tabular-nums; }
.csub { overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); }
.card > .kv:first-child { border-top: 0; }
.kv .k { color: var(--hint); flex: none; }
.kv .v { text-align: right; overflow-wrap: anywhere; }
.kv.col { flex-direction: column; gap: 6px; }
.card .failed { color: var(--text); }
.heavy li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 15px; }
.hpath { overflow-wrap: anywhere; min-width: 0; }
.hsize { flex: none; color: var(--hint); font-variant-numeric: tabular-nums; }

/* рядок питання */
.ask { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; max-width: 720px; margin: 0 auto; padding: 10px var(--pad) calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); z-index: 10; }
.ask-input { flex: 1; min-width: 0; min-height: 44px; border: 0; border-radius: 22px; padding: 0 16px; background: var(--sec); color: var(--text); font: inherit; outline: none; }
.ask-send { flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--btn); color: var(--btn-text); font-size: 18px; cursor: pointer; transition: transform 140ms var(--ease-out), opacity 160ms var(--ease-out); }
.ask-send:disabled { opacity: 0.35; transform: none; }

/* тост */
.toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + 20px + env(safe-area-inset-bottom)); transform: translate(-50%, 8px); max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 15px; opacity: 0; transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out); z-index: 30; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[hidden] { display: none; }
.toast.error { background: var(--err); color: #fff; }

/* PIN */
.pin-screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px var(--pad); gap: 8px; }
.pin { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.pin-title { font-size: 22px; font-weight: 700; }
.pin-dots { display: flex; gap: 16px; min-height: 16px; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--hint); transition: background-color 120ms var(--ease-out), border-color 120ms var(--ease-out); }
.dot.on { background: var(--btn); border-color: var(--btn); }
.pin-msg { min-height: 22px; text-align: center; font-size: 15px; }
.pin-msg.error { color: var(--err); }
.pin-msg.info { color: var(--ok); }
/* «Питання не надіслано…»: не успіх і не помилка — нейтральна плашка, читається в обох темах. */
.pin-msg.warn { color: var(--text); background: var(--sec); border-radius: 10px; padding: 8px 12px; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px 20px; justify-content: center; }
.key { width: 72px; height: 56px; border: 0; border-radius: 14px; background: var(--sec); color: var(--text); font: inherit; font-size: 24px; cursor: pointer; transition: transform 120ms var(--ease-out), background-color 160ms var(--ease-out); }
.pin-submit { width: 100%; }
.pin-hint { color: var(--hint); font-size: 14px; text-align: center; min-height: 20px; }
.cancel { margin-top: 4px; }

/* відрендерений markdown */
.md { overflow-wrap: anywhere; padding-top: 12px; }
.md h1 { font-size: 24px; margin: 20px 0 8px; }
.md h2 { font-size: 20px; margin: 20px 0 8px; }
.md h3 { font-size: 17px; margin: 16px 0 6px; }
.md h4, .md h5, .md h6 { font-size: 16px; margin: 14px 0 4px; }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 0 0 12px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 2px 0; }
.md a.dead { color: inherit; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--hint); }
.md code { background: var(--sec); border-radius: 5px; padding: 1px 5px; font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.md pre { background: var(--sec); border-radius: 10px; padding: 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; overflow-wrap: normal; white-space: pre; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md img { max-width: 100%; height: auto; border-radius: 8px; }
.md img.loading-img { min-height: 80px; min-width: 80px; background: var(--sec); }
.img-ext { color: var(--hint); font-size: 14px; }
.table-wrap { overflow-x: auto; margin: 0 0 12px; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; overflow-wrap: normal; }
.md th { background: var(--sec); }
.md .align-left { text-align: left; }
.md .align-center { text-align: center; }
.md .align-right { text-align: right; }
.code { margin: 8px 0 0; background: var(--sec); border-radius: 10px; padding: 12px; overflow-x: auto; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; tab-size: 4; }
.imgbox { padding: 8px 0; text-align: center; }
.preview { max-width: 100%; height: auto; border-radius: 10px; }

@media (prefers-reduced-motion: reduce) {
  .app, .app.enter { transition: none; transform: none; }
  .toast, .toast.show { transition: opacity 120ms linear; transform: translate(-50%, 0); }
  .btn:active, .chip:active, .key:active, .ask-send:active { transform: none; }
}
