:root {
  --accent: #dc4c3e;
  --accent-dark: #b03d32;
  --accent-soft: #ffefe5;
  --bg: #ffffff;
  --side: #fcfaf8;
  --hover: #f2efed;
  --text: #202020;
  --muted: #808080;
  --line: #eeeeee;
  --overdue: #d1453b;
  --today: #058527;
  --tomorrow: #ad6200;
  --week: #692ec2;
  --later: #808080;
  --chip: #f1f1f1;
  --radius: 8px;
  --side-w: 280px;
  --panel-w: 440px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
input, select, textarea {
  border: 1px solid #ddd; border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #999; }
textarea { resize: vertical; }
code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
kbd { border: 1px solid #ddd; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; color: var(--muted); background: #fff; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 4px 12px; margin: 0; }
.err { color: var(--overdue); min-height: 1.2em; margin: 6px 0; }
.boot { padding: 40px; color: var(--muted); }

/* ---------- Layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--side-w); flex: none; background: var(--side); padding: 10px 10px 0;
  overflow-y: auto; display: flex; flex-direction: column; border-right: 1px solid #f3f0ee;
}
.main { flex: 1; overflow-y: auto; min-width: 0; }
.view { max-width: 820px; margin: 0 auto; padding: 28px 40px 120px; }
.topbar { display: none; }
.scrim { display: none; }

/* ---------- Sidebar ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 6px 12px; }
.brand span { flex: 1; }
.brand.big { font-size: 22px; justify-content: center; }
.brand.big span { flex: none; }
.addtask {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border-radius: 6px;
  color: var(--accent); font-weight: 600; margin-bottom: 4px;
}
.addtask svg { background: var(--accent); color: #fff; border-radius: 50%; padding: 2px; }
.addtask span { flex: 1; text-align: left; }
.addtask:hover { background: var(--hover); }
.nav {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 6px; cursor: pointer;
  color: var(--text); text-decoration: none; user-select: none;
}
.nav svg { color: var(--muted); flex: none; }
.nav .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .cnt { color: var(--muted); font-size: 12px; }
.nav:hover { background: var(--hover); }
.nav.active { background: var(--accent-soft); color: var(--accent-dark); }
.nav.active svg { color: var(--accent); }
.nav.drop-hover { background: var(--accent-soft); outline: 2px dashed var(--accent); }
.navh {
  display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-weight: 600;
  font-size: 12.5px; padding: 16px 8px 4px;
}
.sfoot { margin-top: auto; padding: 14px 0 12px; border-top: 1px solid #f0ebe8; position: sticky; bottom: 0; background: var(--side); }
.who { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 0; gap: 8px; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 4px 8px; border-radius: 6px; width: 100%; text-align: left; }
.status:hover { background: var(--hover); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #bbb; flex: none; }
.status.synced .dot { background: var(--today); }
.status.syncing .dot { background: var(--tomorrow); animation: pulse 1s infinite alternate; }
.status.offline .dot { background: #999; }
.status.error .dot { background: var(--overdue); }
.status.pending .dot { background: var(--tomorrow); }
.status.error { color: var(--overdue); }
@keyframes pulse { to { opacity: .3; } }

.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 6px; color: var(--muted); flex: none; }
.iconbtn:hover { background: var(--hover); color: var(--text); }
.iconbtn.sm { width: 24px; height: 24px; }

/* ---------- View header ---------- */
.vh { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.vh h1 { font-size: 24px; margin: 0; flex: 1; font-weight: 700; }
.optbar { display: flex; gap: 14px; margin: -4px 0 14px; flex-wrap: wrap; }
.opt { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.opt select { width: auto; padding: 3px 6px; font-size: 12.5px; }
.searchbar { display: flex; align-items: center; gap: 8px; border: 1px solid #ddd; border-radius: 8px; padding: 0 10px; margin-bottom: 16px; color: var(--muted); }
.searchbar input { border: 0; padding: 9px 0; }
.tagbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.tagbar select { width: auto; padding: 4px 8px; }
.seg { display: inline-flex; border: 1px solid #ddd; border-radius: 6px; overflow: hidden; }
.seg button { padding: 3px 10px; font-size: 12.5px; }
.seg button.on { background: var(--text); color: #fff; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Week strip */
.strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 18px; }
.strip button { display: flex; flex-direction: column; align-items: center; padding: 6px 0; border-radius: 8px; color: var(--muted); font-size: 12px; }
.strip button b { font-size: 16px; color: var(--text); }
.strip button i { width: 5px; height: 5px; border-radius: 50%; margin-top: 3px; }
.strip button i.has { background: var(--accent); }
.strip button.tod b { color: var(--accent); }
.strip button:hover { background: var(--hover); }

/* ---------- Sections & tasks ---------- */
.sec { margin-bottom: 22px; scroll-margin-top: 10px; }
.sec-h { font-size: 14px; margin: 0; padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; align-items: baseline; gap: 8px; }
.sec-h .sub { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.sec-h .cnt { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: auto; }
.sec-h.overdue { color: var(--overdue); }
.tasks { list-style: none; margin: 0; padding: 0; }
.task {
  display: flex; align-items: flex-start; gap: 6px; padding: 9px 0 9px; border-bottom: 1px solid var(--line);
  position: relative; background: var(--bg);
}
.task:hover .drag { opacity: 1; }
.task.selected { background: #fafafa; }
.task.dragging { opacity: .35; }
.drag { opacity: 0; color: #aaa; cursor: grab; touch-action: none; margin-left: -26px; padding: 1px 2px; display: flex; }
.check {
  width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid #999; flex: none; margin-top: 1px; position: relative;
}
.check:hover::after, .check.on::after, .task.done .check::after {
  content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px; border: solid #999; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
}
.task.done .check, .check.on { background: #999; border-color: #999; }
.task.done .check::after, .check.on::after { border-color: #fff; }
.task.checking .check { background: var(--accent); border-color: var(--accent); }
.task.done .ttitle { text-decoration: line-through; color: var(--muted); }
.check.big { width: 22px; height: 22px; margin-top: 6px; }
.check.big::after { left: 7px !important; top: 3px !important; }
.tbody { flex: 1; min-width: 0; cursor: pointer; padding-left: 4px; }
.ttitle { word-wrap: break-word; }
.tdesc { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tmeta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 12px; margin-top: 3px; }
.tmeta span { display: inline-flex; align-items: center; gap: 3px; }
.tproj { color: var(--muted); margin-left: auto; }
.due.overdue { color: var(--overdue); }
.due.today { color: var(--today); }
.due.tomorrow { color: var(--tomorrow); }
.due.week { color: var(--week); }
.due.later { color: var(--later); }
.tagchip {
  display: inline-flex; align-items: center; gap: 4px; background: var(--chip); color: #555; border-radius: 10px;
  padding: 0 8px; font-size: 12px; line-height: 20px;
}
button.tagchip:hover { background: #e4e4e4; }
.tagchip.on { background: #fdeceb; color: var(--accent-dark); }
.tagchip.on button { color: inherit; font-size: 14px; line-height: 1; }
.addrow { display: flex; align-items: center; gap: 8px; color: var(--muted); padding: 8px 0; width: 100%; }
.addrow svg { color: var(--accent); }
.addrow:hover { color: var(--accent); }
.ghost { position: fixed; z-index: 50; pointer-events: none; box-shadow: 0 6px 24px rgba(0,0,0,.18); border-radius: 6px; padding-left: 8px; opacity: .95; }

/* Columns (board) layout */
.view.wide { max-width: none; }
.board {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(270px, 1fr); gap: 14px;
  overflow-x: auto; align-items: start; padding-bottom: 12px; scroll-snap-type: x proximity;
}
.board .sec {
  background: #faf9f8; border: 1px solid #f0edeb; border-radius: 10px; padding: 4px 12px 6px; margin: 0;
  scroll-snap-align: start; min-width: 0;
}
.board .sec-h { flex-wrap: wrap; position: sticky; top: 0; background: #faf9f8; z-index: 1; }
.board .task { background: transparent; }
.board .drag { margin-left: 0; }
.board .tproj { margin-left: 0; }
.sec.drop-hover { outline: 2px dashed var(--accent); outline-offset: 2px; border-radius: 10px; }
.vh .seg button { padding: 4px 12px; }

/* ---------- Panel (task detail / vault entry) ---------- */
.panel {
  width: var(--panel-w); flex: none; border-left: 1px solid var(--line); overflow-y: auto; background: #fff;
  display: flex; flex-direction: column;
}
.panel[hidden] { display: none; }
.ph { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.crumb { color: var(--muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.pbody { padding: 14px 18px 40px; }
.prow { display: flex; gap: 10px; align-items: flex-start; }
.ptitle { font-size: 18px; font-weight: 600; border-color: transparent; resize: none; overflow: hidden; padding: 4px 6px; }
.ptitle:hover { border-color: #eee; }
.pdesc { border-color: transparent; margin: 4px 0 10px 26px; width: calc(100% - 26px); color: #444; }
.pdesc:hover { border-color: #eee; }
.pgrid { display: grid; grid-template-columns: 76px 1fr; gap: 10px 10px; align-items: center; margin: 8px 0 16px; }
.pgrid > label { color: var(--muted); font-size: 12.5px; }
.inl { display: flex; gap: 6px; align-items: center; }
.inl input { flex: 1; min-width: 0; }
.chip { border: 1px solid #ddd; border-radius: 14px; padding: 2px 9px; font-size: 12px; white-space: nowrap; }
.chip:hover { background: var(--hover); }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.hint.err { color: var(--overdue); }
.tagedit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tagedit input { flex: 1; min-width: 120px; padding: 4px 8px; }
.pact { display: flex; gap: 8px; margin: 10px 0 20px; flex-wrap: wrap; }
.btn { border: 1px solid #ddd; border-radius: 6px; padding: 6px 12px; background: #fff; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { color: var(--overdue); }
.btn.wide { width: 100%; justify-content: center; padding: 9px; }
.panel h4 { margin: 10px 0 6px; font-size: 13px; }
.comments { list-style: none; margin: 0 0 10px; padding: 0; }
.comments li { border-bottom: 1px solid var(--line); padding: 6px 0; }
.cmeta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; }
.cbody { white-space: pre-wrap; word-wrap: break-word; }
.cadd { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; margin-bottom: 14px; }

/* ---------- Modal / quick add ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.modal[hidden] { display: none; }
.mback { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.qa { position: relative; background: #fff; border-radius: 10px; width: min(560px, calc(100vw - 24px)); padding: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25); max-height: 80vh; overflow-y: auto; }
.qa > input { border: 0; font-size: 16px; font-weight: 600; padding: 6px 4px; }
.qa > textarea { border: 0; padding: 2px 4px; color: #555; resize: none; }
.qaprev { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 4px; min-height: 4px; }
.pv { display: inline-flex; align-items: center; gap: 4px; border: 1px solid #ddd; border-radius: 6px; padding: 1px 8px; font-size: 12px; }
.pv.tag { color: var(--accent-dark); border-color: #f4c9c4; }
.qafoot { display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 8px; }
.qafoot select { width: auto; max-width: 45%; }
.sp { flex: 1; }
.qahelp { color: var(--muted); font-size: 11.5px; margin: 8px 4px 0; }
.help h2 { margin: 4px 0 8px; font-size: 18px; }
.help h4 { margin: 14px 0 6px; }
.help ul { margin: 0; padding-left: 18px; }
.help li { margin: 4px 0; }
.help td { padding: 3px 12px 3px 0; }

/* ---------- Toast & popover ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #282828; color: #fff; border-radius: 8px;
  padding: 10px 14px; display: flex; gap: 16px; align-items: center; z-index: 60; box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.toast button { color: #ff9a8f; font-weight: 700; }
.pop { position: fixed; z-index: 45; background: #fff; border: 1px solid #e5e5e5; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: 4px; min-width: 170px; }
.pop[hidden] { display: none; }
.pop button { display: block; width: 100%; text-align: left; padding: 7px 10px; border-radius: 5px; }
.pop button:hover { background: var(--hover); }
.pop .danger { color: var(--overdue); }

/* ---------- Cards, login, vault ---------- */
.card { border: 1px solid var(--line); border-radius: 10px; padding: 18px; background: #fff; }
.vform { max-width: 440px; display: flex; flex-direction: column; gap: 12px; }
.vform label, .login label, .vedit label { display: flex; flex-direction: column; gap: 4px; color: #555; font-size: 13px; }
.vform .chk { flex-direction: row; align-items: flex-start; gap: 8px; }
.vform .chk input { width: auto; margin-top: 3px; }
.vform p { margin: 0; }
.vlist { list-style: none; padding: 0; margin: 0 0 12px; }
.ventry { display: flex; gap: 10px; align-items: center; padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 6px; }
.ventry:hover, .ventry.selected { background: #fafafa; }
.vico { color: var(--accent); display: flex; }
.vedit { display: flex; flex-direction: column; gap: 12px; }
.login { position: fixed; inset: 0; background: var(--side); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.06); }
.login h1 { font-size: 18px; margin: 0; text-align: center; }
.fab { display: none; }

/* ---------- Mobile (phones & narrow windows) ---------- */
@media (max-width: 900px) {
  :root { --panel-w: 380px; }
  .view { padding: 20px 22px 120px; }
}
@media (max-width: 760px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%); transition: transform .2s ease;
    width: min(var(--side-w), 85vw); visibility: hidden;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  body.nav-open .sidebar { transform: none; visibility: visible; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 25; }
  .topbar {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
    position: sticky; top: 0; background: rgba(255,255,255,.96); z-index: 5; border-bottom: 1px solid var(--line);
  }
  .topbar #topTitle { flex: 1; font-weight: 700; font-size: 16px; }
  .view { padding: 14px 16px 120px; }
  .vh h1 { display: none; }
  .vh { justify-content: flex-end; }
  .vh:empty, .vh:not(:has(button)) { display: none; }
  .panel { position: fixed; inset: 0; width: 100%; z-index: 35; border: 0; }
  .fab {
    display: flex; position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 56px; height: 56px;
    border-radius: 50%; background: var(--accent); color: #fff; align-items: center; justify-content: center;
    box-shadow: 0 4px 14px rgba(220,76,62,.45); z-index: 20;
  }
  .fab svg { width: 26px; height: 26px; }
  body.panel-open .fab { display: none; }
  .drag { opacity: 1; margin-left: 0; color: #ccc; }
  .check { width: 20px; height: 20px; }
  .modal { padding-top: 0; align-items: flex-end; }
  .qa { width: 100%; border-radius: 14px 14px 0 0; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(86px + env(safe-area-inset-bottom)); }
  .pgrid { grid-template-columns: 64px 1fr; }
  input, select, textarea { font-size: 16px; } /* stops Android zooming in on focus */
  .opt select { font-size: 14px; }
  .addtask kbd { display: none; }
  .board { grid-auto-columns: 86vw; scroll-snap-type: x mandatory; }
}
