:root {
  --bg: #f4f5f7; --rail: #f0f0f0; --side: #fafafa; --card: #ffffff; --card2: #f2f3f5; --line: #ececec;
  --text: #191919; --text2: #6b6b6b; --muted: #a3a3a3; --accent: #4772FA; --accent2: #3a63e8;
  --q1: #e5554f; --q2: #f0a73a; --q3: #4772FA; --q4: #2fb380; --danger: #e5554f;
  --hover: #f3f4f6; --sel: #e8eeff; --shadow: 0 1px 3px rgba(0,0,0,.06);
  --r: 12px; color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { display: block; }

/* login */
#login { height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 340px; max-width: 100%; background: var(--card); border-radius: 16px; padding: 32px 24px; text-align: center; }
.login-logo img { width: 56px; height: 56px; }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card p { color: var(--text2); margin: 0 0 20px; }
.err { color: var(--danger) !important; margin-top: 12px !important; min-height: 1em; }

/* layout */
#app { display: flex; height: 100%; }
.rail { width: 64px; flex: none; background: var(--rail); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 4px; }
.rail-logo img { width: 32px; height: 32px; margin-bottom: 14px; }
.rail button { position: relative; width: 52px; padding: 8px 0 6px; border: 0; background: none; border-radius: 10px; color: var(--muted);
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.rail button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail button span { font-size: 10px; white-space: nowrap; }
.rail button:hover { color: var(--text2); background: #e6e6e6; }
.rail button.on { color: var(--accent); }
.rail button.running { color: var(--q1); }
.rail-spacer { flex: 1; }
.badge { position: absolute; top: 4px; right: 8px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--q1);
  color: #fff; font: 600 10px/16px sans-serif; font-style: normal; padding: 0 4px; }
.badge:empty { display: none; }
#main { flex: 1; min-width: 0; display: flex; overflow: hidden; }

.side { width: 240px; flex: none; background: var(--side); padding: 16px 10px; overflow-y: auto; }
.side h4 { margin: 18px 10px 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.side a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; cursor: pointer; color: var(--text); text-decoration: none; }
.side a:hover { background: var(--hover); }
.side a.on { background: var(--sel); }
.side a .ic { width: 18px; text-align: center; color: var(--text2); }
.side a .n { margin-left: auto; color: var(--muted); font-size: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }

.page { flex: 1; min-width: 0; overflow-y: auto; padding: 20px 28px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 650; }
.page-head .grow { flex: 1; }

.btn { border: 0; background: var(--card2); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { background: #e7e8eb; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.ghost { background: none; color: var(--text2); }
.btn.ghost:hover { background: var(--card2); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.sel, .inp { background: var(--card2); border: 1px solid transparent; border-radius: 8px; padding: 7px 10px; outline: none; }
.inp:focus, .sel:focus { border-color: var(--accent); }
textarea.inp { resize: vertical; min-height: 80px; width: 100%; }

/* main task of the day */
.frog { display: flex; align-items: center; gap: 12px; background: linear-gradient(90deg, #fff6e6, #fff); border: 1px solid #f6e2bd;
  border-radius: var(--r); padding: 12px 16px; margin-bottom: 16px; }
.frog .lbl { font-size: 11px; color: var(--q2); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.frog .t { font-size: 16px; font-weight: 600; }
.frog.empty { background: var(--card); border-color: var(--line); color: var(--text2); }
.frog .grow { flex: 1; min-width: 0; }

/* matrix */
.matrix { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 12px; height: calc(100% - 120px); min-height: 520px; }
.quad { background: var(--card); box-shadow: var(--shadow); border-radius: var(--r); display: flex; flex-direction: column; min-height: 0; border: 2px solid transparent; }
.quad.over { border-color: var(--accent); }
.quad-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.quad-head .num { width: 22px; height: 22px; border-radius: 6px; color: #fff; font: 700 11px/22px sans-serif; text-align: center; }
.quad-head .ttl { font-weight: 600; }
.quad-head .cnt { margin-left: auto; color: var(--muted); font-size: 12px; }
.quad-list { flex: 1; overflow-y: auto; padding: 0 6px; min-height: 40px; }
.quad-add { padding: 6px 10px 10px; }
.quad-add input, .addbar input { width: 100%; background: transparent; border: 0; outline: none; padding: 8px 6px; color: var(--text);
  border-radius: 6px; }
.quad-add input:focus, .addbar input:focus { background: var(--card2); }
.quad-add input::placeholder, .addbar input::placeholder { color: var(--muted); }
.q1 { --qc: var(--q1); } .q2 { --qc: var(--q2); } .q3 { --qc: var(--q3); } .q4 { --qc: var(--q4); } .q0 { --qc: var(--muted); }
.qbg { background: var(--qc); }

/* task row */
.task { display: flex; align-items: flex-start; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; position: relative; }
.task:hover { background: var(--hover); }
.task.dragging { opacity: .4; }
.chk { width: 17px; height: 17px; flex: none; margin-top: 2px; border: 2px solid var(--qc); border-radius: 4px; cursor: pointer;
  background: color-mix(in srgb, var(--qc) 12%, transparent); display: grid; place-items: center; }
.chk:hover { background: color-mix(in srgb, var(--qc) 35%, transparent); }
.task.done .chk { background: var(--muted); border-color: var(--muted); }
.task.done .chk::after { content: ""; width: 8px; height: 4px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.task.done .tt { color: var(--muted); text-decoration: line-through; }
.tt { flex: 1; min-width: 0; word-break: break-word; }
.meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 1px; flex-wrap: wrap; }
.meta .proj { display: inline-flex; align-items: center; gap: 4px; }
.meta .proj .dot { width: 7px; height: 7px; }
.meta .late { color: var(--q1); }
.meta .today { color: var(--accent2); }
.task .acts { display: none; gap: 2px; }
.task:hover .acts { display: flex; }
.ib { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 5px; border-radius: 5px; font-size: 13px; line-height: 1.2; }
.ib:hover { color: var(--text); background: #e9eaec; }
.ib.on { color: var(--q2); }
.sortq { display: flex; gap: 4px; }
.sortq button { border: 0; width: 26px; height: 22px; border-radius: 5px; font: 700 11px sans-serif; color: #fff; cursor: pointer; opacity: .85; }
.sortq button:hover { opacity: 1; }
.empty-note { color: var(--muted); text-align: center; padding: 30px 10px; }
.list-card { background: var(--card); border-radius: var(--r); padding: 6px; }
.addbar { background: var(--card); border-radius: var(--r); padding: 4px 8px; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: -6px 0 12px 4px; }
.group-h { font-size: 12px; color: var(--text2); margin: 14px 8px 4px; font-weight: 600; }

/* drawer */
#drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.18); z-index: 20; }
#drawer { position: fixed; right: 0; top: 0; bottom: 0; width: 400px; max-width: 100%; background: var(--side); z-index: 21;
  padding: 18px; overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.12); display: flex; flex-direction: column; gap: 12px; }
#drawer .title-inp { font-size: 18px; font-weight: 600; background: none; border: 0; outline: none; width: 100%; padding: 4px 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.qpick { display: flex; gap: 6px; flex-wrap: wrap; }
.qpick button { border: 2px solid transparent; background: var(--card2); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; }
.qpick button.on { border-color: var(--qc); background: color-mix(in srgb, var(--qc) 18%, var(--card2)); }

/* focus */
.focus-wrap { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.card { background: var(--card); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.tabs { display: inline-flex; background: var(--card2); border-radius: 9px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--text2); }
.tabs button.on { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.timer-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.ring { position: relative; width: 280px; height: 280px; max-width: 80vw; max-height: 80vw; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .time { position: absolute; inset: 0; display: grid; place-items: center; font-size: 54px; font-weight: 300; font-variant-numeric: tabular-nums; }
.ring .sub { position: absolute; left: 0; right: 0; top: 64%; color: var(--text2); font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: none; border-radius: 16px;
  padding: 5px 12px; cursor: pointer; color: var(--text2); }
.chip.on { border-color: var(--pc, var(--accent)); color: var(--text); background: color-mix(in srgb, var(--pc, var(--accent)) 15%, transparent); }
.timer-btns { display: flex; gap: 10px; }
.timer-btns .btn { min-width: 110px; padding: 10px 18px; border-radius: 22px; }
.rank { display: flex; align-items: center; gap: 14px; }
.rank .emo { font-size: 38px; width: 56px; height: 56px; display: grid; place-items: center; background: var(--card2); border-radius: 14px; }
.rank .rt { font-size: 18px; font-weight: 650; }
.rank .rs { color: var(--text2); font-size: 13px; }
.bar { height: 6px; background: var(--card2); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.kpi { background: var(--card); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .k { color: var(--text2); font-size: 12px; }
.rec { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
.rec:last-child { border-bottom: 0; }
.rec .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec .tm { color: var(--muted); font-variant-numeric: tabular-nums; }

/* stats */
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.stats-grid .wide { grid-column: 1 / -1; }
.chart { width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text2); font-size: 11px; }
.chart .grid { stroke: #ededed; stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: default; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.pbar { display: grid; grid-template-columns: 130px 1fr auto; gap: 10px; align-items: center; margin: 9px 0; font-size: 13px; }
.pbar .nm { display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pbar .tr { height: 10px; background: var(--card2); border-radius: 5px; overflow: hidden; }
.pbar .tr i { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.pbar .val { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.pbar .val small { color: var(--muted); margin-left: 6px; }
#tip { position: fixed; pointer-events: none; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.12); max-width: 240px; }
#tip b { display: block; margin-bottom: 4px; color: var(--text); }
#tip div { display: flex; align-items: center; gap: 6px; color: var(--text2); }
#tip div em { margin-left: auto; font-style: normal; color: var(--text); padding-left: 10px; }
.heat { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat .col { display: flex; flex-direction: column; gap: 3px; }
.heat .c { width: 11px; height: 11px; border-radius: 2px; background: #ebedf0; }

/* settings */
.set-sec { background: var(--card); border-radius: var(--r); padding: 18px; margin-bottom: 14px; max-width: 760px; }
.set-sec h3 { margin: 0 0 12px; font-size: 15px; }
.set-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; flex-wrap: wrap; }
.set-row label { flex: 1; min-width: 160px; color: var(--text2); }
.swatches { display: flex; gap: 4px; }
.swatches button { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatches button.on { border-color: var(--text); }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #d0d0d0; border-radius: 11px; cursor: pointer; transition: .15s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { left: 19px; }
.rank-row { display: grid; grid-template-columns: 54px 80px 1fr 32px; gap: 8px; margin-bottom: 6px; }
.rank-row .inp { width: 100%; min-width: 0; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b2b2b; color: #fff; padding: 10px 16px; border-radius: 10px;
  z-index: 60; display: flex; gap: 12px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
#toast button { background: none; border: 0; color: #8fa9ff; cursor: pointer; font-weight: 600; }

/* mobile */
@media (max-width: 820px) {
  #app { flex-direction: column-reverse; }
  .rail { width: 100%; flex-direction: row; justify-content: space-around; padding: 4px 0 calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
  .rail-logo, .rail-spacer { display: none; }
  .rail button { width: auto; flex: 1; }
  #main { flex-direction: column; }
  .side { width: 100%; padding: 8px; display: flex; gap: 4px; overflow-x: auto; flex: none; }
  .side h4 { display: none; }
  .side a { white-space: nowrap; flex: none; }
  .page { padding: 14px 16px 30px; }
  .matrix { grid-template-columns: 1fr; grid-template-rows: none; height: auto; }
  .quad { min-height: 160px; }
  .focus-wrap, .stats-grid { grid-template-columns: 1fr; }
  .task .acts { display: flex; }
  .pbar { grid-template-columns: 96px 1fr auto; }
}

/* TickTick-подобные детали */
.quad-head .num { width: 18px; height: 18px; border-radius: 50%; font: 700 9px/18px sans-serif; }
.quad-head .ttl { color: var(--qc); font-weight: 600; }
.quad .task { border-radius: 0; border-bottom: 1px solid var(--line); margin: 0 8px; padding: 9px 4px; }
.quad .task:hover { background: var(--hover); border-radius: 6px; }
.task .side-meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); white-space: nowrap; margin-left: 8px; }
.task .side-meta .proj { display: inline-flex; align-items: center; gap: 4px; }
.task .side-meta .proj .dot { width: 7px; height: 7px; }
.task .side-meta .late { color: var(--q1); } .task .side-meta .today { color: var(--accent); }
.qgroup { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; margin: 8px 10px 2px; color: var(--text); }
.qgroup span { color: var(--muted); font-weight: 400; font-size: 12px; }
.rail { border-right: 1px solid var(--line); }
.side { border-right: 1px solid var(--line); }
.list-card { box-shadow: var(--shadow); }
.addbar { box-shadow: var(--shadow); }
.set-sec { box-shadow: var(--shadow); }
.login-card { box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.ring svg circle:first-child { stroke: #eef0f3; }
.chk { background: #fff; }
.chk:hover { background: color-mix(in srgb, var(--qc) 15%, #fff); }
@media (max-width: 820px) {
  .task .side-meta { display: none; }
  .task .tt .meta.mob { display: flex; }
}
.task .tt .meta.mob { display: none; }
