:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1d222c;
  --line: #2a3040;
  --text: #e8ecf3;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --danger: #ff6b6b;
  --ok: #51cf66;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
.error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; font-size: .9rem; }

body.light {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel2: #eef0f4;
  --line: #d8dce4;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #3b74e8;
  --danger: #d63c3c;
  --ok: #2f9e44;
}

body.viewer .viewer-only,
body.not-owner .owner-only,
body.viewer .viewer-block { display: none !important; }

button, input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .75rem;
}

button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover, button.ghost.active { color: var(--text); border-color: var(--muted); }
button.small { padding: .15rem .5rem; font-size: .78rem; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; width: 100%; }

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.5rem;
  display: grid;
  gap: .75rem;
}

.auth-card h1 { margin: 0; font-size: 1.6rem; }
.auth-card p { margin: 0; }
.auth-card label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
.auth-card input { width: 100%; }

.tabs { display: flex; gap: .5rem; }
.tab { flex: 1; background: transparent; color: var(--muted); }
.tab.active { background: var(--panel2); color: var(--text); border-color: var(--accent); }

.app { display: flex; min-height: 100dvh; }

aside {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1rem .75rem;
  gap: .75rem;
}

.side-head { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }

.side-head strong { font-size: 1.1rem; }

.projects {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: .25rem;
  overflow-y: auto;
}

.projects li {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .5rem .6rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}

.projects li:hover { background: var(--panel2); }
.projects li.active { background: var(--panel2); border-color: var(--accent); }
.projects li.over { border-color: var(--accent); border-style: dashed; }
.projects li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot {
  width: .7rem;
  height: .7rem;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, .25);
}
body.not-owner .projects li .dot { visibility: hidden; }
body.not-owner .projects li.active .dot { visibility: hidden; }

.new-project { display: flex; gap: .4rem; margin-top: auto; }
.new-project input { min-width: 0; flex: 1; }

main {
  flex: 1;
  padding: 1.25rem clamp(1rem, 4vw, 2.5rem);
  max-width: 1000px;
}

.main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.main-head h1 { margin: 0; font-size: 1.5rem; overflow-wrap: anywhere; }
.head-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin: .9rem 0;
}

.filters { display: flex; flex-wrap: wrap; gap: .3rem; }

.chip {
  background: transparent;
  color: var(--muted);
  padding: .3rem .65rem;
  font-size: .85rem;
  border-radius: 999px;
}
.chip.active { background: var(--panel2); color: var(--text); border-color: var(--accent); }

.search-wrap { position: relative; flex: 1; min-width: 150px; }
.search-wrap input { width: 100%; }

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  z-index: 20;
  max-height: 300px;
  overflow: auto;
  display: grid;
}

.search-hit {
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: .55rem .7rem;
  font-size: .9rem;
}
.search-hit:hover { background: var(--panel2); }

.view-toggle { display: flex; gap: .25rem; }

.new-todo { display: flex; gap: .5rem; margin: .5rem 0 1rem; flex-wrap: wrap; }
.new-todo input[name=title] { flex: 1; min-width: 160px; }
.new-todo input[type=date] { width: 9.5rem; }
.new-todo select { width: 11rem; }

.todos {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: .5rem;
  min-height: 120px;
}

.todos.over, .todo.over, .col.over {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  border-radius: 10px;
}

.todo {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .7rem .8rem;
}

.todo.dragging { opacity: .5; }
.todo > input[type="checkbox"] { margin-top: .25rem; width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.todo .body { flex: 1; min-width: 0; display: grid; gap: .35rem; }

.todo .title { cursor: pointer; overflow-wrap: anywhere; }
.todo.done .title { text-decoration: line-through; color: var(--muted); }

.due {
  font-size: .72rem;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .05rem .45rem;
  color: var(--muted);
  cursor: pointer;
}
.due.late { color: var(--danger); border-color: var(--danger); }

.prio { color: var(--danger); font-size: .75rem; vertical-align: 1px; }
.prio.low { color: var(--muted); }

.tag {
  display: inline-block;
  font-size: .72rem;
  color: var(--accent);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .02rem .45rem;
  margin-left: .25rem;
  cursor: pointer;
}

.badge {
  font-size: .68rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .02rem .4rem;
  margin-left: .25rem;
}

.meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.assignee { font-size: .8rem; color: var(--accent); }
.todo.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.todo.prio-high .title { border-left: 3px solid var(--danger); padding-left: .4rem; }
.todo.drop-before { box-shadow: 0 -3px 0 var(--accent); }

.undo-bar {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .6rem .9rem;
  display: flex;
  gap: 1rem;
  align-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  z-index: 50;
}

.keys-hint { margin-top: 1.5rem; }
.keys-hint kbd {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .05rem .3rem;
  font-size: .75rem;
}

.codes {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem;
  font-family: ui-monospace, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

.row.end { justify-content: flex-end; }

.rec { color: var(--accent); font-size: .9rem; cursor: default; }

.todo .notes {
  color: var(--muted);
  font-size: .9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: pointer;
  max-height: 6.5em;
  overflow: auto;
}

.todo details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .35rem .55rem;
  background: var(--panel2);
  font-size: .9rem;
}
.todo details summary { cursor: pointer; color: var(--muted); font-size: .82rem; }
.todo details ul { list-style: none; margin: .4rem 0; padding: 0; display: grid; gap: .25rem; }
.todo details li { display: flex; gap: .45rem; align-items: center; }
.todo details li.done span { text-decoration: line-through; color: var(--muted); }
.todo details li span { flex: 1; }
.todo details .del-sub { border: none; background: transparent; color: var(--muted); padding: 0 .25rem; }
.todo details .del-sub:hover { color: var(--danger); }
.todo details form { display: flex; gap: .4rem; margin-top: .3rem; }
.todo details form input { flex: 1; min-width: 0; padding: .3rem .5rem; font-size: .85rem; }

.comments ul li { border-top: 1px solid var(--line); padding: .35rem 0; }
.comments ul li:first-child { border-top: none; }
.comments ul li div { overflow-wrap: anywhere; }

.files { display: flex; flex-wrap: wrap; gap: .35rem; }

.files a {
  font-size: .8rem;
  color: var(--accent);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .15rem .6rem;
  text-decoration: none;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0 .3rem;
  border-radius: 999px;
}
.files button:hover { color: var(--danger); }

.todo > .del {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 0 .3rem;
  line-height: 1;
}
.todo > .del:hover { color: var(--danger); }

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .75rem;
  align-items: start;
  min-height: 200px;
}

.col {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .6rem;
  min-height: 140px;
}
.col h2 { margin: 0 0 .5rem; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.col-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.col .todo { padding: .5rem .6rem; }
.col .todo .title { font-size: .92rem; }

.drop-hint {
  margin-top: 1rem;
  padding: 1.25rem;
  border: 2px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  font-size: .95rem;
}

main.over .drop-hint { border-color: var(--accent); color: var(--accent); }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem;
  width: min(420px, calc(100vw - 2rem));
}

dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 .75rem; font-size: 1.15rem; }
dialog h3 { margin: .5rem 0 .3rem; font-size: .95rem; color: var(--muted); }
dialog form, dialog > div { display: grid; gap: .75rem; }
dialog label { display: grid; gap: .3rem; font-size: .88rem; color: var(--muted); }
dialog select, dialog input { width: 100%; }
dialog .grid2 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); align-items: end; }
dialog .grid2 button, dialog .grid2 .muted { align-self: end; }
dialog label.check { display: flex; align-items: center; gap: .45rem; }
dialog label.check input { width: auto; }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 0; font-size: .85rem; justify-self: start; cursor: pointer; }
#adminConfig { border-top: 1px solid var(--line); padding-top: .5rem; margin-top: .25rem; }
#adminConfig code { font-size: .8rem; }

.members { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.members li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .4rem .6rem;
  font-size: .95rem;
}
.members select { padding: .2rem .4rem; font-size: .85rem; }

.row { display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; }
.row input, .row select { flex: 1; min-width: 0; }

.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; max-height: 50vh; overflow: auto; }
.activity li { font-size: .9rem; border-bottom: 1px solid var(--line); padding-bottom: .35rem; overflow-wrap: anywhere; }

#mailUrl { font-family: ui-monospace, monospace; font-size: .8rem; }

@media (max-width: 700px) {
  .app { flex-direction: column; }
  aside {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .projects {
    display: flex;
    overflow-x: auto;
    padding-bottom: .25rem;
  }
  .projects li { flex-shrink: 0; }
  .new-project { margin-top: 0; }
  .side-head #logout { margin-left: auto; }
  .board { grid-template-columns: 1fr; }
  .toolbar { gap: .4rem; }
}
