* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e2e6ef;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #4f8cff;
  --primary-hover: #3a72de;
  --danger: #ef4444;
  --shadow: 0 2px 8px rgba(17, 24, 39, 0.06);
  --shadow-lg: 0 8px 24px rgba(17, 24, 39, 0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar h1 { font-size: 20px; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; }
#btn-toggle-drawer {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
#btn-toggle-drawer.active {
  background: #eef4ff;
  border-color: var(--primary);
  color: var(--primary);
}
.drawer-icon { font-size: 16px; }
.drawer-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

button {
  padding: 7px 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { background: #f3f4f6; }
button:active { transform: translateY(1px); }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button.icon { padding: 3px 7px; font-size: 13px; }
button.ghost { background: transparent; }

/* ---------- Holding drawer ---------- */
.holding-drawer {
  position: fixed;
  top: 57px;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 45;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}
.holding-drawer.open { transform: translateX(0); }
.holding-drawer.drop-target {
  background: #eef4ff;
  box-shadow: inset 0 0 0 2px var(--primary), var(--shadow-lg);
}
.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-title { font-size: 14px; font-weight: 600; }
.drawer-hint {
  padding: 8px 16px;
  font-size: 11px;
  color: var(--muted);
  background: #fafbfd;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dept-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dept-group .dept-label {
  width: auto;
  margin-bottom: 2px;
}
.dept-members {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
}

/* When drawer is open, push board to the right */
body.drawer-open .board { margin-left: 280px; }
.dept-label {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

/* ---------- Member icon (unique-location, big) ---------- */
.member-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  box-shadow: var(--shadow);
  transition: transform 0.1s, box-shadow 0.1s;
}
.member-icon:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.member-icon:active { cursor: grabbing; }
.member-icon.dragging { opacity: 0.4; }
.member-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(255,255,255,0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* ---------- Planned chip (small, can be many on one item) ---------- */
.planned-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 2px;
  border-radius: 999px;
  background: #fff;
  border: 1.5px solid;
  font-size: 11px;
  font-weight: 500;
}
.planned-chip .planned-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
}

/* ---------- Board ---------- */
.board {
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
  align-items: start;
}
.board.layout-row {
  grid-template-columns: 1fr;
  gap: 10px;
}
.board.layout-row .project-card { width: 100%; }
.board.layout-row .project-header { padding: 10px 14px; }
.board.layout-row .project-desc { padding: 8px 14px; font-size: 12px; }
.board.layout-row .project-items { padding: 6px 10px 10px; }

.project-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow 0.15s, transform 0.05s, opacity 0.15s;
}
.project-card.dragging { opacity: 0.4; }
/* Drop-position indicators — grid uses left/right edge, row uses top/bottom */
.board:not(.layout-row) .project-card.reorder-before { box-shadow: -3px 0 0 var(--primary); }
.board:not(.layout-row) .project-card.reorder-after  { box-shadow:  3px 0 0 var(--primary); }
.board.layout-row .project-card.reorder-before { box-shadow: 0 -3px 0 var(--primary); }
.board.layout-row .project-card.reorder-after  { box-shadow: 0  3px 0 var(--primary); }

.project-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 16px;
  padding: 2px 4px;
  user-select: none;
  flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }
.project-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.project-title {
  font-size: 16px;
  font-weight: 600;
  word-break: break-word;
}
.project-owner-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.project-owner-pill::before {
  content: "👤";
  margin-right: 4px;
  font-size: 11px;
  line-height: 1;
}
.project-title-input {
  font-size: 16px;
  font-weight: 600;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  color: var(--text);
}
.project-title-input:focus { outline: none; border-color: var(--primary); }
.project-header-actions { display: flex; gap: 4px; flex-shrink: 0; }

.project-desc {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--muted);
  background: #fafbfd;
  border-bottom: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}
.project-desc.empty { color: #b6bcc7; font-style: italic; }
.project-desc-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  resize: vertical;
  min-height: 60px;
}
.project-desc-input:focus { outline: none; border-color: var(--primary); }

.project-card select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
.project-card select:focus { outline: none; border-color: var(--primary); }

.project-items { padding: 12px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- Item row (single line) ---------- */
.item-card {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 30px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.item-card:has(.worker-fig) { padding-top: 16px; }
.item-card:hover { background: #f6f8fc; border-color: var(--border); }
.item-card.drop-target {
  border-color: var(--primary);
  background: #eef4ff;
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.2);
}
.item-card.editing {
  flex-direction: column;
  align-items: stretch;
  background: #fafbfd;
  border-color: var(--border);
  padding: 10px;
  gap: 8px;
}
.item-card.has-desc .item-title::after {
  content: "·";
  margin-left: 4px;
  color: var(--muted);
  opacity: 0.6;
}

.item-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.1s;
}
.item-card:hover .item-actions,
.item-card.editing .item-actions { opacity: 1; }
.item-actions .icon { padding: 2px 5px; font-size: 12px; }

.item-drag-handle {
  flex-shrink: 0;
  cursor: grab;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  padding: 4px 2px;
  user-select: none;
  opacity: 0.35;
  transition: opacity 0.1s;
}
.item-card:hover .item-drag-handle { opacity: 0.9; }
.item-drag-handle:active { cursor: grabbing; }
.item-card.reorder-before {
  box-shadow: 0 -2px 0 var(--primary);
}
.item-card.reorder-after {
  box-shadow: 0 2px 0 var(--primary);
}
.item-card.dragging { opacity: 0.4; }

.item-title {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
  line-height: 1.4;
  cursor: default;
}
.item-title-input {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-family: inherit;
  color: var(--text);
}
.item-title-input:focus { outline: none; border-color: var(--primary); }

.item-desc-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text);
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}
.item-desc-input:focus { outline: none; border-color: var(--primary); }

.item-planned-row {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
  align-items: center;
}
.item-current-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.item-current-row:empty { display: none; }

.inline-edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.edit-section-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-top: 2px;
}

/* Compact member pills used inline on item rows */
.member-dot {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  user-select: none;
  cursor: default;
  box-sizing: border-box;
  white-space: nowrap;
}
.member-dot.planned {
  background: #fff;
  border: 1.5px solid;
  padding: 0 7px;
}
.member-dot.current {
  color: #fff;
  cursor: grab;
  box-shadow: var(--shadow);
}
.member-dot.current:hover { transform: translateY(-1px); }
.member-dot.current:active { cursor: grabbing; }
.member-dot.dragging { opacity: 0.4; }

/* Current-worker figure: icon-only height; name floats above (absolute) */
.worker-fig {
  position: relative;
  display: inline-flex;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: grab;
  user-select: none;
  line-height: 1;
}
.worker-fig > * { pointer-events: none; }
.worker-fig:active { cursor: grabbing; }
.worker-fig.dragging { opacity: 0.4; }
.worker-fig-name {
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  z-index: 2;
}
.worker-fig-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  box-shadow: var(--shadow);
}
.worker-fig:hover .worker-fig-icon { transform: translateY(-1px); }

/* Find-member highlight animation */
@keyframes hl-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(79,140,255,0.7); transform: scale(1); }
  25%  { box-shadow: 0 0 0 12px rgba(79,140,255,0); transform: scale(1.3); }
  50%  { box-shadow: 0 0 0 0 rgba(79,140,255,0.7); transform: scale(1); }
  75%  { box-shadow: 0 0 0 12px rgba(79,140,255,0); transform: scale(1.2); }
  100% { box-shadow: 0 0 0 0 rgba(79,140,255,0); transform: scale(1); }
}
.member-icon.highlight,
.member-dot.highlight,
.worker-fig.highlight {
  animation: hl-pulse 1.8s ease-out 2;
  position: relative;
  z-index: 10;
}

/* Find-member modal */
.find-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 360px;
  overflow-y: auto;
  margin-top: 6px;
}
.find-dept {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  margin-top: 8px;
  padding: 0 4px;
}
.find-dept:first-child { margin-top: 0; }
.find-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.find-row:hover { background: #f3f6fc; border-color: var(--primary); }
.find-row-name {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  min-width: 64px;
  justify-content: center;
}
.find-row-loc {
  font-size: 12px;
  color: var(--muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Planned picker (inside item edit mode) */
.planned-picker {
  padding: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.planned-picker-dept { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.planned-picker-dept-label { font-size: 11px; color: var(--muted); width: 54px; }
.picker-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 3px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.1s;
}
.picker-chip .planned-dot { width: 16px; height: 16px; }
.picker-chip:hover { background: #f3f4f6; }
.picker-chip.selected {
  background: var(--member-color, #f3f4f6);
  border-color: var(--member-color, var(--primary));
  color: #fff;
}

.add-item-btn {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  padding: 8px;
  border-radius: 8px;
  width: 100%;
}
.add-item-btn:hover { color: var(--primary); border-color: var(--primary); background: #f5f8ff; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

/* ---------- Modals (member management only) ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: #fff;
  width: min(560px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-content h2 { font-size: 18px; }
.modal-content h3 { font-size: 14px; color: var(--muted); }
.modal-content label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.modal-content input,
.modal-content select,
.modal-content textarea {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}
.modal-content input:focus,
.modal-content select:focus,
.modal-content textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.15);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 100px;
  gap: 8px;
  align-items: end;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.member-manage-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}
.member-manage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.member-manage-row .member-icon { cursor: default; }
.member-manage-row .member-icon:hover { transform: none; }
