/* Табло конвейера. В Telegram берём цвета темы Telegram, в браузере — светлую или тёмную тему системы. */
:root {
  --bg: var(--tg-theme-bg-color, #f5f6f8);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16181d);
  --muted: var(--tg-theme-hint-color, #6b7280);
  --link: var(--tg-theme-link-color, #2563eb);
  --accent: var(--tg-theme-button-color, #2563eb);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(127, 127, 127, 0.18);

  --red: #dc2626;
  --red-bg: rgba(220, 38, 38, 0.12);
  --orange: #c2410c;
  --orange-bg: rgba(234, 88, 12, 0.13);
  --blue: #1d4ed8;
  --blue-bg: rgba(37, 99, 235, 0.12);
  --green: #15803d;
  --green-bg: rgba(22, 163, 74, 0.13);
  --amber: #a16207;
  --amber-bg: rgba(202, 138, 4, 0.15);
  --gray: #6b7280;
  --gray-bg: rgba(107, 114, 128, 0.12);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #111318);
    --card: var(--tg-theme-secondary-bg-color, #1b1e25);
    --text: var(--tg-theme-text-color, #e8eaed);
    --muted: var(--tg-theme-hint-color, #9aa0aa);
    --link: var(--tg-theme-link-color, #6ea8fe);
    --red: #f87171;
    --orange: #fb923c;
    --blue: #93b4fd;
    --green: #4ade80;
    --amber: #facc15;
    --gray: #9ca3af;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.error { color: var(--red); }
.splash { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty { padding: 24px 0; text-align: center; }
.footer { text-align: center; margin: 24px 0 8px; }

button.link {
  background: none; border: 0; padding: 4px 6px; cursor: pointer; color: var(--link);
}

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--card); border-radius: 16px; padding: 32px 24px; max-width: 400px; width: 100%;
  text-align: center; box-shadow: 0 6px 30px rgba(0, 0, 0, 0.08);
}
.logo {
  width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 14px; background: var(--accent);
  color: var(--accent-text); font-size: 30px; line-height: 56px; font-weight: 700;
}
.tg-login { min-height: 48px; margin: 20px 0 8px; display: flex; justify-content: center; }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.tabs { display: flex; gap: 4px; }
.tabs button, .filters button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 12px; cursor: pointer;
}
.tabs button.on, .filters button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.user { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.content { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- неделя ---------- */
.weeknav { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 12px; }
.weektitle { text-align: center; min-width: 200px; }
.range { font-size: 20px; font-weight: 700; }
.arrow {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  font-size: 22px; cursor: pointer;
}
.arrow:disabled { opacity: 0.35; cursor: default; }

.summary { background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.progress { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.bar { flex: 1; height: 8px; border-radius: 4px; background: var(--gray-bg); overflow: hidden; }
.fill { height: 100%; background: var(--green); border-radius: 4px; transition: width 0.3s; }
.counters { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.st-overdue { background: var(--red-bg); color: var(--red); }
.st-soon { background: var(--orange-bg); color: var(--orange); }
.st-active { background: var(--blue-bg); color: var(--blue); }
.st-waiting { background: var(--gray-bg); color: var(--gray); }
.st-done { background: var(--green-bg); color: var(--green); }
.st-late { background: var(--amber-bg); color: var(--amber); }
.st-skipped { background: var(--gray-bg); color: var(--gray); }

.hot { margin-bottom: 16px; }
.hot h2 { font-size: 16px; }
.hot-card {
  display: block; width: 100%; text-align: left; cursor: pointer; margin-bottom: 8px;
  background: var(--card); border: 0; border-left: 4px solid currentColor; border-radius: 10px; padding: 10px 12px;
}
.hot-card > * { color: var(--text); }
.hot-card.st-overdue { color: var(--red); }
.hot-card.st-soon { color: var(--orange); }
.hot-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.hot-head .title { font-weight: 600; flex: 1; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 12px; }

.day { margin-bottom: 14px; }
.day h3 { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; }
.day.today h3 { color: var(--accent); }
.tag {
  font-size: 11px; text-transform: none; letter-spacing: 0; padding: 1px 7px; border-radius: 6px;
  background: var(--blue-bg); color: var(--blue); font-weight: 600;
}
.tag.off { background: var(--gray-bg); color: var(--gray); }

.row {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) 110px 210px 70px; gap: 12px; align-items: center;
  width: 100%; text-align: left; cursor: pointer; background: var(--card); border: 0; border-radius: 10px;
  padding: 10px 12px; margin-bottom: 6px; border-left: 4px solid transparent;
}
.row:hover { outline: 1px solid var(--line); }
.row-overdue { border-left-color: var(--red); }
.row-soon { border-left-color: var(--orange); }
.row-active { border-left-color: var(--blue); }
.row-late { border-left-color: var(--amber); }
.row-done { border-left-color: var(--green); }
.row-skipped { opacity: 0.6; }
.row-skipped .title { text-decoration: line-through; }
.num {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--gray-bg); font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.num.big { width: 44px; height: 44px; font-size: 18px; border-radius: 10px; }
.main { display: flex; flex-direction: column; min-width: 0; }
.main .title { font-weight: 600; }
.main .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.icons { display: flex; gap: 6px; justify-content: flex-end; font-size: 13px; }

/* ---------- история недель ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: 12px; margin-bottom: 8px; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history-table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.history-table tbody tr { cursor: pointer; }
.history-table tbody tr:hover { background: var(--gray-bg); }
.history-table tr.current td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.c-done { color: var(--green); font-weight: 600; }
.c-late { color: var(--amber); font-weight: 600; }
.c-overdue { color: var(--red); font-weight: 600; }

/* ---------- карточка этапа ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.35); display: flex; justify-content: flex-end;
}
.panel {
  position: relative; width: min(560px, 100%); height: 100%; overflow-y: auto; background: var(--bg);
  padding: 20px 18px 32px; box-shadow: -8px 0 30px rgba(0, 0, 0, 0.15);
}
.close {
  position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--gray-bg); font-size: 22px; cursor: pointer;
}
.panel-head { display: flex; gap: 12px; align-items: flex-start; margin: 0 40px 16px 0; }
.panel-head h2 { margin-bottom: 6px; }
.facts {
  display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0 0 16px;
  background: var(--card); border-radius: 12px; padding: 12px 14px;
}
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; }
.block { background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.comment { white-space: pre-wrap; margin: 0; }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.file {
  display: flex; flex-direction: column; gap: 4px; text-align: left; cursor: pointer;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px;
}
.file img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--gray-bg); }
.file .doc { padding: 18px 6px; word-break: break-word; font-weight: 600; }
.file.cancelled { opacity: 0.6; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 12px 18px; border-left: 2px solid var(--line); margin-left: 5px; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--gray);
}
.timeline li.h-done::before { background: var(--green); }
.timeline li.h-undone::before { background: var(--red); }
.timeline li.h-note::before { background: var(--blue); }
.timeline li.h-moved::before, .timeline li.h-reset::before { background: var(--orange); }
.timeline li:last-child { border-left-color: transparent; }
.timeline .comment { margin-top: 2px; }

.lightbox {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: calc(100vh - 80px); border-radius: 8px; }
.open-full { color: #fff; }

/* ---------- телефон ---------- */
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand { display: none; }
  .content { padding: 12px; }
  .row {
    grid-template-columns: 30px minmax(0, 1fr) auto;
    grid-template-areas: "num main icons" "num status status" "num due due";
    gap: 4px 10px;
  }
  .row .num { grid-area: num; align-self: start; }
  .row .main { grid-area: main; }
  .row .icons { grid-area: icons; align-self: start; }
  .row .status { grid-area: status; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
  .row .due { grid-area: due; color: var(--muted); }
  .row .due br { display: none; }
  .range { font-size: 18px; }
  .weektitle { min-width: 0; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
  .panel { padding-top: 16px; }
}
