/* msa-reviews Mini App (/tg/*) — W2-A tma-core. BUILD_PLAN §2.2 W2-A «CSS-компоненти»; FLOWS §6.7 «Тема».
   CSP style-src 'self': no inline styles anywhere; app.js changes only CSS custom properties (CSSOM).
   Colours come ONLY from the Telegram theme variables («Also available as the CSS variable
   var(--tg-theme-bg-color)» [TG webapps:452]) with our own fallbacks; nothing else fixes a colour here.
   Layout is mobile-first and must fit 320 px without horizontal scrolling (US-4.5; tests/test_tma_layout.py):
   no fixed widths, every replaced element is capped at 100 %, long words wrap.
   Components for every module: screen, card, list / list-row, badge, form / field, banner, btn (primary,
   secondary, danger = destructive, link), actions, tiles / tile, kv, empty, hint, muted; text of a review or a reply —
   text-block (aliases review-text, text), rating, field-check (= choice), <mark> for highlighted guard findings. */
:root {
  --c-bg: var(--tg-theme-bg-color, #ffffff);
  --c-text: var(--tg-theme-text-color, #1d2330);
  --c-hint: var(--tg-theme-hint-color, #6b7280);
  --c-link: var(--tg-theme-link-color, #2481cc);
  --c-button: var(--tg-theme-button-color, #2481cc);
  --c-button-text: var(--tg-theme-button-text-color, #ffffff);
  --c-section: var(--tg-theme-section-bg-color, #ffffff);
  --c-secondary-bg: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --c-header: var(--tg-theme-section-header-text-color, #6b7280);
  --c-separator: var(--tg-theme-section-separator-color, #e2e5ea);
  --c-accent: var(--tg-theme-accent-text-color, #2481cc);
  --c-subtitle: var(--tg-theme-subtitle-text-color, #6b7280);
  --c-destructive: var(--tg-theme-destructive-text-color, #d14343);
  --c-warn: var(--tg-theme-accent-text-color, #b7791f);
  --c-ok: var(--tg-theme-accent-text-color, #2f855a);
  --radius: 12px;
  --gap: 12px;
  --pad: 14px;
  --safe-top: var(--tg-content-safe-area-inset-top, 0px);
  --safe-bottom: var(--tg-content-safe-area-inset-bottom, 0px);
  --safe-left: var(--tg-content-safe-area-inset-left, 0px);
  --safe-right: var(--tg-content-safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  min-height: var(--tg-viewport-stable-height, 100vh);
  background: var(--c-secondary-bg);
  color: var(--c-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: normal;
}
img, video, svg, canvas, iframe, table, pre { max-width: 100%; }
img, video { height: auto; }
pre, code { white-space: pre-wrap; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
a { color: var(--c-link); }
h1, h2, h3, p { margin: 0 0 8px; }
.is-hidden, [hidden] { display: none !important; }

/* ── shell and screens ── */
.app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(12px + var(--safe-left));
}
.screen { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.screen-head { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.screen-title { font-size: 1.25rem; line-height: 1.25; font-weight: 700; }
.screen-loading { min-height: 40vh; justify-content: center; align-items: center; }

/* ── card, key-value, text ── */
.card {
  background: var(--c-section);
  border-radius: var(--radius);
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.card-title { font-size: 0.95rem; font-weight: 600; color: var(--c-header); text-transform: none; }
.text-block, .review-text, .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.rating { white-space: nowrap; font-weight: 600; }
mark { background: var(--tg-theme-secondary-bg-color, #f1f3f6); color: inherit; text-decoration: underline wavy var(--c-destructive); text-underline-offset: 3px; }
.kv { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.kv dt { color: var(--c-hint); }
.kv dd { margin: 0; min-width: 0; }
.muted { color: var(--c-hint); }
.hint { color: var(--c-hint); font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.empty { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; padding: 24px 4px; }

/* ── list ── */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--c-separator);
  min-width: 0;
}
.list-row:last-child { border-bottom: 0; }
.list-main { flex: 1 1 12rem; min-width: 0; }
a.list-row { color: inherit; text-decoration: none; }

/* ── badge ── */
.badge {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--c-secondary-bg);
  color: var(--c-text);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  white-space: nowrap;
}
.badge-ok { color: var(--c-ok); }
.badge-warn { color: var(--c-warn); }
.badge-bad { background: var(--c-destructive); color: var(--c-button-text); }

/* ── banner ── */
.banner {
  border-radius: var(--radius);
  padding: 10px var(--pad);
  background: var(--c-section);
  border-left: 4px solid var(--c-accent);
  min-width: 0;
}
.banner-info { border-left-color: var(--c-accent); }
.banner-ok { border-left-color: var(--c-ok); }
.banner-warn { border-left-color: var(--c-warn); }
.banner-error { border-left-color: var(--c-destructive); }

/* ── forms ── */
.form { display: flex; flex-direction: column; gap: 12px; min-width: 0; margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; padding: 0; margin: 0; }
.field legend, .field > label { font-weight: 600; font-size: 0.9rem; padding: 0; }
.field-row { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.field-row > .field { flex: 1 1 8rem; }
.field-error { color: var(--c-destructive); font-size: 0.875rem; }
.choice, .field-check { display: flex; flex-direction: row; gap: 8px; align-items: center; font-weight: 400; min-width: 0; }
input, select, textarea, button { font: inherit; }
input[type="text"], input[type="time"], input[type="date"], input[type="number"], input[type="tel"],
input[type="email"], input[type="url"], input[type="search"], select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--c-separator);
  border-radius: 10px;
  background: var(--c-bg);
  color: var(--c-text);
}
textarea { min-height: 7rem; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 1.15rem; height: 1.15rem; flex: none; accent-color: var(--c-button); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--c-destructive); }

/* ── buttons ── */
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  max-width: 100%;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  white-space: normal;
}
.btn-primary { background: var(--c-button); color: var(--c-button-text); }
.btn-secondary { background: var(--c-secondary-bg); color: var(--c-link); }
.btn-danger, .btn-destructive { background: var(--c-secondary-bg); color: var(--c-destructive); }
.btn-link { background: transparent; color: var(--c-link); padding-left: 4px; padding-right: 4px; }
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.6; cursor: default; }

/* ── home tiles ── */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr)); gap: 10px; }
.tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-height: 84px;
  min-width: 0;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--c-section);
  color: var(--c-text);
  text-decoration: none;
}
.tile-label { font-weight: 600; }
.tile .badge { align-self: flex-start; }

/* ── copy fallback (data-copy) ── */
.copy-fallback { width: 100%; max-width: 100%; }
.copy-hint { margin-top: 4px; }

@media (min-width: 480px) {
  .app { padding-left: calc(16px + var(--safe-left)); padding-right: calc(16px + var(--safe-right)); }
  .screen-title { font-size: 1.35rem; }
}
