:root {
  --page: #F4F3FA;
  --surface: #FFFFFF;
  --surface-2: #ECEAF6;
  --text: #1C1B2E;
  --text-2: #5B5A72;
  --text-3: #8B8AA0;
  --line: #DEDCEC;
  --line-2: #C6C3DC;
  --accent: #5B4FE0;
  --accent-hover: #4A3FCB;
  --accent-soft: #E9E6FD;
  --on-accent: #FFFFFF;
  --danger: #C62B3A;
  --danger-soft: #FDEBEC;
  --shadow: 0 10px 30px rgba(40, 34, 110, 0.14), 0 2px 6px rgba(40, 34, 110, 0.08);

  --do-fill: #1B7F45;   --do-on: #FFFFFF;   --do-bg: #E6F6EC;   --do-line: #BCE3CA;
  --plan-fill: #2563EB; --plan-on: #FFFFFF; --plan-bg: #E8F0FE; --plan-line: #C2D5FB;
  --pass-fill: #F5A524; --pass-on: #3B2500; --pass-bg: #FEF4DC; --pass-line: #F4DA9A;
  --drop-fill: #D03542; --drop-on: #FFFFFF; --drop-bg: #FDEBEC; --drop-line: #F4C2C6;

  --radius: 10px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #13131B;
    --surface: #1C1C28;
    --surface-2: #262636;
    --text: #EEEDF6;
    --text-2: #B0AFC6;
    --text-3: #8180A0;
    --line: #2E2E42;
    --line-2: #43435C;
    --accent: #6F63F0;
    --accent-hover: #8177F4;
    --accent-soft: #2A2752;
    --on-accent: #FFFFFF;
    --danger: #F2707B;
    --danger-soft: #3A1A1E;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);

    --do-fill: #35B26C;   --do-on: #04200F;   --do-bg: #142A1D;   --do-line: #1F4A31;
    --plan-fill: #6396F8; --plan-on: #06142F; --plan-bg: #162338; --plan-line: #263F6B;
    --pass-fill: #F0B03C; --pass-on: #2B1B00; --pass-bg: #2D2412; --pass-line: #57431A;
    --drop-fill: #F0626E; --drop-on: #2E060A; --drop-bg: #301619; --drop-line: #5C252B;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, p { margin: 0; }

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--text-2); }
.grow { flex: 1; min-width: 0; }
.err { color: var(--danger); font-size: 13px; min-height: 0; }
.err:empty { display: none; }

/* ---------- controls ---------- */

input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="time"], select {
  height: 38px;
  padding: 0 11px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  min-width: 0;
}

input::placeholder { color: var(--text-3); }

input:hover, select:hover { border-color: var(--text-3); }

.btn {
  height: 38px;
  padding: 0 15px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: transparent; color: #FFFFFF; }
.btn.danger-text { border-color: transparent; background: transparent; color: var(--danger); }
.btn.danger-text:hover { background: var(--danger-soft); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: 0.6; cursor: progress; }

.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; }
.link:hover { text-decoration: underline; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
}
.icon-btn:hover { background: rgba(120, 115, 170, 0.18); color: var(--text); }

svg.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.ic.solid { fill: currentColor; stroke: none; }

.field { display: grid; gap: 5px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: 13px; font-weight: 600; color: var(--text-2); padding: 0; }
.field > legend { margin-bottom: 5px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

/* ---------- brand mark ---------- */

.mark { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; width: 44px; height: 44px; }
.mark i { border-radius: 6px; }
.mark i:nth-child(1) { background: var(--do-fill); }
.mark i:nth-child(2) { background: var(--plan-fill); }
.mark i:nth-child(3) { background: var(--pass-fill); }
.mark i:nth-child(4) { background: var(--drop-fill); }
.mark.small { width: 24px; height: 24px; gap: 2px; }
.mark.small i { border-radius: 3px; }

/* ---------- sign in ---------- */

.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }

.auth-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 22px; margin-top: 4px; }
.auth-card .muted:empty { display: none; }

/* ---------- shell ---------- */

.shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100%; }

.side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 14px; font-size: 17px; font-weight: 700; }

.side-h { padding: 16px 10px 4px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }

.nav { display: grid; gap: 2px; }

.nav-row { display: flex; align-items: center; gap: 2px; }
.nav-row .nav-item { flex: 1; min-width: 0; }
.nav-row .icon-btn { opacity: 0; }
.nav-row:hover .icon-btn, .nav-row .icon-btn:focus-visible { opacity: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  text-align: left;
  font-weight: 500;
}
.nav-item > span:not(.dot):not(.count) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.on { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-item.on svg.ic { color: var(--accent); }
.nav-item.new { color: var(--text-3); margin-top: 2px; }

.count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.all { background: conic-gradient(var(--do-fill) 0 25%, var(--plan-fill) 0 50%, var(--drop-fill) 0 75%, var(--pass-fill) 0); }

.side-foot { margin-top: auto; padding: 14px 10px 0; display: grid; gap: 2px; font-size: 13px; border-top: 1px solid var(--line); }
.who { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .link { justify-self: start; }

.main { display: flex; flex-direction: column; min-width: 0; padding: 22px 28px 0; max-width: 1180px; width: 100%; }

.top { margin-bottom: 14px; }
.top h1 { font-size: 24px; letter-spacing: -0.01em; }

/* ---------- stats ---------- */

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }

.stat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  min-width: 0;
}
.stat-ic { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; flex: none; }
.stat-ic svg.ic { width: 21px; height: 21px; }
.stat.time .stat-ic { background: var(--plan-bg); color: var(--plan-fill); }
.stat.done .stat-ic { background: var(--do-bg); color: var(--do-fill); }
.stat.streak .stat-ic { background: var(--pass-bg); color: var(--pass-fill); }
.stat-body { min-width: 0; flex: 1; display: grid; }
.stat-l { font-size: 12px; color: var(--text-2); }
.stat-v { font-size: 19px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.stat-s { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 6px; margin-top: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--do-fill); transition: width 0.25s ease; }

/* ---------- matrix ---------- */

.matrix { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: minmax(190px, auto); gap: 14px; flex: 1; align-content: start; }

.quad { display: flex; flex-direction: column; border-radius: 14px; border: 1px solid var(--q-line); background: var(--q-bg); overflow: hidden; }
.quad.q-do   { --q-fill: var(--do-fill);   --q-on: var(--do-on);   --q-bg: var(--do-bg);   --q-line: var(--do-line); }
.quad.q-plan { --q-fill: var(--plan-fill); --q-on: var(--plan-on); --q-bg: var(--plan-bg); --q-line: var(--plan-line); }
.quad.q-pass { --q-fill: var(--pass-fill); --q-on: var(--pass-on); --q-bg: var(--pass-bg); --q-line: var(--pass-line); }
.quad.q-drop { --q-fill: var(--drop-fill); --q-on: var(--drop-on); --q-bg: var(--drop-bg); --q-line: var(--drop-line); }
.quad.over { outline: 3px solid var(--q-fill); outline-offset: 2px; }

.quad-h { display: flex; align-items: baseline; gap: 10px; padding: 8px 14px; background: var(--q-fill); color: var(--q-on); }
.quad-h h2 { font-size: 15px; font-weight: 700; }
.quad-h .hint { font-size: 12.5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quad-h .n { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }

.tasks { list-style: none; margin: 0; padding: 6px 8px 10px; flex: 1; }

.task { display: flex; align-items: center; gap: 8px; padding: 3px 4px 3px 2px; border-radius: 8px; }
.task:hover { background: rgba(255, 255, 255, 0.55); }
.task.dragging { opacity: 0.4; }
.task .grip { display: grid; place-items: center; color: var(--text-3); cursor: grab; }
.task .grip svg.ic { width: 14px; height: 14px; }
.task .check { width: 17px; height: 17px; flex: none; margin: 0; accent-color: var(--q-fill); cursor: pointer; }
.task-title { flex: 1; min-width: 0; padding: 4px 2px; border: 0; background: none; text-align: left; overflow-wrap: anywhere; }
.task-title:hover { text-decoration: underline; text-decoration-color: var(--text-3); }
.task.done .task-title { text-decoration: line-through; color: var(--text-3); }
.task .due { font-size: 12.5px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.task .due.late { color: var(--danger); font-weight: 600; }
.task .more { opacity: 0.55; }
.task:hover .more, .task .more:focus-visible { opacity: 1; }
.tasks .empty { padding: 10px 8px; font-size: 13.5px; color: var(--text-2); }

@media (prefers-color-scheme: dark) {
  .task:hover { background: rgba(255, 255, 255, 0.06); }
}

/* ---------- add bar ---------- */

.add { position: sticky; bottom: 0; margin: 14px -28px 0; padding: 12px 28px 14px; background: var(--page); border-top: 1px solid var(--line); }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-row #add-title { flex: 1 1 240px; }
.add-row select { flex: 0 1 150px; }
.add .err { margin-top: 6px; }

/* ---------- dialogs, menu, toast ---------- */

.dlg { width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dlg.narrow { width: min(380px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(20, 18, 50, 0.45); }
.dlg form { display: grid; gap: 14px; padding: 22px; }
.dlg h2 { font-size: 18px; }
.dlg-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches label { position: relative; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; }
.swatches input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatches span { display: block; width: 100%; height: 100%; border-radius: 50%; }
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 5px; }

.menu { position: fixed; z-index: 30; min-width: 190px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border: 0; border-radius: 7px; background: none; text-align: left; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu button.danger { color: var(--danger); }
.menu .menu-h { padding: 8px 10px 3px; font-size: 12px; font-weight: 700; color: var(--text-3); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
.menu .sw { width: 12px; height: 12px; border-radius: 4px; }
.sw.q-do { background: var(--do-fill); }
.sw.q-plan { background: var(--plan-fill); }
.sw.q-pass { background: var(--pass-fill); }
.sw.q-drop { background: var(--drop-fill); }

.toast { position: fixed; z-index: 40; left: 50%; bottom: 84px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 10px 16px; background: var(--text); color: var(--page); border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }

/* ---------- small screens ---------- */

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 12px 10px; }
  .brand { padding-bottom: 8px; }
  .side-h { display: none; }
  .nav { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
  .nav-item { width: auto; flex: none; white-space: nowrap; }
  .nav-item > span:not(.dot):not(.count) { overflow: visible; }
  .nav-row { flex: none; }
  .nav-row .icon-btn { opacity: 1; }
  .nav-item.new { width: auto; align-self: flex-start; }
  .side-foot { margin-top: 6px; padding-top: 8px; display: flex; gap: 12px; align-items: center; }
  .who { flex: 1; min-width: 0; }
  .main { padding: 16px 16px 0; }
  .stats { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .matrix { grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; }
  .top { order: 0; }
  .add { order: 1; position: static; margin: 0 0 14px; padding: 0; border-top: 0; }
  .stats { order: 2; }
  .matrix { order: 3; padding-bottom: 20px; }
  .toast { bottom: 20px; }
  .add-row select, .add-row input[type="date"] { flex: 1 1 120px; }
  .add-row .btn { flex: 1 1 100%; }
}

/* ---------- desktop widget (set by the desktop app) ---------- */

html.widget, html.widget body { height: 100%; overflow: hidden; }
.widget body { display: flex; flex-direction: column; font-size: 14px; }

.wbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 8px 7px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  -webkit-app-region: drag;
  user-select: none;
  flex: none;
}
.wbar .mark.small { width: 20px; height: 20px; margin-right: 6px; }
.wbar button { -webkit-app-region: no-drag; }
.wbar-t { display: grid; line-height: 1.2; min-width: 0; }
.wbar-t b { font-size: 13.5px; }
.wbar-t span { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wbar .icon-btn { width: 30px; height: 30px; }
.wbar .icon-btn svg.ic { width: 16px; height: 16px; }
.wbar .icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.wbar #w-hide:hover { background: var(--danger); color: #FFFFFF; }

.widget .auth { flex: 1; min-height: 0; overflow-y: auto; }
.widget .auth-card { padding: 22px; box-shadow: none; }

.widget .shell { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.widget .side, .widget .top { display: none; }
.widget .main { flex: 1; min-height: 0; padding: 0; max-width: none; }

.wpills { order: 1; display: flex; gap: 6px; overflow-x: auto; padding: 10px 12px 0; scrollbar-width: none; flex: none; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex: none;
}
.pill:hover { color: var(--text); border-color: var(--text-3); }
.pill.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.pill .dot { width: 9px; height: 9px; }

.widget .stats { order: 2; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 10px 12px 0; flex: none; }
.widget .stat { padding: 8px 9px; gap: 8px; border-radius: 12px; }
.widget .stat-ic { width: 30px; height: 30px; border-radius: 9px; }
.widget .stat-ic svg.ic { width: 17px; height: 17px; }
.widget .stat-l { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.widget .stat-v { font-size: 16px; white-space: nowrap; }
.widget .stat-s { display: none; }
.widget .bar { margin-top: 3px; height: 5px; }

.widget .matrix {
  order: 3;
  flex: 1;
  min-height: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 8px;
  padding: 10px 12px;
}
.widget .quad { min-height: 0; border-radius: 12px; }
.widget .quad-h { padding: 6px 10px; }
.widget .quad-h h2 { font-size: 13.5px; flex: 1; }
.widget .quad-h .hint { display: none; }
.widget .tasks { overflow-y: auto; min-height: 0; padding: 4px 4px 6px; }
.widget .task { gap: 6px; padding: 1px 2px; }
.widget .task .grip { display: none; }
.widget .task .check { width: 16px; height: 16px; }
.widget .task-title { font-size: 13.5px; padding: 4px 1px; }
.widget .task .due { font-size: 11.5px; }
.widget .task { position: relative; }
.widget .task .more { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; opacity: 0; background: var(--q-bg); box-shadow: 0 0 0 1px var(--q-line); }
.widget .task:hover .more, .widget .task .more:focus-visible { opacity: 1; }
.widget .tasks .empty { font-size: 12.5px; padding: 8px 6px; }

.widget .add { order: 4; position: static; margin: 0; padding: 8px 12px 10px; background: var(--surface); border-top: 1px solid var(--line); flex: none; }
.widget .add-row { gap: 6px; }
.widget .add-row #add-title { flex: 1 1 100%; }
.widget .add-row select { flex: 1 1 0; }
.widget .add-row #add-date { display: none; }
.widget .add-row .btn { flex: none; }
.widget .add-row input, .widget .add-row select, .widget .add-row .btn { height: 34px; }

.widget .toast { bottom: 96px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
