:root {
  --blue: #2b88d9;
  --red: #d74e48;
  --star: #e8453c;
  --text: #262626;
  --muted: #737373;
  --line: #e6e6e6;
  --side-bg: #f7f7f7;
  --row-bg: rgba(255, 255, 255, 0.96);
  --row-done: rgba(255, 255, 255, 0.72);
  --bg: linear-gradient(135deg, #3a7bd5 0%, #3a6073 100%);
  --side-w: 280px;
  --detail-w: 380px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); background-size: cover; background-attachment: fixed; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--red); min-height: 1em; margin: 0; font-size: 14px; }

/* ---------- auth ---------- */
.auth { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; }
.auth-card { background: #fff; border-radius: 10px; padding: 28px; width: min(360px, 100%); display: grid; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.auth-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 6px; font-size: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 700; color: var(--blue); }
.brand img { width: 36px; height: 36px; }
.btn { border: 0; border-radius: 6px; padding: 10px 14px; background: #eee; }
.btn.primary { background: var(--blue); color: #fff; font-weight: 600; }
.btn.danger { background: var(--red); color: #fff; }
.link { background: none; border: 0; color: var(--blue); padding: 4px; }

/* ---------- layout ---------- */
.app { display: flex; height: 100%; }
.sidebar {
  width: var(--side-w); flex: none; background: var(--side-bg); display: flex; flex-direction: column;
  border-right: 1px solid rgba(0,0,0,.08); padding-top: var(--safe-top); padding-bottom: var(--safe-bot); z-index: 30;
}
.side-top { display: flex; align-items: center; background: var(--blue); color: #fff; height: 50px; padding: 0 6px 0 10px; flex: none; }
.user-btn { flex: 1; display: flex; align-items: center; gap: 8px; background: none; border: 0; color: #fff; font-weight: 600; text-align: left; padding: 6px; min-width: 0; }
.user-btn #user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,.25); display: grid; place-items: center; font-size: 13px; text-transform: uppercase; flex: none; }
.chev { opacity: .7; font-size: 11px; }
.icon-btn { background: none; border: 0; width: 38px; height: 38px; border-radius: 6px; font-size: 18px; display: grid; place-items: center; flex: none; }
.side-top .icon-btn { color: #fff; font-size: 22px; }
.icon-btn:hover { background: rgba(0,0,0,.06); }
.side-top .icon-btn:hover { background: rgba(255,255,255,.15); }
.search-wrap { padding: 8px; border-bottom: 1px solid var(--line); }
.search-wrap input { width: 100%; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); font-size: 16px; }
.lists { display: flex; flex-direction: column; padding: 6px 0; }
.user-lists { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
.list-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px; border: 0; background: none; text-align: left;
  width: 100%; border-left: 3px solid transparent; user-select: none;
}
.list-item:hover { background: rgba(0,0,0,.04); }
.list-item.active { background: rgba(43,136,217,.12); border-left-color: var(--blue); font-weight: 600; }
.list-item .li-ico { width: 22px; text-align: center; flex: none; }
.list-item .li-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-count { color: var(--muted); font-size: 13px; }
.list-item .li-shared { font-size: 12px; opacity: .6; }
.list-item.drag-over { box-shadow: inset 0 2px 0 var(--blue); }
.list-item.drop-target { background: rgba(43,136,217,.22); }
.create-list { border: 0; border-top: 1px solid var(--line); background: none; padding: 14px; text-align: left; color: var(--blue); font-weight: 600; flex: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding-top: var(--safe-top); }
.main-head { display: flex; align-items: center; gap: 6px; padding: 8px 14px; height: 54px; flex: none; color: #fff; }
.main-head h1 { flex: 1; margin: 0; font-size: 21px; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.35); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main-head .icon-btn { color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.35); }
.main-head .icon-btn:hover { background: rgba(255,255,255,.18); }
.menu-btn { display: none !important; }
.head-actions { display: flex; gap: 2px; }

.add-task { margin: 0 14px 8px; display: flex; align-items: center; background: rgba(255,255,255,.22); border-radius: 6px; transition: background .15s; flex: none; }
.add-task:focus-within { background: var(--row-bg); }
.add-task .plus { width: 42px; text-align: center; color: #fff; font-size: 18px; }
.add-task:focus-within .plus { color: var(--blue); }
.add-task input { flex: 1; border: 0; background: none; padding: 13px 0; outline: none; color: #fff; font-size: 16px; min-width: 0; }
.add-task input::placeholder { color: rgba(255,255,255,.88); }
.add-task:focus-within input { color: var(--text); }
.add-task:focus-within input::placeholder { color: var(--muted); }
.star-toggle { background: none; border: 0; width: 42px; font-size: 18px; color: rgba(255,255,255,.9); }
.add-task:focus-within .star-toggle { color: var(--muted); }
.star-toggle.on, .add-task:focus-within .star-toggle.on { color: var(--star); }

.task-scroll { flex: 1; overflow-y: auto; padding: 0 14px calc(24px + var(--safe-bot)); -webkit-overflow-scrolling: touch; }
.tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.task {
  display: flex; align-items: center; gap: 4px; background: var(--row-bg); border-radius: 4px; min-height: 46px; padding: 2px 4px;
  cursor: pointer; user-select: none; transition: transform .12s, opacity .2s;
}
.task.selected { background: #e5f1fb; }
.task.dragging { opacity: .4; }
.task.drag-over { box-shadow: 0 -2px 0 var(--blue); }
.task .t-main { flex: 1; min-width: 0; padding: 6px 4px; }
.task .t-title { overflow-wrap: anywhere; line-height: 1.3; }
.task .t-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); margin-top: 2px; }
.task .t-meta:empty { display: none; }
.task .overdue { color: var(--red); }
.task .due-today { color: var(--blue); }
.done .task { background: var(--row-done); }
.done .task .t-title { text-decoration: line-through; color: var(--muted); }
.task.completing { animation: pop .35s ease; }
@keyframes pop { 50% { transform: scale(1.02); } }

.check { position: relative; width: 40px; height: 40px; display: grid; place-items: center; flex: none; cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.check span { width: 20px; height: 20px; border: 2px solid #b3b3b3; border-radius: 3px; display: grid; place-items: center; transition: all .15s; background: #fff; }
.check:hover span { border-color: var(--blue); }
.check input:checked + span { background: var(--blue); border-color: var(--blue); }
.check input:checked + span::after { content: ""; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.star { background: none; border: 0; width: 40px; height: 40px; font-size: 19px; color: #b3b3b3; flex: none; }
.star.on { color: var(--star); }
.task .star.on::before { content: ""; }

.show-done { display: block; margin: 14px 0 8px; background: rgba(0,0,0,.28); color: #fff; border: 0; border-radius: 4px; padding: 6px 12px; font-size: 13px; }
.empty { color: #fff; text-align: center; padding: 60px 20px; text-shadow: 0 1px 3px rgba(0,0,0,.35); font-size: 17px; }

/* ---------- detail ---------- */
.detail {
  width: 0; flex: none; background: #fafafa; border-left: 1px solid rgba(0,0,0,.08); display: flex; flex-direction: column;
  overflow: hidden; transition: width .2s ease; padding-top: var(--safe-top); z-index: 20;
}
.detail.open { width: var(--detail-w); }
.detail > * { min-width: var(--detail-w); }
.detail-head { display: flex; align-items: flex-start; gap: 2px; padding: 8px 6px; background: #fff; border-bottom: 1px solid var(--line); }
.detail-head textarea { flex: 1; border: 0; resize: none; font-size: 18px; font-weight: 600; padding: 8px 4px; outline: none; background: none; overflow: hidden; line-height: 1.35; }
.detail-head .check, .detail-head .star { margin-top: 0; }
.detail-body { flex: 1; overflow-y: auto; padding: 6px 14px 20px; -webkit-overflow-scrolling: touch; }
.detail .row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.detail .row .ico { width: 22px; text-align: center; }
.detail .row label { width: 58px; color: var(--muted); font-size: 13px; }
.detail .row input, .detail .row select { flex: 1; min-width: 0; border: 1px solid transparent; background: none; padding: 6px; border-radius: 4px; font-size: 15px; }
.detail .row input:hover, .detail .row select:hover, .detail .row input:focus, .detail .row select:focus { border-color: var(--line); background: #fff; outline: none; }
.detail .clear { background: none; border: 0; color: var(--muted); width: 28px; height: 28px; border-radius: 4px; }
.detail .clear:hover { background: #eee; }
.detail h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 6px; }
.subtasks { list-style: none; margin: 0; padding: 0; }
.subtasks li { display: flex; align-items: center; gap: 2px; border-bottom: 1px solid var(--line); }
.subtasks li .check { width: 34px; height: 36px; }
.subtasks li .check span { width: 17px; height: 17px; }
.subtasks li input.s-title { flex: 1; border: 0; background: none; padding: 8px 4px; outline: none; min-width: 0; }
.subtasks li.done input.s-title { text-decoration: line-through; color: var(--muted); }
.subtasks li .s-del { background: none; border: 0; color: var(--muted); opacity: 0; width: 30px; height: 30px; }
.subtasks li:hover .s-del { opacity: 1; }
.sub-add { display: flex; align-items: center; }
.sub-add .plus { width: 34px; text-align: center; color: var(--blue); }
.sub-add input { flex: 1; border: 0; background: none; padding: 10px 4px; outline: none; }
#d-notes { width: 100%; min-height: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 10px; resize: vertical; background: #fffef3; outline: none; line-height: 1.45; }
.detail-foot { display: flex; align-items: center; gap: 8px; padding: 6px 8px calc(6px + var(--safe-bot)); border-top: 1px solid var(--line); background: #fff; }
.detail-foot .muted { flex: 1; text-align: center; }
.icon-btn.danger:hover { background: #fdecea; }

/* ---------- modal / menus / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal-card { background: #fff; border-radius: 10px; width: min(440px, 100%); max-height: 88vh; overflow-y: auto; padding: 20px; display: grid; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card h4 { margin: 8px 0 0; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.modal-card input, .modal-card select { padding: 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 16px; width: 100%; }
.modal-card .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-card .inline { display: flex; gap: 8px; }
.modal-card .inline input { flex: 1; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.member .avatar { background: var(--blue); color: #fff; }
.member span.name { flex: 1; }
.menu-list { display: grid; gap: 2px; }
.menu-list button { text-align: left; background: none; border: 0; padding: 11px 10px; border-radius: 6px; }
.menu-list button:hover { background: #f2f2f2; }
.menu-list button.danger { color: var(--red); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 44px; height: 32px; border-radius: 6px; border: 2px solid transparent; }
.swatch.on { border-color: var(--text); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bot)); transform: translateX(-50%); background: #333; color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 200; display: flex; gap: 14px; align-items: center; max-width: 90vw; }
.toast button { background: none; border: 0; color: #8cc4ff; font-weight: 600; }
.scrim { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .detail { position: fixed; right: 0; top: 0; bottom: 0; box-shadow: -4px 0 20px rgba(0,0,0,.15); }
}
@media (max-width: 760px) {
  :root { --detail-w: 100vw; }
  .menu-btn { display: grid !important; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .22s ease; box-shadow: 4px 0 20px rgba(0,0,0,.2); width: min(var(--side-w), 85vw); }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .main-head { padding: 8px; }
  .add-task { margin: 0 8px 8px; }
  .task-scroll { padding-left: 8px; padding-right: 8px; }
  .detail { transition: transform .22s ease; width: 100vw; transform: translateX(100%); }
  .detail.open { width: 100vw; transform: none; }
  .subtasks li .s-del { opacity: 1; }
}
