/* Оперативные задачи. Один экран: таблица, фильтры, карточка задачи. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e2e5ea;
  --text: #1c2024;
  --muted: #6b7480;
  --accent: #1f6feb;
  --red: #c8372d;
  --red-bg: #fdecea;
  --orange: #a85a00;
  --orange-bg: #fdf3e3;
  --green: #1a7f45;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* --- заглушки: вход, ошибка ссылки ------------------------------------- */

body.plain {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
body.plain .card { max-width: 460px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 24px;
}
.card h1 { margin: 0 0 12px; font-size: 20px; }
.card ol { margin: 12px 0; padding-left: 22px; }
.card li { margin: 6px 0; }
.muted { color: var(--muted); font-size: 14px; }

/* --- шапка ------------------------------------------------------------- */

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
}
.top h1 { margin: 0; font-size: 19px; font-weight: 650; }
.who { color: var(--muted); font-size: 14px; display: flex; gap: 10px; align-items: baseline; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.link:hover { text-decoration: underline; }

/* --- фильтры ----------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px;
}
.filters button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 13px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.filters button:hover { border-color: #c9ced6; }
.filters button[aria-current="true"] {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}
.filters .count { opacity: .6; margin-left: 5px; font-variant-numeric: tabular-nums; }
.filters button.warn[aria-current="false"] { color: var(--red); }

.extra {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--muted);
  font-size: 14px;
}
.extra label { display: flex; align-items: center; gap: 6px; }
.extra input, .extra select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}
.updated { margin-left: auto; font-variant-numeric: tabular-nums; }

/* --- таблица ----------------------------------------------------------- */

main { padding: 0 16px 40px; }

.tasks {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.tasks th, .tasks td {
  padding: 9px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
.tasks thead th {
  background: #fafbfc;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.tasks tbody tr:last-child td { border-bottom: 0; }
.tasks tbody tr { cursor: pointer; }
.tasks tbody tr:hover { background: #f8f9fb; }

.num { width: 1%; color: var(--muted); font-variant-numeric: tabular-nums; }
.text { max-width: 420px; }
.nowrap { white-space: nowrap; font-variant-numeric: tabular-nums; }
.comment { max-width: 260px; color: var(--muted); font-size: 14px; }

/* Срок: оранжевый — меньше 30 минут, красный — просрочен. */
.due-soon { color: var(--orange); font-weight: 600; }
.due-over { color: var(--red); font-weight: 600; }
tr.over td { background: var(--red-bg); }
tr.over:hover td { background: #fbe3e0; }
tr.soon td { background: var(--orange-bg); }
tr.soon:hover td { background: #fbecd6; }
tr.closed .text { color: var(--muted); }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12.5px;
  white-space: nowrap;
  background: #eef0f3;
  color: var(--muted);
}
.badge.done { background: #e7f6ec; color: var(--green); }
.badge.rejected { background: var(--red-bg); color: var(--red); }
.badge.not_actual { background: #eef0f3; }

.pin { color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* --- карточка задачи --------------------------------------------------- */

/* display: flex сильнее атрибута hidden, поэтому прячем явно. */
.overlay[hidden] { display: none; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 26, 30, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow: auto;
  z-index: 10;
}
.task-card {
  position: relative;
  width: 100%;
  max-width: 620px;
}
.close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: 0;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.task-card h2 { margin: 0 0 4px; font-size: 17px; }
.task-card .meta { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.task-card .body { font-size: 16px; margin: 0 0 16px; white-space: pre-wrap; }

.field { margin: 14px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field textarea {
  width: 100%;
  min-height: 70px;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions button {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}
.actions button.primary { background: var(--green); border-color: var(--green); color: #fff; }
.actions button.danger { color: var(--red); }
/* Удаление необратимо — кнопка не должна соседствовать со статусами на равных. */
.actions button.ghost { margin-left: auto; border-color: transparent; }
.actions button.ghost:hover { border-color: var(--line); }
.actions button:disabled { opacity: .5; cursor: default; }

.photos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.photos a { display: block; }
.photos img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.log { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.log h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.log ul { list-style: none; margin: 0; padding: 0; font-size: 13.5px; color: var(--muted); }
.log li { padding: 3px 0; }
.log b { color: var(--text); font-weight: 600; }

/* Telegram ID — служебная подробность: нужна в разборе, но не должна
   перебивать имя, рядом с которым стоит. */
.tg {
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 4px;
  background: #eef0f3;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.error { color: var(--red); font-size: 14px; margin-top: 10px; }

/* --- телефон ----------------------------------------------------------- */

@media (max-width: 760px) {
  .tasks thead { display: none; }
  .tasks, .tasks tbody, .tasks tr, .tasks td { display: block; width: 100%; }
  .tasks {
    background: none;
    border: 0;
    border-radius: 0;
  }
  .tasks tbody tr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 10px 12px;
    overflow: hidden;
  }
  .tasks td {
    border: 0;
    padding: 2px 0;
    max-width: none;
  }
  /* Подписи вместо заголовков таблицы. */
  .tasks td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-size: 13px;
  }
  .tasks td.text {
    font-size: 16px;
    padding-bottom: 6px;
  }
  .tasks td.text::before { content: none; }
  /* Номер и так понятен по решётке — подпись «№:» только мешает. */
  .tasks td.num::before { content: "№"; margin-right: 1px; }

  .tasks tbody tr.over td, .tasks tbody tr.soon td { background: none; }
  .tasks tbody tr.over { border-color: #e9a9a2; background: var(--red-bg); }
  .tasks tbody tr.soon { border-color: #e6c48a; background: var(--orange-bg); }
  .extra { gap: 8px; }
  .updated { width: 100%; margin: 0; }
}
