/* Telegram injects --tg-theme-* variables for the user's theme. Layout follows
   Telegram's own settings screens: grey page, rounded section cards, small
   uppercase group titles. Fallbacks apply when opened in a normal browser. */
:root {
  --page: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --field: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
  --group-title: var(--tg-theme-section-header-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --good: #30a46c;
  --warn: #d4870b;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --page: #101418; --card: #1b2026; --field: #252b33; --text: #eceef1; --hint: #8b939e; --link: #6ab3f3; --accent: #3e8ed0;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--page); color: var(--text); }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
main { max-width: 600px; margin: 0 auto; padding: 16px 16px calc(28px + env(safe-area-inset-bottom)); }
h1 { font-size: 22px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 16px 0 6px; }
p { margin: 0 0 8px; }
a { color: var(--link); }
em { font-style: normal; font-weight: 400; color: var(--hint); }
.muted { color: var(--hint); }
.hint { color: var(--hint); font-size: 13px; }

/* ---------- hero ---------- */
.hero { display: flex; gap: 14px; align-items: center; padding: 6px 2px 12px; }
.hero p { color: var(--subtitle); font-size: 14px; margin: 0; }
.logo {
  flex: 0 0 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 30px;
  background: linear-gradient(140deg, color-mix(in srgb, var(--accent) 85%, #fff), var(--accent));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
.covers { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; padding: 0; }
.covers li { font-size: 12.5px; padding: 5px 10px; border-radius: 999px; background: var(--card); color: var(--subtitle); }

/* ---------- grouped form ---------- */
.group-title {
  font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--group-title); margin: 22px 14px 7px;
}
.group { background: var(--card); border-radius: var(--radius); padding: 4px 14px; }
.group-foot { font-size: 13px; color: var(--hint); margin: 7px 14px 0; }
.field { display: block; padding: 11px 0; }
.group > .field + .field, .group > .field-row + .field, .group > .field + .field-row { border-top: 1px solid var(--line); }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; min-width: 0; }
.label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 7px; }
.label em { font-size: 12.5px; margin-left: 4px; }

input, select, textarea {
  display: block; width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: var(--field); border: 1.5px solid transparent; border-radius: 12px; outline: none;
  transition: border-color 0.15s, background-color 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--hint); opacity: 0.55; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[aria-invalid="true"] { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--field)); }
textarea { resize: vertical; min-height: 84px; }
/* No spinner arrows on number fields. */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
select {
  -webkit-appearance: none; appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238a8f98' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}

.affix { position: relative; display: block; }
.affix input { padding-right: 44px; }
.affix > span { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--hint); pointer-events: none; }
.price { display: flex; gap: 8px; }
.price input { flex: 1; min-width: 0; }
.price select { flex: 0 0 96px; }

/* Chips = radio buttons styled as pills. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.stacked { flex-direction: column; padding: 10px 0; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.chip span {
  display: block; padding: 8px 14px; border-radius: 999px; font-size: 14.5px; font-weight: 500;
  background: var(--field); border: 1.5px solid transparent; transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.chips.stacked .chip span { border-radius: 12px; padding: 12px 14px; }
.chip input:checked + span {
  background: color-mix(in srgb, var(--accent) 16%, var(--field)); border-color: var(--accent); color: var(--text);
}
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.error {
  margin: 16px 0 0; padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 500;
  color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--card));
}
.submit-bar {
  position: sticky; bottom: 0; margin: 18px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--page) 70%, transparent);
}
button {
  width: 100%; padding: 15px; font: inherit; font-weight: 600; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-text); cursor: pointer;
}
button:active { filter: brightness(0.92); }
button.secondary { background: var(--card); color: var(--link); }

/* ---------- loading ---------- */
#view-loading { text-align: center; padding-top: 14vh; }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 20px; border-radius: 50%;
  border: 4px solid var(--card); border-top-color: var(--accent); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.checklist {
  list-style: none; text-align: left; max-width: 340px; margin: 18px auto; padding: 6px 16px;
  background: var(--card); border-radius: var(--radius);
}
.checklist li { padding: 10px 0 10px 26px; position: relative; font-size: 14.5px; }
.checklist li + li { border-top: 1px solid var(--line); }
.checklist li::before { content: "🔍"; position: absolute; left: 0; font-size: 14px; }

/* ---------- report ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; overflow-wrap: anywhere; }
.verdict { border-left: 5px solid var(--hint); }
.verdict.good_buy, .verdict.fair_deal { border-left-color: var(--good); }
.verdict.overpriced { border-left-color: var(--warn); }
.verdict.high_risk { border-left-color: var(--danger); }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--hint) 20%, transparent); color: var(--text); vertical-align: middle;
}
.badge.good, .badge.low { background: color-mix(in srgb, var(--good) 22%, transparent); }
.badge.medium, .badge.warn { background: color-mix(in srgb, var(--warn) 26%, transparent); }
.badge.high, .badge.bad { background: color-mix(in srgb, var(--danger) 24%, transparent); }
.place { color: var(--hint); font-size: 13px; margin-bottom: 8px; }
ul { margin: 4px 0 8px; padding-left: 20px; }
li { margin-bottom: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 8px 0; }
.stat { background: var(--field); border-radius: 12px; padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--hint); }
.stat .v { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }

dl.kv { margin: 0; }
dl.kv dt { font-size: 12px; color: var(--hint); margin-top: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
dl.kv dd { margin: 2px 0 0; }

.score { display: grid; grid-template-columns: 118px 1fr 36px; gap: 10px; align-items: center; margin: 7px 0; font-size: 14px; }
.bar { height: 8px; border-radius: 4px; background: var(--field); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.score .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--hint); }

.risk { padding: 10px 0; border-top: 1px solid var(--line); }
.risk:first-of-type { border-top: 0; }
.risk .head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-weight: 600; margin-bottom: 3px; }
.risk .cat { font-size: 12px; color: var(--hint); font-weight: 400; }

.sources li { font-size: 13.5px; }
.disclaimer { font-size: 12px; color: var(--hint); }
.actions { display: flex; gap: 10px; margin-top: 4px; }

/* Collapsible rows in the report. */
.fold { border-top: 1px solid var(--line); }
.card > h2 + .fold, .card > .fold:first-child { border-top: 0; }
.fold > summary {
  list-style: none; cursor: pointer; padding: 12px 26px 12px 0; position: relative; font-weight: 600; font-size: 15px;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after {
  content: ""; position: absolute; right: 4px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--hint); border-bottom: 2px solid var(--hint); transform: rotate(45deg); transition: transform 0.15s;
}
.fold[open] > summary::after { transform: rotate(-135deg); margin-top: -2px; }
.fold-body { padding: 0 0 12px; }
.fold-body .cat { font-size: 12px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 4px; }

.close-note { max-width: 340px; margin: 14px auto 0; padding: 12px 14px; border-radius: 12px; background: var(--card); font-size: 14px; }
.pdf-bar { margin-bottom: 12px; }
.pdf-bar .hint { text-align: center; margin: 8px 0 0; }

/* "Your reports" list on the form page. */
.history-list { padding: 2px 14px; }
.history-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; text-align: left;
  padding: 12px 22px 12px 0; background: none; color: var(--text); border-radius: 0; font-weight: 500; position: relative;
}
.history-item + .history-item { border-top: 1px solid var(--line); }
.history-item::after {
  content: ""; position: absolute; right: 4px; top: 50%; width: 7px; height: 7px; margin-top: -4px;
  border-right: 2px solid var(--hint); border-top: 2px solid var(--hint); transform: rotate(45deg);
}
.history-item .h-place { font-size: 15px; }
.history-item .h-meta { font-size: 12.5px; color: var(--hint); font-weight: 400; }
