:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1d1d1b;
  --muted: #76746f;
  --line: #e4e2dc;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e3ece8;
  --over: #b3261e;
  --over-soft: #fbe9e7;
  --today: #9a5b00;
  --today-soft: #fdf0dc;
  --claim: #2f6f3e;
  --claim-soft: #e5f2e7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --surface: #1f1f1e;
    --ink: #ecebe7;
    --muted: #9b9993;
    --line: #2f2f2d;
    --accent: #7fb8a4;
    --accent-ink: #0f1f1a;
    --accent-soft: #233630;
    --over: #ff8a80;
    --over-soft: #3a1f1d;
    --today: #f0b45a;
    --today-soft: #3a2c16;
    --claim: #8fd19e;
    --claim-soft: #1e3324;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* Атрибут hidden должен побеждать display:flex у всплывашки и строк списка. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* --- шапка --- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; text-decoration: none; }
.brand-lg { font-size: 26px; gap: 10px; }
.back { text-decoration: none; color: var(--accent); font-weight: 600; }

.wrap { max-width: 760px; margin: 0 auto; padding: 14px 16px 80px; }
.narrow { max-width: 640px; }

/* --- кнопки и поля --- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn-done { background: var(--claim); border-color: var(--claim); color: var(--surface); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 14px; }
.btn-block { width: 100%; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
label { display: grid; gap: 5px; font-size: 14px; color: var(--muted); font-weight: 600; }
label > * { font-weight: 400; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- вход --- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; display: grid; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 22px; box-shadow: var(--shadow);
}
.login-card .muted { margin: -8px 0 6px; }
.error { color: var(--over); margin: 0; font-weight: 600; }

/* --- сообщения --- */
.flash { background: var(--accent-soft); border-radius: var(--radius); padding: 8px 14px; margin-bottom: 12px; }
.flash p { margin: 4px 0; }

/* --- фильтры --- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 10px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; text-decoration: none; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 15px; white-space: nowrap;
}
.chip b { color: var(--muted); font-weight: 600; margin-left: 2px; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.on b { color: inherit; opacity: .7; }

.seg { display: flex; background: var(--line); border-radius: 10px; padding: 3px; gap: 2px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.seg a { flex: 1 0 auto; text-align: center; text-decoration: none; padding: 7px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.tools { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; flex-wrap: wrap; }
.search { flex: 1 1 200px; }
.new { flex: none; }
.new summary { list-style: none; }
.new summary::-webkit-details-marker { display: none; }
.new[open] { flex: 1 1 100%; order: 3; }
.new-form { display: grid; gap: 10px; margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--claim-soft); color: var(--ink); border-radius: var(--radius); padding: 10px 12px 10px 14px; margin-bottom: 12px;
}

/* --- список --- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.task { display: flex; align-items: flex-start; gap: 4px; border-top: 1px solid var(--line); transition: opacity .25s, transform .25s; }
.task:first-child { border-top: 0; }
.task.leaving { opacity: 0; transform: translateX(24px); }
.task form { flex: none; }
.check {
  appearance: none; width: 48px; height: 48px; border: 0; background: transparent; cursor: pointer; position: relative; padding: 0;
}
.check::before {
  content: ""; position: absolute; left: 14px; top: 13px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--muted); transition: background .15s, border-color .15s;
}
.check:hover::before { border-color: var(--claim); background: var(--claim-soft); }
.check.is-done::before { background: var(--claim); border-color: var(--claim); }
.check.is-dropped::before { background: var(--line); border-color: var(--muted); }
.check.is-done::after, .check:hover:not(.is-dropped)::after {
  content: ""; position: absolute; left: 22px; top: 18px; width: 6px; height: 11px;
  border: solid var(--claim); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.check.is-done::after { border-color: var(--surface); }
.task-body { flex: 1; min-width: 0; text-decoration: none; padding: 12px 14px 12px 0; display: grid; gap: 4px; }
.task-title { overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.who { font-weight: 600; color: var(--ink); }
.due.over { color: var(--over); font-weight: 700; }
.due.today { color: var(--today); font-weight: 700; }
.claim { color: var(--claim); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* --- карточка задачи --- */
.status-line { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 14px; font-size: 14px; }
.pill { padding: 3px 10px; border-radius: 999px; font-weight: 700; font-size: 13px; background: var(--accent-soft); color: var(--accent); }
.pill-done { background: var(--claim-soft); color: var(--claim); }
.pill-dropped { background: var(--line); color: var(--muted); }
.edit { display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.title-input { font-size: 18px; font-weight: 600; }
.edit .btn { justify-self: start; }
.actions { display: flex; gap: 10px; margin: 14px 0 26px; }
.history h2 { font-size: 17px; margin: 0 0 4px; }
.comment { display: flex; gap: 8px; margin: 10px 0 14px; }
.events { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; font-size: 14px; }
.events li { border-left: 2px solid var(--line); padding-left: 10px; overflow-wrap: anywhere; }
.ev-when { color: var(--muted); font-variant-numeric: tabular-nums; }
.ev-text { white-space: pre-line; }

/* --- всплывашка с отменой --- */
.toast {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 10px 10px 16px; box-shadow: 0 6px 24px rgba(0,0,0,.2); z-index: 10;
}
.toast-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-undo { appearance: none; border: 0; background: transparent; color: var(--accent-soft); font: inherit; font-weight: 700; cursor: pointer; padding: 6px 8px; }

@media (max-width: 480px) {
  .row { grid-template-columns: 1fr; }
  .banner { flex-direction: column; align-items: stretch; }
  .banner .btn { width: 100%; }
}
