:root {
  --bg: #10131a;
  --bg2: #171b25;
  --bg3: #1f2432;
  --border: #2a3042;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --accent: #4f7cff;
  --danger: #e05b5b;
  --ok: #3fbf7f;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }

.btn {
  border: 1px solid var(--border); background: var(--bg3); color: var(--text);
  border-radius: 8px; padding: 8px 14px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.icon-btn {
  background: none; border: none; color: var(--muted); font-size: 20px;
  padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; }

/* ---------- login ---------- */
#login-view { display: flex; align-items: center; justify-content: center; height: 100vh; padding: 20px; }
.login-card {
  width: 320px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px 28px; display: flex; flex-direction: column; gap: 12px;
}
.login-logo {
  width: 52px; height: 52px; border-radius: 14px; background: var(--accent);
  color: #fff; font-size: 30px; display: flex; align-items: center; justify-content: center; margin: 0 auto;
}
.login-card h1 { margin: 0 0 8px; text-align: center; font-size: 20px; }
.login-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* ---------- layout ---------- */
#app-view { display: flex; height: 100vh; }
#sidebar {
  width: 250px; flex-shrink: 0; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 10px;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 12px; }
.side-title { font-weight: 700; font-size: 16px; }
#btn-close-side { display: none; }
.side-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); cursor: pointer; user-select: none;
}
.side-item:hover { background: var(--bg3); }
.side-item.active { background: var(--bg3); }
.side-item .dot {
  width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.side-item .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.grip {
  width: 10px; height: 17px; flex-shrink: 0; cursor: grab; opacity: 0;
  background-image: radial-gradient(var(--muted) 1.5px, transparent 1.6px);
  background-size: 5px 6px; background-position: 0 1px;
  transition: opacity .12s;
}
.side-item:hover .grip, .dash-col-head:hover .grip { opacity: .75; }
.grip:active { cursor: grabbing; }
.dragging { opacity: .35; }
.side-sep { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 14px 10px 6px; }
.side-hint { color: var(--muted); font-size: 12px; padding: 4px 10px; }
.side-add {
  background: none; border: none; color: var(--muted); text-align: left; padding: 8px 10px; border-radius: 8px;
}
.side-add:hover { background: var(--bg3); color: var(--text); }
.side-foot { margin-top: auto; padding: 10px 8px 4px; display: flex; flex-direction: column; gap: 10px; }
.side-user { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; }
.lock { font-size: 11px; margin-left: 4px; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#main-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 20px 8px;
}
#main-head h2 { margin: 0; font-size: 20px; flex: 1; }
#btn-open-side { display: none; }

#quick-wrap { padding: 6px 20px 4px; }
#quick-form { display: flex; gap: 8px; }
#quick-preview {
  margin-top: 6px; font-size: 13px; color: var(--muted);
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
#quick-preview b { color: var(--text); }
#quick-preview .sched { color: var(--accent); }

#task-area { flex: 1; overflow-y: auto; padding: 10px 20px 40px; }

/* ---------- tasks ---------- */
.group-head { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; margin: 18px 0 6px; }
.group-head.overdue { color: var(--danger); }
.task {
  display: flex; align-items: flex-start; gap: 11px; padding: 9px 10px;
  border-radius: 10px; cursor: pointer;
}
.task:hover { background: var(--bg2); }
.task .cb {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted);
  flex-shrink: 0; margin-top: 2px; background: none; padding: 0; color: transparent;
  font-size: 12px; line-height: 1;
}
.task .cb:hover { border-color: var(--ok); color: var(--ok); }
.task.done .cb { border-color: var(--ok); background: var(--ok); color: #fff; }
.task .body { flex: 1; min-width: 0; }
@keyframes task-flash { 0%, 100% { background: transparent; } 20% { background: rgba(79, 124, 255, .28); } }
.task.flash { animation: task-flash 1.4s ease; }
.task .title { word-break: break-word; }
.task.done .title { color: var(--muted); text-decoration: line-through; }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; font-size: 12px; color: var(--muted); }
.chip {
  background: var(--bg3); border-radius: 6px; padding: 1px 7px; white-space: nowrap;
}
.chip.due { color: var(--accent); }
.chip.overdue { color: var(--danger); }
.chip.recur { color: var(--ok); }
.chip.list-chip { display: inline-flex; align-items: center; gap: 5px; }
.chip .cdot { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }
.notes-preview { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { color: var(--muted); text-align: center; margin-top: 60px; }
.completed-toggle {
  background: none; border: none; color: var(--muted); font-size: 13px; padding: 6px 10px; margin-top: 14px;
}

/* ---------- modals ---------- */
/* every modal backdrop id ends in "modal-back" — overlay + center them all */
[id$="modal-back"] {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
  overflow-y: auto;
}
.modal {
  width: 420px; max-width: 100%; max-height: 92vh; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.modal .row { display: flex; gap: 8px; align-items: flex-end; }
.modal .grow, .grow { flex: 1; }
.check-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.check-label input { width: auto; }
.modal-actions { display: flex; gap: 8px; margin-top: 4px; }
.member-list { display: flex; flex-direction: column; gap: 6px; padding: 4px 2px; }
.member-list label {
  flex-direction: row !important; align-items: center; gap: 8px !important;
  color: var(--text); font-size: 14px;
}
.member-list input { width: auto; }
.weekday-row { display: flex; gap: 5px; }
.weekday-row button {
  flex: 1; padding: 7px 0; background: var(--bg3); border: 1px solid var(--border);
  color: var(--muted); border-radius: 7px; font-size: 12px;
}
.weekday-row button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- dashboard ---------- */
/* Upcoming panel above the dashboard board (collapsible) */
.upcoming-panel {
  border: 1px solid var(--border); background: var(--bg2);
  border-radius: 12px; margin-bottom: 14px; overflow: hidden;
}
.upcoming-panel.has-overdue {
  border-color: var(--danger); background: rgba(224, 91, 91, .07);
}
.upcoming-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; cursor: pointer; font: inherit; color: inherit;
  padding: 10px 12px; text-align: left;
}
.upcoming-head:hover { background: rgba(127, 127, 127, .07); }
.upcoming-head .chev { opacity: .6; width: 12px; }
.upcoming-head .uh-title { font-weight: 600; }
.upcoming-head .pill {
  margin-left: auto; font-size: 12px; opacity: .75;
  border: 1px solid var(--border); border-radius: 99px; padding: 1px 8px;
}
.upcoming-head .pill.overdue {
  margin-left: 0; color: var(--danger); border-color: var(--danger); opacity: 1;
}
.upcoming-body { padding: 0 10px 8px; }
.upcoming-body .group-head { margin: 10px 0 4px; }
.dash-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px; align-items: start;
}
.dash-col {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 8px 6px; min-height: 80px;
}
.dash-col-head {
  display: flex; align-items: center; gap: 8px; padding: 0 6px 8px; cursor: pointer;
}
.dash-col-head .cdot { width: 10px; height: 10px; border-radius: 4px; }
.dash-col-head .name { font-weight: 600; flex: 1; }
.dash-col-head .count { color: var(--muted); font-size: 12px; }
.dash-col .empty-col { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 0; }
.dash-add-row { display: flex; align-items: center; gap: 8px; padding: 6px 4px 2px; margin-top: 2px; }
.dash-add-row .cb.ghost {
  width: 20px; height: 20px; border-radius: 50%; border: 2px dashed var(--muted);
  flex-shrink: 0; background: none; color: var(--muted); font-size: 13px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.dash-add-input {
  flex: 1; min-width: 0; background: transparent; border: none; border-bottom: 1px solid transparent;
  border-radius: 0; padding: 5px 2px; font-size: 13px;
}
.dash-add-input::placeholder { color: var(--muted); }
.dash-add-input:focus { outline: none; border-bottom-color: var(--accent); }
.dash-add-row:focus-within .cb.ghost { border-color: var(--accent); color: var(--accent); }
.dash-add-cog {
  background: none; border: none; color: var(--muted); font-size: 15px;
  padding: 4px 5px; border-radius: 6px; flex-shrink: 0; cursor: pointer;
}
.dash-add-cog:hover { background: var(--bg3); color: var(--text); }
.dash-add { width: 100%; background: none; border: 1px dashed var(--border); color: var(--muted);
  border-radius: 8px; padding: 6px; margin-top: 4px; font-size: 13px; }
.dash-add:hover { color: var(--text); border-color: var(--muted); }

/* ---------- manage users ---------- */
.user-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.user-row .u-name { flex: 1; min-width: 120px; }
.user-row .u-uname { color: var(--muted); font-size: 12px; }
.user-row .u-admin { flex-direction: row !important; gap: 5px !important; color: var(--muted); font-size: 12px; }
.user-row .u-admin input { width: auto; }
.users-add { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.users-add h4 { margin: 4px 0; font-size: 14px; }
.you-tag { color: var(--accent); font-size: 11px; }

/* ---------- activity panel ---------- */
#activity-panel {
  width: 300px; flex-shrink: 0; background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.act-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--border);
}
.act-head #btn-activity-close { display: none; }
#activity-list { flex: 1; overflow-y: auto; padding: 6px 6px 30px; }
.act-item { padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.act-item:hover { background: var(--bg3); }
.act-text { font-size: 13px; line-height: 1.45; color: var(--muted); }
.act-text b { color: var(--text); font-weight: 600; }
.act-text .ttl { color: var(--text); }
.act-text .foryou { color: var(--accent); }
.act-when { color: var(--muted); font-size: 11px; margin-top: 3px; }
.act-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 12px; }
#btn-activity { display: none; } /* only shown when the panel can't fit alongside */

@media (max-width: 1180px) {
  #activity-panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 45; width: 300px; max-width: 85vw;
    transform: translateX(105%); transition: transform .18s ease; box-shadow: -4px 0 24px rgba(0,0,0,.4);
  }
  #activity-panel.open { transform: translateX(0); }
  .act-head #btn-activity-close { display: block; }
  #btn-activity { display: block; }
}

/* ---------- feed ---------- */
.feed-item {
  display: flex; gap: 11px; padding: 10px 10px; border-bottom: 1px solid var(--border);
  align-items: baseline;
}
.feed-item .who { color: var(--ok); font-weight: 600; white-space: nowrap; }
.feed-item .what { flex: 1; min-width: 0; }
.feed-item .what .tt { color: var(--text); }
.feed-item .what .ln { color: var(--muted); font-size: 12px; }
.feed-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; }
.cal-head h3 { margin: 0; flex: 1; text-align: center; font-size: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; color: var(--muted); font-size: 11px; text-transform: uppercase; padding: 2px 0; }
.cal-cell {
  min-height: 92px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px; font-size: 12px; overflow: hidden;
}
.cal-cell.other { opacity: .38; }
.cal-cell { cursor: pointer; position: relative; }
.cal-cell:hover { border-color: var(--muted); }
.cal-cell:hover::after {
  content: '+'; position: absolute; top: 2px; right: 6px;
  color: var(--muted); font-size: 13px; pointer-events: none;
}
.cal-ev { cursor: pointer; }
.cal-cell .dnum { color: var(--muted); font-size: 11px; padding: 1px 3px; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.today .dnum { color: var(--accent); font-weight: 700; }
.cal-ev {
  display: block; margin: 2px 0; padding: 1px 5px; border-radius: 5px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--bg3); border-left: 3px solid var(--accent); color: var(--text);
}
.cal-ev.done { text-decoration: line-through; opacity: .5; }
.cal-more { color: var(--muted); font-size: 11px; padding: 0 5px; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  #sidebar {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0;
    transform: translateX(-105%); transition: transform .18s ease; box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  #sidebar.open { transform: translateX(0); }
  #btn-open-side { display: block; }
  #btn-close-side { display: block; }
  #quick-wrap, #task-area { padding-left: 12px; padding-right: 12px; }
  .cal-cell { min-height: 58px; font-size: 10px; }
  .cal-cell .dnum { font-size: 10px; }
  #main-head { padding: 10px 12px 4px; }
}
