:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f3f2f7);
  --text: var(--tg-theme-text-color, #1d1b22);
  --hint: var(--tg-theme-hint-color, #8a8794);
  --link: var(--tg-theme-link-color, #d6457a);
  --accent: var(--tg-theme-button-color, #e8578b);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --pig: #f7a8c4;
  --goal: #e8578b;
  --project: #7b61ff;
  --task: #3a8ee6;
  --idea: #e0a100;
  --note: #8a8794;
  --danger: #d64545;
  --ok: #2e9e5b;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17161b);
    --bg2: var(--tg-theme-secondary-bg-color, #222128);
    --text: var(--tg-theme-text-color, #f1eff6);
    --hint: var(--tg-theme-hint-color, #9a97a6);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--bg2);
}
.coins { font-weight: 600; }

main { flex: 1; position: relative; overflow: hidden; }
.view { display: none; position: absolute; inset: 0; overflow-y: auto; padding: 12px 16px 96px; }
.view.active { display: block; }
#view-canvas { padding: 0; overflow: hidden; }

.tabs {
  display: grid; grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--bg2); background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  border: 0; background: none; padding: 8px 0 6px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 18px; color: var(--hint);
}
.tabs button span { font-size: 11px; }
.tabs button.active { color: var(--accent); }

.fab {
  position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom));
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-text); font-size: 26px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.2);
}

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 18px 0 8px; }
h2:first-child { margin-top: 4px; }
.empty { color: var(--hint); padding: 8px 0; }
.card { background: var(--bg2); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }

.row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--bg2); border-radius: var(--radius); margin-bottom: 6px;
}
.row .title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .meta { font-size: 12px; color: var(--hint); }
.row.done .title { text-decoration: line-through; color: var(--hint); }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--hint);
  background: none; flex: none; display: grid; place-items: center; font-size: 14px; padding: 0;
}
.row.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.star { border: 0; background: none; font-size: 18px; opacity: .35; padding: 0 2px; }
.star.on { opacity: 1; }
.chip {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: var(--bg); color: var(--hint); margin: 2px 4px 0 0;
}
.chip.late { color: var(--danger); }

.canvas-tools {
  position: absolute; top: 8px; left: 12px; right: 12px; display: flex; justify-content: space-between;
  z-index: 2; pointer-events: none;
}
.canvas-tools > * { pointer-events: auto; }
.toggle { background: var(--bg2); border-radius: 999px; padding: 4px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.toggle input { width: auto; margin: 0; padding: 0; }
.ghost { border: 0; background: var(--bg2); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
#canvas { width: 100%; height: 100%; touch-action: none; display: block; background: var(--bg); }
#tree-wrap { position: absolute; top: 44px; left: 0; right: 0; bottom: 0; }
#canvas .node rect.box { fill: var(--bg2); stroke-width: 2; }
#canvas .node text { fill: var(--text); font-size: 13px; }
#canvas .node text.meta { fill: var(--hint); font-size: 11px; }
#canvas .node.done { opacity: .45; }
#canvas .node.someday { opacity: .7; }
#canvas .node.virtual rect.box { fill: none; stroke-dasharray: 4 4; }
#canvas .edge { fill: none; stroke: var(--hint); stroke-opacity: .45; stroke-width: 1.5; }

.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 82vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  z-index: 11; box-shadow: 0 -6px 24px rgb(0 0 0 / .2);
}
.sheet h3 { margin: 0 0 4px; font-size: 18px; overflow-wrap: anywhere; }
.sheet .kind { color: var(--hint); font-size: 13px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.btn {
  border: 0; border-radius: 12px; padding: 10px; background: var(--bg2); text-align: center;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.history { font-size: 13px; color: var(--hint); }
.history li { margin-bottom: 6px; }
.quote { border-left: 3px solid var(--pig); padding: 4px 10px; margin: 8px 0; font-size: 14px; overflow-wrap: anywhere; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid transparent;
  border-radius: 10px; padding: 9px 10px; width: 100%;
}
label.field { display: block; margin-bottom: 10px; font-size: 13px; color: var(--hint); }
label.field > * { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.days label { background: var(--bg2); border-radius: 999px; padding: 4px 10px; font-size: 13px; color: var(--text); }
.days input { width: auto; margin-right: 4px; }

.entry { margin-bottom: 10px; }
.entry .who { font-size: 12px; color: var(--hint); }
.entry .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.entry.user .text { background: var(--bg2); border-radius: var(--radius); padding: 8px 12px; }
.entry.assistant .text { padding: 4px 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(140px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; z-index: 20; font-size: 14px;
}

/* Трекинг ФРИИ */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chips button { border: 0; border-radius: 999px; padding: 4px 12px; background: var(--bg2); font-size: 13px; }
.chips button.on { background: var(--accent); color: var(--accent-text); }
.rail { list-style: none; padding: 0; margin: 0; }
.rail li { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; border-left: 2px solid var(--bg2); margin-left: 10px; padding-left: 12px; position: relative; }
.rail li .mark { position: absolute; left: -11px; top: 5px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; background: var(--bg2); }
.rail li.ready .mark { background: var(--ok); color: #fff; }
.rail li.active .mark { background: var(--accent); color: var(--accent-text); }
.rail li.blocked .mark { background: var(--danger); color: #fff; }
.rail li .stage-title { font-weight: 500; }
.rail li.ready .stage-title { color: var(--hint); }
.rail li .stage-more { font-size: 13px; color: var(--hint); margin-top: 2px; }
.qcard { border: 2px solid var(--accent); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0; }
.qcard .q { font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }
.qcard dl { margin: 0; font-size: 13px; }
.qcard dt { color: var(--hint); margin-top: 4px; }
.qcard dd { margin: 0; overflow-wrap: anywhere; }
.kv { font-size: 14px; }
.kv div { margin-bottom: 4px; overflow-wrap: anywhere; }
.kv span { color: var(--hint); }
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--bg); color: var(--hint); margin-left: 4px; }
.cand.selected { outline: 2px solid var(--project); }
.small { font-size: 13px; color: var(--hint); }

/* Полотно: таймлайн как в Asana (перенос TimelineView из plan-weaver) */
.pv-toolbar {
  position: absolute; top: 0; left: 0; right: 0; height: 44px; display: flex; gap: 6px; align-items: center;
  padding: 0 10px; border-bottom: 1px solid var(--bg2); background: var(--bg); z-index: 6; overflow-x: auto;
}
.seg { display: inline-flex; background: var(--bg2); border-radius: 999px; padding: 2px; flex: none; }
.seg button { border: 0; background: none; border-radius: 999px; padding: 4px 9px; font-size: 13px; color: var(--hint); }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.pv-toolbar .ghost { flex: none; padding: 4px 10px; }
@media (max-width: 420px) {
  .pv-toolbar { gap: 4px; padding: 0 6px; }
  .seg button, .pv-toolbar .ghost { font-size: 12px; padding: 4px 7px; }
}
.tl-label .chev { flex: none; width: 10px; font-size: 14px; color: var(--hint); transition: transform .15s; display: inline-block; }
.tl-label .chev.open { transform: rotate(90deg); }
.tl { position: absolute; top: 44px; left: 0; right: 0; bottom: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.tl-inner { display: grid; position: relative; }
.tl-corner { position: sticky; top: 0; left: 0; z-index: 5; background: var(--bg); border-right: 1px solid var(--bg2); border-bottom: 1px solid var(--bg2); }
.tl-head { position: sticky; top: 0; z-index: 4; background: var(--bg); border-bottom: 1px solid var(--bg2); }
.tl-left { position: sticky; left: 0; z-index: 3; background: var(--bg); border-right: 1px solid var(--bg2); }
.tl-body { position: relative; }
.tl-month { position: absolute; top: 0; height: 24px; line-height: 24px; padding: 0 6px; font-size: 12px; font-weight: 600; color: var(--hint); border-right: 1px solid var(--bg2); white-space: nowrap; overflow: hidden; text-transform: capitalize; }
.tl-day { position: absolute; top: 24px; height: 24px; line-height: 24px; text-align: center; font-size: 11px; color: var(--hint); border-right: 1px solid color-mix(in srgb, var(--bg2) 60%, transparent); }
.tl-day.we { background: color-mix(in srgb, var(--bg2) 70%, transparent); }
.tl-day.today { color: #e5484d; font-weight: 700; }
.tl-col { position: absolute; top: 0; bottom: 0; border-right: 1px solid color-mix(in srgb, var(--bg2) 55%, transparent); }
.tl-col.we { background: color-mix(in srgb, var(--bg2) 45%, transparent); }
.tl-col.week { border-right-color: var(--bg2); }
.tl-row { position: absolute; left: 0; right: 0; border-bottom: 1px solid color-mix(in srgb, var(--bg2) 70%, transparent); }
.tl-row.group { background: color-mix(in srgb, var(--bg2) 55%, transparent); }
.tl-label { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 0 8px; overflow: hidden; border-bottom: 1px solid color-mix(in srgb, var(--bg2) 70%, transparent); }
.tl-label.group { font-size: 12px; font-weight: 600; background: color-mix(in srgb, var(--bg2) 55%, transparent); cursor: pointer; }
.tl-label.section { font-size: 12px; color: var(--hint); padding-left: 16px; }
.tl-label .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tl-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-label small { color: var(--hint); font-weight: 400; }
.tl-today { position: absolute; top: 0; bottom: 0; width: 2px; background: #e5484d; z-index: 2; pointer-events: none; }
.tl-today::before { content: ""; position: absolute; top: -6px; left: -5px; width: 12px; height: 12px; border-radius: 50%; background: #e5484d; }
.tl-bar {
  position: absolute; border-radius: 6px; color: #fff; display: flex; align-items: center; gap: 4px; padding: 0 6px;
  font-size: 11px; font-weight: 500; line-height: 1.2; cursor: pointer; touch-action: pan-y; user-select: none; -webkit-user-select: none;
  box-sizing: border-box; z-index: 1; text-shadow: 0 1px 2px rgb(0 0 0 / .2);
}
.tl-bar .t { flex: 1; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.tl-bar.done { opacity: .55; }
.tl-bar.late { box-shadow: 0 0 0 3px #e5484d inset; }
.tl-bar.dragging { opacity: .85; box-shadow: 0 4px 14px rgb(0 0 0 / .25); z-index: 5; }
.tl-bar .ok { flex: none; width: 16px; height: 16px; border-radius: 50%; background: rgb(255 255 255 / .3); display: grid; place-items: center; font-size: 10px; }
.tl-bar .grip { position: absolute; right: 0; top: 0; bottom: 0; width: 12px; border-radius: 0 6px 6px 0; background: rgb(0 0 0 / .15); cursor: ew-resize; touch-action: none; }
.tl-out { position: absolute; font-size: 11px; color: var(--text); white-space: nowrap; pointer-events: none; z-index: 1; }
.tl-ms { position: absolute; width: 14px; height: 14px; transform: rotate(45deg); border-radius: 3px; z-index: 1; }
.tl-tip { position: fixed; z-index: 30; background: var(--text); color: var(--bg); padding: 4px 10px; border-radius: 999px; font-size: 12px; pointer-events: none; }
.tl-empty { padding: 24px 16px; color: var(--hint); }
.toast button { border: 0; background: none; color: var(--bg); font-weight: 700; margin-left: 8px; text-decoration: underline; }
.toast { pointer-events: auto; }
