/* Цвета берутся из темы Telegram; запасные значения — для обычного браузера, светлая и тёмная схемы. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16191d);
  --muted: var(--tg-theme-hint-color, #6b7280);
  --accent: var(--tg-theme-button-color, #2f6fed);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--muted) 22%, transparent);
  --soft: color-mix(in srgb, var(--muted) 10%, transparent);
  --ok: #1f9d55;
  --bad: #d64545;
  --warn: #c98a00;
  --late: rgba(255, 207, 0, .26);
  --radius: 14px;
  --gutter: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([style*="--tg-theme-bg-color"]) {
    --bg: #0f1216; --surface: #181c22; --text: #e8eaed; --muted: #8b93a1; --accent: #5b92ff; --on-accent: #0b1220;
    --ok: #3ac77b; --bad: #ff7070; --warn: #e5b02e; --late: rgba(255, 207, 0, .2);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h2 { margin: 0 0 4px; font-size: 20px; line-height: 1.25; }
h3 { margin: 4px 0 0; font-size: 16px; line-height: 1.3; }
p { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--bad); padding: var(--gutter); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; background: var(--surface); border-radius: var(--radius); }

/* --- каркас: вкладки сверху, на широком экране консоли — боковое меню --- */
#app { max-width: 880px; margin: 0 auto; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 10px var(--gutter);
  position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 0; border-radius: 999px; padding: 8px 14px; font: inherit; font-weight: 500; color: var(--text);
  background: var(--soft); cursor: pointer; white-space: nowrap; }
.tab:hover { background: var(--line); }
.tab.active { background: var(--accent); color: var(--on-accent); }
.view { padding: var(--gutter); display: grid; gap: 12px; align-content: start; }
.view > * { min-width: 0; }

@media (min-width: 960px) {
  body.wide #app { max-width: 1280px; display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 0; padding-bottom: 40px; }
  body.wide .tabs { flex-direction: column; overflow: visible; position: sticky; top: 0; align-self: start; height: 100vh;
    padding: 24px 14px; border-bottom: 0; border-right: 1px solid var(--line); gap: 2px; }
  body.wide .tab { border-radius: 10px; text-align: left; padding: 10px 14px; background: transparent; }
  body.wide .tab:hover { background: var(--soft); }
  body.wide .tab.active { background: var(--accent); }
  body.wide .view { padding: 28px 32px; }
}
@media (min-width: 720px) { #app:not(.side) .view { padding: 20px 24px; } }

/* --- карточки и строки --- */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }
.card > h3:first-child { margin-top: 0; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 2px 0; }
.row > span { color: var(--muted); flex: none; }
.row b { font-weight: 500; text-align: right; overflow-wrap: anywhere; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
.section-title h3 { margin: 0; }

.stats { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; }
.stat b { font-size: 28px; line-height: 1.1; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.attn b { color: var(--warn); }

/* --- формы и кнопки --- */
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; resize: vertical; }
select { appearance: auto; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
.btn, .chip { border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; }
.btn { background: var(--accent); color: var(--on-accent); }
.btn:hover { filter: brightness(1.06); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn.ghost { background: var(--soft); color: var(--text); }
.btn.small { padding: 6px 12px; min-height: 32px; font-size: 14px; }
.chip { background: var(--surface); color: var(--text); border-radius: 999px; box-shadow: inset 0 0 0 1px var(--line); }
.chip.primary { background: var(--accent); color: var(--on-accent); box-shadow: none; }
button[disabled] { opacity: .5; cursor: default; filter: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
tr.muted-row td { opacity: .6; }
.review { display: grid; gap: 8px; min-width: 220px; }
.inline-form { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .inline-form.two { grid-template-columns: 1fr 1fr; } }

/* --- статусы --- */
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 500; white-space: nowrap;
  background: var(--soft); color: var(--text); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.late-tag { color: var(--warn); font-weight: 600; }
.link-box, code { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.link-box { background: var(--soft); border-radius: 10px; padding: 10px 12px; }
ol.names { margin: 0; padding-left: 22px; display: grid; gap: 2px; }
ol { margin: 0; padding-left: 20px; }
a { color: var(--accent); }
a.chip { color: var(--text); }

/* --- таблицы: на широком экране обычные, на телефоне — карточки с подписями --- */
.scroll { overflow-x: auto; background: var(--surface); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--soft); }
tr.late td { background: var(--late); }
tr.late td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
@media (max-width: 719px) {
  .scroll { background: transparent; overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr { background: var(--surface); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 14px; }
  tr.late { box-shadow: inset 4px 0 0 var(--warn); background: color-mix(in srgb, var(--late) 100%, var(--surface)); }
  tr.late td:first-child, tr.late td, tbody tr:hover td { background: transparent; box-shadow: none; }
  td { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); text-align: right; overflow-wrap: anywhere; }
  td:last-child { border-bottom: 0; }
  td[data-label]::before { content: attr(data-label); color: var(--muted); text-align: left; flex: none; max-width: 45%; }
  td:empty { display: none; }
  td > .actions, td > .review { width: 100%; }
  td > .actions .btn { flex: 1; }
}

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 5; }
.toast.bad { background: var(--bad); color: #fff; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in .18s ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
}
