:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --border-strong: #d0d5dd;
  --text: #1d2330;
  --muted: #6b7385;
  --faint: #9aa1b0;
  --accent: #4f6bed;
  --accent-hover: #3f59d6;
  --accent-weak: #eef1fe;
  --on-accent: #ffffff;
  --danger: #d64545;
  --danger-weak: #fdeeee;
  --warn: #c27a0e;
  --warn-weak: #fdf4e3;
  --ok: #2f9e66;
  --ok-weak: #e7f6ee;

  --st-idea: #8a72d8;
  --st-planning: #d99a1e;
  --st-active: #4f6bed;
  --st-done: #2f9e66;
  --st-cancelled: #8c93a1;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318;
    --surface: #191c23;
    --surface-2: #20242d;
    --border: #2b303b;
    --border-strong: #3a404d;
    --text: #e7e9ee;
    --muted: #8d94a5;
    --faint: #646b7a;
    --accent: #7088ff;
    --accent-hover: #8599ff;
    --accent-weak: #222a4a;
    --on-accent: #0d1020;
    --danger: #f06b6b;
    --danger-weak: #3a1f22;
    --warn: #e5a640;
    --warn-weak: #382c17;
    --ok: #4cc28a;
    --ok-weak: #17322a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }
.pet-svg { image-rendering: pixelated; display: block; }

/* ---------- Каркас ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; color: var(--text); font-weight: 700; font-size: 15px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-weak); color: var(--accent); }
.nav a .count { margin-left: auto; font-size: 12px; color: var(--faint); }
.nav svg, .tabbar svg { width: 18px; height: 18px; flex: 0 0 auto; }
#sidebar-pet { margin-top: auto; }
.sync { display: flex; align-items: center; gap: 6px; padding: 2px 10px; font-size: 12px; color: var(--faint); }
.sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.sync-ok .sync-dot { background: var(--ok); }
.sync-saving .sync-dot { background: var(--warn); }
.sync-offline { color: var(--danger); }
.sync-offline .sync-dot { background: var(--danger); }
code { font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.main { min-width: 0; }
#app { max-width: 1200px; margin: 0 auto; padding: 24px 28px 96px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.tabbar { display: none; }

/* ---------- Карточки ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 16px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 14px; }
.card-body { padding: 12px 16px; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, 1fr); }
.dash { grid-template-columns: 1fr 340px; align-items: start; margin-top: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .delta { font-size: 12px; color: var(--muted); }
.kpi .delta.up { color: var(--ok); }
.kpi .delta.down { color: var(--danger); }

/* ---------- Кнопки и поля ---------- */
.btn {
  font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-weak); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; padding: 0;
  background: transparent; border: 0; border-radius: var(--radius-sm);
  color: var(--faint); cursor: pointer; font: inherit;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[disabled] { opacity: .3; cursor: default; }
.icon-btn svg { width: 15px; height: 15px; }

input, select, textarea {
  font: inherit; color: var(--text);
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  min-height: 34px;
}
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"] { width: auto; min-height: 0; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; }

.check {
  appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; flex: 0 0 auto; margin: 0;
  border: 1.5px solid var(--border-strong); border-radius: 5px;
  background: var(--surface); cursor: pointer; position: relative;
}
.check:hover { border-color: var(--accent); }
.check:checked { background: var(--ok); border-color: var(--ok); }
.check:checked::after {
  content: ''; position: absolute; left: 5px; top: 1.5px; width: 5px; height: 9px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.check:disabled { cursor: default; opacity: .6; }

/* ---------- Метки ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.warn { background: var(--warn-weak); color: var(--warn); }
.pill.danger { background: var(--danger-weak); color: var(--danger); }
.pill.ok { background: var(--ok-weak); color: var(--ok); }
.status-idea { color: var(--st-idea); }
.status-planning { color: var(--st-planning); }
.status-active { color: var(--st-active); }
.status-done { color: var(--st-done); }
.status-cancelled { color: var(--st-cancelled); }
.pill.status { background: color-mix(in srgb, currentColor 12%, transparent); }
.prio-high { color: var(--danger); }
.prio-normal { color: var(--faint); }
.prio-low { color: var(--faint); opacity: .6; }

.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.progress.ok > i { background: var(--ok); }

/* ---------- Воронка (канбан) ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type="search"] { max-width: 260px; }
.toolbar select { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { font: inherit; font-size: 13px; border: 0; background: var(--surface); color: var(--muted); padding: 0 12px; height: 32px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.on { background: var(--accent-weak); color: var(--accent); font-weight: 500; }

.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 12px; align-items: start; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 10px; font-weight: 600; font-size: 13px; }
.col-head .n { color: var(--faint); font-weight: 500; }
.col-head .limit { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--muted); }
.col-head .limit.over { color: var(--danger); }
.col-list { display: flex; flex-direction: column; gap: 8px; }
.col-add input { background: transparent; border-style: dashed; }

.pcard { display: block; padding: 12px; color: var(--text); cursor: pointer; }
.pcard:hover { text-decoration: none; border-color: var(--border-strong); }
.pcard[draggable="true"] { cursor: grab; }
.pcard.dragging { opacity: .4; }
.pcard .t { font-weight: 500; line-height: 1.35; word-break: break-word; }
.pcard .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.pcard .progress { margin-top: 10px; }
.pcard .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface);
}
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr.link { cursor: pointer; }
table.t tbody tr.link:hover td { background: var(--surface-2); }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr.group td { background: var(--surface-2); font-weight: 600; font-size: 13px; }
table.t tr.done td .name { text-decoration: line-through; color: var(--faint); }

/* ---------- Списки задач ---------- */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
}
.rows > li:last-child { border-bottom: 0; }
.rows .txt { flex: 1; min-width: 0; word-break: break-word; }
.rows li.done .txt { text-decoration: line-through; color: var(--faint); }
.rows li.next { background: var(--accent-weak); }
.rows .tools { display: flex; gap: 2px; opacity: 0; transition: opacity .1s; }
.rows li:hover .tools, .rows li:focus-within .tools { opacity: 1; }
.rows .due { font-size: 12px; color: var(--muted); white-space: nowrap; }
.rows .due.overdue { color: var(--danger); font-weight: 500; }
.rows .sub { font-size: 12px; color: var(--muted); }
.rows .date-in { width: 132px; min-height: 28px; padding: 2px 6px; font-size: 12px; }
.empty-row { padding: 18px 16px; color: var(--muted); text-align: center; }

.add-row { padding: 10px 16px; border-top: 1px solid var(--border); }
.add-row form { display: flex; gap: 8px; flex-wrap: wrap; }
.add-row input { flex: 1 1 160px; }

/* ---------- Проект ---------- */

.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 16px; }
.photo {
  position: relative; aspect-ratio: 4/3; border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong); background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--muted); font-size: 12.5px; cursor: pointer; overflow: hidden;
}
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo .cap { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; border-radius: 4px; padding: 0 6px; font-size: 11px; }

.feed { list-style: none; margin: 0; padding: 4px 0; }
.feed li { display: flex; gap: 10px; padding: 7px 16px; font-size: 13px; }
.feed .when { color: var(--faint); white-space: nowrap; font-size: 12px; margin-left: auto; padding-left: 8px; }
.feed .ic { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); margin-top: 6px; flex: 0 0 auto; }

.notes { white-space: pre-wrap; }

/* ---------- Внимание ---------- */
.alert-list li { align-items: flex-start; }
.alert-list .t { font-weight: 500; }

/* ---------- Тепловая карта активности ---------- */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; overflow-x: auto; padding: 14px 16px 6px; }
.heat i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); }
.heat i.l1 { background: color-mix(in srgb, var(--ok) 35%, var(--surface-2)); }
.heat i.l2 { background: color-mix(in srgb, var(--ok) 65%, var(--surface-2)); }
.heat i.l3 { background: var(--ok); }
.heat i.future { visibility: hidden; }
.heat-legend { display: flex; justify-content: space-between; padding: 0 16px 12px; font-size: 12px; color: var(--muted); }

/* ---------- Питомец ---------- */
.pet-mini {
  display: flex; gap: 10px; align-items: center;
  padding: 10px; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
}
.pet-mini:hover { text-decoration: none; background: var(--accent-weak); }
.pet-mini .info { min-width: 0; flex: 1; }
.pet-mini .nm { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pet-mini .st { font-size: 12px; color: var(--muted); }
.pet-mini .progress { margin-top: 6px; height: 4px; }
.pet-stage {
  background: linear-gradient(var(--accent-weak) 72%, color-mix(in srgb, var(--ok) 25%, var(--surface-2)) 72%);
  border-radius: var(--radius-sm); padding: 4px; flex: 0 0 auto;
}

.pet-card { display: flex; gap: 16px; align-items: center; padding: 16px; }
.pet-card .pet-stage { padding: 10px; }
.pet-card .info { flex: 1; min-width: 0; }
.pet-card .nm { font-weight: 600; font-size: 15px; }
.mood { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.mood-dot { width: 8px; height: 8px; border-radius: 50%; }
.mood-happy .mood-dot { background: var(--ok); }
.mood-ok .mood-dot { background: var(--accent); }
.mood-bored .mood-dot { background: var(--warn); }
.mood-sleep .mood-dot { background: var(--faint); }

.pet-svg.mood-happy { animation: hop 1.4s steps(2) infinite; }
.pet-svg.mood-ok { animation: hop 2.4s steps(2) infinite; }
.pet-svg.mood-bored { filter: saturate(.55); }
.pet-svg.mood-sleep { filter: saturate(.3) brightness(.92); }
@keyframes hop { 50% { transform: translateY(-3%); } }

.pet-hero { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: center; padding: 24px; }
.pet-hero .pet-stage { padding: 20px; position: relative; }
.pet-hero .pet-stage .zzz { position: absolute; right: 16px; top: 10px; color: var(--muted); font-weight: 600; }
.pet-hero h1 { display: flex; align-items: center; gap: 6px; }
.stats-line { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 14px; }
.stats-line .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats-line .l { font-size: 12px; color: var(--muted); }

.evo { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 16px; }
.evo-step { text-align: center; padding: 10px 4px; border-radius: var(--radius-sm); }
.evo-step .pet-svg { margin: 0 auto 6px; }
.evo-step.locked { color: var(--border-strong); }
.evo-step.current { background: var(--accent-weak); }
.evo-step .nm { font-size: 12.5px; font-weight: 500; color: var(--text); }
.evo-step .req { font-size: 11.5px; color: var(--muted); }

.species { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.species label {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px; border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-weight: 500;
}
.species input { position: absolute; opacity: 0; pointer-events: none; }
.species label:has(input:checked) { border-color: var(--accent); background: var(--accent-weak); box-shadow: 0 0 0 1px var(--accent); }

.rules { margin: 0; padding: 4px 16px 14px 34px; color: var(--muted); }
.rules li { margin: 6px 0; }
.rules b { color: var(--text); font-weight: 500; }

/* ---------- Модалки и уведомления ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 18, 28, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade .12s ease-out;
}
.modal { width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
.modal .card-body { padding: 16px; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
@keyframes fade { from { opacity: 0; } }

.evolve { text-align: center; }
.evolve .row { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 16px 0; }
.evolve .arrow { color: var(--faint); font-size: 22px; }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--text); color: var(--bg);
  padding: 8px 14px 8px 8px; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  font-size: 13px; animation: toast 3s ease forwards;
}
.toast.plain { padding-left: 14px; }
.toast .pet-svg { background: var(--bg); border-radius: 6px; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

details.archive > summary { cursor: pointer; color: var(--muted); padding: 4px 0; font-size: 13px; }

/* ---------- Адаптив ---------- */
@media (max-width: 1100px) {
  .dash { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  #app { padding: 16px 16px calc(136px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 2px; color: var(--muted); font-size: 11px; font-weight: 500;
  }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a.active { color: var(--accent); }
  .tabbar svg { width: 22px; height: 22px; }
  .board { grid-template-columns: repeat(4, 82vw); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .toasts { left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); align-items: stretch; }
  .rows .tools { opacity: 1; }
}
@media (max-width: 600px) {
  .pet-hero { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .pet-hero h1, .stats-line { justify-content: center; }
  .evo { grid-template-columns: repeat(5, minmax(56px, 1fr)); overflow-x: auto; padding: 12px 8px; }
  .species { grid-template-columns: repeat(3, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar input[type="search"] { max-width: none; flex: 1 1 100%; }
  .hide-sm { display: none; }
}
