:root {
  --bg: #f4f5f7;
  --power-lines: #d0d8e2;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --border: #e0e3ea;
  --accent: #2456c7;
  --accent-text: #ffffff;
  --danger: #c23b32;

  --st-new-bg: #e6eefc;      --st-new: #2456c7;
  --st-progress-bg: #fdf1dc; --st-progress: #a15c00;
  --st-paused-bg: #eceef2;   --st-paused: #5a6273;
  --st-done-bg: #e2f4e8;     --st-done: #1f7a42;

  --urg-1: #9aa3b5; --urg-2: #3a7be0; --urg-3: #e08a1e; --urg-4: #d63a2f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --power-lines: #303945;
    --card: #1d2129;
    --text: #e6e9ef;
    --muted: #8e96a8;
    --border: #2f3541;
    --accent: #5b8cf0;
    --accent-text: #0e1320;
    --danger: #ef6b62;

    --st-new-bg: #1f2c47;      --st-new: #8fb1f5;
    --st-progress-bg: #3a2c14; --st-progress: #f2b35c;
    --st-paused-bg: #2a2e37;   --st-paused: #aab1c0;
    --st-done-bg: #173323;     --st-done: #6fd196;
  }
}

* { box-sizing: border-box; }
body {
  --pylon-height: min(62vh, 67vw);
  margin: 0;
  isolation: isolate;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-color: var(--power-lines);
}
body::before {
  -webkit-mask: url("power-lines.png") left bottom / auto var(--pylon-height) no-repeat;
  mask: url("power-lines.png") left bottom / auto var(--pylon-height) no-repeat;
}
body::after {
  /* Продолжаем край рисунка с пропорциями 1536 × 1024. */
  top: auto;
  left: calc(var(--pylon-height) * 1.5);
  height: var(--pylon-height);
  -webkit-mask: url("power-lines-extension.png") left bottom / 100% 100% no-repeat;
  mask: url("power-lines-extension.png") left bottom / 100% 100% no-repeat;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 16px; margin: 24px 0 10px; }
code { font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Шапка */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.me { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.me form { margin: 0; }

/* Раскладка */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
.page.narrow { max-width: 620px; }
.page.center { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.card.flush { padding: 0; overflow-x: auto; }
.card h2:first-child { margin-top: 0; }

/* Кнопки и формы */
.btn {
  display: inline-block; font: inherit; cursor: pointer;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn:disabled { cursor: default; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
button.link:hover { color: var(--text); }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input[type="checkbox"] { width: auto; }
input[type="file"] {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
  text-overflow: ellipsis;
}
input[type="file"]::file-selector-button {
  margin-inline-end: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--accent); }
input[type="file"]:focus-visible { outline-offset: 2px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 600; padding: 0 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inline { margin: 0; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash-ok { background: var(--st-done-bg); color: var(--st-done); }
.flash-error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.notice { background: var(--st-progress-bg); color: var(--st-progress); padding: 10px 14px; border-radius: 8px; }

/* Сводка и фильтры */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.summary-item { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; color: var(--text); }
.summary-item:hover { text-decoration: none; border-color: var(--accent); }
.summary-num { display: block; font-size: 24px; font-weight: 700; }
.summary-label { color: var(--muted); font-size: 13px; }

.filters { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 20px 0 12px; }
.filters select { width: auto; }
.tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 4px; flex-wrap: wrap; }
.tabs a { color: var(--muted); padding: 6px 12px; border-radius: 7px; font-size: 14px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--accent); color: var(--accent-text); }

/* Список задач */
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-row {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; color: var(--text);
}
.task-row:hover { text-decoration: none; border-color: var(--accent); }
.task-row.status-done .task-title { color: var(--muted); }
.task-main { min-width: 0; }
.task-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.task-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.task-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.due { font-size: 13px; color: var(--muted); }
.overdue { color: var(--danger); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px; background: var(--card); border: 1px dashed var(--border); border-radius: 10px; }

.urg { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.urg-1 { background: var(--urg-1); }
.urg-2 { background: var(--urg-2); }
.urg-3 { background: var(--urg-3); }
.urg-4 { background: var(--urg-4); box-shadow: 0 0 0 3px color-mix(in srgb, var(--urg-4) 25%, transparent); }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge.big { font-size: 14px; padding: 5px 12px; }
.badge-new { background: var(--st-new-bg); color: var(--st-new); }
.badge-in_progress { background: var(--st-progress-bg); color: var(--st-progress); }
.badge-paused { background: var(--st-paused-bg); color: var(--st-paused); }
.badge-done { background: var(--st-done-bg); color: var(--st-done); }
.badge-admin { background: var(--st-new-bg); color: var(--st-new); }

/* Карточка задачи */
.task-layout { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; align-items: start; }
.task-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 16px 0 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.status-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.status-buttons form { margin: 0; }
.status-btn { border-color: transparent; font-weight: 600; }
.status-btn.current { outline: 2px solid currentColor; outline-offset: 1px; }

.timeline { list-style: none; margin: 0 0 16px; padding: 0; }
.ev { padding: 10px 0 10px 14px; border-left: 2px solid var(--border); position: relative; }
.ev::before { content: ""; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.ev-status::before { background: var(--accent); }
.ev-comment::before { background: var(--muted); }
.ev-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.ev-text { margin-top: 4px; background: var(--bg); padding: 8px 10px; border-radius: 8px; font-size: 14px; }

/* Таблицы */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; }
tr.inactive td { color: var(--muted); }
tr.me-row td { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.bar-cell { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.bar { width: 160px; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar-cell strong { min-width: 2ch; }

@media (max-width: 760px) {
  .task-layout { grid-template-columns: 1fr; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .row { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .bar { width: 80px; }
  .task-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .task-side { flex-direction: row; align-items: center; justify-content: space-between; }
}

.urgency-chart { margin-bottom: 16px; }
.urgency-breakdown { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.urgency-ring {
  width: 140px; height: 140px; border-radius: 50%; background: var(--border);
  display: grid; place-items: center;
}
.urgency-ring div {
  width: 70%; height: 70%; border-radius: 50%; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.urgency-ring b { font-size: 26px; line-height: 1.1; }
.urgency-ring span { color: var(--muted); font-size: 14px; }
.urgency-breakdown ul { padding: 0; margin: 0; width: min(100%, 280px); }
.urgency-breakdown li {
  display: grid; grid-template-columns: 10px 1fr auto 6ch; gap: 10px;
  align-items: center; padding: 4px 0; font-variant-numeric: tabular-nums;
}
.urgency-breakdown li .muted { text-align: right; }

.task-delete { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 12px; }
.task-delete summary { cursor: pointer; width: fit-content; color: var(--danger); }
.task-delete button { color: var(--danger); border-color: currentColor; }
