/* Mention Guard admin Mini App. Colours come from the Telegram theme variables. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #111111);
  --muted: var(--tg-theme-hint-color, #6b7280);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f3f4f6);
  --header: var(--tg-theme-header-bg-color, var(--card));
  --section: var(--tg-theme-section-bg-color, var(--card));
  --line: rgba(128, 128, 128, 0.18);
  --danger: #d0342c;
  --warn: #c77700;
  --ok: #2e8b57;
  --radius: 14px;
  --nav-height: 58px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.05);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); text-decoration: none; }
button { font: inherit; }
[hidden] { display: none !important; }

#app { min-height: 100%; }
.screen {
  padding: 14px 14px calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
  animation: fade 0.18s ease-out;
}
.screen.no-nav { padding-bottom: 28px; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* --- navigation --- */
.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  gap: 2px;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--header);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.nav button {
  flex: 1;
  max-width: 120px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background 0.15s, color 0.15s;
}
.nav button .icon { font-size: 20px; line-height: 1.1; }
.nav button.active { color: var(--accent); background: rgba(36, 129, 204, 0.12); }

/* --- typography & layout --- */
h1 { font-size: 22px; font-weight: 700; margin: 4px 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 20px 0 8px; }
h3 { font-size: 14px; margin: 12px 0 6px; color: var(--muted); font-weight: 600; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.danger { color: var(--danger); }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(128, 128, 128, 0.16);
}
.pill.ok { background: rgba(46, 139, 87, 0.15); color: var(--ok); }
.pill.warn { background: rgba(199, 119, 0, 0.16); color: var(--warn); }

/* --- tiles --- */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.tile {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 8px 10px;
  text-align: center;
  border: 0;
  color: var(--fg);
  box-shadow: var(--shadow);
}
.tile.clickable { cursor: pointer; }
.tile.clickable:active { transform: scale(0.97); }
.tile .value { font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.tile .label { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.2; }
.tile.alert .value { color: var(--danger); }
.tile.good .value { color: var(--ok); }
.tile.warn .value { color: var(--warn); }

/* --- cards and lists --- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card.clickable { cursor: pointer; transition: transform 0.1s; }
.card.clickable:active { transform: scale(0.99); }
.card .title { font-weight: 600; }
details.card > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "›"; color: var(--muted); font-size: 20px; transform: rotate(90deg); transition: transform 0.15s; }
details.card[open] > summary::after { transform: rotate(-90deg); }
details.card[open] > summary { margin-bottom: 8px; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(128, 128, 128, 0.16);
  color: var(--fg);
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}
.badge.danger { background: rgba(208, 52, 44, 0.14); color: var(--danger); }
.badge.ok { background: rgba(46, 139, 87, 0.14); color: var(--ok); }
.badge.warn { background: rgba(199, 119, 0, 0.16); color: var(--warn); }
.badge.accent { background: rgba(36, 129, 204, 0.14); color: var(--link); }
.countdown { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; }
.countdown.overdue { color: var(--danger); }
.countdown.soon { color: var(--warn); }
.empty { color: var(--muted); text-align: center; padding: 26px 8px; }

/* --- statistics table --- */
table.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
table.stats th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12px; padding: 2px 4px 8px; }
table.stats th:first-child { text-align: left; }
table.stats td { padding: 7px 4px; border-top: 1px solid var(--line); }
table.stats td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
table.stats td:first-child { color: var(--muted); }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; margin-top: 12px; }
.progress { height: 8px; border-radius: 999px; background: rgba(128, 128, 128, 0.2); overflow: hidden; margin-top: 4px; }
.progress-bar { height: 100%; border-radius: 999px; background: var(--ok); transition: width 0.4s; }
.w0 { width: 0; } .w5 { width: 5%; } .w10 { width: 10%; } .w15 { width: 15%; } .w20 { width: 20%; }
.w25 { width: 25%; } .w30 { width: 30%; } .w35 { width: 35%; } .w40 { width: 40%; } .w45 { width: 45%; }
.w50 { width: 50%; } .w55 { width: 55%; } .w60 { width: 60%; } .w65 { width: 65%; } .w70 { width: 70%; }
.w75 { width: 75%; } .w80 { width: 80%; } .w85 { width: 85%; } .w90 { width: 90%; } .w95 { width: 95%; }
.w100 { width: 100%; }

/* --- review card pages (Telegram HTML subset) --- */
.pages { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.5; }
.pages code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: rgba(128, 128, 128, 0.14); padding: 0 4px; border-radius: 4px; }
.pages + .pages { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }

/* --- buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  transition: transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.secondary { background: rgba(128, 128, 128, 0.16); color: var(--fg); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 12px; min-height: 32px; font-size: 13px; font-weight: 500; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.actions { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.actions.inline { flex-direction: row; flex-wrap: wrap; }

/* --- forms --- */
.field { margin: 10px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(36, 129, 204, 0.15); }
.input.invalid { border-color: var(--danger); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.field .error { font-size: 12px; margin-top: 4px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.setting-row { padding: 11px 0; border-top: 1px solid var(--line); }
.setting-row:first-of-type { border-top: 0; padding-top: 2px; }
.setting-row .key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; color: var(--muted); }
.setting-row .value-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.setting-row .value-row .input { flex: 1; }
.setting-row .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

/* --- incident cards on the overview --- */
.card.pending { border-left: 4px solid var(--danger); }
.facts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0; font-size: 14px; }
.fact-label { color: var(--muted); margin-right: 5px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.quote {
  margin: 6px 0;
  padding: 8px 10px;
  border-left: 3px solid rgba(128, 128, 128, 0.4);
  background: rgba(128, 128, 128, 0.08);
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 7.5em;
  overflow: hidden;
}
.picker-box { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.card .link { display: inline-block; margin-top: 6px; }
.card.pending .actions-grid { margin-top: 8px; }

/* --- review screen --- */
.question { font-size: 16px; font-weight: 600; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.ai-summary { margin-top: 6px; }
.meta { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 6px; }
.meta-row { display: flex; gap: 10px; padding: 5px 0; font-size: 14px; }
.meta-label { flex: 0 0 110px; color: var(--muted); }
.meta-value { flex: 1; min-width: 0; word-break: break-word; }
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.msg-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.msg { padding: 8px 10px; border-radius: 10px; background: rgba(128, 128, 128, 0.1); }
.msg-text { white-space: pre-wrap; word-break: break-word; margin: 4px 0; font-size: 14px; }
.timeline { margin-top: 4px; }
.tl-row { display: flex; gap: 10px; padding: 5px 0; font-size: 13px; border-top: 1px solid var(--line); }
.tl-row:first-child { border-top: 0; }
.tl-time { flex: 0 0 82px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-label { flex: 1; min-width: 0; }
.tl-bad .tl-label { color: var(--danger); }

/* --- foldable list sections --- */
details.section { margin: 18px 0 10px; }
details.section > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::after { content: "›"; color: var(--muted); font-size: 20px; transform: rotate(90deg); transition: transform 0.15s; }
details.section[open] > summary::after { transform: rotate(-90deg); }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

/* --- user picker --- */
.picker-list { max-height: 360px; overflow-y: auto; margin-top: 4px; }
.picker-row { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.picker-row.off { opacity: 0.55; }

/* --- toast --- */
.toast {
  position: fixed;
  left: 14px; right: 14px;
  bottom: calc(var(--nav-height) + 14px + env(safe-area-inset-bottom));
  background: rgba(24, 24, 28, 0.94);
  color: #fff;
  padding: 11px 14px;
  border-radius: 12px;
  z-index: 20;
  font-size: 14px;
  white-space: pre-line;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.section-head .link { font-size: 13px; }
.spinner { text-align: center; color: var(--muted); padding: 24px; }
